diff options
Diffstat (limited to 'lib/scripts/helpers.js')
-rw-r--r-- | lib/scripts/helpers.js | 178 |
1 files changed, 110 insertions, 68 deletions
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 <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); + } +} + |