UNPKG

2.26 kBJavaScriptView Raw
1export var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
2
3export var addEventListener = function addEventListener(node, event, listener) {
4 return node.addEventListener ? node.addEventListener(event, listener, false) : node.attachEvent('on' + event, listener);
5};
6
7export var removeEventListener = function removeEventListener(node, event, listener) {
8 return node.removeEventListener ? node.removeEventListener(event, listener, false) : node.detachEvent('on' + event, listener);
9};
10
11export var getConfirmation = function getConfirmation(message, callback) {
12 return callback(window.confirm(message));
13}; // eslint-disable-line no-alert
14
15/**
16 * Returns true if the HTML5 history API is supported. Taken from Modernizr.
17 *
18 * https://github.com/Modernizr/Modernizr/blob/master/LICENSE
19 * https://github.com/Modernizr/Modernizr/blob/master/feature-detects/history.js
20 * changed to avoid false negatives for Windows Phones: https://github.com/reactjs/react-router/issues/586
21 */
22export var supportsHistory = function supportsHistory() {
23 var ua = window.navigator.userAgent;
24
25 if ((ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) && ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1) return false;
26
27 return window.history && 'pushState' in window.history;
28};
29
30/**
31 * Returns true if browser fires popstate on hash change.
32 * IE10 and IE11 do not.
33 */
34export var supportsPopStateOnHashChange = function supportsPopStateOnHashChange() {
35 return window.navigator.userAgent.indexOf('Trident') === -1;
36};
37
38/**
39 * Returns false if using go(n) with hash history causes a full page reload.
40 */
41export var supportsGoWithoutReloadUsingHash = function supportsGoWithoutReloadUsingHash() {
42 return window.navigator.userAgent.indexOf('Firefox') === -1;
43};
44
45/**
46 * Returns true if a given popstate event is an extraneous WebKit event.
47 * Accounts for the fact that Chrome on iOS fires real popstate events
48 * containing undefined state when pressing the back button.
49 */
50export var isExtraneousPopstateEvent = function isExtraneousPopstateEvent(event) {
51 return event.state === undefined && navigator.userAgent.indexOf('CriOS') === -1;
52};
\No newline at end of file