2014-07-20 17:07:30 +00:00
|
|
|
/*\
|
2014-07-21 12:17:16 +00:00
|
|
|
title: $:/plugins/tiddlywiki/browser-sniff/sniff.js
|
2014-07-20 17:07:30 +00:00
|
|
|
type: application/javascript
|
|
|
|
module-type: info
|
|
|
|
|
|
|
|
Initialise $:/info/browser tiddlers
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
exports.getInfoTiddlerFields = function() {
|
2014-08-30 20:32:55 +00:00
|
|
|
var mapBoolean = function(value) {return value ? "yes" : "no";},
|
2014-07-20 17:07:30 +00:00
|
|
|
infoTiddlerFields = [];
|
|
|
|
// Basics
|
|
|
|
if($tw.browser) {
|
|
|
|
// Mappings from tiddler titles (prefixed with "$:/info/browser/") to bowser.browser property name
|
2014-07-21 12:17:16 +00:00
|
|
|
var bowser = require("$:/plugins/tiddlywiki/browser-sniff/bowser/bowser.js"),
|
2014-07-20 17:07:30 +00:00
|
|
|
mappings = [
|
|
|
|
["name","name","unknown"],
|
|
|
|
["version","version"],
|
|
|
|
["is/webkit","webkit"],
|
|
|
|
["is/gecko","gecko"],
|
|
|
|
["is/chrome","chrome"],
|
|
|
|
["is/firefox","firefox"],
|
|
|
|
["is/ios","ios"],
|
|
|
|
["is/iphone","iphone"],
|
|
|
|
["is/ipad","ipad"],
|
|
|
|
["is/ipod","ios"],
|
|
|
|
["is/opera","opera"],
|
|
|
|
["is/phantomjs","phantomjs"],
|
|
|
|
["is/safari","safari"],
|
|
|
|
["is/seamonkey","seamonkey"],
|
|
|
|
["is/blackberry","blackberry"],
|
|
|
|
["is/webos","webos"],
|
|
|
|
["is/silk","silk"],
|
|
|
|
["is/bada","bada"],
|
|
|
|
["is/tizen","tizen"],
|
|
|
|
["is/sailfish","sailfish"],
|
|
|
|
["is/android","android"],
|
|
|
|
["is/windowsphone","windowsphone"],
|
2022-05-14 13:02:52 +00:00
|
|
|
["is/firefoxos","firefoxos"],
|
|
|
|
["is/mobile","mobile"]
|
2014-07-20 17:07:30 +00:00
|
|
|
];
|
2022-05-14 13:02:52 +00:00
|
|
|
$tw.browser = $tw.utils.extend($tw.browser, {
|
|
|
|
is: bowser.browser,
|
|
|
|
});
|
2014-07-20 17:07:30 +00:00
|
|
|
$tw.utils.each(mappings,function(mapping) {
|
|
|
|
var value = bowser.browser[mapping[1]];
|
|
|
|
if(value === undefined) {
|
|
|
|
value = mapping[2];
|
|
|
|
}
|
|
|
|
if(value === undefined) {
|
|
|
|
value = false;
|
|
|
|
}
|
|
|
|
if(typeof value === "boolean") {
|
|
|
|
value = mapBoolean(value);
|
|
|
|
}
|
|
|
|
infoTiddlerFields.push({title: "$:/info/browser/" + mapping[0], text: value});
|
|
|
|
});
|
|
|
|
// Set $:/info/browser/name to the platform with some changes from Bowser
|
|
|
|
var platform = bowser.browser.name;
|
|
|
|
if("iPad iPhone iPod".split(" ").indexOf(platform) !== -1) {
|
|
|
|
platform = "iOS";
|
|
|
|
}
|
|
|
|
infoTiddlerFields.push({title: "$:/info/browser/name", text: platform});
|
|
|
|
// Non-bowser settings for TiddlyFox and TiddlyDesktop
|
2014-07-23 08:14:21 +00:00
|
|
|
var hasTiddlyFox = !!document.getElementById("tiddlyfox-message-box"), // Fails because message box is added after page load
|
2014-07-20 17:07:30 +00:00
|
|
|
isTiddlyDesktop = false; // Can't detect it until we update TiddlyDesktop to have a distinct useragent string
|
2014-07-23 08:14:21 +00:00
|
|
|
//infoTiddlerFields.push({title: "$:/info/browser/has/tiddlyfox", text: mapBoolean(hasTiddlyFox)});
|
|
|
|
//infoTiddlerFields.push({title: "$:/info/browser/is/tiddlydesktop", text: mapBoolean(isTiddlyDesktop)});
|
2014-07-20 17:07:30 +00:00
|
|
|
if(isTiddlyDesktop) {
|
|
|
|
infoTiddlerFields.push({title: "$:/info/browser/name", text: "TiddlyDesktop"});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return infoTiddlerFields;
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|