Ticket #712: BaseTypes_only.patch
| File BaseTypes_only.patch, 10.5 kB (added by tschaub, 1 year ago) |
|---|
-
lib/OpenLayers/BaseTypes.js
old new 4 4 5 5 /** 6 6 * Header: OpenLayers Base Types 7 * Modifications to standard JavaScript types are described here.7 * OpenLayers custom string, number and function functions are described here. 8 8 */ 9 9 10 10 /********************* … … 13 13 * * 14 14 *********************/ 15 15 16 OpenLayers.String = { 17 /** 18 * APIMethod: OpenLayers.String.startsWith 19 * Whether or not a string starts with another string. 20 * 21 * Parameters: 22 * str - {String} The string to test. 23 * sub - {Sring} The substring to look for. 24 * 25 * Returns: 26 * {Boolean} The first string starts with the second. 27 */ 28 startsWith: function(str, sub) { 29 return (str.indexOf(sub) == 0); 30 }, 16 31 32 /** 33 * APIMethod: OpenLayers.String.contains 34 * Whether or not a string contains another string. 35 * 36 * Parameters: 37 * str - {String} The string to test. 38 * sub - {String} The substring to look for. 39 * 40 * Returns: 41 * {Boolean} The first string contains the second. 42 */ 43 contains: function(str, sub) { 44 return (str.indexOf(sub) != -1); 45 }, 46 47 /** 48 * APIMethod: OpenLayers.String.trim 49 * Removes leading and trailing whitespace characters from a string. 50 * 51 * Parameters: 52 * str - {String} The (potentially) space padded string. This string is not 53 * modified. 54 * 55 * Returns: 56 * {String} A trimmed version of the string - all leading and 57 * trailing spaces removed. 58 */ 59 trim: function(str) { 60 return str.replace(/^\s*(.*?)\s*$/, "$1"); 61 }, 62 63 /** 64 * APIMethod: OpenLayers.String.camelize 65 * Camel-case a hyphenated string. 66 * Ex. "chicken-head" becomes "chickenHead", and 67 * "-chicken-head" becomes "ChickenHead". 68 * 69 * Parameters: 70 * str - {String} The string to be camelized. The original is not modified. 71 * 72 * Returns: 73 * {String} The string, camelized 74 */ 75 camelize: function(str) { 76 var oStringList = str.split('-'); 77 var camelizedString = oStringList[0]; 78 for (var i = 1; i < oStringList.length; i++) { 79 var s = oStringList[i]; 80 camelizedString += s.charAt(0).toUpperCase() + s.substring(1); 81 } 82 return camelizedString; 83 } 84 }; 85 17 86 /** 18 87 * APIMethod: String.startsWith 19 * Whether or not a string starts with another string.88 * Deprecated. Whether or not a string starts with another string. 20 89 * 21 90 * Parameters: 22 91 * sStart - {Sring} The string we're testing for. … … 25 94 * {Boolean} Whether or not this string starts with the string passed in. 26 95 */ 27 96 String.prototype.startsWith = function(sStart) { 28 return (this.substr(0,sStart.length) == sStart); 97 OpenLayers.Console.warn( 98 "This method has been deprecated and will be removed in 3.0. " + 99 "Please use OpenLayers.String.startsWith instead" 100 ); 101 return OpenLayers.String.startsWith(this, sStart); 29 102 }; 30 103 31 104 /** 32 105 * APIMethod: String.contains 33 * Whether or not a string contains another string.106 * Deprecated. Whether or not a string contains another string. 34 107 * 35 108 * Parameters: 36 109 * str - {String} The string that we're testing for. … … 39 112 * {Boolean} Whether or not this string contains with the string passed in. 40 113 */ 41 114 String.prototype.contains = function(str) { 42 return (this.indexOf(str) != -1); 115 OpenLayers.Console.warn( 116 "This method has been deprecated and will be removed in 3.0. " + 117 "Please use OpenLayers.String.contains instead" 118 ); 119 return OpenLayers.String.contains(this, str); 43 120 }; 44 121 45 122 /** 46 123 * APIMethod: String.trim 47 * Removes leading and trailing whitespace characters from a string.124 * Deprecated. Removes leading and trailing whitespace characters from a string. 48 125 * 49 126 * Returns: 50 127 * {String} A trimmed version of the string - all leading and 51 128 * trailing spaces removed 52 129 */ 53 130 String.prototype.trim = function() { 54 return this.replace(/^\s+/, '').replace(/\s+$/, ''); 131 OpenLayers.Console.warn( 132 "This method has been deprecated and will be removed in 3.0. " + 133 "Please use OpenLayers.String.trim instead" 134 ); 135 return OpenLayers.String.trim(this); 55 136 }; 56 137 57 138 /** 58 139 * APIMethod: camelize 59 * Camel-case a hyphenated string.140 * Deprecated. Camel-case a hyphenated string. 60 141 * Ex. "chicken-head" becomes "chickenHead", and 61 142 * "-chicken-head" becomes "ChickenHead". 62 143 * … … 64 145 * {String} The string, camelized 65 146 */ 66 147 String.prototype.camelize = function() { 67 var oStringList = this.split('-'); 68 var camelizedString = oStringList[0]; 69 for (var i = 1; i < oStringList.length; i++) { 70 var s = oStringList[i]; 71 camelizedString += s.charAt(0).toUpperCase() + s.substring(1); 72 } 73 return camelizedString; 148 OpenLayers.Console.warn( 149 "This method has been deprecated and will be removed in 3.0. " + 150 "Please use OpenLayers.String.camelize instead" 151 ); 152 return OpenLayers.String.camelize(this); 74 153 }; 75 154 76 155 … … 80 159 * * 81 160 *********************/ 82 161 162 OpenLayers.Number = { 163 /** 164 * APIMethod: OpenLayers.Number.limitSigDigs 165 * Limit the number of significant digits on an integer. 166 * 167 * Parameters: 168 * num - {Integer} 169 * sig - {Integer} 170 * 171 * Returns: 172 * {Integer} The number, rounded to the specified number of significant 173 * digits. 174 */ 175 limitSigDigs: function(num, sig) { 176 var fig; 177 if(sig > 0) { 178 fig = parseFloat(num.toPrecision(sig)); 179 } else { 180 fig = 0; 181 } 182 return fig; 183 } 184 }; 185 83 186 /** 84 187 * APIMethod: Number.limitSigDigs 85 * Limit the number of significant digits on an integer. Does *not* work86 * w ith floats!188 * Deprecated. Limit the number of significant digits on an integer. Does *not* 189 * work with floats! 87 190 * 88 191 * Parameters: 89 192 * sig - {Integer} … … 93 196 * If null, 0, or negative value passed in, returns 0 94 197 */ 95 198 Number.prototype.limitSigDigs = function(sig) { 96 var numStr = (sig > 0) ? this.toString() : "0"; 97 if (numStr.contains(".")) { 98 var msg = "limitSigDig can not be called on a floating point number"; 99 OpenLayers.Console.error(msg); 100 return null; 101 } 102 if ( (sig > 0) && (sig < numStr.length) ) { 103 var exp = numStr.length - sig; 104 numStr = Math.round( this / Math.pow(10, exp)) * Math.pow(10, exp); 105 } 106 return parseInt(numStr); 199 OpenLayers.Console.warn( 200 "This method has been deprecated and will be removed in 3.0. " + 201 "Please use OpenLayers.Number.limitSigDigs instead" 202 ); 203 return OpenLayers.Number.limitSigDigs(this, sig); 107 204 }; 108 205 109 206 … … 113 210 * * 114 211 *********************/ 115 212 213 OpenLayers.Function = { 214 /** 215 * APIMethod: OpenLayers.Function.bind 216 * Bind a function to an object. Method to easily create closures with 217 * 'this' altered. 218 * 219 * Parameters: 220 * func - {Function} Input function. 221 * object - {Object} The object to bind to the input function (as this). 222 * 223 * Returns: 224 * {Function} A closure with 'this' set to the passed in object. 225 */ 226 bind: function(func, object) { 227 // create a reference to all arguments past the second one 228 var args = Array.prototype.slice.apply(arguments, [2]); 229 return function() { 230 // Push on any additional arguments from the actual function call. 231 // These will come after those sent to the bind call. 232 var newArgs = args.concat( 233 Array.prototype.slice.apply(arguments, [0]) 234 ); 235 return func.apply(object, newArgs); 236 }; 237 }, 238 239 /** 240 * APIMethod: OpenLayers.Function.bindAsEventListener 241 * Bind a function to an object, and configure it to receive the event 242 * object as first parameter when called. 243 * 244 * Parameters: 245 * func - {Function} Input function to serve as an event listener. 246 * object - {Object} A reference to this. 247 * 248 * Returns: 249 * {Function} 250 */ 251 bindAsEventListener: function(func, object) { 252 return function(event) { 253 return func.call(object, event || window.event); 254 }; 255 } 256 }; 257 116 258 /** 117 259 * APIMethod: Function.bind 118 * Bind a function to an object.260 * Deprecated. Bind a function to an object. 119 261 * Method to easily create closures with 'this' altered. 120 262 * 121 263 * Parameters: … … 126 268 * argument. 127 269 */ 128 270 Function.prototype.bind = function() { 129 var __method = this; 130 var args = []; 131 var object = arguments[0]; 132 133 for (var i = 1; i < arguments.length; i++) { 134 args.push(arguments[i]); 135 } 136 137 return function(moreargs) { 138 var i; 139 var newArgs = []; 140 for (i = 0; i < args.length; i++) { 141 newArgs.push(args[i]); 142 } 143 for (i = 0; i < arguments.length; i++) { 144 newArgs.push(arguments[i]); 145 } 146 return __method.apply(object, newArgs); 147 }; 271 OpenLayers.Console.warn( 272 "This method has been deprecated and will be removed in 3.0. " + 273 "Please use OpenLayers.Function.bind instead" 274 ); 275 // new function takes the same arguments with this function up front 276 Array.prototype.unshift.apply(arguments, [this]); 277 return OpenLayers.Function.bind.apply(null, arguments); 148 278 }; 149 279 150 280 /** 151 281 * APIMethod: Function.bindAsEventListener 152 * Bind a function to an object, and configure it to receive the event object153 * as first parameter when called.282 * Deprecated. Bind a function to an object, and configure it to receive the 283 * event object as first parameter when called. 154 284 * 155 285 * Parameters: 156 286 * object - {Object} A reference to this. … … 159 289 * {Function} 160 290 */ 161 291 Function.prototype.bindAsEventListener = function(object) { 162 var __method = this; 163 return function(event) { 164 return __method.call(object, event || window.event); 165 }; 292 OpenLayers.Console.warn( 293 "This method has been deprecated and will be removed in 3.0. " + 294 "Please use OpenLayers.Function.bindAsEventListener instead" 295 ); 296 return OpenLayers.Function.bindAsEventListener(this, object); 166 297 };
