Commit bee04095 by cahrens

Fix eslint violations.

parent b8ddf709
// Generated by CoffeeScript 1.6.1 (function() {
(function () { 'use strict';
this.JavascriptLoader = (function() {
this.JavascriptLoader = (function () {
function JavascriptLoader() { function JavascriptLoader() {
} }
JavascriptLoader.executeModuleScripts = function (el, callback) { /**
var callbackCalled, completed, completionHandlerGenerator, completionHandlerGeneratorIE, i, loaded, placeholders, * Set of library functions that provide common interface for javascript loading
_this = this; * for all module types. All functionality provided by JavascriptLoader should take
if (callback == null) { * place at module scope, i.e. don't run jQuery over entire page.
callback = null; *
* executeModuleScripts:
* Scan the module ('el') for "script_placeholder"s, then:
*
* 1) Fetch each script from server
* 2) Explicitly attach the script to the <head> of document
* 3) Explicitly wait for each script to be loaded
* 4) Return to callback function when all scripts loaded
*/
JavascriptLoader.executeModuleScripts = function(el, callback) {
var callbackCalled, completed, completionHandlerGenerator, loaded, placeholders;
if (!callback) {
callback = null; // eslint-disable-line no-param-reassign
} }
placeholders = el.find(".script_placeholder"); placeholders = el.find('.script_placeholder');
if (placeholders.length === 0) { if (placeholders.length === 0) {
if (callback != null) { if (callback !== null) {
callback(); callback();
} }
return; return [];
} }
completed = (function () { // TODO: Verify the execution order of multiple placeholders
var _i, _ref, _results; completed = (function() {
_results = []; var i, ref, results;
for (i = _i = 1, _ref = placeholders.length; 1 <= _ref ? _i <= _ref : _i >= _ref; i = 1 <= _ref ? ++_i : --_i) { results = [];
_results.push(false); for (i = 1, ref = placeholders.length; ref >= 1 ? i <= ref : i >= ref; ref >= 1 ? ++i : --i) {
results.push(false);
} }
return _results; return results;
})(); }());
callbackCalled = false; callbackCalled = false;
completionHandlerGeneratorIE = function (index) { completionHandlerGenerator = function(index) {
return function () { return function() {
if (this.readyState === 'complete' || this.readyState === 'loaded') { var allComplete, flag, i, len;
return completionHandlerGenerator(index)();
}
};
};
completionHandlerGenerator = function (index) {
return function () {
var allComplete, flag, _i, _len;
allComplete = true; allComplete = true;
completed[index] = true; completed[index] = true;
for (_i = 0, _len = completed.length; _i < _len; _i++) { for (i = 0, len = completed.length; i < len; i++) {
flag = completed[_i]; flag = completed[i];
if (!flag) { if (!flag) {
allComplete = false; allComplete = false;
break; break;
...@@ -49,25 +53,31 @@ ...@@ -49,25 +53,31 @@
} }
if (allComplete && !callbackCalled) { if (allComplete && !callbackCalled) {
callbackCalled = true; callbackCalled = true;
if (callback != null) { if (callback !== null) {
return callback(); return callback();
} }
} }
return undefined;
}; };
}; };
// Keep a map of what sources we're loaded from, and don't do it twice.
loaded = {}; loaded = {};
return placeholders.each(function (index, placeholder) { return placeholders.each(function(index, placeholder) {
var s, src; var s, src;
src = $(placeholder).attr("data-src"); // TODO: Check if the script already exists in DOM. If so, (1) copy it
// into memory; (2) delete the DOM script element; (3) reappend it.
// This would prevent memory bloat and save a network request.
src = $(placeholder).attr('data-src');
if (!(src in loaded)) { if (!(src in loaded)) {
loaded[src] = true; loaded[src] = true;
s = document.createElement('script'); s = document.createElement('script');
s.setAttribute('src', src); s.setAttribute('src', src);
s.setAttribute('type', "text/javascript"); s.setAttribute('type', 'text/javascript');
s.onload = completionHandlerGenerator(index); s.onload = completionHandlerGenerator(index);
s.onreadystatechange = completionHandlerGeneratorIE(index); // Need to use the DOM elements directly or the scripts won't execute properly.
$('head')[0].appendChild(s); $('head')[0].appendChild(s);
} else { } else {
// just call the completion callback directly, without reloading the file
completionHandlerGenerator(index)(); completionHandlerGenerator(index)();
} }
return $(placeholder).remove(); return $(placeholder).remove();
...@@ -75,7 +85,5 @@ ...@@ -75,7 +85,5 @@
}; };
return JavascriptLoader; return JavascriptLoader;
}());
})();
}).call(this); }).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment