1/*jslint sloppy: true */ 2/*global dw_index, dw_qsearch, DEPRECATED_WRAP */ 3 4/** 5 * Mark a JavaScript function as deprecated 6 * 7 * This will print a warning to the JavaScript console (if available) in 8 * Firebug and Chrome and a stack trace (if available) to easily locate the 9 * problematic function call. 10 * 11 * @param msg optional message to print 12 */ 13function DEPRECATED(msg){ 14 if(!window.console) return; 15 if(!msg) msg = ''; 16 17 var func; 18 if(arguments.callee) func = arguments.callee.caller.name; 19 if(func) func = ' '+func+'()'; 20 var line = 'DEPRECATED function call'+func+'. '+msg; 21 22 if(console.warn){ 23 console.warn(line); 24 }else{ 25 console.log(line); 26 } 27 28 if(console.trace) console.trace(); 29} 30 31/** 32 * Construct a wrapper function for deprecated function names 33 * 34 * This function returns a wrapper function which just calls DEPRECATED 35 * and the new function. 36 * 37 * @param func The new function 38 * @param context Optional; The context (`this`) of the call 39 */ 40function DEPRECATED_WRAP(func, context) { 41 return function () { 42 DEPRECATED(); 43 return func.apply(context || this, arguments); 44 } 45} 46 47/** 48 * Handy shortcut to document.getElementById 49 * 50 * This function was taken from the prototype library 51 * 52 * @link http://prototype.conio.net/ 53 */ 54function $() { 55 DEPRECATED('Please use the JQuery() function instead.'); 56 57 var elements = new Array(); 58 59 for (var i = 0; i < arguments.length; i++) { 60 var element = arguments[i]; 61 if (typeof element == 'string') 62 element = document.getElementById(element); 63 64 if (arguments.length == 1) 65 return element; 66 67 elements.push(element); 68 } 69 70 return elements; 71} 72 73 74 75 76var index = { 77 throbber_delay: dw_index.throbber_delay, 78 toggle: DEPRECATED_WRAP(dw_index.toggle, dw_index), 79 treeattach: DEPRECATED_WRAP(dw_index.treeattach, dw_index) 80}; 81 82var ajax_quicksearch = { 83 init: DEPRECATED_WRAP(dw_qsearch.init, dw_qsearch), 84 clear_results: DEPRECATED_WRAP(dw_qsearch.clear_results, dw_qsearch), 85 onCompletion: DEPRECATED_WRAP(dw_qsearch.onCompletion, dw_qsearch) 86}; 87 88var linkwiz = { 89 init: DEPRECATED_WRAP(dw_linkwiz.init, dw_linkwiz), 90 onEntry: DEPRECATED_WRAP(dw_linkwiz.onEntry, dw_linkwiz), 91 getResult: DEPRECATED_WRAP(dw_linkwiz.getResult, dw_linkwiz), 92 select: DEPRECATED_WRAP(dw_linkwiz.select, dw_linkwiz), 93 deselect: DEPRECATED_WRAP(dw_linkwiz.deselect, dw_linkwiz), 94 onResultClick: DEPRECATED_WRAP(dw_linkwiz.onResultClick, dw_linkwiz), 95 resultClick: DEPRECATED_WRAP(dw_linkwiz.resultClick, dw_linkwiz), 96 insertLink: DEPRECATED_WRAP(dw_linkwiz.insertLink, dw_linkwiz), 97 autocomplete: DEPRECATED_WRAP(dw_linkwiz.autocomplete, dw_linkwiz), 98 autocomplete_exec: DEPRECATED_WRAP(dw_linkwiz.autocomplete_exec, dw_linkwiz), 99 show: DEPRECATED_WRAP(dw_linkwiz.show, dw_linkwiz), 100 hide: DEPRECATED_WRAP(dw_linkwiz.hide, dw_linkwiz), 101 toggle: DEPRECATED_WRAP(dw_linkwiz.toggle, dw_linkwiz) 102}; 103 104var media_manager = { 105 // treeattach, selectorattach, confirmattach are munched together into 106 // dw_mediamanager.init 107 attachoptions: DEPRECATED_WRAP(dw_mediamanager.attachoptions, dw_mediamanager), 108 togglekeepopen: function (event, cb) { 109 DEPRECATED('Use dw_mediamanager.toggleOption instead'); 110 return dw_mediamanager.toggleOption.call(cb, 'keepopen'); 111 }, 112 togglehide: function (event, cb) { 113 DEPRECATED('Use dw_mediamanager.toggleOption instead'); 114 return dw_mediamanager.toggleOption.call(cb, 'hide'); 115 }, 116 updatehide: DEPRECATED_WRAP(dw_mediamanager.updatehide, dw_mediamanager), 117 select: function (event, link) { 118 DEPRECATED('Use dw_mediamanager.select instead'); 119 return dw_mediamanager.select.call(link, event); 120 }, 121 initpopup: DEPRECATED_WRAP(dw_mediamanager.initpopup, dw_mediamanager), 122 insert: DEPRECATED_WRAP(dw_mediamanager.insert, dw_mediamanager), 123 list: function (event, link) { 124 DEPRECATED('Use dw_mediamanager.list instead'); 125 return dw_mediamanager.list.call(link, event); 126 }, 127 // toggle is handled by dw_tree 128 suggest: DEPRECATED_WRAP(dw_mediamanager.suggest, dw_mediamanager), 129 initFlashUpload: DEPRECATED_WRAP(dw_mediamanager.initFlashUpload, dw_mediamanager), 130 closePopup: function () { 131 DEPRECATED(); 132 dw_mediamanager.$popup.dialog('close'); 133 }, 134 setalign: function (event, cb) { 135 DEPRECATED('Use dw_mediamanager.setOpt instead'); 136 return dw_mediamanager.setOpt.call(this, 'align', event); 137 }, 138 setlink: function (event, cb) { 139 DEPRECATED('Use dw_mediamanager.setOpt instead'); 140 return dw_mediamanager.setOpt.call(this, 'link', event); 141 }, 142 setsize: function (event, cb) { 143 DEPRECATED('Use dw_mediamanager.setOpt instead'); 144 return dw_mediamanager.setOpt.call(this, 'size', event); 145 }, 146 outSet: function (id) { 147 DEPRECATED(); 148 return jQuery(id).removeClass('selected'); 149 }, 150 inSet: function (id) { 151 DEPRECATED(); 152 return jQuery(id).addClass('selected'); 153 } 154}; 155 156initSizeCtl = DEPRECATED_WRAP(dw_editor.initSizeCtl); 157sizeCtl = DEPRECATED_WRAP(dw_editor.sizeCtl); 158toggleWrap = DEPRECATED_WRAP(dw_editor.toggleWrap); 159setWrap = DEPRECATED_WRAP(dw_editor.setWrap); 160 161function findPosX(object){ 162 DEPRECATED('Use jQuery.position() instead'); 163 return jQuery(object).position().left; 164} 165 166function findPosY(object){ 167 DEPRECATED('Use jQuery.position() instead'); 168 return jQuery(object).position().top; 169} 170 171function getElementsByClass(searchClass,node,tag){ 172 DEPRECATED('Use jQuery() instead'); 173 if(node == null) node = document; 174 if(typeof tag === 'undefined') tag = ''; 175 return jQuery(node).find(tag+'.'+searchClass).toArray(); 176} 177 178function prependChild(parent,element) { 179 DEPRECATED('Use jQuery.prepend() instead'); 180 jQuery(parent).prepend(element); 181} 182 183function addEvent(element, type, handler) { 184 DEPRECATED('Use jQuery.bind() instead.'); 185 jQuery(element).bind(type,{},handler); 186} 187 188function removeEvent(element, type, handler) { 189 DEPRECATED('Use jQuery.unbind() instead.'); 190 jQuery(element).unbind(type,handler); 191} 192 193function addInitEvent(func) { 194 DEPRECATED('Use jQuery(<function>) instead'); 195 jQuery(func); 196} 197 198 199function jsEscape(text){ 200 DEPRECATED('Insert text through jQuery.text() instead of escaping on your own'); 201 var re=new RegExp("\\\\","g"); 202 text=text.replace(re,"\\\\"); 203 re=new RegExp("'","g"); 204 text=text.replace(re,"\\'"); 205 re=new RegExp('"',"g"); 206 text=text.replace(re,'"'); 207 re=new RegExp("\\\\\\\\n","g"); 208 text=text.replace(re,"\\n"); 209 return text; 210} 211 212 213