1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00
TiddlyWiki5/plugins/tiddlywiki/browser-sniff/browser.js
Jermolene 9c74afdd1a JSHint obeisance for plugins folder
Also add a jshintignore file to skip the various imported modules
2014-08-30 21:32:55 +01:00

79 lines
2.5 KiB
JavaScript

/*\
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"), // Fails because message box is added after page load
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;
};
})();