Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: yui/yui3-gallery
base: master
...
head fork: emkay/yui3-gallery
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Jun 22, 2012
@emkay emkay adding gallery-tap module c2c5b05
View
178 build/gallery-tap/gallery-tap-debug.js
@@ -0,0 +1,178 @@
+YUI.add('gallery-tap', function(Y) {
+
+/*
+ Copyright (c) 2012, Yahoo! Inc. All rights reserved.
+
+ Redistribution and use of this software in source and binary forms,
+ with or without modification, are permitted provided that the following
+ conditions are met:
+
+ Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+ Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * Provides 'tap' functionality for touchscreen devices. 'tap' is like a touchscreen 'click',
+ * only it requires much less finger-down time.
+ * 'tap' enables high-usability mobile applications, and more. Code by Yahoo Engineering.
+ */
+
+/**
+ * The tap module provides a gesture events, "tap", which normalizes user interactions
+ * across touch and mouse or pointer based input devices. This can be used by application developers
+ * to build input device agnostic components which behave the same in response to either touch or mouse based
+ * interaction.
+ *
+ */
+var SUPPORTS_TOUCHES = ("createTouch" in document),
+ EVENTS = {
+ START: SUPPORTS_TOUCHES ? 'touchstart' : 'mousedown',
+ MOVE: SUPPORTS_TOUCHES ? 'touchmove' : 'mousemove',
+ END: SUPPORTS_TOUCHES ? 'touchend' : 'mouseup',
+ CANCEL: SUPPORTS_TOUCHES ? 'touchcancel' : 'mousecancel',
+ TAP: 'tap'
+ },
+ HANDLES = {
+ ON: {
+ START: 'Y_TAP_ON_START_HANDLE',
+ MOVE: 'Y_TAP_ON_MOVE_HANDLE',
+ END: 'Y_TAP_ON_END_HANDLE',
+ CANCEL: 'Y_TAP_ON_CANCEL_HANDLE'
+ },
+ DELEGATE: {
+ START: 'Y_TAP_DELEGATE_START_HANDLE',
+ MOVE: 'Y_TAP_DELEGATE_MOVE_HANDLE',
+ END: 'Y_TAP_DELEGATE_END_HANDLE',
+ CANCEL: 'Y_TAP_DELEGATE_CANCEL_HANDLE'
+ }
+ };
+
+function detachHelper(subscription, handles, subset, context) {
+
+ handles = subset ? handles : [ handles.START, handles.MOVE, handles.END, handles.CANCEL ];
+
+ Y.each(handles, function (name) {
+ var handle = subscription[name];
+ if (handle) {
+ handle.detach();
+ subscription[name] = null;
+ }
+ });
+
+}
+
+
+/**
+ * Sets up a "tap" event, that is fired on touch devices in response to a tap event (finger down, finder up).
+ * This event can be used instead of listening for click events which have a 500ms delay on most touch devices.
+ * This event can also be listened for using node.delegate().
+ *
+ * @event tap
+ * @param type {string} "tap"
+ * @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event.
+ *
+ * @return {EventHandle} the detach handle
+ */
+Y.Event.define(EVENTS.TAP, {
+
+ on: function (node, subscription, notifier) {
+ subscription[HANDLES.ON.START] = node.on(EVENTS.START, this.touchStart, this, node, subscription, notifier);
+ },
+
+ detach: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.ON);
+ },
+
+ delegate: function (node, subscription, notifier, filter) {
+ subscription[HANDLES.DELEGATE.START] = node.delegate(EVENTS.START, function (e) {
+ this.touchStart(e, node, subscription, notifier, true);
+ }, filter, this);
+ },
+
+ detachDelegate: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.DELEGATE);
+ },
+
+ touchStart: function (event, node, subscription, notifier, delegate) {
+ var curr_handles = delegate ? HANDLES.DELEGATE : HANDLES.ON,
+ context = {
+ cancelled: false
+ };
+
+ // no right clicks
+ if (event.button && event.button === 3) {
+ return;
+ }
+
+ context.node = delegate ? event.currentTarget : node;
+ context.startXY = SUPPORTS_TOUCHES ? [ event.touches[0].pageX, event.touches[0].pageY ] : [ event.pageX, event.pageY ];
+
+ // for now just support a 1 finger count (later enhance via config)
+ if (event.touches && event.touches.length !== 1) {
+ return;
+ }
+
+ // something is off with the move that it attaches it but never triggers the handler
+ subscription[curr_handles.MOVE] = node.once(EVENTS.MOVE, this.touchMove, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.END] = node.once(EVENTS.END, this.touchEnd, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.CANCEL] = node.once(EVENTS.CANCEL, this.touchMove, this, node, subscription, notifier, delegate, context);
+ },
+
+ touchMove: function (event, node, subscription, notifier, delegate, context) {
+ var handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+ context.cancelled = true;
+
+ },
+
+ touchEnd: function (event, node, subscription, notifier, delegate, context) {
+ var startXY = context.startXY,
+ endXY = SUPPORTS_TOUCHES ? [ event.changedTouches[0].pageX, event.changedTouches[0].pageY ] : [event.pageX, event.pageY],
+ handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+
+ // make sure mouse didn't move
+ if (Math.abs(endXY[0] - startXY[0]) < 1 && Math.abs(endXY[1] - startXY[1]) < 1) {
+
+ event.type = EVENTS.TAP;
+ event.pageX = endXY[0];
+ event.pageY = endXY[1];
+ event.clientX = SUPPORTS_TOUCHES ? event.changedTouches[0].clientX : event.clientX;
+ event.clientY = SUPPORTS_TOUCHES ? event.changedTouches[0].clientY : event.clientY;
+ event.currentTarget = context.node;
+
+ setTimeout(function () {
+ notifier.fire(event);
+ }, 0);
+ }
+ }
+
+});
+
+
+}, '@VERSION@' ,{requires:['node-base', 'event-base', 'event-touch', 'event-synthetic'], skinnable:false});
View
1  build/gallery-tap/gallery-tap-min.js
@@ -0,0 +1 @@
+YUI.add("gallery-tap",function(d){var b=("createTouch" in document),a={START:b?"touchstart":"mousedown",MOVE:b?"touchmove":"mousemove",END:b?"touchend":"mouseup",CANCEL:b?"touchcancel":"mousecancel",TAP:"tap"},e={ON:{START:"Y_TAP_ON_START_HANDLE",MOVE:"Y_TAP_ON_MOVE_HANDLE",END:"Y_TAP_ON_END_HANDLE",CANCEL:"Y_TAP_ON_CANCEL_HANDLE"},DELEGATE:{START:"Y_TAP_DELEGATE_START_HANDLE",MOVE:"Y_TAP_DELEGATE_MOVE_HANDLE",END:"Y_TAP_DELEGATE_END_HANDLE",CANCEL:"Y_TAP_DELEGATE_CANCEL_HANDLE"}};function c(h,g,i,f){g=i?g:[g.START,g.MOVE,g.END,g.CANCEL];d.each(g,function(j){var k=h[j];if(k){k.detach();h[j]=null;}});}d.Event.define(a.TAP,{on:function(h,g,f){g[e.ON.START]=h.on(a.START,this.touchStart,this,h,g,f);},detach:function(h,g,f){c(g,e.ON);},delegate:function(i,h,g,f){h[e.DELEGATE.START]=i.delegate(a.START,function(j){this.touchStart(j,i,h,g,true);},f,this);},detachDelegate:function(h,g,f){c(g,e.DELEGATE);},touchStart:function(l,k,j,i,h){var f=h?e.DELEGATE:e.ON,g={cancelled:false};if(l.button&&l.button===3){return;}g.node=h?l.currentTarget:k;g.startXY=b?[l.touches[0].pageX,l.touches[0].pageY]:[l.pageX,l.pageY];if(l.touches&&l.touches.length!==1){return;}j[f.MOVE]=k.once(a.MOVE,this.touchMove,this,k,j,i,h,g);j[f.END]=k.once(a.END,this.touchEnd,this,k,j,i,h,g);j[f.CANCEL]=k.once(a.CANCEL,this.touchMove,this,k,j,i,h,g);},touchMove:function(l,k,j,i,h,g){var f=h?e.DELEGATE:e.ON;c(j,[f.MOVE,f.END,f.CANCEL],true,g);g.cancelled=true;},touchEnd:function(f,h,m,n,j,g){var i=g.startXY,k=b?[f.changedTouches[0].pageX,f.changedTouches[0].pageY]:[f.pageX,f.pageY],l=j?e.DELEGATE:e.ON;c(m,[l.MOVE,l.END,l.CANCEL],true,g);if(Math.abs(k[0]-i[0])<1&&Math.abs(k[1]-i[1])<1){f.type=a.TAP;f.pageX=k[0];f.pageY=k[1];f.clientX=b?f.changedTouches[0].clientX:f.clientX;f.clientY=b?f.changedTouches[0].clientY:f.clientY;f.currentTarget=g.node;setTimeout(function(){n.fire(f);},0);}}});},"@VERSION@",{requires:["node-base","event-base","event-touch","event-synthetic"],skinnable:false});
View
178 build/gallery-tap/gallery-tap.js
@@ -0,0 +1,178 @@
+YUI.add('gallery-tap', function(Y) {
+
+/*
+ Copyright (c) 2012, Yahoo! Inc. All rights reserved.
+
+ Redistribution and use of this software in source and binary forms,
+ with or without modification, are permitted provided that the following
+ conditions are met:
+
+ Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+ Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * Provides 'tap' functionality for touchscreen devices. 'tap' is like a touchscreen 'click',
+ * only it requires much less finger-down time.
+ * 'tap' enables high-usability mobile applications, and more. Code by Yahoo Engineering.
+ */
+
+/**
+ * The tap module provides a gesture events, "tap", which normalizes user interactions
+ * across touch and mouse or pointer based input devices. This can be used by application developers
+ * to build input device agnostic components which behave the same in response to either touch or mouse based
+ * interaction.
+ *
+ */
+var SUPPORTS_TOUCHES = ("createTouch" in document),
+ EVENTS = {
+ START: SUPPORTS_TOUCHES ? 'touchstart' : 'mousedown',
+ MOVE: SUPPORTS_TOUCHES ? 'touchmove' : 'mousemove',
+ END: SUPPORTS_TOUCHES ? 'touchend' : 'mouseup',
+ CANCEL: SUPPORTS_TOUCHES ? 'touchcancel' : 'mousecancel',
+ TAP: 'tap'
+ },
+ HANDLES = {
+ ON: {
+ START: 'Y_TAP_ON_START_HANDLE',
+ MOVE: 'Y_TAP_ON_MOVE_HANDLE',
+ END: 'Y_TAP_ON_END_HANDLE',
+ CANCEL: 'Y_TAP_ON_CANCEL_HANDLE'
+ },
+ DELEGATE: {
+ START: 'Y_TAP_DELEGATE_START_HANDLE',
+ MOVE: 'Y_TAP_DELEGATE_MOVE_HANDLE',
+ END: 'Y_TAP_DELEGATE_END_HANDLE',
+ CANCEL: 'Y_TAP_DELEGATE_CANCEL_HANDLE'
+ }
+ };
+
+function detachHelper(subscription, handles, subset, context) {
+
+ handles = subset ? handles : [ handles.START, handles.MOVE, handles.END, handles.CANCEL ];
+
+ Y.each(handles, function (name) {
+ var handle = subscription[name];
+ if (handle) {
+ handle.detach();
+ subscription[name] = null;
+ }
+ });
+
+}
+
+
+/**
+ * Sets up a "tap" event, that is fired on touch devices in response to a tap event (finger down, finder up).
+ * This event can be used instead of listening for click events which have a 500ms delay on most touch devices.
+ * This event can also be listened for using node.delegate().
+ *
+ * @event tap
+ * @param type {string} "tap"
+ * @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event.
+ *
+ * @return {EventHandle} the detach handle
+ */
+Y.Event.define(EVENTS.TAP, {
+
+ on: function (node, subscription, notifier) {
+ subscription[HANDLES.ON.START] = node.on(EVENTS.START, this.touchStart, this, node, subscription, notifier);
+ },
+
+ detach: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.ON);
+ },
+
+ delegate: function (node, subscription, notifier, filter) {
+ subscription[HANDLES.DELEGATE.START] = node.delegate(EVENTS.START, function (e) {
+ this.touchStart(e, node, subscription, notifier, true);
+ }, filter, this);
+ },
+
+ detachDelegate: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.DELEGATE);
+ },
+
+ touchStart: function (event, node, subscription, notifier, delegate) {
+ var curr_handles = delegate ? HANDLES.DELEGATE : HANDLES.ON,
+ context = {
+ cancelled: false
+ };
+
+ // no right clicks
+ if (event.button && event.button === 3) {
+ return;
+ }
+
+ context.node = delegate ? event.currentTarget : node;
+ context.startXY = SUPPORTS_TOUCHES ? [ event.touches[0].pageX, event.touches[0].pageY ] : [ event.pageX, event.pageY ];
+
+ // for now just support a 1 finger count (later enhance via config)
+ if (event.touches && event.touches.length !== 1) {
+ return;
+ }
+
+ // something is off with the move that it attaches it but never triggers the handler
+ subscription[curr_handles.MOVE] = node.once(EVENTS.MOVE, this.touchMove, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.END] = node.once(EVENTS.END, this.touchEnd, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.CANCEL] = node.once(EVENTS.CANCEL, this.touchMove, this, node, subscription, notifier, delegate, context);
+ },
+
+ touchMove: function (event, node, subscription, notifier, delegate, context) {
+ var handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+ context.cancelled = true;
+
+ },
+
+ touchEnd: function (event, node, subscription, notifier, delegate, context) {
+ var startXY = context.startXY,
+ endXY = SUPPORTS_TOUCHES ? [ event.changedTouches[0].pageX, event.changedTouches[0].pageY ] : [event.pageX, event.pageY],
+ handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+
+ // make sure mouse didn't move
+ if (Math.abs(endXY[0] - startXY[0]) < 1 && Math.abs(endXY[1] - startXY[1]) < 1) {
+
+ event.type = EVENTS.TAP;
+ event.pageX = endXY[0];
+ event.pageY = endXY[1];
+ event.clientX = SUPPORTS_TOUCHES ? event.changedTouches[0].clientX : event.clientX;
+ event.clientY = SUPPORTS_TOUCHES ? event.changedTouches[0].clientY : event.clientY;
+ event.currentTarget = context.node;
+
+ setTimeout(function () {
+ notifier.fire(event);
+ }, 0);
+ }
+ }
+
+});
+
+
+}, '@VERSION@' ,{requires:['node-base', 'event-base', 'event-touch', 'event-synthetic'], skinnable:false});
View
29 src/gallery-tap/build.properties
@@ -0,0 +1,29 @@
+# tap Build Properties
+
+# As long as the 'builder' project is cloned to the default folder
+# next to the 'yui3-gallery' project folder, the 'builddir' property does not
+# need to be changed
+#
+# If the 'builder' project is checked out to an alternate location, this
+# property should be updated to point to the checkout location.
+builddir=../../builder/componentbuild
+
+# The name of the component. E.g. event, attribute, widget
+component=gallery-tap
+
+# The list of files which should be concatenated to create the component
+# NOTE: For a css component. (e.g. cssfonts, cssgrids etc.) use component.cssfiles instead.
+# component.jsfiles=tap.js, tapHelperClass.js, tapSubComponentClass.js
+component.jsfiles=tap.js
+
+# The list of modules this component. requires. Used to set up the Y.add module call for YUI 3.
+component.requires=node-base, event-base, event-touch, event-synthetic
+
+# The list of modules this component. supersedes. Used to set up the Y.add module call for YUI 3.
+component.supersedes=
+
+# The list of modules that are optional for this module. Used to set up the Y.add module call for YUI 3.
+component.optional=
+# If your module has a skin file, set this flag to "true"
+component.skinnable=false
+#component.skinnable=true
View
7 src/gallery-tap/build.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- YUI 3 Gallery Component Build File -->
+<project name="tap" default="local">
+ <description>tap Build File</description>
+ <property file="build.properties" />
+ <import file="${builddir}/3.x/bootstrap.xml" description="Default Build Properties and Targets" />
+</project>
View
173 src/gallery-tap/js/tap.js
@@ -0,0 +1,173 @@
+/*
+ Copyright (c) 2012, Yahoo! Inc. All rights reserved.
+
+ Redistribution and use of this software in source and binary forms,
+ with or without modification, are permitted provided that the following
+ conditions are met:
+
+ Redistributions of source code must retain the above
+ copyright notice, this list of conditions and the
+ following disclaimer.
+
+ Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+ Neither the name of Yahoo! Inc. nor the names of its
+ contributors may be used to endorse or promote products
+ derived from this software without specific prior
+ written permission of Yahoo! Inc.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+ IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/**
+ * Provides 'tap' functionality for touchscreen devices. 'tap' is like a touchscreen 'click',
+ * only it requires much less finger-down time.
+ * 'tap' enables high-usability mobile applications, and more. Code by Yahoo Engineering.
+ */
+
+/**
+ * The tap module provides a gesture events, "tap", which normalizes user interactions
+ * across touch and mouse or pointer based input devices. This can be used by application developers
+ * to build input device agnostic components which behave the same in response to either touch or mouse based
+ * interaction.
+ *
+ */
+var SUPPORTS_TOUCHES = ("createTouch" in document),
+ EVENTS = {
+ START: SUPPORTS_TOUCHES ? 'touchstart' : 'mousedown',
+ MOVE: SUPPORTS_TOUCHES ? 'touchmove' : 'mousemove',
+ END: SUPPORTS_TOUCHES ? 'touchend' : 'mouseup',
+ CANCEL: SUPPORTS_TOUCHES ? 'touchcancel' : 'mousecancel',
+ TAP: 'tap'
+ },
+ HANDLES = {
+ ON: {
+ START: 'Y_TAP_ON_START_HANDLE',
+ MOVE: 'Y_TAP_ON_MOVE_HANDLE',
+ END: 'Y_TAP_ON_END_HANDLE',
+ CANCEL: 'Y_TAP_ON_CANCEL_HANDLE'
+ },
+ DELEGATE: {
+ START: 'Y_TAP_DELEGATE_START_HANDLE',
+ MOVE: 'Y_TAP_DELEGATE_MOVE_HANDLE',
+ END: 'Y_TAP_DELEGATE_END_HANDLE',
+ CANCEL: 'Y_TAP_DELEGATE_CANCEL_HANDLE'
+ }
+ };
+
+function detachHelper(subscription, handles, subset, context) {
+
+ handles = subset ? handles : [ handles.START, handles.MOVE, handles.END, handles.CANCEL ];
+
+ Y.each(handles, function (name) {
+ var handle = subscription[name];
+ if (handle) {
+ handle.detach();
+ subscription[name] = null;
+ }
+ });
+
+}
+
+
+/**
+ * Sets up a "tap" event, that is fired on touch devices in response to a tap event (finger down, finder up).
+ * This event can be used instead of listening for click events which have a 500ms delay on most touch devices.
+ * This event can also be listened for using node.delegate().
+ *
+ * @event tap
+ * @param type {string} "tap"
+ * @param fn {function} The method the event invokes. It receives the event facade of the underlying DOM event.
+ *
+ * @return {EventHandle} the detach handle
+ */
+Y.Event.define(EVENTS.TAP, {
+
+ on: function (node, subscription, notifier) {
+ subscription[HANDLES.ON.START] = node.on(EVENTS.START, this.touchStart, this, node, subscription, notifier);
+ },
+
+ detach: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.ON);
+ },
+
+ delegate: function (node, subscription, notifier, filter) {
+ subscription[HANDLES.DELEGATE.START] = node.delegate(EVENTS.START, function (e) {
+ this.touchStart(e, node, subscription, notifier, true);
+ }, filter, this);
+ },
+
+ detachDelegate: function (node, subscription, notifier) {
+ detachHelper(subscription, HANDLES.DELEGATE);
+ },
+
+ touchStart: function (event, node, subscription, notifier, delegate) {
+ var curr_handles = delegate ? HANDLES.DELEGATE : HANDLES.ON,
+ context = {
+ cancelled: false
+ };
+
+ // no right clicks
+ if (event.button && event.button === 3) {
+ return;
+ }
+
+ context.node = delegate ? event.currentTarget : node;
+ context.startXY = SUPPORTS_TOUCHES ? [ event.touches[0].pageX, event.touches[0].pageY ] : [ event.pageX, event.pageY ];
+
+ // for now just support a 1 finger count (later enhance via config)
+ if (event.touches && event.touches.length !== 1) {
+ return;
+ }
+
+ // something is off with the move that it attaches it but never triggers the handler
+ subscription[curr_handles.MOVE] = node.once(EVENTS.MOVE, this.touchMove, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.END] = node.once(EVENTS.END, this.touchEnd, this, node, subscription, notifier, delegate, context);
+ subscription[curr_handles.CANCEL] = node.once(EVENTS.CANCEL, this.touchMove, this, node, subscription, notifier, delegate, context);
+ },
+
+ touchMove: function (event, node, subscription, notifier, delegate, context) {
+ var handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+ context.cancelled = true;
+
+ },
+
+ touchEnd: function (event, node, subscription, notifier, delegate, context) {
+ var startXY = context.startXY,
+ endXY = SUPPORTS_TOUCHES ? [ event.changedTouches[0].pageX, event.changedTouches[0].pageY ] : [event.pageX, event.pageY],
+ handles = delegate ? HANDLES.DELEGATE : HANDLES.ON;
+
+ detachHelper(subscription, [ handles.MOVE, handles.END, handles.CANCEL ], true, context);
+
+ // make sure mouse didn't move
+ if (Math.abs(endXY[0] - startXY[0]) < 1 && Math.abs(endXY[1] - startXY[1]) < 1) {
+
+ event.type = EVENTS.TAP;
+ event.pageX = endXY[0];
+ event.pageY = endXY[1];
+ event.clientX = SUPPORTS_TOUCHES ? event.changedTouches[0].clientX : event.clientX;
+ event.clientY = SUPPORTS_TOUCHES ? event.changedTouches[0].clientY : event.clientY;
+ event.currentTarget = context.node;
+
+ setTimeout(function () {
+ notifier.fire(event);
+ }, 0);
+ }
+ }
+
+});

No commit comments for this range

Something went wrong with that request. Please try again.