node-load.js revision 39c4970fb513131af091c2d6404e41437c45fc82
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney
39c4970fb513131af091c2d6404e41437c45fc82Matt SweeneyY.Node.prototype._ioComplete = function(code, response, args) {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney var selector = args[0],
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney callback = args[1],
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney tmp,
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney content;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney if (response && response.responseText) {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney content = response.responseText;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney if (selector) {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney tmp = Y.DOM.create(content);
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney content = Y.Selector.query(selector, tmp);
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney }
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney this.setContent(content);
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney }
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney if (callback) {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney callback.call(this, code, response);
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney }
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney};
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney
39c4970fb513131af091c2d6404e41437c45fc82Matt SweeneyY.Node.prototype.load = function(url, selector, callback) {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney if (typeof selector == 'function') {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney callback = selector;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney selector = null;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney }
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney var config = {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney context: this,
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney on: {
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney complete: this._ioComplete
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney },
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney arguments: [selector, callback]
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney };
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney Y.io(url, config);
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney return this;
39c4970fb513131af091c2d6404e41437c45fc82Matt Sweeney}