[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('yui2-yahoo', function(Y) { 2 /* 3 Copyright (c) 2011, Yahoo! Inc. All rights reserved. 4 Code licensed under the BSD License: 5 http://developer.yahoo.com/yui/license.html 6 version: 2.9.0 7 */ 8 /** 9 * The YAHOO object is the single global object used by YUI Library. It 10 * contains utility function for setting up namespaces, inheritance, and 11 * logging. YAHOO.util, YAHOO.widget, and YAHOO.example are namespaces 12 * created automatically for and used by the library. 13 * @module yahoo 14 * @title YAHOO Global 15 */ 16 17 /** 18 * YAHOO_config is not included as part of the library. Instead it is an 19 * object that can be defined by the implementer immediately before 20 * including the YUI library. The properties included in this object 21 * will be used to configure global properties needed as soon as the 22 * library begins to load. 23 * @class YAHOO_config 24 * @static 25 */ 26 27 /** 28 * A reference to a function that will be executed every time a YAHOO module 29 * is loaded. As parameter, this function will receive the version 30 * information for the module. See <a href="YAHOO.env.html#getVersion"> 31 * YAHOO.env.getVersion</a> for the description of the version data structure. 32 * @property listener 33 * @type Function 34 * @static 35 * @default undefined 36 */ 37 38 /** 39 * Set to true if the library will be dynamically loaded after window.onload. 40 * Defaults to false 41 * @property injecting 42 * @type boolean 43 * @static 44 * @default undefined 45 */ 46 47 /** 48 * Instructs the yuiloader component to dynamically load yui components and 49 * their dependencies. See the yuiloader documentation for more information 50 * about dynamic loading 51 * @property load 52 * @static 53 * @default undefined 54 * @see yuiloader 55 */ 56 57 /** 58 * Forces the use of the supplied locale where applicable in the library 59 * @property locale 60 * @type string 61 * @static 62 * @default undefined 63 */ 64 65 if (typeof YAHOO == "undefined" || !YAHOO) { 66 /** 67 * The YAHOO global namespace object. If YAHOO is already defined, the 68 * existing YAHOO object will not be overwritten so that defined 69 * namespaces are preserved. 70 * @class YAHOO 71 * @static 72 */ 73 var YAHOO = {}; 74 } 75 76 /** 77 * Returns the namespace specified and creates it if it doesn't exist 78 * <pre> 79 * YAHOO.namespace("property.package"); 80 * YAHOO.namespace("YAHOO.property.package"); 81 * </pre> 82 * Either of the above would create YAHOO.property, then 83 * YAHOO.property.package 84 * 85 * Be careful when naming packages. Reserved words may work in some browsers 86 * and not others. For instance, the following will fail in Safari: 87 * <pre> 88 * YAHOO.namespace("really.long.nested.namespace"); 89 * </pre> 90 * This fails because "long" is a future reserved word in ECMAScript 91 * 92 * For implementation code that uses YUI, do not create your components 93 * in the namespaces defined by YUI ( 94 * <code>YAHOO.util</code>, 95 * <code>YAHOO.widget</code>, 96 * <code>YAHOO.lang</code>, 97 * <code>YAHOO.tool</code>, 98 * <code>YAHOO.example</code>, 99 * <code>YAHOO.env</code>) -- create your own namespace (e.g., 'companyname'). 100 * 101 * @method namespace 102 * @static 103 * @param {String*} arguments 1-n namespaces to create 104 * @return {Object} A reference to the last namespace object created 105 */ 106 YAHOO.namespace = function() { 107 var a=arguments, o=null, i, j, d; 108 for (i=0; i<a.length; i=i+1) { 109 d=(""+a[i]).split("."); 110 o=YAHOO; 111 112 // YAHOO is implied, so it is ignored if it is included 113 for (j=(d[0] == "YAHOO") ? 1 : 0; j<d.length; j=j+1) { 114 o[d[j]]=o[d[j]] || {}; 115 o=o[d[j]]; 116 } 117 } 118 119 return o; 120 }; 121 122 /** 123 * Uses YAHOO.widget.Logger to output a log message, if the widget is 124 * available. 125 * Note: LogReader adds the message, category, and source to the DOM as HTML. 126 * 127 * @method log 128 * @static 129 * @param {HTML} msg The message to log. 130 * @param {HTML} cat The log category for the message. Default 131 * categories are "info", "warn", "error", time". 132 * Custom categories can be used as well. (opt) 133 * @param {HTML} src The source of the the message (opt) 134 * @return {Boolean} True if the log operation was successful. 135 */ 136 YAHOO.log = function(msg, cat, src) { 137 var l=YAHOO.widget.Logger; 138 if(l && l.log) { 139 return l.log(msg, cat, src); 140 } else { 141 return false; 142 } 143 }; 144 145 /** 146 * Registers a module with the YAHOO object 147 * @method register 148 * @static 149 * @param {String} name the name of the module (event, slider, etc) 150 * @param {Function} mainClass a reference to class in the module. This 151 * class will be tagged with the version info 152 * so that it will be possible to identify the 153 * version that is in use when multiple versions 154 * have loaded 155 * @param {Object} data metadata object for the module. Currently it 156 * is expected to contain a "version" property 157 * and a "build" property at minimum. 158 */ 159 YAHOO.register = function(name, mainClass, data) { 160 var mods = YAHOO.env.modules, m, v, b, ls, i; 161 162 if (!mods[name]) { 163 mods[name] = { 164 versions:[], 165 builds:[] 166 }; 167 } 168 169 m = mods[name]; 170 v = data.version; 171 b = data.build; 172 ls = YAHOO.env.listeners; 173 174 m.name = name; 175 m.version = v; 176 m.build = b; 177 m.versions.push(v); 178 m.builds.push(b); 179 m.mainClass = mainClass; 180 181 // fire the module load listeners 182 for (i=0;i<ls.length;i=i+1) { 183 ls[i](m); 184 } 185 // label the main class 186 if (mainClass) { 187 mainClass.VERSION = v; 188 mainClass.BUILD = b; 189 } else { 190 YAHOO.log("mainClass is undefined for module " + name, "warn"); 191 } 192 }; 193 194 /** 195 * YAHOO.env is used to keep track of what is known about the YUI library and 196 * the browsing environment 197 * @class YAHOO.env 198 * @static 199 */ 200 YAHOO.env = YAHOO.env || { 201 202 /** 203 * Keeps the version info for all YUI modules that have reported themselves 204 * @property modules 205 * @type Object[] 206 */ 207 modules: [], 208 209 /** 210 * List of functions that should be executed every time a YUI module 211 * reports itself. 212 * @property listeners 213 * @type Function[] 214 */ 215 listeners: [] 216 }; 217 218 /** 219 * Returns the version data for the specified module: 220 * <dl> 221 * <dt>name:</dt> <dd>The name of the module</dd> 222 * <dt>version:</dt> <dd>The version in use</dd> 223 * <dt>build:</dt> <dd>The build number in use</dd> 224 * <dt>versions:</dt> <dd>All versions that were registered</dd> 225 * <dt>builds:</dt> <dd>All builds that were registered.</dd> 226 * <dt>mainClass:</dt> <dd>An object that was was stamped with the 227 * current version and build. If 228 * mainClass.VERSION != version or mainClass.BUILD != build, 229 * multiple versions of pieces of the library have been 230 * loaded, potentially causing issues.</dd> 231 * </dl> 232 * 233 * @method getVersion 234 * @static 235 * @param {String} name the name of the module (event, slider, etc) 236 * @return {Object} The version info 237 */ 238 YAHOO.env.getVersion = function(name) { 239 return YAHOO.env.modules[name] || null; 240 }; 241 242 /** 243 * Do not fork for a browser if it can be avoided. Use feature detection when 244 * you can. Use the user agent as a last resort. YAHOO.env.ua stores a version 245 * number for the browser engine, 0 otherwise. This value may or may not map 246 * to the version number of the browser using the engine. The value is 247 * presented as a float so that it can easily be used for boolean evaluation 248 * as well as for looking for a particular range of versions. Because of this, 249 * some of the granularity of the version info may be lost (e.g., Gecko 1.8.0.9 250 * reports 1.8). 251 * @class YAHOO.env.ua 252 * @static 253 */ 254 255 /** 256 * parses a user agent string (or looks for one in navigator to parse if 257 * not supplied). 258 * @method parseUA 259 * @since 2.9.0 260 * @static 261 */ 262 YAHOO.env.parseUA = function(agent) { 263 264 var numberify = function(s) { 265 var c = 0; 266 return parseFloat(s.replace(/\./g, function() { 267 return (c++ == 1) ? '' : '.'; 268 })); 269 }, 270 271 nav = navigator, 272 273 o = { 274 275 /** 276 * Internet Explorer version number or 0. Example: 6 277 * @property ie 278 * @type float 279 * @static 280 */ 281 ie: 0, 282 283 /** 284 * Opera version number or 0. Example: 9.2 285 * @property opera 286 * @type float 287 * @static 288 */ 289 opera: 0, 290 291 /** 292 * Gecko engine revision number. Will evaluate to 1 if Gecko 293 * is detected but the revision could not be found. Other browsers 294 * will be 0. Example: 1.8 295 * <pre> 296 * Firefox 1.0.0.4: 1.7.8 <-- Reports 1.7 297 * Firefox 1.5.0.9: 1.8.0.9 <-- 1.8 298 * Firefox 2.0.0.3: 1.8.1.3 <-- 1.81 299 * Firefox 3.0 <-- 1.9 300 * Firefox 3.5 <-- 1.91 301 * </pre> 302 * @property gecko 303 * @type float 304 * @static 305 */ 306 gecko: 0, 307 308 /** 309 * AppleWebKit version. KHTML browsers that are not WebKit browsers 310 * will evaluate to 1, other browsers 0. Example: 418.9 311 * <pre> 312 * Safari 1.3.2 (312.6): 312.8.1 <-- Reports 312.8 -- currently the 313 * latest available for Mac OSX 10.3. 314 * Safari 2.0.2: 416 <-- hasOwnProperty introduced 315 * Safari 2.0.4: 418 <-- preventDefault fixed 316 * Safari 2.0.4 (419.3): 418.9.1 <-- One version of Safari may run 317 * different versions of webkit 318 * Safari 2.0.4 (419.3): 419 <-- Tiger installations that have been 319 * updated, but not updated 320 * to the latest patch. 321 * Webkit 212 nightly: 522+ <-- Safari 3.0 precursor (with native 322 * SVG and many major issues fixed). 323 * Safari 3.0.4 (523.12) 523.12 <-- First Tiger release - automatic 324 * update from 2.x via the 10.4.11 OS patch. 325 * Webkit nightly 1/2008:525+ <-- Supports DOMContentLoaded event. 326 * yahoo.com user agent hack removed. 327 * </pre> 328 * http://en.wikipedia.org/wiki/Safari_version_history 329 * @property webkit 330 * @type float 331 * @static 332 */ 333 webkit: 0, 334 335 /** 336 * Chrome will be detected as webkit, but this property will also 337 * be populated with the Chrome version number 338 * @property chrome 339 * @type float 340 * @static 341 */ 342 chrome: 0, 343 344 /** 345 * The mobile property will be set to a string containing any relevant 346 * user agent information when a modern mobile browser is detected. 347 * Currently limited to Safari on the iPhone/iPod Touch, Nokia N-series 348 * devices with the WebKit-based browser, and Opera Mini. 349 * @property mobile 350 * @type string 351 * @static 352 */ 353 mobile: null, 354 355 /** 356 * Adobe AIR version number or 0. Only populated if webkit is detected. 357 * Example: 1.0 358 * @property air 359 * @type float 360 */ 361 air: 0, 362 /** 363 * Detects Apple iPad's OS version 364 * @property ipad 365 * @type float 366 * @static 367 */ 368 ipad: 0, 369 /** 370 * Detects Apple iPhone's OS version 371 * @property iphone 372 * @type float 373 * @static 374 */ 375 iphone: 0, 376 /** 377 * Detects Apples iPod's OS version 378 * @property ipod 379 * @type float 380 * @static 381 */ 382 ipod: 0, 383 /** 384 * General truthy check for iPad, iPhone or iPod 385 * @property ios 386 * @type float 387 * @static 388 */ 389 ios: null, 390 /** 391 * Detects Googles Android OS version 392 * @property android 393 * @type float 394 * @static 395 */ 396 android: 0, 397 /** 398 * Detects Palms WebOS version 399 * @property webos 400 * @type float 401 * @static 402 */ 403 webos: 0, 404 405 /** 406 * Google Caja version number or 0. 407 * @property caja 408 * @type float 409 */ 410 caja: nav && nav.cajaVersion, 411 412 /** 413 * Set to true if the page appears to be in SSL 414 * @property secure 415 * @type boolean 416 * @static 417 */ 418 secure: false, 419 420 /** 421 * The operating system. Currently only detecting windows or macintosh 422 * @property os 423 * @type string 424 * @static 425 */ 426 os: null 427 428 }, 429 430 ua = agent || (navigator && navigator.userAgent), 431 432 loc = window && window.location, 433 434 href = loc && loc.href, 435 436 m; 437 438 o.secure = href && (href.toLowerCase().indexOf("https") === 0); 439 440 if (ua) { 441 442 if ((/windows|win32/i).test(ua)) { 443 o.os = 'windows'; 444 } else if ((/macintosh/i).test(ua)) { 445 o.os = 'macintosh'; 446 } else if ((/rhino/i).test(ua)) { 447 o.os = 'rhino'; 448 } 449 450 // Modern KHTML browsers should qualify as Safari X-Grade 451 if ((/KHTML/).test(ua)) { 452 o.webkit = 1; 453 } 454 // Modern WebKit browsers are at least X-Grade 455 m = ua.match(/AppleWebKit\/([^\s]*)/); 456 if (m && m[1]) { 457 o.webkit = numberify(m[1]); 458 459 // Mobile browser check 460 if (/ Mobile\//.test(ua)) { 461 o.mobile = 'Apple'; // iPhone or iPod Touch 462 463 m = ua.match(/OS ([^\s]*)/); 464 if (m && m[1]) { 465 m = numberify(m[1].replace('_', '.')); 466 } 467 o.ios = m; 468 o.ipad = o.ipod = o.iphone = 0; 469 470 m = ua.match(/iPad|iPod|iPhone/); 471 if (m && m[0]) { 472 o[m[0].toLowerCase()] = o.ios; 473 } 474 } else { 475 m = ua.match(/NokiaN[^\/]*|Android \d\.\d|webOS\/\d\.\d/); 476 if (m) { 477 // Nokia N-series, Android, webOS, ex: NokiaN95 478 o.mobile = m[0]; 479 } 480 if (/webOS/.test(ua)) { 481 o.mobile = 'WebOS'; 482 m = ua.match(/webOS\/([^\s]*);/); 483 if (m && m[1]) { 484 o.webos = numberify(m[1]); 485 } 486 } 487 if (/ Android/.test(ua)) { 488 o.mobile = 'Android'; 489 m = ua.match(/Android ([^\s]*);/); 490 if (m && m[1]) { 491 o.android = numberify(m[1]); 492 } 493 494 } 495 } 496 497 m = ua.match(/Chrome\/([^\s]*)/); 498 if (m && m[1]) { 499 o.chrome = numberify(m[1]); // Chrome 500 } else { 501 m = ua.match(/AdobeAIR\/([^\s]*)/); 502 if (m) { 503 o.air = m[0]; // Adobe AIR 1.0 or better 504 } 505 } 506 } 507 508 if (!o.webkit) { // not webkit 509 // @todo check Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4509/1316; fi; U; ssr) 510 m = ua.match(/Opera[\s\/]([^\s]*)/); 511 if (m && m[1]) { 512 o.opera = numberify(m[1]); 513 m = ua.match(/Version\/([^\s]*)/); 514 if (m && m[1]) { 515 o.opera = numberify(m[1]); // opera 10+ 516 } 517 m = ua.match(/Opera Mini[^;]*/); 518 if (m) { 519 o.mobile = m[0]; // ex: Opera Mini/2.0.4509/1316 520 } 521 } else { // not opera or webkit 522 m = ua.match(/MSIE\s([^;]*)/); 523 if (m && m[1]) { 524 o.ie = numberify(m[1]); 525 } else { // not opera, webkit, or ie 526 m = ua.match(/Gecko\/([^\s]*)/); 527 if (m) { 528 o.gecko = 1; // Gecko detected, look for revision 529 m = ua.match(/rv:([^\s\)]*)/); 530 if (m && m[1]) { 531 o.gecko = numberify(m[1]); 532 } 533 } 534 } 535 } 536 } 537 } 538 539 return o; 540 }; 541 542 YAHOO.env.ua = YAHOO.env.parseUA(); 543 544 /* 545 * Initializes the global by creating the default namespaces and applying 546 * any new configuration information that is detected. This is the setup 547 * for env. 548 * @method init 549 * @static 550 * @private 551 */ 552 (function() { 553 YAHOO.namespace("util", "widget", "example"); 554 /*global YAHOO_config*/ 555 if ("undefined" !== typeof YAHOO_config) { 556 var l=YAHOO_config.listener, ls=YAHOO.env.listeners,unique=true, i; 557 if (l) { 558 // if YAHOO is loaded multiple times we need to check to see if 559 // this is a new config object. If it is, add the new component 560 // load listener to the stack 561 for (i=0; i<ls.length; i++) { 562 if (ls[i] == l) { 563 unique = false; 564 break; 565 } 566 } 567 568 if (unique) { 569 ls.push(l); 570 } 571 } 572 } 573 })(); 574 /** 575 * Provides the language utilites and extensions used by the library 576 * @class YAHOO.lang 577 */ 578 YAHOO.lang = YAHOO.lang || {}; 579 580 (function() { 581 582 583 var L = YAHOO.lang, 584 585 OP = Object.prototype, 586 ARRAY_TOSTRING = '[object Array]', 587 FUNCTION_TOSTRING = '[object Function]', 588 OBJECT_TOSTRING = '[object Object]', 589 NOTHING = [], 590 591 HTML_CHARS = { 592 '&': '&', 593 '<': '<', 594 '>': '>', 595 '"': '"', 596 "'": ''', 597 '/': '/', 598 '`': '`' 599 }, 600 601 // ADD = ["toString", "valueOf", "hasOwnProperty"], 602 ADD = ["toString", "valueOf"], 603 604 OB = { 605 606 /** 607 * Determines wheather or not the provided object is an array. 608 * @method isArray 609 * @param {any} o The object being testing 610 * @return {boolean} the result 611 */ 612 isArray: function(o) { 613 return OP.toString.apply(o) === ARRAY_TOSTRING; 614 }, 615 616 /** 617 * Determines whether or not the provided object is a boolean 618 * @method isBoolean 619 * @param {any} o The object being testing 620 * @return {boolean} the result 621 */ 622 isBoolean: function(o) { 623 return typeof o === 'boolean'; 624 }, 625 626 /** 627 * Determines whether or not the provided object is a function. 628 * Note: Internet Explorer thinks certain functions are objects: 629 * 630 * var obj = document.createElement("object"); 631 * YAHOO.lang.isFunction(obj.getAttribute) // reports false in IE 632 * 633 * var input = document.createElement("input"); // append to body 634 * YAHOO.lang.isFunction(input.focus) // reports false in IE 635 * 636 * You will have to implement additional tests if these functions 637 * matter to you. 638 * 639 * @method isFunction 640 * @param {any} o The object being testing 641 * @return {boolean} the result 642 */ 643 isFunction: function(o) { 644 return (typeof o === 'function') || OP.toString.apply(o) === FUNCTION_TOSTRING; 645 }, 646 647 /** 648 * Determines whether or not the provided object is null 649 * @method isNull 650 * @param {any} o The object being testing 651 * @return {boolean} the result 652 */ 653 isNull: function(o) { 654 return o === null; 655 }, 656 657 /** 658 * Determines whether or not the provided object is a legal number 659 * @method isNumber 660 * @param {any} o The object being testing 661 * @return {boolean} the result 662 */ 663 isNumber: function(o) { 664 return typeof o === 'number' && isFinite(o); 665 }, 666 667 /** 668 * Determines whether or not the provided object is of type object 669 * or function 670 * @method isObject 671 * @param {any} o The object being testing 672 * @return {boolean} the result 673 */ 674 isObject: function(o) { 675 return (o && (typeof o === 'object' || L.isFunction(o))) || false; 676 }, 677 678 /** 679 * Determines whether or not the provided object is a string 680 * @method isString 681 * @param {any} o The object being testing 682 * @return {boolean} the result 683 */ 684 isString: function(o) { 685 return typeof o === 'string'; 686 }, 687 688 /** 689 * Determines whether or not the provided object is undefined 690 * @method isUndefined 691 * @param {any} o The object being testing 692 * @return {boolean} the result 693 */ 694 isUndefined: function(o) { 695 return typeof o === 'undefined'; 696 }, 697 698 699 /** 700 * IE will not enumerate native functions in a derived object even if the 701 * function was overridden. This is a workaround for specific functions 702 * we care about on the Object prototype. 703 * @property _IEEnumFix 704 * @param {Function} r the object to receive the augmentation 705 * @param {Function} s the object that supplies the properties to augment 706 * @static 707 * @private 708 */ 709 _IEEnumFix: (YAHOO.env.ua.ie) ? function(r, s) { 710 var i, fname, f; 711 for (i=0;i<ADD.length;i=i+1) { 712 713 fname = ADD[i]; 714 f = s[fname]; 715 716 if (L.isFunction(f) && f!=OP[fname]) { 717 r[fname]=f; 718 } 719 } 720 } : function(){}, 721 722 /** 723 * <p> 724 * Returns a copy of the specified string with special HTML characters 725 * escaped. The following characters will be converted to their 726 * corresponding character entities: 727 * <code>& < > " ' / `</code> 728 * </p> 729 * 730 * <p> 731 * This implementation is based on the 732 * <a href="http://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet">OWASP 733 * HTML escaping recommendations</a>. In addition to the characters 734 * in the OWASP recommendation, we also escape the <code>`</code> 735 * character, since IE interprets it as an attribute delimiter when used in 736 * innerHTML. 737 * </p> 738 * 739 * @method escapeHTML 740 * @param {String} html String to escape. 741 * @return {String} Escaped string. 742 * @static 743 * @since 2.9.0 744 */ 745 escapeHTML: function (html) { 746 return html.replace(/[&<>"'\/`]/g, function (match) { 747 return HTML_CHARS[match]; 748 }); 749 }, 750 751 /** 752 * Utility to set up the prototype, constructor and superclass properties to 753 * support an inheritance strategy that can chain constructors and methods. 754 * Static members will not be inherited. 755 * 756 * @method extend 757 * @static 758 * @param {Function} subc the object to modify 759 * @param {Function} superc the object to inherit 760 * @param {Object} overrides additional properties/methods to add to the 761 * subclass prototype. These will override the 762 * matching items obtained from the superclass 763 * if present. 764 */ 765 extend: function(subc, superc, overrides) { 766 if (!superc||!subc) { 767 throw new Error("extend failed, please check that " + 768 "all dependencies are included."); 769 } 770 var F = function() {}, i; 771 F.prototype=superc.prototype; 772 subc.prototype=new F(); 773 subc.prototype.constructor=subc; 774 subc.superclass=superc.prototype; 775 if (superc.prototype.constructor == OP.constructor) { 776 superc.prototype.constructor=superc; 777 } 778 779 if (overrides) { 780 for (i in overrides) { 781 if (L.hasOwnProperty(overrides, i)) { 782 subc.prototype[i]=overrides[i]; 783 } 784 } 785 786 L._IEEnumFix(subc.prototype, overrides); 787 } 788 }, 789 790 /** 791 * Applies all properties in the supplier to the receiver if the 792 * receiver does not have these properties yet. Optionally, one or 793 * more methods/properties can be specified (as additional 794 * parameters). This option will overwrite the property if receiver 795 * has it already. If true is passed as the third parameter, all 796 * properties will be applied and _will_ overwrite properties in 797 * the receiver. 798 * 799 * @method augmentObject 800 * @static 801 * @since 2.3.0 802 * @param {Function} r the object to receive the augmentation 803 * @param {Function} s the object that supplies the properties to augment 804 * @param {String*|boolean} arguments zero or more properties methods 805 * to augment the receiver with. If none specified, everything 806 * in the supplier will be used unless it would 807 * overwrite an existing property in the receiver. If true 808 * is specified as the third parameter, all properties will 809 * be applied and will overwrite an existing property in 810 * the receiver 811 */ 812 augmentObject: function(r, s) { 813 if (!s||!r) { 814 throw new Error("Absorb failed, verify dependencies."); 815 } 816 var a=arguments, i, p, overrideList=a[2]; 817 if (overrideList && overrideList!==true) { // only absorb the specified properties 818 for (i=2; i<a.length; i=i+1) { 819 r[a[i]] = s[a[i]]; 820 } 821 } else { // take everything, overwriting only if the third parameter is true 822 for (p in s) { 823 if (overrideList || !(p in r)) { 824 r[p] = s[p]; 825 } 826 } 827 828 L._IEEnumFix(r, s); 829 } 830 831 return r; 832 }, 833 834 /** 835 * Same as YAHOO.lang.augmentObject, except it only applies prototype properties 836 * @see YAHOO.lang.augmentObject 837 * @method augmentProto 838 * @static 839 * @param {Function} r the object to receive the augmentation 840 * @param {Function} s the object that supplies the properties to augment 841 * @param {String*|boolean} arguments zero or more properties methods 842 * to augment the receiver with. If none specified, everything 843 * in the supplier will be used unless it would overwrite an existing 844 * property in the receiver. if true is specified as the third 845 * parameter, all properties will be applied and will overwrite an 846 * existing property in the receiver 847 */ 848 augmentProto: function(r, s) { 849 if (!s||!r) { 850 throw new Error("Augment failed, verify dependencies."); 851 } 852 //var a=[].concat(arguments); 853 var a=[r.prototype,s.prototype], i; 854 for (i=2;i<arguments.length;i=i+1) { 855 a.push(arguments[i]); 856 } 857 L.augmentObject.apply(this, a); 858 859 return r; 860 }, 861 862 863 /** 864 * Returns a simple string representation of the object or array. 865 * Other types of objects will be returned unprocessed. Arrays 866 * are expected to be indexed. Use object notation for 867 * associative arrays. 868 * @method dump 869 * @since 2.3.0 870 * @param o {Object} The object to dump 871 * @param d {int} How deep to recurse child objects, default 3 872 * @return {String} the dump result 873 */ 874 dump: function(o, d) { 875 var i,len,s=[],OBJ="{...}",FUN="f(){...}", 876 COMMA=', ', ARROW=' => '; 877 878 // Cast non-objects to string 879 // Skip dates because the std toString is what we want 880 // Skip HTMLElement-like objects because trying to dump 881 // an element will cause an unhandled exception in FF 2.x 882 if (!L.isObject(o)) { 883 return o + ""; 884 } else if (o instanceof Date || ("nodeType" in o && "tagName" in o)) { 885 return o; 886 } else if (L.isFunction(o)) { 887 return FUN; 888 } 889 890 // dig into child objects the depth specifed. Default 3 891 d = (L.isNumber(d)) ? d : 3; 892 893 // arrays [1, 2, 3] 894 if (L.isArray(o)) { 895 s.push("["); 896 for (i=0,len=o.length;i<len;i=i+1) { 897 if (L.isObject(o[i])) { 898 s.push((d > 0) ? L.dump(o[i], d-1) : OBJ); 899 } else { 900 s.push(o[i]); 901 } 902 s.push(COMMA); 903 } 904 if (s.length > 1) { 905 s.pop(); 906 } 907 s.push("]"); 908 // objects {k1 => v1, k2 => v2} 909 } else { 910 s.push("{"); 911 for (i in o) { 912 if (L.hasOwnProperty(o, i)) { 913 s.push(i + ARROW); 914 if (L.isObject(o[i])) { 915 s.push((d > 0) ? L.dump(o[i], d-1) : OBJ); 916 } else { 917 s.push(o[i]); 918 } 919 s.push(COMMA); 920 } 921 } 922 if (s.length > 1) { 923 s.pop(); 924 } 925 s.push("}"); 926 } 927 928 return s.join(""); 929 }, 930 931 /** 932 * Does variable substitution on a string. It scans through the string 933 * looking for expressions enclosed in { } braces. If an expression 934 * is found, it is used a key on the object. If there is a space in 935 * the key, the first word is used for the key and the rest is provided 936 * to an optional function to be used to programatically determine the 937 * value (the extra information might be used for this decision). If 938 * the value for the key in the object, or what is returned from the 939 * function has a string value, number value, or object value, it is 940 * substituted for the bracket expression and it repeats. If this 941 * value is an object, it uses the Object's toString() if this has 942 * been overridden, otherwise it does a shallow dump of the key/value 943 * pairs. 944 * 945 * By specifying the recurse option, the string is rescanned after 946 * every replacement, allowing for nested template substitutions. 947 * The side effect of this option is that curly braces in the 948 * replacement content must be encoded. 949 * 950 * @method substitute 951 * @since 2.3.0 952 * @param s {String} The string that will be modified. 953 * @param o {Object} An object containing the replacement values 954 * @param f {Function} An optional function that can be used to 955 * process each match. It receives the key, 956 * value, and any extra metadata included with 957 * the key inside of the braces. 958 * @param recurse {boolean} default true - if not false, the replaced 959 * string will be rescanned so that nested substitutions are possible. 960 * @return {String} the substituted string 961 */ 962 substitute: function (s, o, f, recurse) { 963 var i, j, k, key, v, meta, saved=[], token, lidx=s.length, 964 DUMP='dump', SPACE=' ', LBRACE='{', RBRACE='}', 965 dump, objstr; 966 967 for (;;) { 968 i = s.lastIndexOf(LBRACE, lidx); 969 if (i < 0) { 970 break; 971 } 972 j = s.indexOf(RBRACE, i); 973 if (i + 1 > j) { 974 break; 975 } 976 977 //Extract key and meta info 978 token = s.substring(i + 1, j); 979 key = token; 980 meta = null; 981 k = key.indexOf(SPACE); 982 if (k > -1) { 983 meta = key.substring(k + 1); 984 key = key.substring(0, k); 985 } 986 987 // lookup the value 988 v = o[key]; 989 990 // if a substitution function was provided, execute it 991 if (f) { 992 v = f(key, v, meta); 993 } 994 995 if (L.isObject(v)) { 996 if (L.isArray(v)) { 997 v = L.dump(v, parseInt(meta, 10)); 998 } else { 999 meta = meta || ""; 1000 1001 // look for the keyword 'dump', if found force obj dump 1002 dump = meta.indexOf(DUMP); 1003 if (dump > -1) { 1004 meta = meta.substring(4); 1005 } 1006 1007 objstr = v.toString(); 1008 1009 // use the toString if it is not the Object toString 1010 // and the 'dump' meta info was not found 1011 if (objstr === OBJECT_TOSTRING || dump > -1) { 1012 v = L.dump(v, parseInt(meta, 10)); 1013 } else { 1014 v = objstr; 1015 } 1016 } 1017 } else if (!L.isString(v) && !L.isNumber(v)) { 1018 // This {block} has no replace string. Save it for later. 1019 v = "~-" + saved.length + "-~"; 1020 saved[saved.length] = token; 1021 1022 // break; 1023 } 1024 1025 s = s.substring(0, i) + v + s.substring(j + 1); 1026 1027 if (recurse === false) { 1028 lidx = i-1; 1029 } 1030 1031 } 1032 1033 // restore saved {block}s 1034 for (i=saved.length-1; i>=0; i=i-1) { 1035 s = s.replace(new RegExp("~-" + i + "-~"), "{" + saved[i] + "}", "g"); 1036 } 1037 1038 return s; 1039 }, 1040 1041 1042 /** 1043 * Returns a string without any leading or trailing whitespace. If 1044 * the input is not a string, the input will be returned untouched. 1045 * @method trim 1046 * @since 2.3.0 1047 * @param s {string} the string to trim 1048 * @return {string} the trimmed string 1049 */ 1050 trim: function(s){ 1051 try { 1052 return s.replace(/^\s+|\s+$/g, ""); 1053 } catch(e) { 1054 return s; 1055 } 1056 }, 1057 1058 /** 1059 * Returns a new object containing all of the properties of 1060 * all the supplied objects. The properties from later objects 1061 * will overwrite those in earlier objects. 1062 * @method merge 1063 * @since 2.3.0 1064 * @param arguments {Object*} the objects to merge 1065 * @return the new merged object 1066 */ 1067 merge: function() { 1068 var o={}, a=arguments, l=a.length, i; 1069 for (i=0; i<l; i=i+1) { 1070 L.augmentObject(o, a[i], true); 1071 } 1072 return o; 1073 }, 1074 1075 /** 1076 * Executes the supplied function in the context of the supplied 1077 * object 'when' milliseconds later. Executes the function a 1078 * single time unless periodic is set to true. 1079 * @method later 1080 * @since 2.4.0 1081 * @param when {int} the number of milliseconds to wait until the fn 1082 * is executed 1083 * @param o the context object 1084 * @param fn {Function|String} the function to execute or the name of 1085 * the method in the 'o' object to execute 1086 * @param data [Array] data that is provided to the function. This accepts 1087 * either a single item or an array. If an array is provided, the 1088 * function is executed with one parameter for each array item. If 1089 * you need to pass a single array parameter, it needs to be wrapped in 1090 * an array [myarray] 1091 * @param periodic {boolean} if true, executes continuously at supplied 1092 * interval until canceled 1093 * @return a timer object. Call the cancel() method on this object to 1094 * stop the timer. 1095 */ 1096 later: function(when, o, fn, data, periodic) { 1097 when = when || 0; 1098 o = o || {}; 1099 var m=fn, d=data, f, r; 1100 1101 if (L.isString(fn)) { 1102 m = o[fn]; 1103 } 1104 1105 if (!m) { 1106 throw new TypeError("method undefined"); 1107 } 1108 1109 if (!L.isUndefined(data) && !L.isArray(d)) { 1110 d = [data]; 1111 } 1112 1113 f = function() { 1114 m.apply(o, d || NOTHING); 1115 }; 1116 1117 r = (periodic) ? setInterval(f, when) : setTimeout(f, when); 1118 1119 return { 1120 interval: periodic, 1121 cancel: function() { 1122 if (this.interval) { 1123 clearInterval(r); 1124 } else { 1125 clearTimeout(r); 1126 } 1127 } 1128 }; 1129 }, 1130 1131 /** 1132 * A convenience method for detecting a legitimate non-null value. 1133 * Returns false for null/undefined/NaN, true for other values, 1134 * including 0/false/'' 1135 * @method isValue 1136 * @since 2.3.0 1137 * @param o {any} the item to test 1138 * @return {boolean} true if it is not null/undefined/NaN || false 1139 */ 1140 isValue: function(o) { 1141 // return (o || o === false || o === 0 || o === ''); // Infinity fails 1142 return (L.isObject(o) || L.isString(o) || L.isNumber(o) || L.isBoolean(o)); 1143 } 1144 1145 }; 1146 1147 /** 1148 * Determines whether or not the property was added 1149 * to the object instance. Returns false if the property is not present 1150 * in the object, or was inherited from the prototype. 1151 * This abstraction is provided to enable hasOwnProperty for Safari 1.3.x. 1152 * There is a discrepancy between YAHOO.lang.hasOwnProperty and 1153 * Object.prototype.hasOwnProperty when the property is a primitive added to 1154 * both the instance AND prototype with the same value: 1155 * <pre> 1156 * var A = function() {}; 1157 * A.prototype.foo = 'foo'; 1158 * var a = new A(); 1159 * a.foo = 'foo'; 1160 * alert(a.hasOwnProperty('foo')); // true 1161 * alert(YAHOO.lang.hasOwnProperty(a, 'foo')); // false when using fallback 1162 * </pre> 1163 * @method hasOwnProperty 1164 * @param {any} o The object being testing 1165 * @param prop {string} the name of the property to test 1166 * @return {boolean} the result 1167 */ 1168 L.hasOwnProperty = (OP.hasOwnProperty) ? 1169 function(o, prop) { 1170 return o && o.hasOwnProperty && o.hasOwnProperty(prop); 1171 } : function(o, prop) { 1172 return !L.isUndefined(o[prop]) && 1173 o.constructor.prototype[prop] !== o[prop]; 1174 }; 1175 1176 // new lang wins 1177 OB.augmentObject(L, OB, true); 1178 1179 /* 1180 * An alias for <a href="YAHOO.lang.html">YAHOO.lang</a> 1181 * @class YAHOO.util.Lang 1182 */ 1183 YAHOO.util.Lang = L; 1184 1185 /** 1186 * Same as YAHOO.lang.augmentObject, except it only applies prototype 1187 * properties. This is an alias for augmentProto. 1188 * @see YAHOO.lang.augmentObject 1189 * @method augment 1190 * @static 1191 * @param {Function} r the object to receive the augmentation 1192 * @param {Function} s the object that supplies the properties to augment 1193 * @param {String*|boolean} arguments zero or more properties methods to 1194 * augment the receiver with. If none specified, everything 1195 * in the supplier will be used unless it would 1196 * overwrite an existing property in the receiver. if true 1197 * is specified as the third parameter, all properties will 1198 * be applied and will overwrite an existing property in 1199 * the receiver 1200 */ 1201 L.augment = L.augmentProto; 1202 1203 /** 1204 * An alias for <a href="YAHOO.lang.html#augment">YAHOO.lang.augment</a> 1205 * @for YAHOO 1206 * @method augment 1207 * @static 1208 * @param {Function} r the object to receive the augmentation 1209 * @param {Function} s the object that supplies the properties to augment 1210 * @param {String*} arguments zero or more properties methods to 1211 * augment the receiver with. If none specified, everything 1212 * in the supplier will be used unless it would 1213 * overwrite an existing property in the receiver 1214 */ 1215 YAHOO.augment = L.augmentProto; 1216 1217 /** 1218 * An alias for <a href="YAHOO.lang.html#extend">YAHOO.lang.extend</a> 1219 * @method extend 1220 * @static 1221 * @param {Function} subc the object to modify 1222 * @param {Function} superc the object to inherit 1223 * @param {Object} overrides additional properties/methods to add to the 1224 * subclass prototype. These will override the 1225 * matching items obtained from the superclass if present. 1226 */ 1227 YAHOO.extend = L.extend; 1228 1229 })(); 1230 YAHOO.register("yahoo", YAHOO, {version: "2.9.0", build: "2800"}); 1231 1232 Y.YUI2 = YAHOO; 1233 }, '2.9.0' ,{});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |