<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Remove onClick delay on webkit for iPhone</title>
	<atom:link href="http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/feed" rel="self" type="application/rss+xml" />
	<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone</link>
	<description>Web and mobile development</description>
	<lastBuildDate>Thu, 17 May 2012 03:17:56 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: luwes</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-26098</link>
		<dc:creator>luwes</dc:creator>
		<pubDate>Sun, 01 Apr 2012 08:13:02 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-26098</guid>
		<description>Just noticed that &lt;code&gt;e.stopPropagation();&lt;/code&gt; should be &lt;code&gt;e.stopImmediatePropagation();&lt;/code&gt; to prevent the ghost click from happening in every case.</description>
		<content:encoded><![CDATA[<p>Just noticed that <code>e.stopPropagation();</code> should be <code>e.stopImmediatePropagation();</code> to prevent the ghost click from happening in every case.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: luwes</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-26097</link>
		<dc:creator>luwes</dc:creator>
		<pubDate>Sun, 01 Apr 2012 07:55:18 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-26097</guid>
		<description>Thanks for an awesome script Matteo.

The code needed some changes in my use-case, so here is a take on it to get the default behavior back like scrolling, pinching, etc. without getting the second click event (ghost click).

&lt;pre&gt;function NoClickDelay(el) {
	if (&#039;ontouchstart&#039; in window) {
		this.element = typeof el === &quot;object&quot; ? el : document.getElementById(el);
		this.element.addEventListener(&#039;touchstart&#039;, this, false);
		this.element.addEventListener(&#039;click&#039;, this, true);
	}
}

NoClickDelay.prototype = {
	handleEvent: function(e) {
		this[e.type](e);
	},

	touchstart: function(e) {
		this.moved = false;

		this.theTarget = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
		if (this.theTarget.nodeType == 3) this.theTarget = theTarget.parentNode;
		this.theTarget.className += &quot; pressed&quot;;

		this.element.addEventListener(&#039;touchmove&#039;, this, false);
		this.element.addEventListener(&#039;touchend&#039;, this, false);
	},

	touchmove: function(e) {
		this.moved = true;
		this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, &#039;&#039;);
	},

	touchend: function(e) {
		this.element.removeEventListener(&#039;touchmove&#039;, this, false);
		this.element.removeEventListener(&#039;touchend&#039;, this, false);

		if (!this.moved &amp;&amp; this.theTarget) {
			this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, &#039;&#039;);
			var theEvent = document.createEvent(&#039;MouseEvents&#039;);
			theEvent.initEvent(&#039;click&#039;, true, true);
			this.theTarget.dispatchEvent(theEvent);
		}

		this.theTarget = undefined;
	},

	click: function(e) {
		if (this.theTarget === undefined) {
			e.stopPropagation();
			e.preventDefault();
		}
	}
};&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Thanks for an awesome script Matteo.</p>
<p>The code needed some changes in my use-case, so here is a take on it to get the default behavior back like scrolling, pinching, etc. without getting the second click event (ghost click).</p>
<pre>function NoClickDelay(el) {
	if (&#x27;ontouchstart&#x27; in window) {
		this.element = typeof el === &quot;object&quot; ? el : document.getElementById(el);
		this.element.addEventListener(&#x27;touchstart&#x27;, this, false);
		this.element.addEventListener(&#x27;click&#x27;, this, true);
	}
}

NoClickDelay.prototype = {
	handleEvent: function(e) {
		this[e.type](e);
	},

	touchstart: function(e) {
		this.moved = false;

		this.theTarget = document.elementFromPoint(e.targetTouches[0].clientX, e.targetTouches[0].clientY);
		if (this.theTarget.nodeType == 3) this.theTarget = theTarget.parentNode;
		this.theTarget.className += &quot; pressed&quot;;

		this.element.addEventListener(&#x27;touchmove&#x27;, this, false);
		this.element.addEventListener(&#x27;touchend&#x27;, this, false);
	},

	touchmove: function(e) {
		this.moved = true;
		this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, &#x27;&#x27;);
	},

	touchend: function(e) {
		this.element.removeEventListener(&#x27;touchmove&#x27;, this, false);
		this.element.removeEventListener(&#x27;touchend&#x27;, this, false);

		if (!this.moved &amp;amp;&amp;amp; this.theTarget) {
			this.theTarget.className = this.theTarget.className.replace(/ ?pressed/gi, &#x27;&#x27;);
			var theEvent = document.createEvent(&#x27;MouseEvents&#x27;);
			theEvent.initEvent(&#x27;click&#x27;, true, true);
			this.theTarget.dispatchEvent(theEvent);
		}

		this.theTarget = undefined;
	},

	click: function(e) {
		if (this.theTarget === undefined) {
			e.stopPropagation();
			e.preventDefault();
		}
	}
};</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiwi</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-26010</link>
		<dc:creator>kiwi</dc:creator>
		<pubDate>Fri, 16 Mar 2012 16:14:22 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-26010</guid>
		<description>no, it&#039;s just an option. I recommend to use it in the body</description>
		<content:encoded><![CDATA[<p>no, it&#8217;s just an option. I recommend to use it in the body</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ghostCoder</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-26003</link>
		<dc:creator>ghostCoder</dc:creator>
		<pubDate>Thu, 15 Mar 2012 14:06:27 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-26003</guid>
		<description>remove the e.preventDefault() and see</description>
		<content:encoded><![CDATA[<p>remove the e.preventDefault() and see</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiwi</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-26002</link>
		<dc:creator>kiwi</dc:creator>
		<pubDate>Thu, 15 Mar 2012 13:43:02 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-26002</guid>
		<description>and in the end jQuery and Zepto are Javascript... The class can be easily imported in both frameworks for all users but please bare in mind that when working on web development, it&#039;s better to know what&#039;s behind a framework, what&#039;s using and how&#039;s working. I&#039;m not saying is bad attitude to use a js framework but imo is better to use/study &#039;original&#039; js examples :)</description>
		<content:encoded><![CDATA[<p>and in the end jQuery and Zepto are Javascript&#8230; The class can be easily imported in both frameworks for all users but please bare in mind that when working on web development, it&#8217;s better to know what&#8217;s behind a framework, what&#8217;s using and how&#8217;s working. I&#8217;m not saying is bad attitude to use a js framework but imo is better to use/study &#8216;original&#8217; js examples <img src='http://cubiq.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andrew</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-25996</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Tue, 13 Mar 2012 23:10:33 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-25996</guid>
		<description>Is this a de facto solution still or is there a better approach with jquery now a days?

If so, is there any reason not to attach this to the body once, or does it make more sense to attach it to the elements (or maybe one level up?)

Thanks!
Andrew</description>
		<content:encoded><![CDATA[<p>Is this a de facto solution still or is there a better approach with jquery now a days?</p>
<p>If so, is there any reason not to attach this to the body once, or does it make more sense to attach it to the elements (or maybe one level up?)</p>
<p>Thanks!<br />
Andrew</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matteo Spinelli</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-25928</link>
		<dc:creator>Matteo Spinelli</dc:creator>
		<pubDate>Wed, 29 Feb 2012 07:21:21 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-25928</guid>
		<description>at the time I did this snippet jquery was not ready for mobile, zepto not even existed :)</description>
		<content:encoded><![CDATA[<p>at the time I did this snippet jquery was not ready for mobile, zepto not even existed <img src='http://cubiq.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Max</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-25918</link>
		<dc:creator>Max</dc:creator>
		<pubDate>Mon, 27 Feb 2012 22:09:46 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-25918</guid>
		<description>Not particularly useful. If you can make a jQuery/Zepto plugin that integrates in framework core and allows you to make $el.on(&#039;press&#039;, function(){}); that would be much better. Here&#039;s my approach, but it&#039;s not quite there yet http://maxdegterev.name/javascript-2/fast-buttons-for-webapps/</description>
		<content:encoded><![CDATA[<p>Not particularly useful. If you can make a jQuery/Zepto plugin that integrates in framework core and allows you to make $el.on(&#8216;press&#8217;, function(){}); that would be much better. Here&#8217;s my approach, but it&#8217;s not quite there yet <a href="http://maxdegterev.name/javascript-2/fast-buttons-for-webapps/" rel="nofollow">http://maxdegterev.name/javascript-2/fast-buttons-for-webapps/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kiwi</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-25857</link>
		<dc:creator>kiwi</dc:creator>
		<pubDate>Thu, 16 Feb 2012 16:42:59 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-25857</guid>
		<description>Here&#039;s my version. It&#039;s complete with everything:

- Responsive click
- If finger is moved more than 10px the click is canceled
- ghostclick is prevented
- works with touch device and common browser (touch and click events)

how to use:

to set all elements responsive (the entire body):
&lt;code&gt;
var bdy = document.getElementsByTagName(&#039;body&#039;);
new FastClick(bdy[0]); 
&lt;/code&gt;		

to a specific element:
&lt;code&gt;
var el1 = document.getElementById(&quot;elementId&quot;);
new FastClick(el1); 
&lt;/code&gt;

the code:


&lt;pre&gt;
function FastClick(el) {

		this.el = el &#124;&#124; document.getElementById(el);
		this.moved = false;
		this.startX = 0;
		this.startY = 0;
		this.coordinates = [];
		
//		if (window.Touch) 
		this.el.addEventListener(&#039;touchstart&#039;, this, false);
		
		this.el.addEventListener(&#039;click&#039;, this, false);
		
	}
	
FastClick.prototype = {
	
	handleEvent: function(e) {
		
		switch(e.type) {
		
		case &#039;touchstart&#039;: this.onTouchStart(e); break;
		case &#039;touchmove&#039;: this.onTouchMove(e); break;
		case &#039;touchend&#039;: this.onTouchEnd(e); break;
		case &#039;click&#039;: this.onMouseClick(e); break;
		
		}
	},
	
	onTouchStart: function(e) {		

		e.stopPropagation();
		
		this.moved = false;
				
		this.target = document.elementFromPoint(
				e.changedTouches[0].clientX,
				e.changedTouches[0].clientY);
		if (this.target.nodeType == 3) this.target = this.target.parentNode;
		
		this.startX = e.touches[0].clientX;
		this.startY = e.touches[0].clientY;
		
		this.el.addEventListener(&#039;touchmove&#039;, this, false);
		this.el.addEventListener(&#039;touchend&#039;, this, false);
		
	},
	
	onTouchMove: function(e) {
		
		//if finger moves more than 10px flag to cancel
        //code.google.com/mobile/articles/fast_buttons.html
		if (Math.abs(e.touches[0].clientX - this.startX) &gt; 10 &#124;&#124;
				Math.abs(e.touches[0].clientY - this.startY) &gt; 10) {			
			this.moved = true;
		}
		
	},
	
	onTouchEnd: function(e) {
		
		e.preventDefault();
		e.stopPropagation();
		
		 this.preventGhostClick(this.startX, this.startY);
		
		 this.el.removeEventListener(&#039;touchmove&#039;, this, false);
		 this.el.removeEventListener(&#039;touchend&#039;, this, false);
		
		if(!this.moved &amp;&amp; this.target){
			var evt = document.createEvent(&#039;MouseEvents&#039;);
			evt.initMouseEvent(&#039;click&#039;, true, true);
			this.target.dispatchEvent(evt);
		}
		
		//reset
		this.target = undefined;
		this.startX = 0;
		this.startY = 0;
		this.moved = false;

	},
	
	onTouchCancel: function(e) {

		//reset
		this.target = undefined;
		this.startX = 0;
		this.startY = 0;
		this.moved = false;
	},
	
	
	preventGhostClick: function(x, y) {

		 this.coordinates.push(x, y);
		 var self = this;
		 setTimeout(self.popArr, 2500);
	},
		

	popArr: function() {
		 this.coordinates.splice(0, 2);
	},
		

	onMouseClick: function(e) {		

		for (var i = 0; i &lt;  this.coordinates.length; i += 2) {
			var x =  this.coordinates[i];
			var y =  this.coordinates[i + 1];
			if (Math.abs(e.clientX - x) &lt; 25 &amp;&amp; Math.abs(e.clientY - y) &lt; 25) {
				e.stopPropagation();
				e.preventDefault();
			}
		}
	}
};
&lt;/pre&gt;


Hope it helps!</description>
		<content:encoded><![CDATA[<p>Here&#8217;s my version. It&#8217;s complete with everything:</p>
<p>- Responsive click<br />
- If finger is moved more than 10px the click is canceled<br />
- ghostclick is prevented<br />
- works with touch device and common browser (touch and click events)</p>
<p>how to use:</p>
<p>to set all elements responsive (the entire body):<br />
<code><br />
var bdy = document.getElementsByTagName('body');<br />
new FastClick(bdy[0]);<br />
</code>		</p>
<p>to a specific element:<br />
<code><br />
var el1 = document.getElementById("elementId");<br />
new FastClick(el1);<br />
</code></p>
<p>the code:</p>
<pre>
function FastClick(el) {

		this.el = el || document.getElementById(el);
		this.moved = false;
		this.startX = 0;
		this.startY = 0;
		this.coordinates = [];

//		if (window.Touch)
		this.el.addEventListener(&#x27;touchstart&#x27;, this, false);

		this.el.addEventListener(&#x27;click&#x27;, this, false);

	}

FastClick.prototype = {

	handleEvent: function(e) {

		switch(e.type) {

		case &#x27;touchstart&#x27;: this.onTouchStart(e); break;
		case &#x27;touchmove&#x27;: this.onTouchMove(e); break;
		case &#x27;touchend&#x27;: this.onTouchEnd(e); break;
		case &#x27;click&#x27;: this.onMouseClick(e); break;

		}
	},

	onTouchStart: function(e) {		

		e.stopPropagation();

		this.moved = false;

		this.target = document.elementFromPoint(
				e.changedTouches[0].clientX,
				e.changedTouches[0].clientY);
		if (this.target.nodeType == 3) this.target = this.target.parentNode;

		this.startX = e.touches[0].clientX;
		this.startY = e.touches[0].clientY;

		this.el.addEventListener(&#x27;touchmove&#x27;, this, false);
		this.el.addEventListener(&#x27;touchend&#x27;, this, false);

	},

	onTouchMove: function(e) {

		//if finger moves more than 10px flag to cancel
        //code.google.com/mobile/articles/fast_buttons.html
		if (Math.abs(e.touches[0].clientX - this.startX) &amp;gt; 10 ||
				Math.abs(e.touches[0].clientY - this.startY) &amp;gt; 10) {
			this.moved = true;
		}

	},

	onTouchEnd: function(e) {

		e.preventDefault();
		e.stopPropagation();

		 this.preventGhostClick(this.startX, this.startY);

		 this.el.removeEventListener(&#x27;touchmove&#x27;, this, false);
		 this.el.removeEventListener(&#x27;touchend&#x27;, this, false);

		if(!this.moved &amp;amp;&amp;amp; this.target){
			var evt = document.createEvent(&#x27;MouseEvents&#x27;);
			evt.initMouseEvent(&#x27;click&#x27;, true, true);
			this.target.dispatchEvent(evt);
		}

		//reset
		this.target = undefined;
		this.startX = 0;
		this.startY = 0;
		this.moved = false;

	},

	onTouchCancel: function(e) {

		//reset
		this.target = undefined;
		this.startX = 0;
		this.startY = 0;
		this.moved = false;
	},

	preventGhostClick: function(x, y) {

		 this.coordinates.push(x, y);
		 var self = this;
		 setTimeout(self.popArr, 2500);
	},

	popArr: function() {
		 this.coordinates.splice(0, 2);
	},

	onMouseClick: function(e) {		

		for (var i = 0; i &amp;lt;  this.coordinates.length; i += 2) {
			var x =  this.coordinates[i];
			var y =  this.coordinates[i + 1];
			if (Math.abs(e.clientX - x) &amp;lt; 25 &amp;amp;&amp;amp; Math.abs(e.clientY - y) &amp;lt; 25) {
				e.stopPropagation();
				e.preventDefault();
			}
		}
	}
};
</pre>
<p>Hope it helps!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vasco Costa</title>
		<link>http://cubiq.org/remove-onclick-delay-on-webkit-for-iphone/comment-page-1#comment-25848</link>
		<dc:creator>Vasco Costa</dc:creator>
		<pubDate>Wed, 15 Feb 2012 10:54:50 +0000</pubDate>
		<guid isPermaLink="false">http://cubiq.org/?p=9#comment-25848</guid>
		<description>I&#039;m using this with a twist. I use modernizr because I want to target as many devices as possible, and use the &#039;touch&#039; property to determine if it should act on click or on touchstart.

&lt;code&gt;var CLICK_EVENT = &quot;click&quot;;
if(Modernizr.touch)
{
    CLICK_EVENT = &quot;ontouchstart&quot;;
}

function doStuff()
{
    $(&#039;#selector&#039;).on(CLICK_EVENT, function() { //stuff });
}&lt;/code&gt;

Hope it helps.</description>
		<content:encoded><![CDATA[<p>I&#8217;m using this with a twist. I use modernizr because I want to target as many devices as possible, and use the &#8216;touch&#8217; property to determine if it should act on click or on touchstart.</p>
<p><code>var CLICK_EVENT = "click";<br />
if(Modernizr.touch)<br />
{<br />
    CLICK_EVENT = "ontouchstart";<br />
}</p>
<p>function doStuff()<br />
{<br />
    $('#selector').on(CLICK_EVENT, function() { //stuff });<br />
}</code></p>
<p>Hope it helps.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

