Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Added smt2e missing scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
luis.leiva.torres committed Nov 1, 2013
1 parent 98c8462 commit e67835c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/js/smt2e.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* smt2e -- simple mouse tracking
* Copyleft (cc) 2012 Luis Leiva
* http://smt2.googlecode.com & http://smt.speedzinemedia.com
*/
(function(){var b=document.getElementsByTagName("script");var h=b[b.length-1].src;var e=h.split("/");e.splice(e.length-1,1);var g=e.join("/");var d=e[e.length-1]=="src"?".js":".min.js";var f=["smt-aux","smt-record"];for(var c=0;c<f.length;++c){var a=document.createElement("script");a.src=g+"/"+f[c]+d;document.body.appendChild(a)}})();
47 changes: 47 additions & 0 deletions core/js/src/smt2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
* smt2e -- simple mouse tracking
* Copyleft (cc) 2012 Luis Leiva
* http://smt2.googlecode.com & http://smt.speedzinemedia.com
*/
(function(){

// Delay recording function until smt2 libs are fully loaded
var smt2cache;
window.smt2 = {
record: function(opts) {
smt2cache = function() { window.smt2.record(opts); }
}
}

function createScript(filepath) {
var scriptElem = document.createElement('script');
scriptElem.type = "text/javascript";
scriptElem.src = filepath;
return scriptElem;
}

// Grab path of currently executing script
var scripts = document.getElementsByTagName('script');
var currentScript = scripts[scripts.length - 1];
// Remove filename
var pathParts = currentScript.src.split("/");
pathParts.splice(pathParts.length - 1, 1);
// Now we have the full script path
var path = pathParts.join("/");
// Load smt2 libs accordingly: first aux functions, then record
var ext = pathParts[pathParts.length - 1] == "src" ? ".js" : ".min.js";
var aux = createScript(path + "/" + "smt-aux" + ext);
currentScript.parentNode.insertBefore(aux, currentScript.nextSibling);
aux.onload = function() {
var record = createScript(path + "/" + "smt-record" + ext);
currentScript.parentNode.insertBefore(record, aux.nextSibling);
record.onload = function() {
smt2cache();
// DOM is already loaded, so make this explicit fn call
smt2.methods.init();
}
// Finally remove loader script
currentScript.parentNode.removeChild(currentScript);
}

})();

0 comments on commit e67835c

Please sign in to comment.