Expose document location via $:/info/url/* info tiddlers

This commit is contained in:
Jermolene
2016-10-18 09:12:55 +01:00
parent 8fbcfaa79b
commit 2f590a365e
2 changed files with 28 additions and 2 deletions
+15
View File
@@ -18,6 +18,21 @@ exports.getInfoTiddlerFields = function() {
// Basics
infoTiddlerFields.push({title: "$:/info/browser", text: mapBoolean(!!$tw.browser)});
infoTiddlerFields.push({title: "$:/info/node", text: mapBoolean(!!$tw.node)});
// Document location
if($tw.browser) {
var setLocationProperty = function(name,value) {
infoTiddlerFields.push({title: "$:/info/url/" + name, text: value});
},
location = document.location;
setLocationProperty("full", (location.toString()).split("#")[0]);
setLocationProperty("host", location.host);
setLocationProperty("hostname", location.hostname);
setLocationProperty("protocol", location.protocol);
setLocationProperty("port", location.port);
setLocationProperty("pathname", location.pathname);
setLocationProperty("search", location.search);
setLocationProperty("origin", location.origin);
}
return infoTiddlerFields;
};