get.js revision 62e7a7d39cc0c6d25fec20964c26bc35b9fa116a
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffYUI.add("get", function(Y) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var ua=Y.UA,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff L=Y.Lang;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff/*
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * Provides a mechanism to fetch remote resources and
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * insert them into a document
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * @module get
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff/**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Fetches and inserts one or more script or link nodes into the document
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @class Get
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @static
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff ConniffY.Get = function() {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * hash of queues to manage multiple requests
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @property queues
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var queues={},
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * queue index used to generate transaction ids
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @property qidx
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @type int
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @private
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
f47f024e093853ad3957be898687fc8317a835daJeff Conniff qidx=0,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * node index used to generate unique node ids
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @property nidx
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @type int
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff nidx=0,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // ridx=0,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff // sandboxFrame=null,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * interal property used to prevent multiple simultaneous purge
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * processes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @property purging
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @type boolean
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff purging=false;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Generates an HTML element, this is not appended to a document
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method _node
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param type {string} the type of element
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param attr {string} the attributes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param win {Window} optional window to create the element in
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @return {HTMLElement} the generated node
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff var _node = function(type, attr, win) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var w = win || Y.config.win, d=w.document, n=d.createElement(type);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff for (var i in attr) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (attr[i] && Y.Object.owns(attr, i)) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff n.setAttribute(i, attr[i]);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return n;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Generates a link node
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method _linkNode
04f7ef259d54aeab53258697e1e7f8856adcc8a6Jeff Conniff * @param url {string} the url for the css file
04f7ef259d54aeab53258697e1e7f8856adcc8a6Jeff Conniff * @param win {Window} optional window to create the node in
04f7ef259d54aeab53258697e1e7f8856adcc8a6Jeff Conniff * @return {HTMLElement} the generated node
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var _linkNode = function(url, win, charset) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var c = charset || "utf-8";
04f7ef259d54aeab53258697e1e7f8856adcc8a6Jeff Conniff return _node("link", {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff "id": "yui__dyn_" + (nidx++),
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "type": "text/css",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "charset": c,
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "rel": "stylesheet",
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff "href": url
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }, win);
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff };
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff /**
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * Generates a script node
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * @method _scriptNode
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param url {string} the url for the script file
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param win {Window} optional window to create the node in
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @return {HTMLElement} the generated node
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @private
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff */
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var _scriptNode = function(url, win, charset) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var c = charset || "utf-8";
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff return _node("script", {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff "id": "yui__dyn_" + (nidx++),
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff "type": "text/javascript",
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff "charset": c,
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff "src": url
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }, win);
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff };
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff /*
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * The request failed, execute fail handler with whatever
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * was accomplished. There isn't a failure case at the
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * moment unless you count aborted transactions
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * @method _fail
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param id {string} the id of the request
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @private
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff */
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var _fail = function(id, msg) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff Y.log("get failure: " + msg, "warn", "Get");
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff var q = queues[id];
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff // execute failure callback
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff if (q.onFailure) {
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff var sc=q.context || q;
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff q.onFailure.call(sc, _returnData(q, msg));
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff };
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff var _get = function(nId, tId) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var q = queues[tId],
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff n = (L.isString(nId)) ? q.win.document.getElementById(nId) : nId;
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff if (!n) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff _fail(tId, "target node not found: " + nId);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return n;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff };
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Removes the nodes for the specified queue
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @method _purge
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @private
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var _purge = function(tId) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var q=queues[tId];
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (q) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var n=q.nodes, l=n.length, d=q.win.document,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff h=d.getElementsByTagName("head")[0];
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (q.insertBefore) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var s = _get(q.insertBefore, tId);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (s) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff h = s.parentNode;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff for (var i=0; i<l; i=i+1) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff h.removeChild(n[i]);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.nodes = [];
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff };
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Returns the data payload for callback functions
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method _returnData
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @private
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var _returnData = function(q, msg) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff tId: q.tId,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff win: q.win,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff data: q.data,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff nodes: q.nodes,
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff msg: msg,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff purge: function() {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff _purge(this.tId);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff };
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff };
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /**
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * The request is complete, so executing the requester's callback
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * @method _finish
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * @param id {string} the id of the request
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * @private
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff */
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff var _finish = function(id) {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff Y.log("Finishing transaction " + id);
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff var q = queues[id];
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff q.finished = true;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (q.aborted) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var msg = "transaction " + id + " was aborted";
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff _fail(id, msg);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return;
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // execute success callback
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff if (q.onSuccess) {
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff var sc=q.context || q;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.onSuccess.call(sc, _returnData(q));
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
a90f7fefd9901a8da896d4bfe602441e0b7078d3Jeff Conniff };
a90f7fefd9901a8da896d4bfe602441e0b7078d3Jeff Conniff
59927fc7ef43db5ef49fce3811b307e2f0a4267cJeff Conniff /**
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * Timeout detected
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff * @method _timeout
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param id {string} the id of the request
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var _timeout = function(id) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff Y.log("Get utility timeout " + id);
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff var q = queues[id];
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (q.onTimeout) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var sc=q.context || q;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.onTimeout.call(sc, _returnData(q));
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Loads the next item for a given request
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @method _next
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param id {string} the id of the request
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param loaded {string} the url that was just loaded, if any
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var _next = function(id, loaded) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff Y.log("_next: " + id + ", loaded: " + loaded, "info", "Get");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var q = queues[id];
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (q.timer) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff // Y.log('cancel timer');
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.timer.cancel();
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (q.aborted) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var msg = "transaction " + id + " was aborted";
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff _fail(id, msg);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (loaded) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff q.url.shift();
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff if (q.varName) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff q.varName.shift();
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff } else {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff // This is the first pass: make sure the url is an array
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff q.url = (L.isString(q.url)) ? [q.url] : q.url;
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff if (q.varName) {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff q.varName = (L.isString(q.varName)) ? [q.varName] : q.varName;
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff var w=q.win, d=w.document, h=d.getElementsByTagName("head")[0], n;
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
59927fc7ef43db5ef49fce3811b307e2f0a4267cJeff Conniff if (q.url.length === 0) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff _finish(id);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
44c68f247b9311ea767cb4656220793317e3383bJeff Conniff var url = q.url[0];
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Y.log("attempting to load " + url, "info", "Get");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (q.timeout) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // Y.log('create timer');
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.timer = L.later(q.timeout, q, _timeout, id);
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff }
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
f47f024e093853ad3957be898687fc8317a835daJeff Conniff if (q.type === "script") {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff n = _scriptNode(url, w, q.charset);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff } else {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff n = _linkNode(url, w, q.charset);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // track this node's load progress
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff _track(q.type, n, id, url, w, q.url.length);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff // add the node to the queue so we can return it to the user supplied callback
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff q.nodes.push(n);
f47f024e093853ad3957be898687fc8317a835daJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // add it to the head or insert it before 'insertBefore'
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (q.insertBefore) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var s = _get(q.insertBefore, id);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (s) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff s.parentNode.insertBefore(n, s);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff } else {
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff h.appendChild(n);
3e16868ea3bfcadfeeb8e23aca5bb2317a6a8ba9Jeff Conniff }
f47f024e093853ad3957be898687fc8317a835daJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff Y.log("Appending node: " + url, "info", "Get");
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // FireFox does not support the onload event for link nodes, so there is
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // no way to make the css requests synchronous. This means that the css
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // rules in multiple files could be applied out of order in this browser
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // if a later request returns before an earlier one. Safari too.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if ((ua.webkit || ua.gecko) && q.type === "css") {
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff _next(id, url);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
f47f024e093853ad3957be898687fc8317a835daJeff Conniff };
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Removes processed queues and corresponding nodes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method _autoPurge
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @private
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff var _autoPurge = function() {
aa1805d3af3a9ac854fadba9707e18ee5f006804Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff if (purging) {
f47f024e093853ad3957be898687fc8317a835daJeff Conniff return;
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff purging = true;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff for (var i in queues) {
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff if (queues.hasOwnProperty(i)) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var q = queues[i];
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff if (q.autopurge && q.finished) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff _purge(q.tId);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff delete queues[i];
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }
04f7ef259d54aeab53258697e1e7f8856adcc8a6Jeff Conniff }
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff }
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff purging = false;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Saves the state for the request and begins loading
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * the requested urls
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @method queue
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param type {string} the type of node to insert
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @param url {string} the url to load
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @param opts the hash of options for this request
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * @private
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff */
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff var _queue = function(type, url, opts) {
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var id = "q" + (qidx++);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff opts = opts || {};
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff if (qidx % Y.Get.PURGE_THRESH === 0) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff _autoPurge();
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff }
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff queues[id] = Y.merge(opts, {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff tId: id,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff type: type,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff url: url,
f47f024e093853ad3957be898687fc8317a835daJeff Conniff finished: false,
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff nodes: []
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff });
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff var q = queues[id];
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff q.win = q.win || Y.config.win;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff q.context = q.context || q;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff q.autopurge = ("autopurge" in q) ? q.autopurge :
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff (type === "script") ? true : false;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff L.later(0, q, _next, id);
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff return {
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff tId: id
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff /**
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * Detects when a node has been loaded. In the case of
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * script nodes, this does not guarantee that contained
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * script is ready to use.
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @method _track
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * @param type {string} the type of node to track
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * @param n {HTMLElement} the node to track
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @param id {string} the id of the request
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * @param url {string} the url that is being loaded
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * @param win {Window} the targeted window
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * @param qlength the number of remaining items in the queue,
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * including this one
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * @param trackfn {Function} function to execute when finished
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * the default is _next
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff * @private
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff */
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff var _track = function(type, n, id, url, win, qlength, trackfn) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var f = trackfn || _next;
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff // IE supports the readystatechange event for script and css nodes
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff if (ua.ie) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff n.onreadystatechange = function() {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var rs = this.readyState;
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff if ("loaded" === rs || "complete" === rs) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff Y.log(id + " onload " + url, "info", "Get");
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff f(id, url);
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff }
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff };
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff // webkit prior to 3.x is no longer supported
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff } else if (ua.webkit) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff if (type === "script") {
e81cc12bafc201061ba76fdfd173f1412371e0ecJeff Conniff // Safari 3.x supports the load event for script nodes (DOM2)
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff n.addEventListener("load", function() {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff Y.log(id + " DOM2 onload " + url, "info", "Get");
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff f(id, url);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff });
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff }
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
f47f024e093853ad3957be898687fc8317a835daJeff Conniff // FireFox and Opera support onload (but not DOM2 in FF) handlers for
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff // script nodes. Opera, but not FF, supports the onload event for link
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff // nodes.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff } else {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff n.onload = function() {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Y.log(id + " onload " + url, "info", "Get");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff f(id, url);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff };
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff }
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff };
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
41af0d917f0352d732a7dbf9c9594f3ef30b82a0Jeff Conniff return {
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff
41af0d917f0352d732a7dbf9c9594f3ef30b82a0Jeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * The number of request required before an automatic purge.
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * property PURGE_THRESH
2353184083624510261e335c156a05e8cae2fc41Jeff Conniff * @static
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @type int
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @default 20
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff PURGE_THRESH: 20,
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff /**
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * Called by the the helper for detecting script load in Safari
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @method _finalize
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @param id {string} the transaction id
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @private
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff */
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff _finalize: function(id) {
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff Y.log(id + " finalized ", "info", "Get");
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff L.later(0, null, _finish, id);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff },
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Abort a transaction
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method abort
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param {string|object} either the tId or the object returned from
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * script() or css()
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff abort: function(o) {
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff var id = (L.isString(o)) ? o : o.tId;
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff var q = queues[id];
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff if (q) {
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff Y.log("Aborting " + id, "info", "Get");
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff q.aborted = true;
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff }
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff },
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff /**
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * Fetches and inserts one or more script nodes into the head
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * of the current document or the document in a specified window.
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff *
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @method script
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * @static
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * @param url {string|string[]} the url or urls to the script(s)
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @param opts {object} Options:
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dl>
7defd8450188bddcb9e79a7d1c2246aa027ed78fJeff Conniff * <dt>onSuccess</dt>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dd>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * callback to execute when the script(s) are finished loading
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * The callback receives an object back with the following
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * data:
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dl>
dcb17c0ed0cc508b4c74234b7477b05e6a8723ebJeff Conniff * <dt>win</dt>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dd>the window the script(s) were inserted into</dd>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dt>data</dt>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dd>the data object passed in when the request was made</dd>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dt>nodes</dt>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dd>An array containing references to the nodes that were
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * inserted</dd>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dt>purge</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>A function that, when executed, will remove the nodes
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * that were inserted</dd>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * <dt>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * </dl>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * </dd>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dt>onTimeout</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * callback to execute when a timeout occurs.
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * The callback receives an object back with the following
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * data:
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dl>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dt>win</dt>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dd>the window the script(s) were inserted into</dd>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dt>data</dt>
82cdeb4d776987d0e2501978b1e1c50143931bbcJeff Conniff * <dd>the data object passed in when the request was made</dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dt>nodes</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>An array containing references to the nodes that were
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * inserted</dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>purge</dt>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dd>A function that, when executed, will remove the nodes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * that were inserted</dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * </dl>
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * </dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>onFailure</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * callback to execute when the script load operation fails
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * The callback receives an object back with the following
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * data:
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dl>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dt>win</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>the window the script(s) were inserted into</dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dt>data</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>the data object passed in when the request was made</dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>nodes</dt>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dd>An array containing references to the nodes that were
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * inserted successfully</dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>purge</dt>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dd>A function that, when executed, will remove any nodes
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * that were inserted</dd>
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * <dt>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * </dl>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * </dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dt>context</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>the execution context for the callbacks</dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dt>win</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>a window other than the one the utility occupies</dd>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dt>autopurge</dt>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * setting to true will let the utilities cleanup routine purge
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * the script once loaded
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * </dd>
24ef71067b8f34f90df1fc636a73424647c97f4bJeff Conniff * <dt>data</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * data that is supplied to the callback when the script(s) are
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * loaded.
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * </dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>insertBefore</dt>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dd>node or node id that will become the new node's nextSibling</dd>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * </dl>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>charset</dt>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dd>Node charset, default utf-8</dd>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * <dt>timeout</dt>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dd>Number of milliseconds to wait before aborting and firing the timeout event</dd>
f47f024e093853ad3957be898687fc8317a835daJeff Conniff * <pre>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * &nbsp;&nbsp;Y.Get.script(
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * &nbsp;&nbsp;["http://yui.yahooapis.com/2.3.1/build/dragdrop/dragdrop-min.js",
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.3.1/build/animation/animation-min.js"], &#123;
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function(o) &#123;
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(o.data); // foo
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Y.DDProxy("dd1"); // also new o.reference("dd1"); would work
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log("won't cause error because Y is the context");
7defd8450188bddcb9e79a7d1c2246aa027ed78fJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log(o.nodes.length === 2) // true
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// o.purge(); // optionally remove the script nodes immediately
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;onFailure: function(o) &#123;
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log("transaction failed");
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;data: "foo",
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;context: Y,
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;// win: otherframe // target another window/frame
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * &nbsp;&nbsp;&nbsp;&nbsp;autopurge: true // allow the utility to choose when to remove the nodes
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * &nbsp;&nbsp;&#125;);
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * </pre>
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff * @return {tId: string} an object containing info about the transaction
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff */
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff script: function(url, opts) {
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff return _queue("script", url, opts);
736745cee753d967cf5fb1063c21578ecca61b4aJeff Conniff },
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff /**
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * Fetches and inserts one or more css link nodes into the
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * head of the current document or the document in a specified
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * window.
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * @method css
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @static
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * @param url {string} the url or urls to the css file(s)
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * @param opts Options:
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * <dl>
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * <dt>onSuccess</dt>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * <dd>
df71f95acec70ebddf0ab97cc1e0ff2b70048017Jeff Conniff * callback to execute when the css file(s) are finished loading
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * The callback receives an object back with the following
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * data:
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dl>win</dl>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dd>the window the link nodes(s) were inserted into</dd>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dt>data</dt>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dd>the data object passed in when the request was made</dd>
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * <dt>nodes</dt>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dd>An array containing references to the nodes that were
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * inserted</dd>
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * <dt>purge</dt>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dd>A function that, when executed, will remove the nodes
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * that were inserted</dd>
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * <dt>
41a8874f3c14857a5a311a43eaf30a123f376771Jeff Conniff * </dl>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * </dd>
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff * <dt>context</dt>
dcb17c0ed0cc508b4c74234b7477b05e6a8723ebJeff Conniff * <dd>the execution context for the callbacks</dd>
dcb17c0ed0cc508b4c74234b7477b05e6a8723ebJeff Conniff * <dt>win</dt>
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * <dd>a window other than the one the utility occupies</dd>
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff * <dt>data</dt>
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * <dd>
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * data that is supplied to the callbacks when the nodes(s) are
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * loaded.
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * </dd>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dt>insertBefore</dt>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dd>node or node id that will become the new node's nextSibling</dd>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dt>charset</dt>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <dd>Node charset, default utf-8</dd>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * </dl>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <pre>
7928e2ef0532df9064d9374ceda31d6ab080eb2dJeff Conniff * Y.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * </pre>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * <pre>
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * Y.Get.css(["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff * "http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"]);
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * </pre>
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff * @return {tId: string} an object containing info about the transaction
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff */
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff css: function(url, opts) {
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff return _queue("css", url, opts);
11b81e1c54469a27a52271a2bcff20794d259d27Jeff Conniff }
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff };
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff}();
691af6c84a00ad5f629ffcfa3b1e42c38da5da4fJeff Conniff
2aa0883432cf56a974eb9261afcf6ede4313384cJeff Conniff}, "@VERSION@");
624b3d25f12c6e63f607b2690315293ad7ef6481Jeff Conniff