NOBUG: Fixed file access permissions
[moodle.git] / lib / yuilib / 3.13.0 / node-load / node-load.js
blob02549c4fa4b694f7d742bcf461ddd709bd87c41f
1 /*
2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
6 */
8 YUI.add('node-load', function (Y, NAME) {
10 /**
11  * Extended Node interface with a basic IO API.
12  * @module node
13  * @submodule node-load
14  */
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  */
26 Y.Node.prototype._ioComplete = function(code, response, args) {
27     var selector = args[0],
28         callback = args[1],
29         tmp,
30         content;
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     }
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     };
67     Y.io(url, config);
68     return this;
72 }, '3.13.0', {"requires": ["node-base", "io-base"]});