about summary refs log tree commit diff stats
path: root/wiki/lib/scripts/compatibility.js
diff options
context:
space:
mode:
Diffstat (limited to 'wiki/lib/scripts/compatibility.js')
-rw-r--r--wiki/lib/scripts/compatibility.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/wiki/lib/scripts/compatibility.js b/wiki/lib/scripts/compatibility.js
new file mode 100644
index 0000000..154aead
--- /dev/null
+++ b/wiki/lib/scripts/compatibility.js
@@ -0,0 +1,42 @@
+/**
+ * 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);
+    };
+}