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

github.com/twbs/mq4-hover-shim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/dist
diff options
context:
space:
mode:
authorChris Rebert <code@rebertia.com>2015-01-10 00:16:57 +0300
committerChris Rebert <code@rebertia.com>2015-01-10 00:16:57 +0300
commit8ed37db94c999b356c782da2192899909c4b4436 (patch)
treedba41a867d15df5d36af5d082395a12c46d33af7 /dist
parent9b43d737448b08cc9ddcb205aafbb379f06b1eb5 (diff)
grunt dist
Diffstat (limited to 'dist')
-rw-r--r--dist/browser/mq4-hover-hover-shim.js154
-rw-r--r--dist/cjs/mq4-hover-hover-shim.js150
2 files changed, 224 insertions, 80 deletions
diff --git a/dist/browser/mq4-hover-hover-shim.js b/dist/browser/mq4-hover-hover-shim.js
index 81a16bb..ad19682 100644
--- a/dist/browser/mq4-hover-hover-shim.js
+++ b/dist/browser/mq4-hover-hover-shim.js
@@ -1,5 +1,5 @@
/*!
- * mq4-hover-hover-shim v0.0.1
+ * mq4-hover-hover-shim v0.0.2
* 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).
@@ -8,74 +8,146 @@
!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";
+var _interopRequireWildcard = function (obj) {
+ return obj && obj.constructor === Object ? obj : {
+ "default": obj
+ };
+};
+
exports.supportsTrueHover = supportsTrueHover;
/*eslint-env browser */
/* jshint browser: true, esnext: true */
+/* jshint -W080 */
+/**
+* @module mq4HoverShim
+* @requires jquery
+*/
+var $ = (function () {
+ try {
+ var jQuery = _interopRequireWildcard(require("jquery"));
+
+ return jQuery;
+ } catch (importErr) {
+ var globaljQuery = window.$ || window.jQuery || window.Zepto;
+ if (!globaljQuery) {
+ throw new Error("mq4HoverShim needs jQuery (or similar)");
+ }
+ return globaljQuery;
+ }
+})();
+
+/** @type {boolean|undefined} */
+var canTrulyHover = undefined;
/**
-* 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}
+* @private
+* @fires mq4HoverShim#mq4hsChange
*/
-function supportsTrueHover() {
+function triggerEvent() {
+ $(document).trigger($.Event("mq4hsChange", { bubbles: false, trueHover: canTrulyHover }));
+}
+
+// IIFE so we can use `return`s to avoid deeply-nested if-s
+(function () {
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;
+ // Opera Mini, IE<=9, Android<=2.3, ancient, or obscure; per http://caniuse.com/#feat=matchmedia
+
+ // Opera Mini, Android, and IE Mobile don't support true hovering, so they're what we'll check for.
+ // Other browsers are either:
+ // (a) obscure
+ // (b) touch-based but old enough not to attempt to emulate hovering
+ // (c) old desktop browsers that do support true hovering
+
+ // Explanation of this UA regex:
+ // IE Mobile <9 seems to always have "Windows CE", "Windows Phone", or "IEMobile" in its UA string.
+ // IE Mobile 9 in desktop view doesn't include "IEMobile" or "Windows Phone" in the UA string,
+ // but it instead includes "XBLWP7" and/or "ZuneWP7".
+ canTrulyHover = !/Opera Mini|Android|IEMobile|Windows (Phone|CE)|(XBL|Zune)WP7/.test(navigator.userAgent);
+
+ // Since there won't be any event handlers to fire our events, do the one-and-only firing of it here and now.
+ triggerEvent();
+ return;
}
// 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;
+ var HOVER_NONE = "(hover: none),(-moz-hover: none),(-ms-hover: none),(-webkit-hover: none)";
+ var HOVER_ON_DEMAND = "(hover: on-demand),(-moz-hover: on-demand),(-ms-hover: on-demand),(-webkit-hover: on-demand)";
+ var HOVER_HOVER = "(hover: hover),(-moz-hover: hover),(-ms-hover: hover),(-webkit-hover: hover)";
+ if (window.matchMedia("" + HOVER_NONE + "," + HOVER_ON_DEMAND + "," + HOVER_HOVER).matches) {
+ var _ret = (function () {
+ // Browser understands the `hover` media feature
+ var hoverCallback = function (mql) {
+ var doesMatch = mql.matches;
+ if (doesMatch !== canTrulyHover) {
+ canTrulyHover = doesMatch;
+ triggerEvent();
+ }
+ };
+ var atHoverQuery = window.matchMedia(HOVER_HOVER);
+ atHoverQuery.addListener(hoverCallback);
+ hoverCallback(atHoverQuery);
+ return {
+ v: undefined
+ };
+ })();
+
+ if (typeof _ret === "object") return _ret.v;
}
- // `hover` media feature not implemented by this browser; keep probing
+ // Check for touch support instead.
// 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/
+ // W3C Pointer Events PR, 16 December 2014
+ // http://www.w3.org/TR/2014/PR-pointerevents-20141216/
// 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;
+ if (window.PointerEvent || window.MSPointerEvent) {
+ // Browser supports Pointer Events
+
+ // Browser supports touch if it has touch points
+ /* jshint -W018 */
+ canTrulyHover = !((window.navigator.maxTouchPoints || window.navigator.msMaxTouchPoints) > 0);
+ /* jshint +W018 */
+ triggerEvent();
+ return;
}
// 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;
+ var touchEnabledQuery = window.matchMedia("(touch-enabled),(-moz-touch-enabled),(-ms-touch-enabled),(-webkit-touch-enabled)");
+ if (touchEnabledQuery.matches) {
+ canTrulyHover = false;
+ triggerEvent();
+ return;
}
- // W3C Touch Events
+ // W3C Touch Events REC, 10 October 2013
// http://www.w3.org/TR/2013/REC-touch-events-20131010/
if ("ontouchstart" in window) {
- return false;
+ canTrulyHover = false;
+ triggerEvent();
+ return;
}
// UA's pointer is non-touch and thus likely either supports true hovering or at least does not try to emulate it.
- return true;
+ canTrulyHover = true;
+ triggerEvent();
+})();
+
+
+/**
+* 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.
+* @public
+* @returns {boolean}
+* @since 0.0.1
+*/
+function supportsTrueHover() {
+ return canTrulyHover;
}
-},{}]},{},[1])(1)
+},{"jquery":undefined}]},{},[1])(1)
}); \ No newline at end of file
diff --git a/dist/cjs/mq4-hover-hover-shim.js b/dist/cjs/mq4-hover-hover-shim.js
index 6955bff..9610dc5 100644
--- a/dist/cjs/mq4-hover-hover-shim.js
+++ b/dist/cjs/mq4-hover-hover-shim.js
@@ -1,71 +1,143 @@
"use strict";
+var _interopRequireWildcard = function (obj) {
+ return obj && obj.constructor === Object ? obj : {
+ "default": obj
+ };
+};
+
exports.supportsTrueHover = supportsTrueHover;
/*eslint-env browser */
/* jshint browser: true, esnext: true */
+/* jshint -W080 */
+/**
+* @module mq4HoverShim
+* @requires jquery
+*/
+var $ = (function () {
+ try {
+ var jQuery = _interopRequireWildcard(require("jquery"));
+
+ return jQuery;
+ } catch (importErr) {
+ var globaljQuery = window.$ || window.jQuery || window.Zepto;
+ if (!globaljQuery) {
+ throw new Error("mq4HoverShim needs jQuery (or similar)");
+ }
+ return globaljQuery;
+ }
+})();
+
+/** @type {boolean|undefined} */
+var canTrulyHover = undefined;
/**
-* 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}
+* @private
+* @fires mq4HoverShim#mq4hsChange
*/
-function supportsTrueHover() {
+function triggerEvent() {
+ $(document).trigger($.Event("mq4hsChange", { bubbles: false, trueHover: canTrulyHover }));
+}
+
+// IIFE so we can use `return`s to avoid deeply-nested if-s
+(function () {
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;
+ // Opera Mini, IE<=9, Android<=2.3, ancient, or obscure; per http://caniuse.com/#feat=matchmedia
+
+ // Opera Mini, Android, and IE Mobile don't support true hovering, so they're what we'll check for.
+ // Other browsers are either:
+ // (a) obscure
+ // (b) touch-based but old enough not to attempt to emulate hovering
+ // (c) old desktop browsers that do support true hovering
+
+ // Explanation of this UA regex:
+ // IE Mobile <9 seems to always have "Windows CE", "Windows Phone", or "IEMobile" in its UA string.
+ // IE Mobile 9 in desktop view doesn't include "IEMobile" or "Windows Phone" in the UA string,
+ // but it instead includes "XBLWP7" and/or "ZuneWP7".
+ canTrulyHover = !/Opera Mini|Android|IEMobile|Windows (Phone|CE)|(XBL|Zune)WP7/.test(navigator.userAgent);
+
+ // Since there won't be any event handlers to fire our events, do the one-and-only firing of it here and now.
+ triggerEvent();
+ return;
}
// 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;
+ var HOVER_NONE = "(hover: none),(-moz-hover: none),(-ms-hover: none),(-webkit-hover: none)";
+ var HOVER_ON_DEMAND = "(hover: on-demand),(-moz-hover: on-demand),(-ms-hover: on-demand),(-webkit-hover: on-demand)";
+ var HOVER_HOVER = "(hover: hover),(-moz-hover: hover),(-ms-hover: hover),(-webkit-hover: hover)";
+ if (window.matchMedia("" + HOVER_NONE + "," + HOVER_ON_DEMAND + "," + HOVER_HOVER).matches) {
+ var _ret = (function () {
+ // Browser understands the `hover` media feature
+ var hoverCallback = function (mql) {
+ var doesMatch = mql.matches;
+ if (doesMatch !== canTrulyHover) {
+ canTrulyHover = doesMatch;
+ triggerEvent();
+ }
+ };
+ var atHoverQuery = window.matchMedia(HOVER_HOVER);
+ atHoverQuery.addListener(hoverCallback);
+ hoverCallback(atHoverQuery);
+ return {
+ v: undefined
+ };
+ })();
+
+ if (typeof _ret === "object") return _ret.v;
}
- // `hover` media feature not implemented by this browser; keep probing
+ // Check for touch support instead.
// 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/
+ // W3C Pointer Events PR, 16 December 2014
+ // http://www.w3.org/TR/2014/PR-pointerevents-20141216/
// 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;
+ if (window.PointerEvent || window.MSPointerEvent) {
+ // Browser supports Pointer Events
+
+ // Browser supports touch if it has touch points
+ /* jshint -W018 */
+ canTrulyHover = !((window.navigator.maxTouchPoints || window.navigator.msMaxTouchPoints) > 0);
+ /* jshint +W018 */
+ triggerEvent();
+ return;
}
// 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;
+ var touchEnabledQuery = window.matchMedia("(touch-enabled),(-moz-touch-enabled),(-ms-touch-enabled),(-webkit-touch-enabled)");
+ if (touchEnabledQuery.matches) {
+ canTrulyHover = false;
+ triggerEvent();
+ return;
}
- // W3C Touch Events
+ // W3C Touch Events REC, 10 October 2013
// http://www.w3.org/TR/2013/REC-touch-events-20131010/
if ("ontouchstart" in window) {
- return false;
+ canTrulyHover = false;
+ triggerEvent();
+ return;
}
// UA's pointer is non-touch and thus likely either supports true hovering or at least does not try to emulate it.
- return true;
+ canTrulyHover = true;
+ triggerEvent();
+})();
+
+
+/**
+* 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.
+* @public
+* @returns {boolean}
+* @since 0.0.1
+*/
+function supportsTrueHover() {
+ return canTrulyHover;
} \ No newline at end of file