Created
March 25, 2011 02:05
-
-
Save arextar/886235 to your computer and use it in GitHub Desktop.
Modules in commented blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*+Module:Alert | |
alert("this script is loaded but not executed until later called(can be multiple times)") | |
*/ | |
Module("Alert") | |
Module("Alert") | |
/*-Module:RunOnce | |
alert("this code will only run once") | |
*/ | |
Module("RunOnce") | |
Module("RunOnce") | |
/*+Module:WithData(module) | |
alert("This module uses data! "+module.data.message) | |
*/ | |
Module("WithData",{ | |
message:"Hola!" | |
}) | |
Module("WithData",{ | |
message:"Bonjour!" | |
}) | |
/*!Module:CommentedOut | |
alert("this code will not run") | |
*/ | |
Module("CommentedOut") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
var executed = {} | |
this.Module = function (name, data) { | |
var w = String.fromCharCode(9000), | |
t = document.documentElement.innerHTML.replace(/\*\//g, w), | |
a = new RegExp("/\\*\\n?(\\-|\\+)Module:" + name + "\\(?([^\\)]+)?\\)?([^" + w + "]+)" + w).exec(t) | |
if (a && (a[1] != "-" || !executed[name])) { | |
arguments.callee[name] = { | |
name: name, | |
data: d, | |
run:a[1] | |
} | |
var d = document.createElement("script"); | |
d.innerHTML = d.text = "(function(" + a[2] + "){" + a[3] + "})(Module['" + name + "']);"; | |
document.getElementsByTagName("script")[0].parentNode.appendChild(d); | |
d.parentNode.removeChild(d); | |
executed[name] = true | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment