Script Inner INI
by sanford
HTML
<!--
Demonstrating three different experiments:
[1] grabbing an inline event handler's text and turning it back into a Function (you can't run this.onreadystatechange() when it is assigned as inline code, but you can read the code into a Function and then run that)
[2] storing the configuration for a script in a loose INI-style format stored inside the <script> tag itself (content is allowed inside a script tag that has a remote src=). Weird as it seems this was inspired and U gyess legitimized by the LinkedIn API, which expects the same thing. I guess the idea is not *just* to be cool but to allow non-devs to enter info into what is basically a code block without being so precise about formatting. Actually, the LinkedIn version is colon-delimited (so it's like the inside of a JS object). I decided to go with the equals sign to make it look sufficiently different but of course will become a JS object after parsin. Much of the work involved making sure the user could put as much or as little whitespace as they wanted (partic. CRLF) to and neatly massaging all that away.
TODO: allow the user to enter proper JSON instead -- so basically try to parse the raw innerHTML as JSON, and only if it doesn't work, expect they used INI format and try to parse again.
NOTE: whitespace can only be included if user enters real JSON.
[3] getting a handle to the current (synchronous) script by simply chcecking for the last SCRIPT tag in the DOM. As the DOM should not be fake-completed at that point, per spec, you should know what script you're in -- and therefore be able to read the inner INI as in [2] above. All ITW browsers as of 4/2015 are cool with it!
-->
<script>
function whenReady(el,e) {
el.setAttribute('data-load-state','loaded');
new Function(el.getAttribute("onreadystatechange")).apply(el,[e]);
}
</script>
<script
id = "MultiMunch"
onload = "whenReady(this,arguments[0]);"
onreadystatechange='
// debugger;
if...