get-debug.js revision 87b084086b5937585acc7e091b2f1951e94d9145
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTrippYUI.add('get', function(Y) {
0fdefaa9ca017edfb76b736c825b34186f33045aTripp
0fdefaa9ca017edfb76b736c825b34186f33045aTripp(function() {
0fdefaa9ca017edfb76b736c825b34186f33045aTripp
0fdefaa9ca017edfb76b736c825b34186f33045aTripp/**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Provides a mechanism to fetch remote resources and
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * insert them into a document.
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp * @module yui
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @submodule get
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTrippvar ua=Y.UA,
a89ad754cce3cfc8aee71760e10217b54020360dTripp L=Y.Lang,
a89ad754cce3cfc8aee71760e10217b54020360dTripp PREFIX = Y.guid('yui_');
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp/**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Fetches and inserts one or more script or link nodes into the document
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @class Get
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @static
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
c093c1aed867e18aa4778708592e1ceb45d18cffTrippY.Get = function() {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * hash of queues to manage multiple requests
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property queues
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var queues={},
c093c1aed867e18aa4778708592e1ceb45d18cffTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * queue index used to generate transaction ids
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property qidx
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp qidx=0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * node index used to generate unique node ids
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @property nidx
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp nidx=0,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * interal property used to prevent multiple simultaneous purge
a89ad754cce3cfc8aee71760e10217b54020360dTripp * processes
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @property purging
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @type boolean
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
c093c1aed867e18aa4778708592e1ceb45d18cffTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp purging=false,
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Generates an HTML element, this is not appended to a document
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param type {string} the type of element
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param attr {string} the attributes
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param win {Window} optional window to create the element in
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @return {HTMLElement} the generated node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp _node = function(type, attr, win) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var w = win || Y.config.win, d=w.document, n=d.createElement(type),
a89ad754cce3cfc8aee71760e10217b54020360dTripp i;
c093c1aed867e18aa4778708592e1ceb45d18cffTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp for (i in attr) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (attr[i] && attr.hasOwnProperty(i)) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp n.setAttribute(i, attr[i]);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp return n;
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Generates a link node
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _linkNode
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param url {string} the url for the css file
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param win {Window} optional window to create the node in
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @return {HTMLElement} the generated node
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @private
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
a89ad754cce3cfc8aee71760e10217b54020360dTripp _linkNode = function(url, win, charset) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp var c = charset || "utf-8";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return _node("link", {
a89ad754cce3cfc8aee71760e10217b54020360dTripp "id": PREFIX + (nidx++),
a89ad754cce3cfc8aee71760e10217b54020360dTripp "type": "text/css",
a89ad754cce3cfc8aee71760e10217b54020360dTripp "charset": c,
a89ad754cce3cfc8aee71760e10217b54020360dTripp "rel": "stylesheet",
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp "href": url
a89ad754cce3cfc8aee71760e10217b54020360dTripp }, win);
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Generates a script node
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @method _scriptNode
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @param url {string} the url for the script file
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param win {Window} optional window to create the node in
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @return {HTMLElement} the generated node
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @private
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp _scriptNode = function(url, win, charset) {
527cf651dc5df871799abd06cf589bca3f3a665fTripp var c = charset || "utf-8";
527cf651dc5df871799abd06cf589bca3f3a665fTripp return _node("script", {
527cf651dc5df871799abd06cf589bca3f3a665fTripp "id": PREFIX + (nidx++),
527cf651dc5df871799abd06cf589bca3f3a665fTripp "type": "text/javascript",
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp "charset": c,
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp "src": url
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp }, win);
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp },
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp /**
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * Removes the nodes for the specified queue
c093c1aed867e18aa4778708592e1ceb45d18cffTripp * @method _purge
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @private
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp _purge = function(tId) {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp var q=queues[tId], n, l, d, h, s, i;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp if (q) {
527cf651dc5df871799abd06cf589bca3f3a665fTripp n = q.nodes;
527cf651dc5df871799abd06cf589bca3f3a665fTripp l = n.length;
527cf651dc5df871799abd06cf589bca3f3a665fTripp d = q.win.document;
527cf651dc5df871799abd06cf589bca3f3a665fTripp h = d.getElementsByTagName("head")[0];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.insertBefore) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp s = _get(q.insertBefore, tId);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (s) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp h = s.parentNode;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c093c1aed867e18aa4778708592e1ceb45d18cffTripp for (i=0; i<l; i=i+1) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp h.removeChild(n[i]);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.nodes = [];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Returns the data payload for callback functions
bf801d6851ecf7ed14742ef3639a077daecb5cf8Tripp * @method _returnData
a4d2446149b07f9e5c32947091dcbcf4d2eee765Tripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c093c1aed867e18aa4778708592e1ceb45d18cffTripp _returnData = function(q, msg) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp tId: q.tId,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp win: q.win,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp data: q.data,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp nodes: q.nodes,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp msg: msg,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp purge: function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _purge(this.tId);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /*
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The request failed, execute fail handler with whatever
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * was accomplished. There isn't a failure case at the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * moment unless you count aborted transactions
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _fail
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param id {string} the id of the request
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c093c1aed867e18aa4778708592e1ceb45d18cffTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _fail = function(id, msg) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log("get failure: " + msg, "warn", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var q = queues[id], sc;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.timer) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.timer.cancel();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // execute failure callback
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.onFailure) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp sc = q.context || q;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.onFailure.call(sc, _returnData(q, msg));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _get = function(nId, tId) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var q = queues[tId],
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n = (L.isString(nId)) ? q.win.document.getElementById(nId) : nId;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (!n) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _fail(tId, "target node not found: " + nId);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c093c1aed867e18aa4778708592e1ceb45d18cffTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return n;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The request is complete, so executing the requester's callback
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _finish
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param id {string} the id of the request
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _finish = function(id) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log("Finishing transaction " + id, "info", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var q = queues[id], msg, sc;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.timer) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.timer.cancel();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp q.finished = true;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp if (q.aborted) {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp msg = "transaction " + id + " was aborted";
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _fail(id, msg);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c093c1aed867e18aa4778708592e1ceb45d18cffTripp // execute success callback
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.onSuccess) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp sc = q.context || q;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.onSuccess.call(sc, _returnData(q));
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Timeout detected
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @method _timeout
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @param id {string} the id of the request
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * @private
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp */
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp _timeout = function(id) {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp Y.log("Timeout " + id, "info", "get");
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp var q = queues[id], sc;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp if (q.onTimeout) {
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp sc = q.context || q;
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp q.onTimeout.call(sc, _returnData(q));
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp }
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp },
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp /**
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * Loads the next item for a given request
a75ebc38c1de401b679953a9b87bd323f0f48d02Tripp * @method _next
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param id {string} the id of the request
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param loaded {string} the url that was just loaded, if any
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @private
a89ad754cce3cfc8aee71760e10217b54020360dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _next = function(id, loaded) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp Y.log("_next: " + id + ", loaded: " + loaded, "info", "get");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
cec703a844d9691646231634fe709f4ea41d278aTripp var q = queues[id], msg, w, d, h, n, url, s;
cec703a844d9691646231634fe709f4ea41d278aTripp
cec703a844d9691646231634fe709f4ea41d278aTripp if (q.timer) {
cec703a844d9691646231634fe709f4ea41d278aTripp // Y.log('cancel timer');
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.timer.cancel();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.aborted) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp msg = "transaction " + id + " was aborted";
cec703a844d9691646231634fe709f4ea41d278aTripp _fail(id, msg);
cec703a844d9691646231634fe709f4ea41d278aTripp return;
cec703a844d9691646231634fe709f4ea41d278aTripp }
cec703a844d9691646231634fe709f4ea41d278aTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (loaded) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.url.shift();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (q.varName) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.varName.shift();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // This is the first pass: make sure the url is an array
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp q.url = (L.isString(q.url)) ? [q.url] : q.url;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (q.varName) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp q.varName = (L.isString(q.varName)) ? [q.varName] : q.varName;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp w = q.win;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp d = w.document;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h = d.getElementsByTagName("head")[0];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (q.url.length === 0) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _finish(id);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp url = q.url[0];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // if the url is undefined, this is probably a trailing comma problem in IE
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (!url) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q.url.shift();
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log('skipping empty url');
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp return _next(id);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log("attempting to load " + url, "info", "get");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (q.timeout) {
a89ad754cce3cfc8aee71760e10217b54020360dTripp // Y.log('create timer');
a89ad754cce3cfc8aee71760e10217b54020360dTripp q.timer = L.later(q.timeout, q, _timeout, id);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (q.type === "script") {
a89ad754cce3cfc8aee71760e10217b54020360dTripp n = _scriptNode(url, w, q.charset);
a89ad754cce3cfc8aee71760e10217b54020360dTripp } else {
a89ad754cce3cfc8aee71760e10217b54020360dTripp n = _linkNode(url, w, q.charset);
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // track this node's load progress
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _track(q.type, n, id, url, w, q.url.length);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // add the node to the queue so we can return it to the user supplied callback
a89ad754cce3cfc8aee71760e10217b54020360dTripp q.nodes.push(n);
a89ad754cce3cfc8aee71760e10217b54020360dTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // add it to the head or insert it before 'insertBefore'
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (q.insertBefore) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp s = _get(q.insertBefore, id);
a89ad754cce3cfc8aee71760e10217b54020360dTripp if (s) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp s.parentNode.insertBefore(n, s);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp } else {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp h.appendChild(n);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp Y.log("Appending node: " + url, "info", "get");
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // FireFox does not support the onload event for link nodes, so there is
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // no way to make the css requests synchronous. This means that the css
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // rules in multiple files could be applied out of order in this browser
a89ad754cce3cfc8aee71760e10217b54020360dTripp // if a later request returns before an earlier one. Safari too.
a89ad754cce3cfc8aee71760e10217b54020360dTripp if ((ua.webkit || ua.gecko) && q.type === "css") {
a89ad754cce3cfc8aee71760e10217b54020360dTripp _next(id, url);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Removes processed queues and corresponding nodes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @method _autoPurge
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _autoPurge = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (purging) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp purging = true;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var i, q;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp for (i in queues) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (queues.hasOwnProperty(i)) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp q = queues[i];
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (q.autopurge && q.finished) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _purge(q.tId);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp delete queues[i];
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp }
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp purging = false;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp },
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Saves the state for the request and begins loading
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * the requested urls
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @method queue
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param type {string} the type of node to insert
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param url {string} the url to load
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param opts the hash of options for this request
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _queue = function(type, url, opts) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp opts = opts || {};
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp var id = "q" + (qidx++), q,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp thresh = opts.purgethreshold || Y.Get.PURGE_THRESH;
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp if (qidx % thresh === 0) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp _autoPurge();
a89ad754cce3cfc8aee71760e10217b54020360dTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp queues[id] = Y.merge(opts, {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp tId: id,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp type: type,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp url: url,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp finished: false,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp nodes: []
a89ad754cce3cfc8aee71760e10217b54020360dTripp });
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp q = queues[id];
a89ad754cce3cfc8aee71760e10217b54020360dTripp q.win = q.win || Y.config.win;
a89ad754cce3cfc8aee71760e10217b54020360dTripp q.context = q.context || q;
a89ad754cce3cfc8aee71760e10217b54020360dTripp q.autopurge = ("autopurge" in q) ? q.autopurge :
a89ad754cce3cfc8aee71760e10217b54020360dTripp (type === "script") ? true : false;
66ca16dd76367c074fe4df1dcf7b555489a9bf85Tripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp L.later(0, q, _next, id);
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp return {
a89ad754cce3cfc8aee71760e10217b54020360dTripp tId: id
a89ad754cce3cfc8aee71760e10217b54020360dTripp };
a89ad754cce3cfc8aee71760e10217b54020360dTripp },
a89ad754cce3cfc8aee71760e10217b54020360dTripp
a89ad754cce3cfc8aee71760e10217b54020360dTripp /**
a89ad754cce3cfc8aee71760e10217b54020360dTripp * Detects when a node has been loaded. In the case of
a89ad754cce3cfc8aee71760e10217b54020360dTripp * script nodes, this does not guarantee that contained
a89ad754cce3cfc8aee71760e10217b54020360dTripp * script is ready to use.
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @method _track
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param type {string} the type of node to track
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param n {HTMLElement} the node to track
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param id {string} the id of the request
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param url {string} the url that is being loaded
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @param win {Window} the targeted window
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param qlength the number of remaining items in the queue,
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * including this one
a89ad754cce3cfc8aee71760e10217b54020360dTripp * @param trackfn {Function} function to execute when finished
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * the default is _next
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * @private
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _track = function(type, n, id, url, win, qlength, trackfn) {
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp var f = trackfn || _next;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // IE supports the readystatechange event for script and css nodes
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Opera only for script nodes. Opera support onload for script
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp // nodes, but this doesn't fire when there is a load failure.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // The onreadystatechange appears to be a better way to respond
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // to both success and failure.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (ua.ie) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n.onreadystatechange = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp var rs = this.readyState;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if ("loaded" === rs || "complete" === rs) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log(id + " onreadstatechange " + url, "info", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n.onreadystatechange = null;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f(id, url);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // webkit prior to 3.x is no longer supported
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else if (ua.webkit) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp if (type === "script") {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // Safari 3.x supports the load event for script nodes (DOM2)
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n.addEventListener("load", function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log(id + " DOM2 onload " + url, "info", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f(id, url);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp });
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // FireFox and Opera support onload (but not DOM2 in FF) handlers for
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // script nodes. Opera, but not FF, supports the onload event for link
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp // nodes.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp } else {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp n.onload = function() {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log(id + " onload " + url, "info", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp f(id, url);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp n.onerror = function(e) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _fail(id, e + ": " + url);
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The number of request required before an automatic purge.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * property PURGE_THRESH
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @type int
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @default 20
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp PURGE_THRESH: 20,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Called by the the helper for detecting script load in Safari
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method _finalize
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param id {string} the transaction id
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @private
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp _finalize: function(id) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp Y.log(id + " finalized ", "info", "get");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp L.later(0, null, _finish, id);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Abort a transaction
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method abort
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @static
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @param o {string|object} Either the tId or the object returned from
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * script() or css()
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp */
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp abort: function(o) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp var id = (L.isString(o)) ? o : o.tId,
cec703a844d9691646231634fe709f4ea41d278aTripp q = queues[id];
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp if (q) {
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp Y.log("Aborting " + id, "info", "get");
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp q.aborted = true;
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp }
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp },
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp /**
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * Fetches and inserts one or more script nodes into the head
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * of the current document or the document in a specified window.
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp *
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @method script
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @static
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @param url {string|string[]} the url or urls to the script(s)
6c4ec9d420df654d019b936fd06bef6f769db4cbTripp * @param opts {object} Options:
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dl>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>onSuccess</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * callback to execute when the script(s) are finished loading
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * The callback receives an object back with the following
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * data:
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>win</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>the window the script(s) were inserted into</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>data</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>the data object passed in when the request was made</dd>
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp * <dt>nodes</dt>
bbd1285cbb2183b7f89010412ad97ae1680b4b5eTripp * <dd>An array containing references to the nodes that were
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * inserted</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>purge</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>A function that, when executed, will remove the nodes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * that were inserted</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>onTimeout</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * callback to execute when a timeout occurs.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * The callback receives an object back with the following
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * data:
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>win</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>the window the script(s) were inserted into</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>data</dt>
9eaaa502227248d304ac9170902697d02158c1d9Tripp * <dd>the data object passed in when the request was made</dd>
9eaaa502227248d304ac9170902697d02158c1d9Tripp * <dt>nodes</dt>
9eaaa502227248d304ac9170902697d02158c1d9Tripp * <dd>An array containing references to the nodes that were
9eaaa502227248d304ac9170902697d02158c1d9Tripp * inserted</dd>
9eaaa502227248d304ac9170902697d02158c1d9Tripp * <dt>purge</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>A function that, when executed, will remove the nodes
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * that were inserted</dd>
4ef2f7e4cb7c7d255be077c47d542199f7bf8607Tripp * <dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>onFailure</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * callback to execute when the script load operation fails
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The callback receives an object back with the following
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * data:
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dl>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>win</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>the window the script(s) were inserted into</dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>data</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>the data object passed in when the request was made</dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>nodes</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>An array containing references to the nodes that were
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * inserted successfully</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>purge</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>A function that, when executed, will remove any nodes
b79c07ef87dd1a48a03fc33a91c37d04f3addae2Tripp * that were inserted</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dl>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>context</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>the execution context for the callbacks</dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>win</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>a window other than the one the utility occupies</dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>autopurge</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * setting to true will let the utilities cleanup routine purge
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * the script once loaded
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>purgethreshold</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The number of transaction before autopurge should be initiated
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>data</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * data that is supplied to the callback when the script(s) are
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * loaded.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>insertBefore</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>node or node id that will become the new node's nextSibling</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </dl>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>charset</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>Node charset, default utf-8</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>timeout</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>Number of milliseconds to wait before aborting and firing the timeout event</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;Y.Get.script(
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;["http://yui.yahooapis.com/2.5.2/build/yahoo/yahoo-min.js",
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.5.2/build/event/event-min.js"], &#123;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;&nbsp;&nbsp;onSuccess: function(o) &#123;
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.log("won't cause error because Y is the context");
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log(o.data); // foo
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log(o.nodes.length === 2) // true
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// o.purge(); // optionally remove the script nodes immediately
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,
0fdefaa9ca017edfb76b736c825b34186f33045aTripp * &nbsp;&nbsp;&nbsp;&nbsp;onFailure: function(o) &#123;
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log("transaction failed");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;onTimeout: function(o) &#123;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Y.log("transaction timed out");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;&#125;,
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;data: "foo",
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;timeout: 10000, // 10 second timeout
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;context: Y, // make the YUI instance
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;// win: otherframe // target another window/frame
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;autopurge: true // allow the utility to choose when to remove the nodes
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;purgetheshold: 1 // purge previous transaction before next transaction
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&#125;);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {tId: string} an object containing info about the transaction
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp script: function(url, opts) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return _queue("script", url, opts);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp },
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp /**
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * Fetches and inserts one or more css link nodes into the
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * head of the current document or the document in a specified
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * window.
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @method css
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @static
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param url {string} the url or urls to the css file(s)
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * @param opts Options:
e0caea9528bfbb244d27129aa9dea5aebc07fc18Tripp * <dl>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dt>onSuccess</dt>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * <dd>
b57ff76ab2ce5f3017d61855f13ed04ab46a965cTripp * callback to execute when the css file(s) are finished loading
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * The callback receives an object back with the following
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * data:
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dl>win</dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>the window the link nodes(s) were inserted into</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>data</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>the data object passed in when the request was made</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>nodes</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>An array containing references to the nodes that were
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * inserted</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>purge</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>A function that, when executed, will remove the nodes
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * that were inserted</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>context</dt>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dd>the execution context for the callbacks</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <dt>win</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>a window other than the one the utility occupies</dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dt>data</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * data that is supplied to the callbacks when the nodes(s) are
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * loaded.
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dd>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dt>insertBefore</dt>
a89ad754cce3cfc8aee71760e10217b54020360dTripp * <dd>node or node id that will become the new node's nextSibling</dd>
7947db4b7d8682ea81598e3a4283e659a8103be6Tripp * <dt>charset</dt>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * <dd>Node charset, default utf-8</dd>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * </dl>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * Y.Get.css("http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css");
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </pre>
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * <pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;Y.Get.css(
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;["http://yui.yahooapis.com/2.3.1/build/menu/assets/skins/sam/menu.css",
09688ec5ffb8b9cf9883a770e2f9ebd60b28888dTripp * &nbsp;&nbsp;&nbsp;"http://yui.yahooapis.com/2.3.1/build/logger/assets/skins/sam/logger.css"], &#123;
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&nbsp;&nbsp;insertBefore: 'custom-styles' // nodes will be inserted before the specified node
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * &nbsp;&nbsp;&#125;);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * </pre>
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp * @return {tId: string} an object containing info about the transaction
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp */
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp css: function(url, opts) {
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp return _queue("css", url, opts);
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp }
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp };
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp}();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp})();
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp}, '@VERSION@' );
c7ba96d16d58075a9ab8d5c1e46c6c83ce11cb4eTripp