mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Tweaks to format of JavaScript modules
Particularly, we're now picking the module fields out of the script tag, rather than from the comment at the top of the module. This will allow us to minify modules safely (otherwise we'd lose the metadata fields)
This commit is contained in:
parent
6ad2886013
commit
b81fdd9ced
@ -389,7 +389,7 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/js","t
|
||||
match = headerCommentRegExp.exec(text);
|
||||
fields.text = text;
|
||||
if(match) {
|
||||
fields = $tw.utils.parseFields(match[1],fields);
|
||||
fields = $tw.utils.parseFields(match[1].split("\n\n")[0],fields);
|
||||
}
|
||||
return [fields];
|
||||
}
|
||||
@ -473,11 +473,16 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom","
|
||||
var text = node.innerHTML,
|
||||
s = text.indexOf("{"),
|
||||
e = text.lastIndexOf("}");
|
||||
if(s !== -1 && e !== -1) {
|
||||
if(node.hasAttribute("data-module") && s !== -1 && e !== -1) {
|
||||
text = text.substring(s+1,e-1);
|
||||
}
|
||||
var fields = $tw.wiki.deserializeTiddlers("application/javascript",text)[0];
|
||||
fields.title = node.getAttribute("data-tiddler-title");
|
||||
var fields = {text: text},
|
||||
attributes = node.attributes;
|
||||
for(var a=0; a<attributes.length; a++) {
|
||||
if(attributes[a].nodeName.substr(0,13) === "data-tiddler-") {
|
||||
fields[attributes[a].nodeName.substr(13)] = attributes[a].nodeValue;
|
||||
}
|
||||
}
|
||||
return fields;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -21,14 +21,37 @@ exports["text/html"] = function(tiddler) {
|
||||
return text ? text : "";
|
||||
};
|
||||
|
||||
exports["application/javascript"] = function(tiddler) {
|
||||
var attributes = {type: "text/javascript"}; // The script type is set to text/javascript for compatibility with old browsers
|
||||
for(var f in tiddler.fields) {
|
||||
if(f !== "text") {
|
||||
attributes["data-tiddler-" + f] = tiddler.getFieldString(f);
|
||||
}
|
||||
}
|
||||
return $tw.Tree.Element(
|
||||
"script",
|
||||
attributes,
|
||||
[$tw.Tree.Raw(tiddler.fields.text)]
|
||||
).render("text/html");
|
||||
};
|
||||
|
||||
exports["application/x-tiddler-module"] = function(tiddler) {
|
||||
var result = [];
|
||||
result.push("<" + "script type=\"text/javascript\" data-tiddler-title=\"" + tiddler.fields.title + "\">\n");
|
||||
result.push("$tw.modules.define(\"" + tiddler.fields.title + "\",\"" + tiddler.fields["module-type"] + "\",function(module,exports,require) {");
|
||||
result.push(tiddler.fields.text);
|
||||
result.push("});\n");
|
||||
result.push("</" + "script>");
|
||||
return result.join("");
|
||||
var attributes = {
|
||||
type: "text/javascript",
|
||||
"data-module": "yes"
|
||||
}, // The script type is set to text/javascript for compatibility with old browsers
|
||||
text = tiddler.fields.text;
|
||||
text = "$tw.modules.define(\"" + tiddler.fields.title + "\",\"" + tiddler.fields["module-type"] + "\",function(module,exports,require) {" + text + "});\n";
|
||||
for(var f in tiddler.fields) {
|
||||
if(f !== "text") {
|
||||
attributes["data-tiddler-" + f] = tiddler.getFieldString(f);
|
||||
}
|
||||
}
|
||||
return $tw.Tree.Element(
|
||||
"script",
|
||||
attributes,
|
||||
[$tw.Tree.Raw(text)]
|
||||
).render("text/html");
|
||||
};
|
||||
|
||||
exports["application/x-tiddler-html-div"] = function(tiddler) {
|
||||
|
@ -36,16 +36,12 @@ type: text/x-tiddlywiki-html
|
||||
<<^"[is[tiddler]]" application/x-tiddler-html-div>>
|
||||
</div>
|
||||
<!----------- Boot kernel prologue ----------->
|
||||
<script id="jsBootStartArea" type="text/javascript">
|
||||
<<^"$:/core/bootprefix.js" text/plain>>
|
||||
</script>
|
||||
<<^"$:/core/bootprefix.js" application/javascript>>
|
||||
<!----------- Plugin modules ----------->
|
||||
<div id="pluginModules" style="display:none;">
|
||||
<<^"[is[shadowModule]]" application/x-tiddler-module>>
|
||||
</div>
|
||||
<!----------- Boot kernel ----------->
|
||||
<script id="jsBootEndArea" type="text/javascript">
|
||||
<<^"$:/core/boot.js" text/plain>>
|
||||
</script>
|
||||
<<^"$:/core/boot.js" application/javascript>>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user