Skip to content

Commit

Permalink
YUI & Loader build
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Nov 29, 2011
1 parent 3ac2043 commit 9bcccaf
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 2,535 deletions.
323 changes: 3 additions & 320 deletions build/loader-base/loader-base-debug.js
Expand Up @@ -2121,59 +2121,6 @@ Y.log('Undefined module: ' + mname + ', matched a pattern: ' +
onSuccess: complete
});
}


/*
this.loadType = type;
if (!type) {
var self = this;
// Y.log("trying to load css first");
this._internalCallback = function() {
var f = self.onCSS, n, p, sib;
// IE hack for style overrides that are not being applied
if (this.insertBefore && Y.UA.ie) {
n = Y.config.doc.getElementById(this.insertBefore);
p = n.parentNode;
sib = n.nextSibling;
p.removeChild(n);
if (sib) {
p.insertBefore(n, sib);
} else {
p.appendChild(n);
}
}
if (f) {
f.call(self.context, Y);
}
self._internalCallback = null;
self._insert(null, null, JS);
};
this._insert(null, null, CSS);
return;
}
// set a flag to indicate the load has started
this._loading = true;
// flag to indicate we are done with the combo service
// and any additional files will need to be loaded
// individually
this._combineComplete = {};
// start the load
this.loadNext();
*/

},
/**
* Once a loader operation is completely finished, process any additional queued items.
Expand Down Expand Up @@ -2213,278 +2160,14 @@ Y.log('Undefined module: ' + mname + ', matched a pattern: ' +
* is possible to call this if using a method other than
* Y.register to determine when scripts are fully loaded
* @method loadNext
* @deprecated
* @param {string} mname optional the name of the module that has
* been loaded (which is usually why it is time to load the next
* one).
*/
loadNext: function(mname) {
Y.log('loadNext was called..', 'warn', 'loader');
// It is possible that this function is executed due to something
// else on the page loading a YUI module. Only react when we
// are actively loading something
if (!this._loading) {
return;
}

var s, len, i, m, url, fn, msg, attr, group, groupName, j, frag,
comboSource, comboSources, mods, combining, urls, comboBase,
self = this,
type = self.loadType,
handleSuccess = function(o) {
self.loadNext(o.data);
},
handleCombo = function(o) {
self._combineComplete[type] = true;
var i, len = combining.length;

for (i = 0; i < len; i++) {
self.inserted[combining[i]] = true;
}

handleSuccess(o);
};

if (self.combine && (!self._combineComplete[type])) {

combining = [];

self._combining = combining;
s = self.sorted;
len = s.length;

// the default combo base
comboBase = self.comboBase;

url = comboBase;
urls = [];

comboSources = {};

for (i = 0; i < len; i++) {
comboSource = comboBase;
m = self.getModule(s[i]);
groupName = m && m.group;
if (groupName) {

group = self.groups[groupName];

if (!group.combine) {
m.combine = false;
continue;
}
m.combine = true;
if (group.comboBase) {
comboSource = group.comboBase;
}

if ("root" in group && L.isValue(group.root)) {
m.root = group.root;
}

}

comboSources[comboSource] = comboSources[comboSource] || [];
comboSources[comboSource].push(m);
}

for (j in comboSources) {
if (comboSources.hasOwnProperty(j)) {
url = j;
mods = comboSources[j];
len = mods.length;

for (i = 0; i < len; i++) {
// m = self.getModule(s[i]);
m = mods[i];

// Do not try to combine non-yui JS unless combo def
// is found
if (m && (m.type === type) && (m.combine || !m.ext)) {

frag = ((L.isValue(m.root)) ? m.root : self.root) + m.path;
frag = self._filter(frag, m.name);
if ((url !== j) && (i <= (len - 1)) &&
((frag.length + url.length) > self.maxURLLength)) {
//Hack until this is rewritten to use an array and not string concat:
if (url.substr(url.length - 1, 1) === self.comboSep) {
url = url.substr(0, (url.length - 1));
}
urls.push(self._filter(url));
url = j;
}

url += frag;
if (i < (len - 1)) {
url += self.comboSep;
}

combining.push(m.name);
}

}

if (combining.length && (url != j)) {
//Hack until this is rewritten to use an array and not string concat:
if (url.substr(url.length - 1, 1) === self.comboSep) {
url = url.substr(0, (url.length - 1));
}
urls.push(self._filter(url));
}
}
}

if (combining.length) {

Y.log('Attempting to use combo: ' + combining, 'info', 'loader');

// if (m.type === CSS) {
if (type === CSS) {
fn = Y.Get.css;
attr = self.cssAttributes;
} else {
fn = Y.Get.script;
attr = self.jsAttributes;
}

fn(urls, {
data: self._loading,
onSuccess: handleCombo,
onFailure: self._onFailure,
onTimeout: self._onTimeout,
insertBefore: self.insertBefore,
charset: self.charset,
attributes: attr,
timeout: self.timeout,
autopurge: false,
context: self
});

return;

} else {
self._combineComplete[type] = true;
}
}

if (mname) {

// if the module that was just loaded isn't what we were expecting,
// continue to wait
if (mname !== self._loading) {
return;
}

// Y.log("loadNext executing, just loaded " + mname + ", " +
// Y.id, "info", "loader");

// The global handler that is called when each module is loaded
// will pass that module name to this function. Storing this
// data to avoid loading the same module multiple times
// centralize this in the callback
self.inserted[mname] = true;
// self.loaded[mname] = true;

// provided = self.getProvides(mname);
// Y.mix(self.loaded, provided);
// Y.mix(self.inserted, provided);

if (self.onProgress) {
self.onProgress.call(self.context, {
name: mname,
data: self.data
});
}
}

s = self.sorted;
len = s.length;

for (i = 0; i < len; i = i + 1) {
// this.inserted keeps track of what the loader has loaded.
// move on if this item is done.
if (s[i] in self.inserted) {
continue;
}

// Because rollups will cause multiple load notifications
// from Y, loadNext may be called multiple times for
// the same module when loading a rollup. We can safely
// skip the subsequent requests
if (s[i] === self._loading) {
Y.log('still loading ' + s[i] + ', waiting', 'info', 'loader');
return;
}

// log("inserting " + s[i]);
m = self.getModule(s[i]);

if (!m) {
if (!self.skipped[s[i]]) {
msg = 'Undefined module ' + s[i] + ' skipped';
Y.log(msg, 'warn', 'loader');
// self.inserted[s[i]] = true;
self.skipped[s[i]] = true;
}
continue;

}

group = (m.group && self.groups[m.group]) || NOT_FOUND;

// The load type is stored to offer the possibility to load
// the css separately from the script.
if (!type || type === m.type) {
self._loading = s[i];
Y.log('attempting to load ' + s[i] + ', ' + self.base, 'info', 'loader');

if (m.type === CSS) {
fn = Y.Get.css;
attr = self.cssAttributes;
if (m.cssAttributes) {
attr = Y.mix(attr || {}, m.cssAttributes);
}
} else {
fn = Y.Get.script;
attr = self.jsAttributes;
if (m.jsAttributes) {
attr = Y.mix(attr || {}, m.jsAttributes);
}
}

url = (m.fullpath) ? self._filter(m.fullpath, s[i]) :
self._url(m.path, s[i], group.base || m.base);

fn(url, {
data: s[i],
onSuccess: handleSuccess,
insertBefore: self.insertBefore,
charset: self.charset,
attributes: attr,
onFailure: self._onFailure,
onTimeout: self._onTimeout,
timeout: self.timeout,
autopurge: false,
context: self
});

return;
}
}

// we are finished
self._loading = null;

fn = self._internalCallback;

// internal callback for loading css first
if (fn) {
// Y.log('loader internal');
self._internalCallback = null;
fn.call(self);
} else {
// Y.log('loader complete');
self._onSuccess();
}
Y.log('loadNext was called..', 'error', 'loader');
return;
},

/**
Expand Down

0 comments on commit 9bcccaf

Please sign in to comment.