mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-06 08:34:08 +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);
|
match = headerCommentRegExp.exec(text);
|
||||||
fields.text = text;
|
fields.text = text;
|
||||||
if(match) {
|
if(match) {
|
||||||
fields = $tw.utils.parseFields(match[1],fields);
|
fields = $tw.utils.parseFields(match[1].split("\n\n")[0],fields);
|
||||||
}
|
}
|
||||||
return [fields];
|
return [fields];
|
||||||
}
|
}
|
||||||
@ -473,11 +473,16 @@ $tw.plugins.registerPlugin($tw.config.root + "/kernel/tiddlerdeserializer/dom","
|
|||||||
var text = node.innerHTML,
|
var text = node.innerHTML,
|
||||||
s = text.indexOf("{"),
|
s = text.indexOf("{"),
|
||||||
e = text.lastIndexOf("}");
|
e = text.lastIndexOf("}");
|
||||||
if(s !== -1 && e !== -1) {
|
if(node.hasAttribute("data-module") && s !== -1 && e !== -1) {
|
||||||
text = text.substring(s+1,e-1);
|
text = text.substring(s+1,e-1);
|
||||||
}
|
}
|
||||||
var fields = $tw.wiki.deserializeTiddlers("application/javascript",text)[0];
|
var fields = {text: text},
|
||||||
fields.title = node.getAttribute("data-tiddler-title");
|
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;
|
return fields;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
@ -21,14 +21,37 @@ exports["text/html"] = function(tiddler) {
|
|||||||
return text ? text : "";
|
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) {
|
exports["application/x-tiddler-module"] = function(tiddler) {
|
||||||
var result = [];
|
var attributes = {
|
||||||
result.push("<" + "script type=\"text/javascript\" data-tiddler-title=\"" + tiddler.fields.title + "\">\n");
|
type: "text/javascript",
|
||||||
result.push("$tw.modules.define(\"" + tiddler.fields.title + "\",\"" + tiddler.fields["module-type"] + "\",function(module,exports,require) {");
|
"data-module": "yes"
|
||||||
result.push(tiddler.fields.text);
|
}, // The script type is set to text/javascript for compatibility with old browsers
|
||||||
result.push("});\n");
|
text = tiddler.fields.text;
|
||||||
result.push("</" + "script>");
|
text = "$tw.modules.define(\"" + tiddler.fields.title + "\",\"" + tiddler.fields["module-type"] + "\",function(module,exports,require) {" + text + "});\n";
|
||||||
return result.join("");
|
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) {
|
exports["application/x-tiddler-html-div"] = function(tiddler) {
|
||||||
|
@ -36,16 +36,12 @@ type: text/x-tiddlywiki-html
|
|||||||
<<^"[is[tiddler]]" application/x-tiddler-html-div>>
|
<<^"[is[tiddler]]" application/x-tiddler-html-div>>
|
||||||
</div>
|
</div>
|
||||||
<!----------- Boot kernel prologue ----------->
|
<!----------- Boot kernel prologue ----------->
|
||||||
<script id="jsBootStartArea" type="text/javascript">
|
<<^"$:/core/bootprefix.js" application/javascript>>
|
||||||
<<^"$:/core/bootprefix.js" text/plain>>
|
|
||||||
</script>
|
|
||||||
<!----------- Plugin modules ----------->
|
<!----------- Plugin modules ----------->
|
||||||
<div id="pluginModules" style="display:none;">
|
<div id="pluginModules" style="display:none;">
|
||||||
<<^"[is[shadowModule]]" application/x-tiddler-module>>
|
<<^"[is[shadowModule]]" application/x-tiddler-module>>
|
||||||
</div>
|
</div>
|
||||||
<!----------- Boot kernel ----------->
|
<!----------- Boot kernel ----------->
|
||||||
<script id="jsBootEndArea" type="text/javascript">
|
<<^"$:/core/boot.js" application/javascript>>
|
||||||
<<^"$:/core/boot.js" text/plain>>
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user