1/** 2 * jQuery.fastClick.js 3 * 4 * Work around the 300ms delay for the click event in some mobile browsers. 5 * 6 * Code based on <http://code.google.com/mobile/articles/fast_buttons.html> 7 * 8 * @usage 9 * $('button').fastClick(function() {alert('clicked!');}); 10 * 11 * @license MIT 12 * @author Dave Hulbert (dave1010) 13 * @version 1.0.0 2013-01-17 14 */ 15 16/*global document, window, jQuery, Math */ 17 18(function($) { 19 20$.fn.fastClick = function(handler) { 21 return $(this).each(function(){ 22 $.FastButton($(this)[0], handler); 23 }); 24}; 25 26$.FastButton = function(element, handler) { 27 var startX, startY; 28 29 var reset = function() { 30 $(element).unbind('touchend'); 31 $("body").unbind('touchmove.fastClick'); 32 }; 33 34 var onClick = function(event) { 35 event.stopPropagation(); 36 reset(); 37 handler.call(this, event); 38 39 if (event.type === 'touchend') { 40 $.clickbuster.preventGhostClick(startX, startY); 41 } 42 }; 43 44 var onTouchMove = function(event) { 45 if (Math.abs(event.originalEvent.touches[0].clientX - startX) > 10 || 46 Math.abs(event.originalEvent.touches[0].clientY - startY) > 10) { 47 reset(); 48 } 49 }; 50 51 var onTouchStart = function(event) { 52 event.stopPropagation(); 53 54 $(element).bind('touchend', onClick); 55 $("body").bind('touchmove.fastClick', onTouchMove); 56 57 startX = event.originalEvent.touches[0].clientX; 58 startY = event.originalEvent.touches[0].clientY; 59 }; 60 61 $(element).bind({ 62 touchstart: onTouchStart, 63 click: onClick 64 }); 65}; 66 67$.clickbuster = { 68 coordinates: [], 69 70 preventGhostClick: function(x, y) { 71 $.clickbuster.coordinates.push(x, y); 72 window.setTimeout($.clickbuster.pop, 2500); 73 }, 74 75 pop: function() { 76 $.clickbuster.coordinates.splice(0, 2); 77 }, 78 79 onClick: function(event) { 80 var x, y, i; 81 for (i = 0; i < $.clickbuster.coordinates.length; i += 2) { 82 x = $.clickbuster.coordinates[i]; 83 y = $.clickbuster.coordinates[i + 1]; 84 if (Math.abs(event.clientX - x) < 25 && Math.abs(event.clientY - y) < 25) { 85 event.stopPropagation(); 86 event.preventDefault(); 87 } 88 } 89 } 90}; 91 92$(function(){ 93 if (document.addEventListener){ 94 document.addEventListener('click', $.clickbuster.onClick, true); 95 } else if (document.attachEvent){ 96 // for IE 7/8 97 document.attachEvent('onclick', $.clickbuster.onClick); 98 } 99}); 100 101}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.