hammer-timejs
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,1 @@ | ||
{"":{"version":0.4,"tips":{"master":"51ac523ba2b04bdeeb698714a467abd498969003"}}," last run":{"hammer-time.js":{"":4480},"dist/hammer-time.min.js":{"":1835}},"master":{"hammer-time.js":{"":3994},"dist/hammer-time.min.js":{"":1667}}} | ||
{"":{"version":0.4,"tips":{"master":"51ac523ba2b04bdeeb698714a467abd498969003"}}," last run":{"hammer-time.js":{"":5432},"dist/hammer-time.min.js":{"":2468}},"master":{"hammer-time.js":{"":3994},"dist/hammer-time.min.js":{"":1667}}} |
@@ -1,1 +0,1 @@ | ||
!function(){void 0!==document.documentElement.style["touch-action"],window.Hammer=window.Hammer||{};var a=window.MutationObserver||window.WebKitMutationObserver,b=/touch-action[:][\s]*none[^;'"]*/,c=/touch-action/,d=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1,e=function(){try{var a=document.createElement("canvas");return!(!window.WebGLRenderingContext||!a.getContext("webgl")&&!a.getContext("experimental-webgl"))}catch(b){return!1}}(),f=e&&d;window.Hammer.time={getTouchAction:function(a){return this.checkStyleString(a.getAttribute("style"))},checkStyleString:function(a){return c.test(a)?b.test(a)?"none":!0:void 0},touchHandler:function(a){if(this.hasTouchNone(a.target)&&(!f||Date.now()-a.target.lastStart<125)){if("touchend"===a.type){var b=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!0});setTimeout(function(){a.target.dispatchEvent(b)},0)}a.preventDefault()}delete a.target.lastStart},styleWatcher:function(a){a.forEach(this.styleUpdater,this)},styleUpdater:function(a){if(a.target.updateNext)return void(a.target.updateNext=!1);var b=this.getTouchAction(a.target);return b?void("none"!==b&&(a.target.hadTouchNone=!1)):void(!b&&(a.oldValue&&this.checkStyleString(a.oldValue)||a.target.hadTouchNone)&&(a.target.hadTouchNone=!0,a.target.updateNext=!1,a.target.setAttribute("style",a.target.getAttribute("style")+" touch-action: none;")))},install:function(){document.addEventListener("touchend",this.touchHandler.bind(this),!0),document.addEventListener("mouseup",this.touchHandler.bind(this),!0),f&&document.addEventListener("touchstart",function(a){this.hasTouchNone(a.target)&&(a.target.lastStart=Date.now())}.bind(this)),this.observer=new a(this.styleWatcher.bind(this)).observe(document,{subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["style"]})}},window.Hammer.time.install()}(); | ||
!function(){var a=window.MutationObserver||window.WebKitMutationObserver,b="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,c=void 0!==document.documentElement.style["touch-action"]||document.documentElement.style["-ms-touch-action"];if(!c&&b&&a){window.Hammer=window.Hammer||{};var d=/touch-action[:][\s]*(none)[^;'"]*/,e=/touch-action[:][\s]*(manipulation)[^;'"]*/,f=/touch-action/,g=navigator.userAgent.match(/(iPad|iPhone|iPod)/g)?!0:!1,h=function(){try{var a=document.createElement("canvas");return!(!window.WebGLRenderingContext||!a.getContext("webgl")&&!a.getContext("experimental-webgl"))}catch(b){return!1}}(),i=h&&g;window.Hammer.time={getTouchAction:function(a){return this.checkStyleString(a.getAttribute("style"))},checkStyleString:function(a){return f.test(a)?d.test(a)?"none":e.test(a)?"manipulation":!0:void 0},shouldHammer:function(a){var b=this.hasParent(a.target);return b&&(!i||Date.now()-a.target.lastStart<125)?b:!1},touchHandler:function(a){var b=a.target.getBoundingClientRect(),c=b.top!==this.pos.top||b.left!==this.pos.left,d=this.shouldHammer(a);("none"===d||c===!1&&"manipulation"===d)&&("touchend"===a.type&&(a.target.focus(),setTimeout(function(){a.target.click()},0)),a.preventDefault()),this.scrolled=!1,delete a.target.lastStart},touchStart:function(a){this.pos=a.target.getBoundingClientRect(),i&&this.hasParent(a.target)&&(a.target.lastStart=Date.now())},styleWatcher:function(a){a.forEach(this.styleUpdater,this)},styleUpdater:function(a){if(a.target.updateNext)return void(a.target.updateNext=!1);var b=this.getTouchAction(a.target);return b?void("none"!==b&&(a.target.hadTouchNone=!1)):void(!b&&(a.oldValue&&this.checkStyleString(a.oldValue)||a.target.hadTouchNone)&&(a.target.hadTouchNone=!0,a.target.updateNext=!1,a.target.setAttribute("style",a.target.getAttribute("style")+" touch-action: none;")))},hasParent:function(a){for(var b,c=a;c&&c.parentNode;c=c.parentNode)if(b=this.getTouchAction(c))return b;return!1},installStartEvents:function(){document.addEventListener("touchstart",this.touchStart.bind(this)),document.addEventListener("mousedown",this.touchStart.bind(this))},installEndEvents:function(){document.addEventListener("touchend",this.touchHandler.bind(this),!0),document.addEventListener("mouseup",this.touchHandler.bind(this),!0)},installObserver:function(){this.observer=new a(this.styleWatcher.bind(this)).observe(document,{subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["style"]})},install:function(){this.installEndEvents(),this.installStartEvents(),this.installObserver()}},window.Hammer.time.install()}}(); |
@@ -12,6 +12,7 @@ /* Hammer-time - v0.3.0 | ||
( function() { | ||
// Detect support for necessary features; | ||
var MO = window.MutationObserver || window.WebKitMutationObserver; | ||
var touchevents = ('ontouchstart' in window) || | ||
(window.DocumentTouch && document instanceof DocumentTouch); | ||
var touchevents = ( "ontouchstart" in window ) || | ||
( window.DocumentTouch && document instanceof DocumentTouch ); | ||
var nativeTouchAction = document.documentElement.style[ "touch-action" ] !== undefined || | ||
@@ -34,15 +35,7 @@ document.documentElement.style[ "-ms-touch-action" ]; | ||
var touchMatch = /touch-action/; | ||
var iOS = ( navigator.userAgent.match( /(iPad|iPhone|iPod)/g ) ? true : false ); | ||
var gl = ( function() { | ||
try { | ||
var canvas = document.createElement( "canvas" ); | ||
return !!( window.WebGLRenderingContext && ( canvas.getContext( "webgl" ) || | ||
canvas.getContext( "experimental-webgl" ) ) ); | ||
} | ||
catch ( e ) { return false; } } )(); | ||
var timeTouch = gl && iOS; | ||
var timeTouch = /(iP(ad|hone|od))/.test( navigator.userAgent ) && ( "indexedDB" in window || !!window.performance ); | ||
window.Hammer.time = { | ||
// Checkes if an element has touch action none in its style attribute and thusly should | ||
// Check if an element has touch action none in its style attribute and thusly should | ||
// be hammered upon | ||
@@ -65,3 +58,3 @@ getTouchAction: function( element ) { | ||
shouldHammer: function( e ) { | ||
var parentAction = this.hasParent( e.target ); | ||
var parentAction = e.target.hasParent; | ||
return ( parentAction && ( !timeTouch || Date.now() - e.target.lastStart < 125 ) ) ? | ||
@@ -71,4 +64,2 @@ parentAction : false; | ||
touchHandler: function( e ) { | ||
var pos = e.target.getBoundingClientRect(); | ||
var scrolled = pos.top !== this.pos.top || pos.left !== this.pos.left; | ||
var hammerType = this.shouldHammer( e ); | ||
@@ -78,22 +69,30 @@ | ||
// native fast click | ||
if ( hammerType === "none" || | ||
( scrolled === false && hammerType === "manipulation" ) ) { | ||
if ( e.type === "touchend" ) { | ||
e.target.focus(); | ||
// Wait for next tic so events fire in proper order | ||
setTimeout( function() { | ||
e.target.click(); | ||
}, 0 ); | ||
} | ||
// Prevent the click which will come after this otherwise but with a 300ms delay | ||
e.preventDefault(); | ||
if ( hammerType === "none" ) { | ||
this.dropHammer( e ); | ||
} else if ( hammerType === "manipulation" ) { | ||
var pos = e.target.getBoundingClientRect(); | ||
var scrolled = pos.top !== this.pos.top || pos.left !== this.pos.left; | ||
!scrolled && this.dropHammer( e ); | ||
} | ||
this.scrolled = false; | ||
delete e.target.lastStart; | ||
delete e.target.hasParent; | ||
}, | ||
dropHammer: function( e ) { | ||
if ( e.type === "touchend" ) { | ||
e.target.focus(); | ||
// Wait for next tic so events fire in proper order | ||
setTimeout( function() { | ||
e.target.click(); | ||
}, 0 ); | ||
} | ||
// Prevent the click which will come after this otherwise but with a 300ms delay | ||
e.preventDefault(); | ||
}, | ||
touchStart: function( e ) { | ||
this.pos = e.target.getBoundingClientRect(); | ||
if ( timeTouch && this.hasParent( e.target ) ) { | ||
e.target.hasParent = this.hasParent( e.target ); | ||
if ( timeTouch && e.target.hasParent ) { | ||
e.target.lastStart = Date.now(); | ||
@@ -128,3 +127,3 @@ } | ||
// We save this because durring animations which update the style in quick succession | ||
// We save this because during animations which update the style in quick succession | ||
// style tag can update quicker then the mutation observer fires so we lose the oldValue | ||
@@ -131,0 +130,0 @@ // property which contains our refrence to the original which contained touch-action. |
@@ -5,3 +5,3 @@ { | ||
"description": "A fast click based on the touch-action css property", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"author": { | ||
@@ -8,0 +8,0 @@ "name": "Alex Schmitz", |
@@ -11,3 +11,3 @@ # Hammer Time! | ||
The first box uses `touch-action:none;` to remove the 300ms delay. The second box has no `touch-action` property set. On touch screens you will see a noticeable difference in the response time of the background and in the outputing of the end vs click events. | ||
The first box uses `touch-action:none;` to remove the 300ms delay. The second box has no `touch-action` property set. On touch screens you will see a noticeable difference in the response time of the background and in the outputting of the end vs click events. | ||
@@ -28,8 +28,8 @@ The `touch-action` css property is part of the Pointer Events spec [http://www.w3.org/TR/pointerevents/#the-touch-action-css-property](http://www.w3.org/TR/pointerevents/#the-touch-action-css-property) | ||
* **Only works when applied directly to the style attribute on an element not to a stylesheet** | ||
* Does not prevent scrolling or other behivors which happen on move or double tap zoom | ||
* Does not prevent scrolling or other behaviors which happen on move or double tap zoom | ||
* You cannot set the touch-action property via `element.style[ touch-action ]` browsers that do not support touch action will ignore this | ||
* Removing the touch-action property from an existing element is not supported, Hammer-time has no way of knowing the difference between you removing the property and it being removed as a result or browser sanitization. Instead of removng the property completely simply change it to the default value of auto | ||
* Removing the touch-action property from an existing element is not supported, Hammer-time has no way of knowing the difference between you removing the property and it being removed as a result or browser sanitization. Instead of removing the property completely simply change it to the default value of auto | ||
* Direct manipulation of the style property in a loop on elements with touch-action set from JavaScript ( JS animations for example ) should be avoided. Because of how browsers sanitize the style attribute when setting properties we use a mutation observe to restore the the touch action property when it is removed | ||
* To properly support IE10 you need to add both `touch-action` and `-ms-touch-action` | ||
To read more about UI response times and how this effects user experience see [http://www.nngroup.com/articles/response-times-3-important-limits/](http://www.nngroup.com/articles/response-times-3-important-limits/) | ||
To read more about UI response times and how this effects user experience see [http://www.nngroup.com/articles/response-times-3-important-limits/](http://www.nngroup.com/articles/response-times-3-important-limits/) |
Sorry, the diff of this file is not supported yet
31721
34
377