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/compatibility.js | 172 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 3 deletions(-) (limited to 'lib/scripts/compatibility.js') diff --git a/lib/scripts/compatibility.js b/lib/scripts/compatibility.js index ddc8823d3..39f703c71 100644 --- a/lib/scripts/compatibility.js +++ b/lib/scripts/compatibility.js @@ -1,6 +1,3 @@ -/*jslint sloppy: true */ -/*global dw_index, dw_qsearch, DEPRECATED_WRAP */ - /** * Mark a JavaScript function as deprecated * @@ -209,4 +206,173 @@ function jsEscape(text){ return text; } +/** + * 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){ + DEPRECATED("Use `typeof var !== 'undefined'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'undefined'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'function'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'string'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'number'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'number' && !isNaN(var) && isFinite(var)` instead"); + 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 */ { + DEPRECATED("Use `var instanceof Array` instead"); + 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 */ { + DEPRECATED("Use `var instanceof RegExp` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'boolean'` instead"); + 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 */ { + DEPRECATED("Use `typeof var === 'string' || (typeof var === 'number' &&" + + " !isNaN(var) && isFinite(var))` instead"); + 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 */ { + DEPRECATED(); + var i; + if (isBoolean(prop)) { + return false; + } else if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) { + return true; + } else if (isString(prop) || isNumber(prop)) { + return !prop; + } else if (Boolean(prop) && false != prop) { + for (i in prop) { + if(prop.hasOwnProperty(i)) { + return false; + } + } + } + return true; +} + +/** + * 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){ + DEPRECATED('Use jQuery(node).style() instead'); + if(node.currentStyle){ + return node.currentStyle; + }else{ + return node.ownerDocument.defaultView.getComputedStyle(node, null); + } +} -- cgit v1.2.3