mirror of
https://github.com/TiddlyWiki/TiddlyWiki5.git
synced 2026-05-01 22:07:26 +00:00
Move browser sniffing into a plugin
This commit is contained in:
78
plugins/tiddlywiki/browser-sniff/browser.js
Normal file
78
plugins/tiddlywiki/browser-sniff/browser.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/*\
|
||||
title: $:/plugins/tiddlywiki/browser-sniff/sniff.js
|
||||
type: application/javascript
|
||||
module-type: info
|
||||
|
||||
Initialise $:/info/browser tiddlers
|
||||
|
||||
\*/
|
||||
(function(){
|
||||
|
||||
/*jslint node: true, browser: true */
|
||||
/*global $tw: false */
|
||||
"use strict";
|
||||
|
||||
exports.getInfoTiddlerFields = function() {
|
||||
var mapBoolean = function(value) {return value ? "yes" : "no"},
|
||||
infoTiddlerFields = [];
|
||||
// Basics
|
||||
if($tw.browser) {
|
||||
// Mappings from tiddler titles (prefixed with "$:/info/browser/") to bowser.browser property name
|
||||
var bowser = require("$:/plugins/tiddlywiki/browser-sniff/bowser/bowser.js"),
|
||||
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"],
|
||||
["is/firefoxos","firefoxos"]
|
||||
];
|
||||
$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
|
||||
var hasTiddlyFox = !!document.getElementById("tiddlyfox-message-box"),
|
||||
isTiddlyDesktop = false; // Can't detect it until we update TiddlyDesktop to have a distinct useragent string
|
||||
infoTiddlerFields.push({title: "$:/info/browser/has/tiddlyfox", text: mapBoolean(hasTiddlyFox)});
|
||||
infoTiddlerFields.push({title: "$:/info/browser/is/tiddlydesktop", text: mapBoolean(isTiddlyDesktop)});
|
||||
if(isTiddlyDesktop) {
|
||||
infoTiddlerFields.push({title: "$:/info/browser/name", text: "TiddlyDesktop"});
|
||||
}
|
||||
}
|
||||
return infoTiddlerFields;
|
||||
};
|
||||
|
||||
})();
|
||||
Reference in New Issue
Block a user