2017-06-20 16:41:01 +02:00

118 lines
3.7 KiB
JavaScript

//--------------------------------------------------------------------
// DEBUG
//--------------------------------------------------------------------
window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}};
//var log = function(msg) { if(debug) {try { if (console != null && console.log != null && debug != false) { console.log(msg); } } catch (e) { } } }
//--------------------------------------------------------------------
// FEATURE DETECTION
//--------------------------------------------------------------------
var isiPad = navigator.userAgent.toLowerCase().indexOf('ipad');
var isIphone = navigator.userAgent.toLowerCase().indexOf("iphone");
var isIpod = navigator.userAgent.toLowerCase().indexOf("isIpod");
var isAndroid = navigator.userAgent.toLowerCase().indexOf("android");
var isMobile = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry)/);
var isMobileOrTablet = ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) ? true : false;
function isApple() {
var isiPhone = navigator.userAgent.toLowerCase().indexOf('iphone');
var isiPad = navigator.userAgent.toLowerCase().indexOf('ipad');
var isiPod = navigator.userAgent.toLowerCase().indexOf('ipod');
if(isiPhone > -1 || isiPad > -1 || isiPod > -1) return true;
else return false;
}
//BrowserDetect.init();
//alert(BrowserDetect.browser+ ' ' +BrowserDetect.version)
var BrowserDetect =
{
init: function ()
{
this.browser = this.searchString(this.dataBrowser) || "Other";
this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "Unknown";
},
searchString: function (data)
{
for (var i=0 ; i < data.length ; i++)
{
var dataString = data[i].string;
this.versionSearchString = data[i].subString;
if (dataString.indexOf(data[i].subString) != -1)
{
return data[i].identity;
}
}
},
searchVersion: function (dataString)
{
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser:
[
{ string: navigator.userAgent, subString: "Chrome", identity: "Chrome" },
{ string: navigator.userAgent, subString: "MSIE", identity: "Explorer" },
{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
{ string: navigator.userAgent, subString: "Safari", identity: "Safari" },
{ string: navigator.userAgent, subString: "Opera", identity: "Opera" }
]
};
//--------------------------------------------------------------------
// TOUCH
//--------------------------------------------------------------------
/* Determine touch events support */
var hasTouchSupport = (function(){
if ('ontouchstart' in document.documentElement) {
return true;
}
}());
function isTouchDevice()
{
try {
document.createEvent("TouchEvent");
return true;
}
catch (e) {
return false;
}
}
var eventListenerStart,
eventListenerMove,
eventListenerEnd;
/* Define event names */
var events;
if (hasTouchSupport) {
events = {
start: "touchstart",
move: "touchmove",
end: "touchend",
cancel: "touchcancel"
};
} else {
events = {
start: "mousedown",
move: "mousemove",
end: "mouseup",
cancel: "touchcancel" // unnecessary here
};
}
//--------------------------------------------------------------------
// MATH
//--------------------------------------------------------------------
function isOdd(num) { return num % 2;}