From 26fc53c6a8fe022cd60b5df5474cfbe35afd34e4 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 19 Aug 2011 15:40:58 +0200 Subject: moved more stuff out from script.js the file is nearly empty now --- lib/scripts/compatibility.js | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) (limited to 'lib/scripts/compatibility.js') diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js index a5cc87e58..ddc8823d3 100644 --- a/lib/scripts/compatibility.js +++ b/lib/scripts/compatibility.js @@ -1,6 +1,78 @@ /*jslint sloppy: true */ /*global dw_index, dw_qsearch, DEPRECATED_WRAP */ +/** + * Mark a JavaScript function as deprecated + * + * This will print a warning to the JavaScript console (if available) in + * Firebug and Chrome and a stack trace (if available) to easily locate the + * problematic function call. + * + * @param msg optional message to print + */ +function DEPRECATED(msg){ + if(!window.console) return; + if(!msg) msg = ''; + + var func; + if(arguments.callee) func = arguments.callee.caller.name; + if(func) func = ' '+func+'()'; + var line = 'DEPRECATED function call'+func+'. '+msg; + + if(console.warn){ + console.warn(line); + }else{ + console.log(line); + } + + if(console.trace) console.trace(); +} + +/** + * Construct a wrapper function for deprecated function names + * + * This function returns a wrapper function which just calls DEPRECATED + * and the new function. + * + * @param func The new function + * @param context Optional; The context (`this`) of the call + */ +function DEPRECATED_WRAP(func, context) { + return function () { + DEPRECATED(); + return func.apply(context || this, arguments); + } +} + +/** + * Handy shortcut to document.getElementById + * + * This function was taken from the prototype library + * + * @link http://prototype.conio.net/ + */ +function $() { + DEPRECATED('Please use the JQuery() function instead.'); + + var elements = new Array(); + + for (var i = 0; i < arguments.length; i++) { + var element = arguments[i]; + if (typeof element == 'string') + element = document.getElementById(element); + + if (arguments.length == 1) + return element; + + elements.push(element); + } + + return elements; +} + + + + var index = { throbber_delay: dw_index.throbber_delay, toggle: DEPRECATED_WRAP(dw_index.toggle, dw_index), @@ -123,3 +195,18 @@ function addInitEvent(func) { jQuery(func); } + +function jsEscape(text){ + DEPRECATED('Insert text through jQuery.text() instead of escaping on your own'); + var re=new RegExp("\\\\","g"); + text=text.replace(re,"\\\\"); + re=new RegExp("'","g"); + text=text.replace(re,"\\'"); + re=new RegExp('"',"g"); + text=text.replace(re,'"'); + re=new RegExp("\\\\\\\\n","g"); + text=text.replace(re,"\\n"); + return text; +} + + -- cgit v1.2.3