1/** 2 * Mark a JavaScript function as deprecated 3 * 4 * This will print a warning to the JavaScript console (if available) in 5 * Firebug and Chrome and a stack trace (if available) to easily locate the 6 * problematic function call. 7 * 8 * @param msg optional message to print 9 */ 10function DEPRECATED(msg){ 11 if(!window.console) return; 12 if(!msg) msg = ''; 13 14 var func; 15 if(arguments.callee) func = arguments.callee.caller.name; 16 if(func) func = ' '+func+'()'; 17 var line = 'DEPRECATED function call'+func+'. '+msg; 18 19 if(console.warn){ 20 console.warn(line); 21 }else{ 22 console.log(line); 23 } 24 25 if(console.trace) console.trace(); 26} 27 28/** 29 * Construct a wrapper function for deprecated function names 30 * 31 * This function returns a wrapper function which just calls DEPRECATED 32 * and the new function. 33 * 34 * @param func The new function 35 * @param context Optional; The context (`this`) of the call 36 */ 37function DEPRECATED_WRAP(func, context) { 38 return function () { 39 DEPRECATED(); 40 return func.apply(context || this, arguments); 41 }; 42} 43 44/** 45 * Handy shortcut to document.getElementById 46 * 47 * This function was taken from the prototype library 48 * 49 * @link http://prototype.conio.net/ 50 */ 51function $() { 52 DEPRECATED('Please use the jQuery() function instead.'); 53 54 var elements = new Array(); 55 56 for (var i = 0; i < arguments.length; i++) { 57 var element = arguments[i]; 58 if (typeof element == 'string') 59 element = document.getElementById(element); 60 61 if (arguments.length == 1) 62 return element; 63 64 elements.push(element); 65 } 66 67 return elements; 68} 69 70 71 72 73var index = { 74 throbber_delay: dw_index.throbber_delay, 75 toggle: DEPRECATED_WRAP(dw_index.toggle, dw_index), 76 treeattach: DEPRECATED_WRAP(dw_index.treeattach, dw_index) 77}; 78 79var ajax_quicksearch = { 80 init: function() { 81 DEPRECATED('Use jQuery().dw_qsearch() instead'); 82 jQuery('#qsearch__in').dw_qsearch({ 83 output: '#qsearch__out' 84 }); 85 }, 86 clear_results: function() { 87 DEPRECATED('ajax_quicksearch.clear_results is removed'); 88 }, 89 onCompletion: function() { 90 DEPRECATED('ajax_quicksearch.onCompletion is removed'); 91 } 92}; 93var dw_qsearch = { 94 init: function(input, output) { 95 DEPRECATED('Use jQuery().dw_qsearch() instead'); 96 jQuery(input).dw_qsearch({ 97 output: output 98 }); 99 }, 100 clear_results: function() { 101 DEPRECATED('dw_qsearch.clear_results is removed'); 102 }, 103 onCompletion: function() { 104 DEPRECATED('dw_qsearch.onCompletion is removed'); 105 } 106}; 107 108var linkwiz = { 109 init: DEPRECATED_WRAP(dw_linkwiz.init, dw_linkwiz), 110 onEntry: DEPRECATED_WRAP(dw_linkwiz.onEntry, dw_linkwiz), 111 getResult: DEPRECATED_WRAP(dw_linkwiz.getResult, dw_linkwiz), 112 select: DEPRECATED_WRAP(dw_linkwiz.select, dw_linkwiz), 113 deselect: DEPRECATED_WRAP(dw_linkwiz.deselect, dw_linkwiz), 114 onResultClick: DEPRECATED_WRAP(dw_linkwiz.onResultClick, dw_linkwiz), 115 resultClick: DEPRECATED_WRAP(dw_linkwiz.resultClick, dw_linkwiz), 116 insertLink: DEPRECATED_WRAP(dw_linkwiz.insertLink, dw_linkwiz), 117 autocomplete: DEPRECATED_WRAP(dw_linkwiz.autocomplete, dw_linkwiz), 118 autocomplete_exec: DEPRECATED_WRAP(dw_linkwiz.autocomplete_exec, dw_linkwiz), 119 show: DEPRECATED_WRAP(dw_linkwiz.show, dw_linkwiz), 120 hide: DEPRECATED_WRAP(dw_linkwiz.hide, dw_linkwiz), 121 toggle: DEPRECATED_WRAP(dw_linkwiz.toggle, dw_linkwiz) 122}; 123 124var locktimer = { 125 init: DEPRECATED_WRAP(dw_locktimer.init, dw_locktimer), 126 reset: DEPRECATED_WRAP(dw_locktimer.reset, dw_locktimer), 127 warning: DEPRECATED_WRAP(dw_locktimer.warning, dw_locktimer), 128 clear: DEPRECATED_WRAP(dw_locktimer.clear, dw_locktimer), 129 refresh: DEPRECATED_WRAP(dw_locktimer.refresh, dw_locktimer), 130 refreshed: DEPRECATED_WRAP(dw_locktimer.refreshed, dw_locktimer) 131}; 132 133var media_manager = { 134 // treeattach, selectorattach, confirmattach are munched together into 135 // dw_mediamanager.init 136 attachoptions: DEPRECATED_WRAP(dw_mediamanager.attachoptions, dw_mediamanager), 137 togglekeepopen: function (event, cb) { 138 DEPRECATED('Use dw_mediamanager.toggleOption instead'); 139 return dw_mediamanager.toggleOption.call(cb, 'keepopen'); 140 }, 141 togglehide: function (event, cb) { 142 DEPRECATED('Use dw_mediamanager.toggleOption instead'); 143 return dw_mediamanager.toggleOption.call(cb, 'hide'); 144 }, 145 updatehide: DEPRECATED_WRAP(dw_mediamanager.updatehide, dw_mediamanager), 146 select: function (event, link) { 147 DEPRECATED('Use dw_mediamanager.select instead'); 148 return dw_mediamanager.select.call(link, event); 149 }, 150 initpopup: DEPRECATED_WRAP(dw_mediamanager.initpopup, dw_mediamanager), 151 insert: DEPRECATED_WRAP(dw_mediamanager.insert, dw_mediamanager), 152 list: function (event, link) { 153 DEPRECATED('Use dw_mediamanager.list instead'); 154 return dw_mediamanager.list.call(link, event); 155 }, 156 // toggle is handled by dw_tree 157 suggest: DEPRECATED_WRAP(dw_mediamanager.suggest, dw_mediamanager), 158 initFlashUpload: DEPRECATED_WRAP(dw_mediamanager.initFlashUpload, dw_mediamanager), 159 closePopup: function () { 160 DEPRECATED(); 161 dw_mediamanager.$popup.dialog('close'); 162 }, 163 setalign: function (event, cb) { 164 DEPRECATED('Use dw_mediamanager.setOpt instead'); 165 return dw_mediamanager.setOpt.call(this, 'align', event); 166 }, 167 setlink: function (event, cb) { 168 DEPRECATED('Use dw_mediamanager.setOpt instead'); 169 return dw_mediamanager.setOpt.call(this, 'link', event); 170 }, 171 setsize: function (event, cb) { 172 DEPRECATED('Use dw_mediamanager.setOpt instead'); 173 return dw_mediamanager.setOpt.call(this, 'size', event); 174 }, 175 outSet: function (id) { 176 DEPRECATED(); 177 return jQuery(id).removeClass('selected'); 178 }, 179 inSet: function (id) { 180 DEPRECATED(); 181 return jQuery(id).addClass('selected'); 182 } 183}; 184 185initSizeCtl = DEPRECATED_WRAP(dw_editor.initSizeCtl); 186sizeCtl = DEPRECATED_WRAP(dw_editor.sizeCtl); 187toggleWrap = DEPRECATED_WRAP(dw_editor.toggleWrap); 188setWrap = DEPRECATED_WRAP(dw_editor.setWrap); 189 190function findPosX(object){ 191 DEPRECATED('Use jQuery.offset() instead'); 192 return jQuery(object).offset().left; 193} 194 195function findPosY(object){ 196 DEPRECATED('Use jQuery.offset() instead'); 197 return jQuery(object).offset().top; 198} 199 200function getElementsByClass(searchClass,node,tag){ 201 DEPRECATED('Use jQuery() instead'); 202 if(node == null) node = document; 203 if(typeof tag === 'undefined') tag = ''; 204 return jQuery(node).find(tag+'.'+searchClass).toArray(); 205} 206 207function prependChild(parent,element) { 208 DEPRECATED('Use jQuery.prepend() instead'); 209 jQuery(parent).prepend(element); 210} 211 212function addEvent(element, type, handler) { 213 DEPRECATED('Use jQuery.bind() instead. Note that jQuery’s behaviour' + 214 ' when a handler returns false differs from addEvent’s'); 215 jQuery(element).bind(type,{},function (e) { 216 // returning false in an addEvent event handler did not prevent 217 // bubbling but just canceled handlers on this node and prevented 218 // default behavior, so wrap the handler call and mimic that behavior. 219 // 220 // Refer to jQuery.event.handle(). 221 var ret = handler.apply(this, Array.prototype.slice.call(arguments, 0)); 222 if (typeof ret !== 'undefined') { 223 if ( ret !== false ) { 224 return ret; 225 } 226 // What jQuery does. 227 e.result = ret; 228 e.preventDefault(); 229 // Not what jQuery does. This would be: event.stopPropagation(); 230 // Hack it so that immediate propagation (other event handlers on 231 // this element) appears stopped without stopping the actual 232 // propagation (bubbling) 233 e.isImmediatePropagationStopped = function () { return true; }; 234 } 235 }); 236} 237 238function removeEvent(element, type, handler) { 239 DEPRECATED('Use jQuery.unbind() instead.'); 240 jQuery(element).unbind(type,handler); 241} 242 243function addInitEvent(func) { 244 DEPRECATED('Use jQuery(<function>) instead'); 245 jQuery(func); 246} 247 248 249function jsEscape(text){ 250 DEPRECATED('Insert text through jQuery.text() instead of escaping on your own'); 251 var re=new RegExp("\\\\","g"); 252 text=text.replace(re,"\\\\"); 253 re=new RegExp("'","g"); 254 text=text.replace(re,"\\'"); 255 re=new RegExp('"',"g"); 256 text=text.replace(re,'"'); 257 re=new RegExp("\\\\\\\\n","g"); 258 text=text.replace(re,"\\n"); 259 return text; 260} 261 262/** 263 * Simple function to check if a global var is defined 264 * 265 * @author Kae Verens 266 * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 267 */ 268function isset(varname){ 269 DEPRECATED("Use `typeof var !== 'undefined'` instead"); 270 return(typeof(window[varname])!='undefined'); 271} 272 273/** 274 * Checks if property is undefined 275 * 276 * @param {Object} prop value to check 277 * @return {Boolean} true if matched 278 * @scope public 279 * @author Ilya Lebedev <ilya@lebedev.net> 280 */ 281function isUndefined (prop /* :Object */) /* :Boolean */ { 282 DEPRECATED("Use `typeof var === 'undefined'` instead"); 283 return (typeof prop == 'undefined'); 284} 285 286/** 287 * Checks if property is function 288 * 289 * @param {Object} prop value to check 290 * @return {Boolean} true if matched 291 * @scope public 292 * @author Ilya Lebedev <ilya@lebedev.net> 293 */ 294function isFunction (prop /* :Object */) /* :Boolean */ { 295 DEPRECATED("Use `typeof var === 'function'` instead"); 296 return (typeof prop == 'function'); 297} 298/** 299 * Checks if property is string 300 * 301 * @param {Object} prop value to check 302 * @return {Boolean} true if matched 303 * @scope public 304 * @author Ilya Lebedev <ilya@lebedev.net> 305 */ 306function isString (prop /* :Object */) /* :Boolean */ { 307 DEPRECATED("Use `typeof var === 'string'` instead"); 308 return (typeof prop == 'string'); 309} 310 311/** 312 * Checks if property is number 313 * 314 * @param {Object} prop value to check 315 * @return {Boolean} true if matched 316 * @scope public 317 * @author Ilya Lebedev <ilya@lebedev.net> 318 */ 319function isNumber (prop /* :Object */) /* :Boolean */ { 320 DEPRECATED("Use `typeof var === 'number'` instead"); 321 return (typeof prop == 'number'); 322} 323 324/** 325 * Checks if property is the calculable number 326 * 327 * @param {Object} prop value to check 328 * @return {Boolean} true if matched 329 * @scope public 330 * @author Ilya Lebedev <ilya@lebedev.net> 331 */ 332function isNumeric (prop /* :Object */) /* :Boolean */ { 333 DEPRECATED("Use `typeof var === 'number' && !isNaN(var) && isFinite(var)` instead"); 334 return isNumber(prop)&&!isNaN(prop)&&isFinite(prop); 335} 336 337/** 338 * Checks if property is array 339 * 340 * @param {Object} prop value to check 341 * @return {Boolean} true if matched 342 * @scope public 343 * @author Ilya Lebedev <ilya@lebedev.net> 344 */ 345function isArray (prop /* :Object */) /* :Boolean */ { 346 DEPRECATED("Use `var instanceof Array` instead"); 347 return (prop instanceof Array); 348} 349 350/** 351 * Checks if property is regexp 352 * 353 * @param {Object} prop value to check 354 * @return {Boolean} true if matched 355 * @scope public 356 * @author Ilya Lebedev <ilya@lebedev.net> 357 */ 358function isRegExp (prop /* :Object */) /* :Boolean */ { 359 DEPRECATED("Use `var instanceof RegExp` instead"); 360 return (prop instanceof RegExp); 361} 362 363/** 364 * Checks if property is a boolean value 365 * 366 * @param {Object} prop value to check 367 * @return {Boolean} true if matched 368 * @scope public 369 * @author Ilya Lebedev <ilya@lebedev.net> 370 */ 371function isBoolean (prop /* :Object */) /* :Boolean */ { 372 DEPRECATED("Use `typeof var === 'boolean'` instead"); 373 return ('boolean' == typeof prop); 374} 375 376/** 377 * Checks if property is a scalar value (value that could be used as the hash key) 378 * 379 * @param {Object} prop value to check 380 * @return {Boolean} true if matched 381 * @scope public 382 * @author Ilya Lebedev <ilya@lebedev.net> 383 */ 384function isScalar (prop /* :Object */) /* :Boolean */ { 385 DEPRECATED("Use `typeof var === 'string' || (typeof var === 'number' &&" + 386 " !isNaN(var) && isFinite(var))` instead"); 387 return isNumeric(prop)||isString(prop); 388} 389 390/** 391 * Checks if property is empty 392 * 393 * @param {Object} prop value to check 394 * @return {Boolean} true if matched 395 * @scope public 396 * @author Ilya Lebedev <ilya@lebedev.net> 397 */ 398function isEmpty (prop /* :Object */) /* :Boolean */ { 399 DEPRECATED(); 400 var i; 401 if (isBoolean(prop)) { 402 return false; 403 } else if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) { 404 return true; 405 } else if (isString(prop) || isNumber(prop)) { 406 return !prop; 407 } else if (Boolean(prop) && false != prop) { 408 for (i in prop) { 409 if(prop.hasOwnProperty(i)) { 410 return false; 411 } 412 } 413 } 414 return true; 415} 416 417/** 418 * Get the computed style of a node. 419 * 420 * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/ 421 * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js 422 */ 423function gcs(node){ 424 DEPRECATED('Use jQuery(node).style() instead'); 425 if(node.currentStyle){ 426 return node.currentStyle; 427 }else{ 428 return node.ownerDocument.defaultView.getComputedStyle(node, null); 429 } 430} 431 432/** 433 * Until 2011-05-25 "Rincewind", a code intended to fix some Safari issue 434 * always declared the global _timer. plugin:sortablejs relies on _timer 435 * being declared. 436 */ 437var _timer; 438