Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mq4-hover-hover-shim.js « browser « dist - github.com/twbs/mq4-hover-shim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 81a16bbca57f0c672a8b88345f5c6169ac2fe692 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*!
 * mq4-hover-hover-shim v0.0.1
 * https://github.com/cvrebert/mq4-hover-hover-shim
 * Copyright (c) 2014 Christopher Rebert
 * Licensed under the MIT License (https://github.com/cvrebert/mq4-hover-hover-shim/blob/master/LICENSE).
 */

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.mq4HoverShim=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";

exports.supportsTrueHover = supportsTrueHover;
/*eslint-env browser */
/* jshint browser: true, esnext: true */

/**
* Does this UA's primary pointer support true hovering
* OR does the UA at least not try to quirkily emulate hovering,
* such that :hover CSS styles are appropriate?
* Essentially tries to shim the `@media (hover: hover)` CSS media query feature.
* @type {boolean}
*/
function supportsTrueHover() {
  if (!window.matchMedia) {
    // Opera Mini, IE<=9, or ancient; per http://caniuse.com/#feat=matchmedia
    var ua = navigator.userAgent;
    if (ua.indexOf("Opera Mini") > -1) {
      // Opera Mini doesn't support true hovering
      return false;
    }
    if (ua.indexOf("IEMobile") > -1 || ua.indexOf("Windows Phone") > -1 || ua.indexOf("XBLWP7") > -1 || ua.indexOf("ZuneWP7") > -1 || // IE Mobile 9 in desktop view
    ua.indexOf("Windows CE") > -1 // out of an abundance of caution
    ) {
      // IE Mobile <=9
      return false;
    }
    // UA is ancient enough to probably be a desktop computer or at least not attempt emulation of hover.
    return true;
  }

  // CSSWG Media Queries Level 4 draft
  //     http://drafts.csswg.org/mediaqueries/#hover
  if (window.matchMedia("(hover: none),(-moz-hover: none),(-ms-hover: none),(-webkit-hover: none)," + "(hover: on-demand),(-moz-hover: on-demand),(-ms-hover: on-demand),(-webkit-hover: on-demand)").matches) {
    // true hovering explicitly not supported by primary pointer
    return false;
  }
  if (window.matchMedia("(hover: hover),(-moz-hover: hover),(-ms-hover: hover),(-webkit-hover: hover)").matches) {
    // true hovering explicitly supported by primary pointer
    return true;
  }
  // `hover` media feature not implemented by this browser; keep probing

  // Touch generally implies that hovering is merely emulated,
  // which doesn't count as true hovering support for our purposes
  // due to the quirkiness of the emulation (e.g. :hover being sticky).

  // W3C Pointer Events LC WD, 13 November 2014
  //     http://www.w3.org/TR/2014/WD-pointerevents-20141113/
  // Prefixed in IE10, per http://caniuse.com/#feat=pointer
  var supportsPointerEvents = window.PointerEvent || window.MSPointerEvent;
  if (supportsPointerEvents) {
    var pointerEventsIsTouch = (window.navigator.maxTouchPoints || window.navigator.msMaxTouchPoints) > 0;
    return !pointerEventsIsTouch;
  }

  // Mozilla's -moz-touch-enabled
  //     https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries#-moz-touch-enabled
  if (window.matchMedia("(touch-enabled),(-moz-touch-enabled),(-ms-touch-enabled),(-webkit-touch-enabled)").matches) {
    return false;
  }

  // W3C Touch Events
  //     http://www.w3.org/TR/2013/REC-touch-events-20131010/
  if ("ontouchstart" in window) {
    return false;
  }

  // UA's pointer is non-touch and thus likely either supports true hovering or at least does not try to emulate it.
  return true;
}
},{}]},{},[1])(1)
});