|
1 /** ## jquery.flot.browser.js |
|
2 |
|
3 This plugin is used to make available some browser-related utility functions. |
|
4 |
|
5 ### Methods |
|
6 */ |
|
7 |
|
8 (function ($) { |
|
9 'use strict'; |
|
10 |
|
11 var browser = { |
|
12 /** |
|
13 - getPageXY(e) |
|
14 |
|
15 Calculates the pageX and pageY using the screenX, screenY properties of the event |
|
16 and the scrolling of the page. This is needed because the pageX and pageY |
|
17 properties of the event are not correct while running tests in Edge. */ |
|
18 getPageXY: function (e) { |
|
19 // This code is inspired from https://stackoverflow.com/a/3464890 |
|
20 var doc = document.documentElement, |
|
21 pageX = e.clientX + (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0), |
|
22 pageY = e.clientY + (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0); |
|
23 return { X: pageX, Y: pageY }; |
|
24 }, |
|
25 |
|
26 /** |
|
27 - getPixelRatio(context) |
|
28 |
|
29 This function returns the current pixel ratio defined by the product of desktop |
|
30 zoom and page zoom. |
|
31 Additional info: https://www.html5rocks.com/en/tutorials/canvas/hidpi/ |
|
32 */ |
|
33 getPixelRatio: function(context) { |
|
34 var devicePixelRatio = window.devicePixelRatio || 1, |
|
35 backingStoreRatio = |
|
36 context.webkitBackingStorePixelRatio || |
|
37 context.mozBackingStorePixelRatio || |
|
38 context.msBackingStorePixelRatio || |
|
39 context.oBackingStorePixelRatio || |
|
40 context.backingStorePixelRatio || 1; |
|
41 return devicePixelRatio / backingStoreRatio; |
|
42 }, |
|
43 |
|
44 /** |
|
45 - isSafari, isMobileSafari, isOpera, isFirefox, isIE, isEdge, isChrome, isBlink |
|
46 |
|
47 This is a collection of functions, used to check if the code is running in a |
|
48 particular browser or Javascript engine. |
|
49 */ |
|
50 isSafari: function() { |
|
51 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
52 // Safari 3.0+ "[object HTMLElementConstructor]" |
|
53 return /constructor/i.test(window.top.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window.top['safari'] || (typeof window.top.safari !== 'undefined' && window.top.safari.pushNotification)); |
|
54 }, |
|
55 |
|
56 isMobileSafari: function() { |
|
57 //isMobileSafari adapted from https://stackoverflow.com/questions/3007480/determine-if-user-navigated-from-mobile-safari |
|
58 return navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/); |
|
59 }, |
|
60 |
|
61 isOpera: function() { |
|
62 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
63 //Opera 8.0+ |
|
64 return (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0; |
|
65 }, |
|
66 |
|
67 isFirefox: function() { |
|
68 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
69 // Firefox 1.0+ |
|
70 return typeof InstallTrigger !== 'undefined'; |
|
71 }, |
|
72 |
|
73 isIE: function() { |
|
74 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
75 // Internet Explorer 6-11 |
|
76 return /*@cc_on!@*/false || !!document.documentMode; |
|
77 }, |
|
78 |
|
79 isEdge: function() { |
|
80 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
81 // Edge 20+ |
|
82 return !browser.isIE() && !!window.StyleMedia; |
|
83 }, |
|
84 |
|
85 isChrome: function() { |
|
86 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
87 // Chrome 1+ |
|
88 return !!window.chrome && !!window.chrome.webstore; |
|
89 }, |
|
90 |
|
91 isBlink: function() { |
|
92 // *** https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser |
|
93 return (browser.isChrome() || browser.isOpera()) && !!window.CSS; |
|
94 } |
|
95 }; |
|
96 |
|
97 $.plot.browser = browser; |
|
98 })(jQuery); |