summaryrefslogtreecommitdiff
path: root/lib/scripts/compatibility.js
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2011-08-19 15:40:58 +0200
committerAndreas Gohr <andi@splitbrain.org>2011-08-19 15:40:58 +0200
commit26fc53c6a8fe022cd60b5df5474cfbe35afd34e4 (patch)
tree0d6faf3abacf42545604ab88afd33ac30f919324 /lib/scripts/compatibility.js
parent38331508a78e955e63596e778f863996dfa7763b (diff)
downloadrpg-26fc53c6a8fe022cd60b5df5474cfbe35afd34e4.tar.gz
rpg-26fc53c6a8fe022cd60b5df5474cfbe35afd34e4.tar.bz2
moved more stuff out from script.js
the file is nearly empty now
Diffstat (limited to 'lib/scripts/compatibility.js')
-rw-r--r--lib/scripts/compatibility.js87
1 files changed, 87 insertions, 0 deletions
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,'&quot;');
+ re=new RegExp("\\\\\\\\n","g");
+ text=text.replace(re,"\\n");
+ return text;
+}
+
+