1YUI.add('aui-base-lang', function (A, NAME) { 2 3(function() { 4 var Lang = A.Lang, 5 aArray = A.Array, 6 AObject = A.Object, 7 8 isArray = Lang.isArray, 9 isNumber = Lang.isNumber, 10 isString = Lang.isString, 11 isUndefined = Lang.isUndefined, 12 13 owns = AObject.owns; 14 15 A.fn = function(fn, context, args) { 16 var wrappedFn, 17 dynamicLookup; 18 19 // Explicitly set function arguments 20 if (!isNumber(fn)) { 21 var xargs = arguments; 22 23 if (xargs.length > 2) { 24 xargs = aArray(xargs, 2, true); 25 } 26 27 dynamicLookup = (isString(fn) && context); 28 29 wrappedFn = function() { 30 var method = (!dynamicLookup) ? fn : context[fn]; 31 32 return method.apply(context || fn, xargs); 33 }; 34 } 35 else { 36 // Set function arity 37 var argLength = fn; 38 39 fn = context; 40 context = args; 41 dynamicLookup = (isString(fn) && context); 42 43 wrappedFn = function() { 44 var method = (!dynamicLookup) ? fn : context[fn], 45 returnValue; 46 47 context = context || method; 48 49 if (argLength > 0) { 50 returnValue = method.apply(context, aArray(arguments, 0, true).slice(0, argLength)); 51 } 52 else { 53 returnValue = method.call(context); 54 } 55 56 return returnValue; 57 }; 58 } 59 60 return wrappedFn; 61 }; 62 63 A.mix(Lang, { 64 constrain: function(num, min, max) { 65 return Math.min(Math.max(num, min), max); 66 }, 67 68 emptyFn: function() {}, 69 70 emptyFnFalse: function() { 71 return false; 72 }, 73 74 emptyFnTrue: function() { 75 return true; 76 }, 77 78 isGuid: function(id) { 79 return String(id).indexOf(A.Env._guidp) === 0; 80 }, 81 82 isInteger: function(val) { 83 return typeof val === 'number' && 84 isFinite(val) && 85 val > -9007199254740992 && 86 val < 9007199254740992 && 87 Math.floor(val) === val; 88 }, 89 90 isNode: function(val) { 91 return A.instanceOf(val, A.Node); 92 }, 93 94 isNodeList: function(val) { 95 return A.instanceOf(val, A.NodeList); 96 }, 97 98 toFloat: function(value, defaultValue) { 99 return parseFloat(value) || defaultValue || 0; 100 }, 101 102 toInt: function(value, radix, defaultValue) { 103 return parseInt(value, radix || 10) || defaultValue || 0; 104 } 105 }); 106 107 A.mix(aArray, { 108 remove: function(a, from, to) { 109 var rest = a.slice((to || from) + 1 || a.length); 110 a.length = (from < 0) ? (a.length + from) : from; 111 112 return a.push.apply(a, rest); 113 }, 114 115 removeItem: function(a, item) { 116 var index = aArray.indexOf(a, item); 117 118 if (index > -1) { 119 return aArray.remove(a, index); 120 } 121 122 return a; 123 } 124 }); 125 126 var LString = A.namespace('Lang.String'), 127 128 DOC = A.config.doc, 129 REGEX_DASH = /-([a-z])/gi, 130 REGEX_ESCAPE_REGEX = /([.*+?^$(){}|[\]\/\\])/g, 131 REGEX_NL2BR = /\r?\n/g, 132 REGEX_STRIP_SCRIPTS = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/gi, 133 REGEX_STRIP_TAGS = /<\/?[^>]+>/gi, 134 REGEX_UNCAMELIZE = /([a-zA-Z][a-zA-Z])([A-Z])([a-z])/g, 135 REGEX_UNCAMELIZE_REPLACE_SEPARATOR = /([a-z])([A-Z])/g, 136 STR_ELLIPSIS = '...', 137 138 htmlUnescapedValues = [], 139 140 MAP_HTML_CHARS_ESCAPED = { 141 '&': '&', 142 '<': '<', 143 '>': '>', 144 '"': '"', 145 '\'': ''', 146 '/': '/', 147 '`': '`' 148 }, 149 htmlChar, 150 MAP_HTML_CHARS_UNESCAPED = {}; 151 152 for (htmlChar in MAP_HTML_CHARS_ESCAPED) { 153 if (MAP_HTML_CHARS_ESCAPED.hasOwnProperty(htmlChar)) { 154 var escapedValue = MAP_HTML_CHARS_ESCAPED[htmlChar]; 155 156 MAP_HTML_CHARS_UNESCAPED[escapedValue] = htmlChar; 157 158 htmlUnescapedValues.push(htmlChar); 159 } 160 } 161 162 var REGEX_HTML_ESCAPE = new RegExp('[' + htmlUnescapedValues.join('') + ']', 'g'), 163 REGEX_HTML_UNESCAPE = /&([^;]+);/g; 164 165 A.mix(LString, { 166 camelize: A.cached( 167 function(str, separator) { 168 var regex = REGEX_DASH; 169 170 str = String(str); 171 172 if (separator) { 173 regex = new RegExp(separator + '([a-z])', 'gi'); 174 } 175 176 return str.replace(regex, LString._camelize); 177 } 178 ), 179 180 capitalize: A.cached( 181 function(str) { 182 if (str) { 183 str = String(str); 184 185 str = str.charAt(0).toUpperCase() + str.substr(1).toLowerCase(); 186 } 187 188 return str; 189 } 190 ), 191 192 contains: function(str, searchString) { 193 return str.indexOf(searchString) !== -1; 194 }, 195 196 defaultValue: function(str, defaultValue) { 197 if (isUndefined(str) || str === '') { 198 if (isUndefined(defaultValue)) { 199 defaultValue = ''; 200 } 201 202 str = defaultValue; 203 } 204 205 return str; 206 }, 207
208 endsWith: function(str, suffix) { 209 var length = (str.length - suffix.length); 210 211 return ((length >= 0) && (str.indexOf(suffix, length) === length)); 212 }, 213 214 escapeHTML: function(str) { 215 return str.replace(REGEX_HTML_ESCAPE, LString._escapeHTML); 216 }, 217 218 // Courtesy of: http://simonwillison.net/2006/Jan/20/escape/ 219 escapeRegEx: function(str) { 220 return str.replace(REGEX_ESCAPE_REGEX, '\\$1'); 221 }, 222 223 nl2br: function(str) { 224 return String(str).replace(REGEX_NL2BR, '<br />'); 225 }, 226 227 padNumber: function(num, length, precision) { 228 var str = precision ? Number(num).toFixed(precision) : String(num); 229 var index = str.indexOf('.'); 230 231 if (index === -1) { 232 index = str.length; 233 } 234 235 return LString.repeat('0', Math.max(0, length - index)) + str; 236 }, 237 238 pluralize: function(count, singularVersion, pluralVersion) { 239 var suffix; 240 241 if (count === 1) { 242 suffix = singularVersion; 243 } 244 else { 245 suffix = pluralVersion || singularVersion + 's'; 246 } 247 248 return count + ' ' + suffix; 249 }, 250 251 prefix: function(prefix, str) { 252 str = String(str); 253 254 if (str.indexOf(prefix) !== 0) { 255 str = prefix + str; 256 } 257 258 return str; 259 }, 260 261 remove: function(str, substitute, all) { 262 var re = new RegExp(LString.escapeRegEx(substitute), all ? 'g' : ''); 263 264 return str.replace(re, ''); 265 }, 266 267 removeAll: function(str, substitute) { 268 return LString.remove(str, substitute, true); 269 }, 270 271 repeat: function(str, length) { 272 return new Array(length + 1).join(str); 273 }, 274 275 round: function(value, precision) { 276 value = Number(value); 277 278 if (isNumber(precision)) { 279 precision = Math.pow(10, precision); 280 value = Math.round(value * precision) / precision; 281 } 282 283 return value; 284 }, 285 286 startsWith: function(str, prefix) { 287 return (str.lastIndexOf(prefix, 0) === 0); 288 }, 289 290 stripScripts: function(str) { 291 if (str) { 292 str = String(str).replace(REGEX_STRIP_SCRIPTS, ''); 293 } 294 295 return str; 296 }, 297 298 stripTags: function(str) { 299 if (str) { 300 str = String(str).replace(REGEX_STRIP_TAGS, ''); 301 } 302 303 return str; 304 }, 305 306 substr: function(str, start, length) { 307 return String(str).substr(start, length); 308 }, 309 310 uncamelize: A.cached( 311 function(str, separator) { 312 separator = separator || ' '; 313 314 str = String(str); 315 316 str = str.replace(REGEX_UNCAMELIZE, '$1' + separator + '$2$3'); 317 str = str.replace(REGEX_UNCAMELIZE_REPLACE_SEPARATOR, '$1' + separator + '$2'); 318 319 return str; 320 } 321 ), 322 323 toLowerCase: function(str) { 324 return String(str).toLowerCase(); 325 }, 326 327 toUpperCase: function(str) { 328 return String(str).toUpperCase(); 329 }, 330 331 trim: Lang.trim, 332 333 truncate: function(str, length, where) { 334 str = String(str); 335 336 var ellipsisLength = STR_ELLIPSIS.length, 337 strLength = str.length; 338 339 if (length > 3) { 340 if (str && (strLength > length)) { 341 where = where || 'end'; 342 343 if (where === 'end') { 344 str = str.substr(0, (length - ellipsisLength)) + STR_ELLIPSIS; 345 } 346 else if (where === 'middle') { 347 var middlePointA = Math.floor((length - ellipsisLength) / 2), 348 middlePointB = middlePointA; 349 350 if (length % 2 === 0) {
351 middlePointA = Math.ceil((length - ellipsisLength) / 2); 352 middlePointB = Math.floor((length - ellipsisLength) / 2); 353 } 354 355 str = str.substr(0, middlePointA) + STR_ELLIPSIS + str.substr(strLength - middlePointB); 356 } 357 else if (where === 'start') { 358 str = STR_ELLIPSIS + str.substr(strLength - length + ellipsisLength); 359 } 360 } 361 } 362 else { 363 str = STR_ELLIPSIS; 364 } 365 366 return str; 367 }, 368 369 undef: function(str) { 370 if (isUndefined(str)) { 371 str = ''; 372 } 373 374 return str; 375 }, 376 377 // inspired from Google unescape entities 378 unescapeEntities: function(str) { 379 if (LString.contains(str, '&')) { 380 if (DOC && !LString.contains(str, '<')) { 381 str = LString._unescapeEntitiesUsingDom(str); 382 } 383 else { 384 str = LString.unescapeHTML(str); 385 } 386 } 387 388 return str; 389 }, 390 391 unescapeHTML: function(str) { 392 return str.replace(REGEX_HTML_UNESCAPE, LString._unescapeHTML); 393 }, 394 395 _camelize: function(match0, match1) { 396 return match1.toUpperCase(); 397 }, 398 399 _escapeHTML: function(match) { 400 return MAP_HTML_CHARS_ESCAPED[match]; 401 }, 402 403 _unescapeHTML: function(match, entity) { 404 var value = MAP_HTML_CHARS_UNESCAPED[match] || match; 405 406 if (!value && entity.charAt(0) === '#') { 407 var charCode = Number('0' + value.substr(1)); 408 409 if (!isNaN(charCode)) { 410 value = String.fromCharCode(charCode); 411 } 412 } 413 414 return value; 415 }, 416 417 _unescapeEntitiesUsingDom: function(str) { 418 var el = DOC.createElement('a'); 419 420 el.innerHTML = str; 421 422 if (el.normalize) { 423 el.normalize(); 424 } 425 426 str = el.firstChild.nodeValue; 427 428 el.innerHTML = ''; 429 430 return str; 431 } 432 }); 433 434 /* 435 * Maps an object to an array, using the return value of fn as the values 436 * for the new array. 437 */ 438 AObject.map = function(obj, fn, context) { 439 var map = [], 440 i; 441 442 for (i in obj) { 443 if (owns(obj, i)) { 444 map[map.length] = fn.call(context, obj[i], i, obj); 445 } 446 } 447 448 return map; 449 }; 450 451 /* 452 * Maps an array or object to a resulting array, using the return value of 453 * fn as the values for the new array. Like A.each, this function can accept 454 * an object or an array. 455 */ 456 A.map = function(obj) { 457 var module = AObject; 458 459 if (isArray(obj)) { 460 module = aArray; 461 } 462 463 return module.map.apply(this, arguments); 464 }; 465}()); 466 467 468}, '3.1.0-deprecated.112');
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.