From b2a330ca75f1ceec063a08029abb0204110e3601 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 6 Aug 2011 13:56:57 +0200 Subject: removed events.js --- lib/scripts/helpers.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/scripts/helpers.js') diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js index 77e7ffc4a..b286965cf 100644 --- a/lib/scripts/helpers.js +++ b/lib/scripts/helpers.js @@ -163,3 +163,32 @@ function substr_replace(str, replace, start, length) { b1 = (length < 0 ? str.length : a2) + length; return str.substring(0, a2) + replace + str.substring(b1); } + +/** + * Bind variables to a function call creating a closure + * + * Use this to circumvent variable scope problems when creating closures + * inside a loop + * + * @author Adrian Lang + * @link http://www.cosmocode.de/en/blog/gohr/2009-10/15-javascript-fixing-the-closure-scope-in-loops + * @param functionref fnc - the function to be called + * @param mixed - any arguments to be passed to the function + * @returns functionref + */ +function bind(fnc/*, ... */) { + var Aps = Array.prototype.slice; + // Store passed arguments in this scope. + // Since arguments is no Array nor has an own slice method, + // we have to apply the slice method from the Array.prototype + var static_args = Aps.call(arguments, 1); + + // Return a function evaluating the passed function with the + // given args and optional arguments passed on invocation. + return function (/* ... */) { + // Same here, but we use Array.prototype.slice solely for + // converting arguments to an Array. + return fnc.apply(this, + static_args.concat(Aps.call(arguments, 0))); + }; +} -- cgit v1.2.3 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/helpers.js | 178 ++++++++++++++++++++++++++++++------------------- 1 file changed, 110 insertions(+), 68 deletions(-) (limited to 'lib/scripts/helpers.js') diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js index b286965cf..b0f76cdb0 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 - * @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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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 */ 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); + } +} + -- cgit v1.2.3 From cb42e5f1de77ce65441002c0b0b94d5855cab1f0 Mon Sep 17 00:00:00 2001 From: Adrian Lang Date: Mon, 22 Aug 2011 15:25:15 +0200 Subject: Deprecate several helper functions, JSLINT helpers.js --- lib/scripts/helpers.js | 176 ++----------------------------------------------- 1 file changed, 5 insertions(+), 171 deletions(-) (limited to 'lib/scripts/helpers.js') diff --git a/lib/scripts/helpers.js b/lib/scripts/helpers.js index b0f76cdb0..d6f36967d 100644 --- a/lib/scripts/helpers.js +++ b/lib/scripts/helpers.js @@ -2,156 +2,6 @@ * Various helper functions */ - -/** - * 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'); -} - -/** - * Checks if property is undefined - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isUndefined (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'undefined'); -} - -/** - * Checks if property is function - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isFunction (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'function'); -} -/** - * Checks if property is string - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isString (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'string'); -} - -/** - * Checks if property is number - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isNumber (prop /* :Object */) /* :Boolean */ { - return (typeof prop == 'number'); -} - -/** - * Checks if property is the calculable number - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isNumeric (prop /* :Object */) /* :Boolean */ { - return isNumber(prop)&&!isNaN(prop)&&isFinite(prop); -} - -/** - * Checks if property is array - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isArray (prop /* :Object */) /* :Boolean */ { - return (prop instanceof Array); -} - -/** - * Checks if property is regexp - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isRegExp (prop /* :Object */) /* :Boolean */ { - return (prop instanceof RegExp); -} - -/** - * Checks if property is a boolean value - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -function isBoolean (prop /* :Object */) /* :Boolean */ { - return ('boolean' == typeof prop); -} - -/** - * 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 - * @author Ilya Lebedev - */ -function isScalar (prop /* :Object */) /* :Boolean */ { - return isNumeric(prop)||isString(prop); -} - -/** - * Checks if property is empty - * - * @param {Object} prop value to check - * @return {Boolean} true if matched - * @scope public - * @author Ilya Lebedev - */ -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; -} - -/** - * 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 - * @author Ilya Lebedev - */ -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]); - }; -} - /** * Very simplistic Flash plugin check, probably works for Flash 8 and higher only * @@ -163,13 +13,12 @@ function hasFlash(version){ if(navigator.plugins != null && navigator.plugins.length > 0){ ver = navigator.plugins["Shockwave Flash"].description.split(' ')[2].split('.')[0]; }else{ - var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); - ver = axo.GetVariable("$version").split(' ')[1].split(',')[0]; + ver = (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) + .GetVariable("$version").split(' ')[1].split(',')[0]; } }catch(e){ } - if(ver >= version) return true; - return false; + return ver >= version; } /** @@ -204,11 +53,11 @@ function substr_replace(str, replace, start, length) { * @returns functionref */ function bind(fnc/*, ... */) { - var Aps = Array.prototype.slice; + var Aps = Array.prototype.slice, // Store passed arguments in this scope. // Since arguments is no Array nor has an own slice method, // we have to apply the slice method from the Array.prototype - var static_args = Aps.call(arguments, 1); + static_args = Aps.call(arguments, 1); // Return a function evaluating the passed function with the // given args and optional arguments passed on invocation. @@ -219,18 +68,3 @@ 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); - } -} - -- cgit v1.2.3