src/cm/media/js/lib/yui/yui_3.10.3/build/node-load/node-load-debug.js
changeset 525 89ef5ed3c48b
equal deleted inserted replaced
524:322d0feea350 525:89ef5ed3c48b
       
     1 /*
       
     2 YUI 3.10.3 (build 2fb5187)
       
     3 Copyright 2013 Yahoo! Inc. All rights reserved.
       
     4 Licensed under the BSD License.
       
     5 http://yuilibrary.com/license/
       
     6 */
       
     7 
       
     8 YUI.add('node-load', function (Y, NAME) {
       
     9 
       
    10 /**
       
    11  * Extended Node interface with a basic IO API.
       
    12  * @module node
       
    13  * @submodule node-load
       
    14  */
       
    15 
       
    16 /**
       
    17  * The default IO complete handler.
       
    18  * @method _ioComplete
       
    19  * @protected
       
    20  * @for Node
       
    21  * @param {String} code The response code.
       
    22  * @param {Object} response The response object.
       
    23  * @param {Array} args An array containing the callback and selector
       
    24  */
       
    25 
       
    26 Y.Node.prototype._ioComplete = function(code, response, args) {
       
    27     var selector = args[0],
       
    28         callback = args[1],
       
    29         tmp,
       
    30         content;
       
    31 
       
    32     if (response && response.responseText) {
       
    33         content = response.responseText;
       
    34         if (selector) {
       
    35             tmp = Y.DOM.create(content);
       
    36             content = Y.Selector.query(selector, tmp);
       
    37         }
       
    38         this.setContent(content);
       
    39     }
       
    40     if (callback) {
       
    41         callback.call(this, code, response);
       
    42     }
       
    43 };
       
    44 
       
    45 /**
       
    46  * Loads content from the given url and replaces the Node's
       
    47  * existing content with the remote content.
       
    48  * @method load
       
    49  * @param {String} url The URL to load via XMLHttpRequest.
       
    50  * @param {String} selector An optional selector representing a subset of an HTML document to load.
       
    51  * @param {Function} callback An optional function to run after the content has been loaded.
       
    52  * @chainable
       
    53  */
       
    54 Y.Node.prototype.load = function(url, selector, callback) {
       
    55     if (typeof selector == 'function') {
       
    56         callback = selector;
       
    57         selector = null;
       
    58     }
       
    59     var config = {
       
    60         context: this,
       
    61         on: {
       
    62             complete: this._ioComplete
       
    63         },
       
    64         arguments: [selector, callback]
       
    65     };
       
    66 
       
    67     Y.io(url, config);
       
    68     return this;
       
    69 };
       
    70 
       
    71 
       
    72 }, '3.10.3', {"requires": ["node-base", "io-base"]});