public
Last active

Genuinely Unobtrusive Javascript

  • Download Gist
meek.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
(function(scope) {
function destroyAutoGlobals(options) {
var allElements = document.getElementsByTagName("*"), elementId;
for (var i=allElements.length; i--; ) {
elementId = allElements[i].id;
if (elementId && window[elementId] instanceof HTMLElement) {
options && options.verbose && console.log('Destroying window["' + elementId + '"]');
window[elementId] = null;
}
}
}
function guid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
return v.toString(16);
});
}
function load(scripts) {
var runLast = scripts.pop(),
runBefore = scripts.length;
for (var i=runBefore; i--; ) {
appendScript(scripts[i]);
}
function appendScript(scriptSrc) {
var scriptEl = document.createElement('script')
scriptEl.src = scriptSrc;
scriptEl.async = true;
scriptEl.onload = function() {
if (!--runBefore) {
appendScript(runLast);
}
};
document.head.appendChild(scriptEl);
}
}
var MEEK = scope.MEEK = scope.MEEK || {
appId: (function() {
var appId;
return function() {
return appId || (function() {
appId = guid();
return appId;
})();
}
})(),
destroyAutoGlobals: destroyAutoGlobals,
guid: guid,
load: load
};
})(this);
 
(function(){
/*
* <script src="http://jsfiddle.net/dexygen/vFseA/show_js/">
* <script src="http://jsfiddle.net/dexygen/APERM/show_js/">
* <script src="http://jsfiddle.net/dexygen/7G8pX/show_js">
*
* The above (with closing script tags of course) will run EXACTLY THE SAME as the following
*/
var scripts = [
'http://jsfiddle.net/dexygen/vFseA/show_js/',
'http://jsfiddle.net/dexygen/APERM/show_js/',
'http://jsfiddle.net/dexygen/7G8pX/show_js/' //runs code loaded in previous scripts
];
MEEK.load(scripts);
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.