diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js index a5cc87e58bfe434839e440e12aa7230c720f8ff4..ddc8823d3a79f2fd681e3c6abaa1b09033a66292 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; +} + + diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js index b286965cf3c583b578c7c4f2bd7a09f2778b656a..b0f76cdb0207c2d2fc3a8b56143bdc18e75619a1 100644 --- a/lib/scripts/helpers.js +++ b/lib/scripts/helpers.js @@ -1,134 +1,161 @@ /** - * Differrent helper functions + * Various helper functions + */ + + +/** + * Simple function to check if a global var is defined * - * @author Ilya Lebedev <ilya@lebedev.net> - * @license LGPL + * @author Kae Verens + * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 */ -//----------------------------------------------------------------------------- -// Variable/property checks -//----------------------------------------------------------------------------- +function isset(varname){ + return(typeof(window[varname])!='undefined'); +} + /** - * Checks if property is undefined + * Checks if property is undefined * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isUndefined (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'undefined'); + return (typeof prop == 'undefined'); } + /** - * Checks if property is function + * Checks if property is function * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isFunction (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'function'); + return (typeof prop == 'function'); } /** - * Checks if property is string + * Checks if property is string * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isString (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'string'); + return (typeof prop == 'string'); } + /** - * Checks if property is number + * Checks if property is number * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isNumber (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'number'); + return (typeof prop == 'number'); } + /** - * Checks if property is the calculable number + * Checks if property is the calculable number * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isNumeric (prop /* :Object */) /* :Boolean */ { - return isNumber(prop)&&!isNaN(prop)&&isFinite(prop); + return isNumber(prop)&&!isNaN(prop)&&isFinite(prop); } + /** - * Checks if property is array + * Checks if property is array * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isArray (prop /* :Object */) /* :Boolean */ { - return (prop instanceof Array); + return (prop instanceof Array); } + /** * Checks if property is regexp * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isRegExp (prop /* :Object */) /* :Boolean */ { - return (prop instanceof RegExp); + return (prop instanceof RegExp); } + /** - * Checks if property is a boolean value + * Checks if property is a boolean value * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isBoolean (prop /* :Object */) /* :Boolean */ { - return ('boolean' == typeof prop); + return ('boolean' == typeof prop); } + /** - * Checks if property is a scalar value (value that could be used as the hash key) + * Checks if property is a scalar value (value that could be used as the hash key) * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isScalar (prop /* :Object */) /* :Boolean */ { - return isNumeric(prop)||isString(prop); + return isNumeric(prop)||isString(prop); } + /** - * Checks if property is empty + * Checks if property is empty * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public + * @param {Object} prop value to check + * @return {Boolean} true if matched + * @scope public + * @author Ilya Lebedev <ilya@lebedev.net> */ function isEmpty (prop /* :Object */) /* :Boolean */ { - if (isBoolean(prop)) return false; - if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true; - if (isString(prop) || isNumber(prop)) return !prop; - if (Boolean(prop)&&false != prop) { - for (var i in prop) if(prop.hasOwnProperty(i)) return false; - } - return true; + if (isBoolean(prop)) return false; + if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) return true; + if (isString(prop) || isNumber(prop)) return !prop; + if (Boolean(prop)&&false != prop) { + for (var i in prop) if(prop.hasOwnProperty(i)) return false; + } + return true; } /** - * Checks if property is derived from prototype, applies method if it is not exists + * Checks if property is derived from prototype, applies method if it is not exists * - * @param string property name - * @return bool true if prototyped - * @access public + * @param string property name + * @return bool true if prototyped + * @access public + * @author Ilya Lebedev <ilya@lebedev.net> */ if ('undefined' == typeof Object.hasOwnProperty) { - Object.prototype.hasOwnProperty = function (prop) { - return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]); - }; + Object.prototype.hasOwnProperty = function (prop) { + return !('undefined' == typeof this[prop] || this.constructor && this.constructor.prototype[prop] && this[prop] === this.constructor.prototype[prop]); + }; } /** * Very simplistic Flash plugin check, probably works for Flash 8 and higher only + * + * @author Andreas Gohr <andi@splitbrain.org> */ function hasFlash(version){ var ver = 0; @@ -192,3 +219,18 @@ function bind(fnc/*, ... */) { static_args.concat(Aps.call(arguments, 0))); }; } + +/** + * Get the computed style of a node. + * + * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/ + * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js + */ +function gcs(node){ + if(node.currentStyle){ + return node.currentStyle; + }else{ + return node.ownerDocument.defaultView.getComputedStyle(node, null); + } +} + diff --git a/lib/scripts/script.js b/lib/scripts/script.js index caa2a107c48472a541c00d2698619df8b370b2e7..8db223d612019bc7e9d710ab54b7cd006457cbd3 100644 --- a/lib/scripts/script.js +++ b/lib/scripts/script.js @@ -3,53 +3,6 @@ if ('function' === typeof jQuery && 'function' === typeof jQuery.noConflict) { jQuery.noConflict(); } -/** - * 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); - } -} - -/** - * Some of these scripts were taken from wikipedia.org and were modified for DokuWiki - */ - /** * Some browser detection */ @@ -65,87 +18,6 @@ if (clientPC.indexOf('opera')!=-1) { var is_opera_seven = (window.opera && document.childNodes); } -/** - * 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; -} - -/** - * Simple function to check if a global var is defined - * - * @author Kae Verens - * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835 - */ -function isset(varname){ - return(typeof(window[varname])!='undefined'); -} - -/** - * Get the computed style of a node. - * - * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/ - * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js - */ -function gcs(node){ - if(node.currentStyle){ - return node.currentStyle; - }else{ - return node.ownerDocument.defaultView.getComputedStyle(node, null); - } -} - -/** - * Escape special chars in JavaScript - * - * @author Andreas Gohr <andi@splitbrain.org> - */ -function jsEscape(text){ - 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; -} - -/** - * This function escapes some special chars - * @deprecated by above function - */ -function escapeQuotes(text) { - var 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; -} - /** * Prints a animated gif to show the search is performed *