From 97a8c88df81340ab89d6d4aeac66df6d2e933bc9 Mon Sep 17 00:00:00 2001 From: Olivier Paroz Date: Wed, 17 Feb 2016 18:31:54 +0100 Subject: [PATCH] Add drag'n drop support for mobile devices You need to tap and hold to be able to move elements --- css/styles.css | 8 + js/galleryview.js | 1 + js/vendor/jquery-touch-events/README.md | 195 ++++ .../src/1.0.1/jquery.mobile-events.js | 875 ++++++++++++++++++ .../src/1.0.1/jquery.mobile-events.min.js | 1 + js/vendor/jquery.ui.touch-punch-custom.js | 184 ++++ js/vendor/jqueryui-touch-punch/README.md | 41 + .../jquery.ui.touch-punch.js | 180 ++++ templates/part.content.php | 2 + 9 files changed, 1487 insertions(+) create mode 100644 js/vendor/jquery-touch-events/README.md create mode 100644 js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.js create mode 100644 js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.min.js create mode 100644 js/vendor/jquery.ui.touch-punch-custom.js create mode 100644 js/vendor/jqueryui-touch-punch/README.md create mode 100644 js/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.js diff --git a/css/styles.css b/css/styles.css index 0038d34569..c0edb6511a 100644 --- a/css/styles.css +++ b/css/styles.css @@ -110,10 +110,16 @@ a.row-element { vertical-align: top; -webkit-transition: transform .2s ease-in-out; transition: transform .2s ease-in-out; + -webkit-user-select:none; + -moz-user-select:none; + -ms-user-select:none; + user-select:none; + -webkit-touch-callout:none; } .album-droppable { transform: scale(0.9); + -webkit-transform: scale(0.9); } .album-droppable .album { @@ -128,10 +134,12 @@ a.row-element { .album-droppable .album .cropped { transform: scale(0.9); + -webkit-transform: scale(0.9); } .album-droppable-hover { transform: scale(1.0); + -webkit-transform: scale(1.0); -webkit-transition: transform .1s ease-in; transition: transform .1s ease-in; } diff --git a/js/galleryview.js b/js/galleryview.js index 6ba7f7f99b..ac2f316328 100644 --- a/js/galleryview.js +++ b/js/galleryview.js @@ -206,6 +206,7 @@ * @private */ _initButtons: function () { + this.element.on("contextmenu", function(e) { e.preventDefault(); }); $('#filelist-button').click(Gallery.switchToFilesView); $('#download').click(Gallery.download); $('#share-button').click(Gallery.share); diff --git a/js/vendor/jquery-touch-events/README.md b/js/vendor/jquery-touch-events/README.md new file mode 100644 index 0000000000..4e48727508 --- /dev/null +++ b/js/vendor/jquery-touch-events/README.md @@ -0,0 +1,195 @@ +jQuery Touch Events +==================== + +This is a series of plugins that create additional events that can be used in combination with jQuery when developing for mobile devices. The events are also compatible with desktop browsers to ensure ultimate compatibility for your projects. In time, we will update the Repository to include some very basic demonstrations to get you started with using the events, but for now, we've put together a list of the events that are provided, and what they do. + +As explained, the events are each triggered by native touch events, or alternatively by click events. The plugin automatically detects whether the user's device is touch compatible, and will use the correct native events whenever required. It is hoped that these events will help to aid single-environment development with jQuery for mobile web app development. + +Version History: +--------------- + +After almost 2 years in public beta, I am pleased to announce that the library is now officially launched as **version 1.0.0**. I'll be updating the version history over time with digests of fixes, features and improvements: + ++ **2015-07-18 - Version 1.0.0** + + The library officially entered 1.0.0 after minor bug fixes and final adjustments. + ++ **2015-08-21 - Version 1.0.1** + + Added Bower package for easy install + + Fixed a bug where Internet Explorer under Windows Mobile did not trigger certain events. + +Utility Functions: +----------------- +In addition to the numerous additional events that are provided, the library also includes a number of utility functions that can be used to further leverage the power of native events within your website or application. These utility functions can be used for unifying basic events, such as `tapstart` or `mousedown`. + +The following utility functions are provided (each function is registered to the jQuery namespace, and should be called with `$.funcName()` (or `jQuery.funcName()` for compatibility): + ++ `isTouchCapable()`: +Returns `true` or `false` depending upon whether touch events are supported. ++ `getStartEvent()`: +Returns `touchstart` for touch-enabled devices, or `mousedown` for standard environments. ++ `getEndEvent()`: +Returns `touchend` for touch-enabled devices, or `mouseup` for standard environments. ++ `getMoveEvent()`: +Returns `touchmove` for touch-enabled devices, or `mousemove` for standard environments. ++ `getTapEvent()`: +Returns `tap` for touch-enabled devices, or `click` for standard environments. ++ `getScrollEvent()`: +Returns `touchmove` for touch-enabled devices, or `scroll` for standard environments. **Caution should be exercised when using this function, since some mobile browsers will correctly bind to `scroll` as well as `touchmove`.** + +Events Provided: +--------------- + ++ **`tapstart`** +Fired as soon as the user begins touching an element (or clicking, for desktop environments). ++ **`tapend`** +Fired after the user releases their finger from the target element (or releases their mouse button on desktops). ++ **`tapmove`** +Fired as soon as the user begins moving their finger on an element (or moving their mouse, for desktop environments). ++ **`tap`** +This event is fired whenever the user taps and releases their finger on the target element. Caution should be observed when using this event in conjunction without tap events, especially ``doubletap``. This event will be fired twice when ``doubletap`` is used, so it is recommended to use ``singletap`` in this case. ++ **`singletap`** +Unlike ``tap`` this event is only triggered once we are certain the user has only tapped the target element a single time. This will not be triggered by ``doubletap`` or ``taphold``, unlike ``tap``. Since we need to run some tests to make sure the user isn't double tapping or holding a tap on the target element, this event is fired with a short delay (currently of 500 milliseconds). ++ **`doubletap`** +Triggered whenever the user double taps on the target element. The threshold (time between taps) is currently set at 500 milliseconds. ++ **`taphold`** +This event is triggered whenever the user taps on the target element and leaves their finger on the element for at least *750 milliseconds*. ++ **`swipe`** +This is called whenever the user swipes their finger on the target element. It is not direction-dependent, and is fired regardless of the direction the user swiped. ++ **`swipeup`** +Similar to ``swipe``, except only called when the user swipes their finger in an upward direction on the target element (i.e. bottom to top) ++ **`swiperight`** +Similar to ``swipe``, but triggered only when the user swipes their finger left to right on the target element. ++ **`swipedown`** +Similar to ``swipe``, but triggered only when the user swipes their finger top to bottom on the target element. ++ **`swipeleft`** +Similar to ``swipe``, but triggered only when the user swipes their finger from right to left. ++ **`swipeend`** +The ``swipeend`` event is trigged whenever a swipe event ends (i.e. the user finished moving their finger / cursor and released it). This event should be used to handle custom functions, since it will be triggered only when the swipe ends, rather than triggering immediately when the threshold has been met. ++ **`scrollstart`** +Triggered as soon as scrolling begins on the target element. ++ **`scrollend`** +Triggered as soon as scrolling is stopped on the target element. ++ **`orientationchange`** +This event is triggered when the orientation of the device is changed. Please note that it uses throttling for non-mobile devices, or devices which do not support the native ``orientationchange`` event. In the latter instance, a detection of the viewport size change occurs. + +Callback Data: +-------------- +Each event now features a second argument that can be passed to the specified callback function. This argument includes some basic data relating specifically to the event, and can be accessed as a standard JavaScript object. To hook into this parameter, you should use the following code: + +`$(element).swipeend(function(e, touch) { });` + +Given the example above, `touch` will now contain some basic data that can be accessed through `touch.`. The first argument will represent the last *native* event that occurred (the names used for these two arguments is irrelevant). + +Each event provides different callback data. The following shows the numerous data that are passed back to the callback function inside the second parameter: + +##`tapstart`, `tapend`, `tapmove`, `tap`, `singletap`: + +`offset` - object containing the X and Y positions of the event relative to the element to which is was bound. Accessed through `offset.x` and `offset.y` respectively. + +`position` - object containing the X and Y positions of the event relative to the screen. Accessed through `position.x` and `position.y` respectively. + +`target` - the jQuery object from which the event was triggered. + +`time` - JavaScript timestamp the event occurred (milliseconds since the Unix Epoch) + +##`taphold`: + +`duration`: the time in milliseconds that the user tapped for. + +`endOffset` - object containing the X and Y positions of the end event (i.e. when the user released their finger or mouse) relative to the element to which the event was bound. Accessed through `endOffset.x` and `endOffset.y` respectively. + +`endPosition` - object containing the X and Y positions of the end event (i.e. when the user released their finger or mouse) relative to the screen. Accessed through `endPosition.x` and `endPosition.y` respectively. + +`endTime` - JavaScript timestamp the `taphold` was triggered (milliseconds since the Unix Epoch). This will ordinarily be equal to the `startTime` + `taphold` threshold. + +`startOffset` - object containing the X and Y positions of the start event (i.e. when the user pressed their finger or mouse) relative to the element to which the event was bound. Accessed through `endOffset.x` and `endOffset.y` respectively. + +`startPosition` - object containing the X and Y positions of the start event (i.e. when the user pressed their finger or mouse) relative to the screen. Accessed through `endPosition.x` and `endPosition.y` respectively. + +`startTime` - JavaScript timestamp the `taphold` started (milliseconds since the Unix Epoch). + +`target` - the jQuery object from which the event was triggered. + +##`doubletap`: + +`firstTap` - Object containing the same data as a `tap` event, but for the first tap to occur. + +`secondTap` - Object containing the same data as a `tap` event, but for the second (i.e. final) tap to occur. + +`interval` - the time in milliseconds between the two tap. + +##`swipe`, `swipeup`, `swiperight`, `swipedown`, `swipeleft`, `swipeend`: + +`direction` - string representing the swipe direction (either `up`, `right`, `down` or `left`). + +`duration` - the time in milliseconds over which the swipe took place (for best results, use with `swipeend` only, as this will typically be equal to the defined `swipe-threshold`. + +`xAmount` - number of pixels the swipe occupied on the X-axis (returned regardless of direction). + +`yAmount` - number of pixels the swipe occupied on the Y-axis (returned regardless of direction). + +`startEvent` - Object containing the same data as a `tap` event, but captured when swiping begins. + +`endEvent` - Object containing the same data as a `tap` event, but captured when swiping is complete. + +Demo: +----- +I have put together a simple demo application that shows the numerous events in action. The console on the left hand side is used to show information about the events that have been called. You can examine the code easily by viewing the page's source to lear more about how this works. Please click on the below to check out the demo: + +http://ben-major.co.uk/jquery-mobile-events/ + +Please be aware that this demonstration uses Google's hosted jQuery file, and also pulls the latest version of the events library from GitHub. It is a great place to check the status of the library. Since this demo uses the vanilla code, it is a good idea to check the library functionality here for your own reference. If you're running into problems with the library, please check this demonstration using your device in the first instance. You can scan in the QR below to go directly to the web page: + +![Demonstration QR Code](http://qrfree.kaywa.com/?l=1&s=8&d=http%3A%2F%2Fben-major.co.uk%2Fjquery-mobile-events%2F) + +Usage: +------ +All of the events outlined above have been written using jQuery's ``event.special`` object, and so can be used in conjunction with jQuery's event handling functions, as well as shortcut wrappers. + +**Binding a ``tap`` event to an element:** +``$('#myElement').bind('tap', function(e) { console.log('User tapped #myElement'); });`` + +**Using with ``.on()`` and ``.live()``:** +``$('#myElement').live('tap', function(e) { console.log('User tapped #myElement'); });`` +``$('#myElement').on('tap', function(e) { console.log('User tapped #myElement'); });`` + +**Triggering the event:** +``$('#myElement').trigger('tap');`` + +**Removing the event with ``.off()``, ``.die()`` and ``.unbind()``:** +``$('#myElement').off('tap', hander);`` +``$('#myElement').die('tap', hander);`` +``$('#myElement').unbind('tap', hander);`` + +**Using method wrapper:** +``$('#myElement').tap(function(e) { console.log('User tapped #myElement'); });`` + +**Method chaining:** +Chaining has also been preserved, so you can easily use these events in conjuction with other jQuery functions, or attach multiple events in a single, chained LOC: +``$('#myElement').singletap(function() { console.log('singletap'); }).doubletap(function() { console.log('doubletap'); });`` + +Defining Thresholds: +-------------------- +You can also define custom thresholds to be used for ``swipe`` events (``swipeup``, ``swiperight``, ``swipedown`` and ``swipeleft``) to prevent interference with scrolling and other events. To do so, simply assign a `data-xthreshold` or `date-ythreshold` to the target element as follows: + +``
`` + +The value you define is the difference in pixels that the user must move before the event is triggered on the target element. If no threshold is defined, a default of `50px` will be used. + +``data-xthreshold`` defines the horizontal threshold. + +``data-ythreshold`` defines the vertical threshold. + +Requirements: +------------- +The library works with jQuery 1.7.0+. All major browsers have been tested without problem. The library is not compatible with jQuery < 1.7. + +License: +-------- +Licensed under the MIT License: + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.js b/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.js new file mode 100644 index 0000000000..92041d0c34 --- /dev/null +++ b/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.js @@ -0,0 +1,875 @@ +/*! + * jQuery Mobile Events + * by Ben Major (www.ben-major.co.uk) + * + * Copyright 2011, Ben Major + * Licensed under the MIT License: + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +(function ($) { + $.attrFn = $.attrFn || {}; + + // navigator.userAgent.toLowerCase() isn't reliable for Chrome installs + // on mobile devices. As such, we will create a boolean isChromeDesktop + // The reason that we need to do this is because Chrome annoyingly + // purports support for touch events even if the underlying hardware + // does not! + var agent = navigator.userAgent.toLowerCase(), + isChromeDesktop = (agent.indexOf('chrome') > -1 && ((agent.indexOf('windows') > -1) || (agent.indexOf('macintosh') > -1) || (agent.indexOf('linux') > -1)) && agent.indexOf('mobile') < 0 && agent.indexOf('android') < 0), + + settings = { + tap_pixel_range: 5, + swipe_h_threshold: 50, + swipe_v_threshold: 50, + taphold_threshold: 750, + doubletap_int: 500, + + touch_capable: (window.navigator.msPointerEnabled) ? false : ('ontouchstart' in window && !isChromeDesktop), + orientation_support: ('orientation' in window && 'onorientationchange' in window), + + startevent: (window.navigator.msPointerEnabled) ? 'MSPointerDown' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchstart' : 'mousedown'), + endevent: (window.navigator.msPointerEnabled) ? 'MSPointerUp' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchend' : 'mouseup'), + moveevent: (window.navigator.msPointerEnabled) ? 'MSPointerMove' : (('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'mousemove'), + tapevent: ('ontouchstart' in window && !isChromeDesktop) ? 'tap' : 'click', + scrollevent: ('ontouchstart' in window && !isChromeDesktop) ? 'touchmove' : 'scroll', + + hold_timer: null, + tap_timer: null + }; + + // Convenience functions: + $.isTouchCapable = function() { return settings.touch_capable; }; + $.getStartEvent = function() { return settings.startevent; }; + $.getEndEvent = function() { return settings.endevent; }; + $.getMoveEvent = function() { return settings.moveevent; }; + $.getTapEvent = function() { return settings.tapevent; }; + $.getScrollEvent = function() { return settings.scrollevent; }; + + // Add Event shortcuts: + $.each(['tapstart', 'tapend', 'tapmove', 'tap', 'tap2', 'tap3', 'tap4', 'singletap', 'doubletap', 'taphold', 'swipe', 'swipeup', 'swiperight', 'swipedown', 'swipeleft', 'swipeend', 'scrollstart', 'scrollend', 'orientationchange'], function (i, name) { + $.fn[name] = function (fn) { + return fn ? this.on(name, fn) : this.trigger(name); + }; + + $.attrFn[name] = true; + }); + + // tapstart Event: + $.event.special.tapstart = { + setup: function () { + var thisObject = this, + $this = $(thisObject); + + $this.on(settings.startevent, function (e) { + $this.data('callee', arguments.callee); + if (e.which && e.which !== 1) { + return false; + } + + var origEvent = e.originalEvent, + touchData = { + 'position': { + 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX), + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + triggerCustomEvent(thisObject, 'tapstart', e, touchData); + return true; + }); + }, + + remove: function () { + $(this).off(settings.startevent, $(this).data.callee); + } + }; + + // tapmove Event: + $.event.special.tapmove = { + setup: function() { + var thisObject = this, + $this = $(thisObject); + + $this.on(settings.moveevent, function(e) { + $this.data('callee', arguments.callee); + + var origEvent = e.originalEvent, + touchData = { + 'position': { + 'x': ((settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX), + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + triggerCustomEvent(thisObject, 'tapmove', e, touchData); + return true; + }); + }, + remove: function() { + $(this).off(settings.moveevent, $(this).data.callee); + } + } + + // tapend Event: + $.event.special.tapend = { + setup: function () { + var thisObject = this, + $this = $(thisObject); + + $this.on(settings.endevent, function (e) { + // Touch event data: + $this.data('callee', arguments.callee); + + var origEvent = e.originalEvent; + var touchData = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + triggerCustomEvent(thisObject, 'tapend', e, touchData); + return true; + }); + }, + remove: function () { + $(this).off(settings.endevent, $(this).data.callee); + } + }; + + // taphold Event: + $.event.special.taphold = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + origTarget, + timer, + start_pos = { + x: 0, + y: 0 + }, + end_x = 0, + end_y = 0; + + $this.on(settings.startevent, function (e) { + if (e.which && e.which !== 1) { + return false; + } else { + $this.data('tapheld', false); + origTarget = e.target; + + var origEvent = e.originalEvent; + var start_time = Date.now(), + startPosition = { + 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + startOffset = { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }; + + start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + + end_x = start_pos.x; + end_y = start_pos.y; + + settings.hold_timer = window.setTimeout(function () { + + var diff_x = (start_pos.x - end_x), + diff_y = (start_pos.y - end_y); + + if (e.target == origTarget && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) { + $this.data('tapheld', true); + + var end_time = Date.now(), + endPosition = { + 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + endOffset = { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }; + duration = end_time - start_time; + + // Build the touch data: + var touchData = { + 'startTime': start_time, + 'endTime': end_time, + 'startPosition': startPosition, + 'startOffset': startOffset, + 'endPosition': endPosition, + 'endOffset': endOffset, + 'duration': duration, + 'target': e.target + } + $this.data('callee1', arguments.callee); + triggerCustomEvent(thisObject, 'taphold', e, touchData); + } + }, settings.taphold_threshold); + + return true; + } + }).on(settings.endevent, function () { + $this.data('callee2', arguments.callee); + $this.data('tapheld', false); + window.clearTimeout(settings.hold_timer); + }) + .on(settings.moveevent, function (e) { + $this.data('callee3', arguments.callee); + + end_x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + end_y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + }); + }, + + remove: function () { + $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2).off(settings.moveevent, $(this).data.callee3); + } + }; + + // doubletap Event: + $.event.special.doubletap = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + origTarget, + action, + firstTap, + origEvent, + cooloff, + cooling = false; + + $this.on(settings.startevent, function (e) { + if (e.which && e.which !== 1) { + return false; + } + $this.data('doubletapped', false); + origTarget = e.target; + $this.data('callee1', arguments.callee); + + origEvent = e.originalEvent; + firstTap = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + return true; + }).on(settings.endevent, function (e) { + + var now = Date.now(); + var lastTouch = $this.data('lastTouch') || now + 1; + var delta = now - lastTouch; + window.clearTimeout(action); + $this.data('callee2', arguments.callee); + + if (delta < settings.doubletap_int && (e.target == origTarget) && delta > 100) { + $this.data('doubletapped', true); + window.clearTimeout(settings.tap_timer); + + // Now get the current event: + var lastTap = { + 'position': { + 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageX - e.originalEvent.changedTouches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? e.originalEvent.changedTouches[0].pageY - e.originalEvent.changedTouches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + } + + var touchData = { + 'firstTap': firstTap, + 'secondTap': lastTap, + 'interval': lastTap.time - firstTap.time + }; + + if (!cooling) { + triggerCustomEvent(thisObject, 'doubletap', e, touchData); + } + + cooling = true; + + cooloff = window.setTimeout(function (e) { + cooling = false; + }, settings.doubletap_int); + + } else { + $this.data('lastTouch', now); + action = window.setTimeout(function (e) { + window.clearTimeout(action); + }, settings.doubletap_int, [e]); + } + $this.data('lastTouch', now); + }); + }, + remove: function () { + $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2); + } + }; + + // singletap Event: + // This is used in conjuction with doubletap when both events are needed on the same element + $.event.special.singletap = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + origTarget = null, + startTime = null, + start_pos = { + x: 0, + y: 0 + }; + + $this.on(settings.startevent, function (e) { + if (e.which && e.which !== 1) { + return false; + } else { + startTime = Date.now(); + origTarget = e.target; + $this.data('callee1', arguments.callee); + + // Get the start x and y position: + start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + return true; + } + }).on(settings.endevent, function (e) { + $this.data('callee2', arguments.callee); + if (e.target == origTarget) { + // Get the end point: + end_pos_x = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX; + end_pos_y = (e.originalEvent.changedTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY; + + // We need to check if it was a taphold: + + settings.tap_timer = window.setTimeout(function () { + if (!$this.data('doubletapped') && !$this.data('tapheld') && (start_pos.x == end_pos_x) && (start_pos.y == end_pos_y)) { + var origEvent = e.originalEvent; + var touchData = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + // Was it a taphold? + if((touchData.time - startTime) < settings.taphold_threshold) + { + triggerCustomEvent(thisObject, 'singletap', e, touchData); + } + } + }, settings.doubletap_int); + } + }); + }, + + remove: function () { + $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2); + } + }; + + // tap Event: + $.event.special.tap = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + started = false, + origTarget = null, + start_time, + start_pos = { + x: 0, + y: 0 + }, + touches; + + $this.on(settings.startevent, function (e) { + $this.data('callee1', arguments.callee); + + if (e.which && e.which !== 1) { + return false; + } else { + started = true; + start_pos.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + start_pos.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + start_time = Date.now(); + origTarget = e.target; + + touches = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches : [ e ]; + return true; + } + }).on(settings.endevent, function (e) { + $this.data('callee2', arguments.callee); + + // Only trigger if they've started, and the target matches: + var end_x = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageX : e.pageX, + end_y = (e.originalEvent.targetTouches) ? e.originalEvent.changedTouches[0].pageY : e.pageY, + diff_x = (start_pos.x - end_x), + diff_y = (start_pos.y - end_y), + eventName; + + if (origTarget == e.target && started && ((Date.now() - start_time) < settings.taphold_threshold) && ((start_pos.x == end_x && start_pos.y == end_y) || (diff_x >= -(settings.tap_pixel_range) && diff_x <= settings.tap_pixel_range && diff_y >= -(settings.tap_pixel_range) && diff_y <= settings.tap_pixel_range))) { + var origEvent = e.originalEvent; + var touchData = [ ]; + + for( var i = 0; i < touches.length; i++) + { + var touch = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[i].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[i].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[i].pageX - origEvent.changedTouches[i].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[i].pageY - origEvent.changedTouches[i].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + touchData.push( touch ); + } + + switch( touches.length ) + { + case 1: + eventName = 'tap'; + break; + + case 2: + eventName = 'tap2'; + break; + + case 3: + eventName = 'tap3'; + break; + + case 4: + eventName = 'tap4'; + break; + } + + triggerCustomEvent(thisObject, eventName, e, touchData); + } + }); + }, + + remove: function () { + $(this).off(settings.startevent, $(this).data.callee1).off(settings.endevent, $(this).data.callee2); + } + }; + + // swipe Event (also handles swipeup, swiperight, swipedown and swipeleft): + $.event.special.swipe = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + started = false, + hasSwiped = false, + originalCoord = { + x: 0, + y: 0 + }, + finalCoord = { + x: 0, + y: 0 + }, + startEvnt; + + // Screen touched, store the original coordinate + + function touchStart(e) { + $this = $(e.currentTarget); + $this.data('callee1', arguments.callee); + originalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + originalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + finalCoord.x = originalCoord.x; + finalCoord.y = originalCoord.y; + started = true; + var origEvent = e.originalEvent; + // Read event data into our startEvt: + startEvnt = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + } + + // Store coordinates as finger is swiping + + function touchMove(e) { + $this = $(e.currentTarget); + $this.data('callee2', arguments.callee); + finalCoord.x = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageX : e.pageX; + finalCoord.y = (e.originalEvent.targetTouches) ? e.originalEvent.targetTouches[0].pageY : e.pageY; + + var swipedir; + + // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold: + var ele_x_threshold = ($this.parent().data('xthreshold')) ? $this.parent().data('xthreshold') : $this.data('xthreshold'), + ele_y_threshold = ($this.parent().data('ythreshold')) ? $this.parent().data('ythreshold') : $this.data('ythreshold'), + h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold, + v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold; + + if (originalCoord.y > finalCoord.y && (originalCoord.y - finalCoord.y > v_threshold)) { + swipedir = 'swipeup'; + } + if (originalCoord.x < finalCoord.x && (finalCoord.x - originalCoord.x > h_threshold)) { + swipedir = 'swiperight'; + } + if (originalCoord.y < finalCoord.y && (finalCoord.y - originalCoord.y > v_threshold)) { + swipedir = 'swipedown'; + } + if (originalCoord.x > finalCoord.x && (originalCoord.x - finalCoord.x > h_threshold)) { + swipedir = 'swipeleft'; + } + if (swipedir != undefined && started) { + originalCoord.x = 0; + originalCoord.y = 0; + finalCoord.x = 0; + finalCoord.y = 0; + started = false; + + // Read event data into our endEvnt: + var origEvent = e.originalEvent; + endEvnt = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.touches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.touches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.touches[0].pageX - origEvent.touches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.touches[0].pageY - origEvent.touches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + // Calculate the swipe amount (normalized): + var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x), + yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y); + + var touchData = { + 'startEvnt': startEvnt, + 'endEvnt': endEvnt, + 'direction': swipedir.replace('swipe', ''), + 'xAmount': xAmount, + 'yAmount': yAmount, + 'duration': endEvnt.time - startEvnt.time + } + hasSwiped = true; + $this.trigger('swipe', touchData).trigger(swipedir, touchData); + } + } + + function touchEnd(e) { + $this = $(e.currentTarget); + var swipedir = ""; + $this.data('callee3', arguments.callee); + if (hasSwiped) { + // We need to check if the element to which the event was bound contains a data-xthreshold | data-vthreshold: + var ele_x_threshold = $this.data('xthreshold'), + ele_y_threshold = $this.data('ythreshold'), + h_threshold = (typeof ele_x_threshold !== 'undefined' && ele_x_threshold !== false && parseInt(ele_x_threshold)) ? parseInt(ele_x_threshold) : settings.swipe_h_threshold, + v_threshold = (typeof ele_y_threshold !== 'undefined' && ele_y_threshold !== false && parseInt(ele_y_threshold)) ? parseInt(ele_y_threshold) : settings.swipe_v_threshold; + + var origEvent = e.originalEvent; + endEvnt = { + 'position': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].screenX : e.screenX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].screenY : e.screenY + }, + 'offset': { + 'x': (settings.touch_capable) ? origEvent.changedTouches[0].pageX - origEvent.changedTouches[0].target.offsetLeft : e.offsetX, + 'y': (settings.touch_capable) ? origEvent.changedTouches[0].pageY - origEvent.changedTouches[0].target.offsetTop : e.offsetY + }, + 'time': Date.now(), + 'target': e.target + }; + + // Read event data into our endEvnt: + if (startEvnt.position.y > endEvnt.position.y && (startEvnt.position.y - endEvnt.position.y > v_threshold)) { + swipedir = 'swipeup'; + } + if (startEvnt.position.x < endEvnt.position.x && (endEvnt.position.x - startEvnt.position.x > h_threshold)) { + swipedir = 'swiperight'; + } + if (startEvnt.position.y < endEvnt.position.y && (endEvnt.position.y - startEvnt.position.y > v_threshold)) { + swipedir = 'swipedown'; + } + if (startEvnt.position.x > endEvnt.position.x && (startEvnt.position.x - endEvnt.position.x > h_threshold)) { + swipedir = 'swipeleft'; + } + + // Calculate the swipe amount (normalized): + var xAmount = Math.abs(startEvnt.position.x - endEvnt.position.x), + yAmount = Math.abs(startEvnt.position.y - endEvnt.position.y); + + var touchData = { + 'startEvnt': startEvnt, + 'endEvnt': endEvnt, + 'direction': swipedir.replace('swipe', ''), + 'xAmount': xAmount, + 'yAmount': yAmount, + 'duration': endEvnt.time - startEvnt.time + } + $this.trigger('swipeend', touchData); + } + + started = false; + hasSwiped = false; + } + + $this.on(settings.startevent, touchStart); + $this.on(settings.moveevent, touchMove); + $this.on(settings.endevent, touchEnd); + }, + + remove: function () { + $(this).off(settings.startevent, $(this).data.callee1).off(settings.moveevent, $(this).data.callee2).off(settings.endevent, $(this).data.callee3); + } + }; + + // scrollstart Event (also handles scrollend): + $.event.special.scrollstart = { + setup: function () { + var thisObject = this, + $this = $(thisObject), + scrolling, + timer; + + function trigger(event, state) { + scrolling = state; + triggerCustomEvent(thisObject, scrolling ? 'scrollstart' : 'scrollend', event); + } + + // iPhone triggers scroll after a small delay; use touchmove instead + $this.on(settings.scrollevent, function (event) { + $this.data('callee', arguments.callee); + + if (!scrolling) { + trigger(event, true); + } + + clearTimeout(timer); + timer = setTimeout(function () { + trigger(event, false); + }, 50); + }); + }, + + remove: function () { + $(this).off(settings.scrollevent, $(this).data.callee); + } + }; + + // This is the orientation change (largely borrowed from jQuery Mobile): + var win = $(window), + special_event, + get_orientation, + last_orientation, + initial_orientation_is_landscape, + initial_orientation_is_default, + portrait_map = { + '0': true, + '180': true + }; + + if (settings.orientation_support) { + var ww = window.innerWidth || win.width(), + wh = window.innerHeight || win.height(), + landscape_threshold = 50; + + initial_orientation_is_landscape = ww > wh && (ww - wh) > landscape_threshold; + initial_orientation_is_default = portrait_map[window.orientation]; + + if ((initial_orientation_is_landscape && initial_orientation_is_default) || (!initial_orientation_is_landscape && !initial_orientation_is_default)) { + portrait_map = { + '-90': true, + '90': true + }; + } + } + + $.event.special.orientationchange = special_event = { + setup: function () { + // If the event is supported natively, return false so that jQuery + // will on to the event using DOM methods. + if (settings.orientation_support) { + return false; + } + + // Get the current orientation to avoid initial double-triggering. + last_orientation = get_orientation(); + + win.on('throttledresize', handler); + return true; + }, + teardown: function () { + if (settings.orientation_support) { + return false; + } + + win.off('throttledresize', handler); + return true; + }, + add: function (handleObj) { + // Save a reference to the bound event handler. + var old_handler = handleObj.handler; + + handleObj.handler = function (event) { + event.orientation = get_orientation(); + return old_handler.apply(this, arguments); + }; + } + }; + + // If the event is not supported natively, this handler will be bound to + // the window resize event to simulate the orientationchange event. + + function handler() { + // Get the current orientation. + var orientation = get_orientation(); + + if (orientation !== last_orientation) { + // The orientation has changed, so trigger the orientationchange event. + last_orientation = orientation; + win.trigger("orientationchange"); + } + } + + $.event.special.orientationchange.orientation = get_orientation = function () { + var isPortrait = true, + elem = document.documentElement; + + if (settings.orientation_support) { + isPortrait = portrait_map[window.orientation]; + } else { + isPortrait = elem && elem.clientWidth / elem.clientHeight < 1.1; + } + + return isPortrait ? 'portrait' : 'landscape'; + }; + + // throttle Handler: + $.event.special.throttledresize = { + setup: function () { + $(this).on('resize', throttle_handler); + }, + teardown: function () { + $(this).off('resize', throttle_handler); + } + }; + + var throttle = 250, + throttle_handler = function () { + curr = Date.now(); + diff = curr - lastCall; + + if (diff >= throttle) { + lastCall = curr; + $(this).trigger('throttledresize'); + + } else { + if (heldCall) { + window.clearTimeout(heldCall); + } + + // Promise a held call will still execute + heldCall = window.setTimeout(handler, throttle - diff); + } + }, + lastCall = 0, + heldCall, + curr, + diff; + + // Trigger a custom event: + + function triggerCustomEvent(obj, eventType, event, touchData) { + var originalType = event.type; + event.type = eventType; + + $.event.dispatch.call(obj, event, touchData); + event.type = originalType; + } + + // Correctly on anything we've overloaded: + $.each({ + scrollend: 'scrollstart', + swipeup: 'swipe', + swiperight: 'swipe', + swipedown: 'swipe', + swipeleft: 'swipe', + swipeend: 'swipe', + tap2: 'tap' + }, function (e, srcE, touchData) { + $.event.special[e] = { + setup: function () { + $(this).on(srcE, $.noop); + } + }; + }); + +})(jQuery); diff --git a/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.min.js b/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.min.js new file mode 100644 index 0000000000..24e60d1c18 --- /dev/null +++ b/js/vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.min.js @@ -0,0 +1 @@ +!function(e){function t(){var e=c();e!==r&&(r=e,l.trigger("orientationchange"))}function a(t,a,n,o){var i=n.type;n.type=a,e.event.dispatch.call(t,n,o),n.type=i}e.attrFn=e.attrFn||{};var n=navigator.userAgent.toLowerCase(),o=n.indexOf("chrome")>-1&&(n.indexOf("windows")>-1||n.indexOf("macintosh")>-1||n.indexOf("linux")>-1)&&n.indexOf("mobile")<0&&n.indexOf("android")<0,i={tap_pixel_range:5,swipe_h_threshold:50,swipe_v_threshold:50,taphold_threshold:750,doubletap_int:500,touch_capable:window.navigator.msPointerEnabled?!1:"ontouchstart"in window&&!o,orientation_support:"orientation"in window&&"onorientationchange"in window,startevent:window.navigator.msPointerEnabled?"MSPointerDown":"ontouchstart"in window&&!o?"touchstart":"mousedown",endevent:window.navigator.msPointerEnabled?"MSPointerUp":"ontouchstart"in window&&!o?"touchend":"mouseup",moveevent:window.navigator.msPointerEnabled?"MSPointerMove":"ontouchstart"in window&&!o?"touchmove":"mousemove",tapevent:"ontouchstart"in window&&!o?"tap":"click",scrollevent:"ontouchstart"in window&&!o?"touchmove":"scroll",hold_timer:null,tap_timer:null};e.isTouchCapable=function(){return i.touch_capable},e.getStartEvent=function(){return i.startevent},e.getEndEvent=function(){return i.endevent},e.getMoveEvent=function(){return i.moveevent},e.getTapEvent=function(){return i.tapevent},e.getScrollEvent=function(){return i.scrollevent},e.each(["tapstart","tapend","tapmove","tap","tap2","tap3","tap4","singletap","doubletap","taphold","swipe","swipeup","swiperight","swipedown","swipeleft","swipeend","scrollstart","scrollend","orientationchange"],function(t,a){e.fn[a]=function(e){return e?this.on(a,e):this.trigger(a)},e.attrFn[a]=!0}),e.event.special.tapstart={setup:function(){var t=this,n=e(t);n.on(i.startevent,function(e){if(n.data("callee",arguments.callee),e.which&&1!==e.which)return!1;var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapstart",e,s),!0})},remove:function(){e(this).off(i.startevent,e(this).data.callee)}},e.event.special.tapmove={setup:function(){var t=this,n=e(t);n.on(i.moveevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.touches[0].screenX:e.screenX,y:i.touch_capable?o.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.touches[0].pageX-o.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.touches[0].pageY-o.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapmove",e,s),!0})},remove:function(){e(this).off(i.moveevent,e(this).data.callee)}},e.event.special.tapend={setup:function(){var t=this,n=e(t);n.on(i.endevent,function(e){n.data("callee",arguments.callee);var o=e.originalEvent,s={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};return a(t,"tapend",e,s),!0})},remove:function(){e(this).off(i.endevent,e(this).data.callee)}},e.event.special.taphold={setup:function(){var t,n=this,o=e(n),s={x:0,y:0},c=0,r=0;o.on(i.startevent,function(e){if(e.which&&1!==e.which)return!1;o.data("tapheld",!1),t=e.target;var h=e.originalEvent,u=Date.now(),l={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},p={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};return s.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,s.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,c=s.x,r=s.y,i.hold_timer=window.setTimeout(function(){var g=s.x-c,d=s.y-r;if(e.target==t&&(s.x==c&&s.y==r||g>=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){o.data("tapheld",!0);var f=Date.now(),v={x:i.touch_capable?h.touches[0].screenX:e.screenX,y:i.touch_capable?h.touches[0].screenY:e.screenY},w={x:i.touch_capable?h.touches[0].pageX-h.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?h.touches[0].pageY-h.touches[0].target.offsetTop:e.offsetY};duration=f-u;var _={startTime:u,endTime:f,startPosition:l,startOffset:p,endPosition:v,endOffset:w,duration:duration,target:e.target};o.data("callee1",arguments.callee),a(n,"taphold",e,_)}},i.taphold_threshold),!0}).on(i.endevent,function(){o.data("callee2",arguments.callee),o.data("tapheld",!1),window.clearTimeout(i.hold_timer)}).on(i.moveevent,function(e){o.data("callee3",arguments.callee),c=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,r=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2).off(i.moveevent,e(this).data.callee3)}},e.event.special.doubletap={setup:function(){var t,n,o,s,c,r=this,h=e(r),u=!1;h.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(h.data("doubletapped",!1),t=e.target,h.data("callee1",arguments.callee),s=e.originalEvent,o={position:{x:i.touch_capable?s.touches[0].screenX:e.screenX,y:i.touch_capable?s.touches[0].screenY:e.screenY},offset:{x:i.touch_capable?s.touches[0].pageX-s.touches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?s.touches[0].pageY-s.touches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},!0)}).on(i.endevent,function(e){var s=Date.now(),l=h.data("lastTouch")||s+1,p=s-l;if(window.clearTimeout(n),h.data("callee2",arguments.callee),p100){h.data("doubletapped",!0),window.clearTimeout(i.tap_timer);var g={position:{x:i.touch_capable?e.originalEvent.changedTouches[0].screenX:e.screenX,y:i.touch_capable?e.originalEvent.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?e.originalEvent.changedTouches[0].pageX-e.originalEvent.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?e.originalEvent.changedTouches[0].pageY-e.originalEvent.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target},d={firstTap:o,secondTap:g,interval:g.time-o.time};u||a(r,"doubletap",e,d),u=!0,c=window.setTimeout(function(){u=!1},i.doubletap_int)}else h.data("lastTouch",s),n=window.setTimeout(function(){window.clearTimeout(n)},i.doubletap_int,[e]);h.data("lastTouch",s)})},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.endevent,e(this).data.callee2)}},e.event.special.singletap={setup:function(){var t=this,n=e(t),o=null,s=null,c={x:0,y:0};n.on(i.startevent,function(e){return e.which&&1!==e.which?!1:(s=Date.now(),o=e.target,n.data("callee1",arguments.callee),c.x=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageX:e.pageX,c.y=e.originalEvent.targetTouches?e.originalEvent.targetTouches[0].pageY:e.pageY,!0)}).on(i.endevent,function(e){n.data("callee2",arguments.callee),e.target==o&&(end_pos_x=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageX:e.pageX,end_pos_y=e.originalEvent.changedTouches?e.originalEvent.changedTouches[0].pageY:e.pageY,i.tap_timer=window.setTimeout(function(){if(!n.data("doubletapped")&&!n.data("tapheld")&&c.x==end_pos_x&&c.y==end_pos_y){var o=e.originalEvent,r={position:{x:i.touch_capable?o.changedTouches[0].screenX:e.screenX,y:i.touch_capable?o.changedTouches[0].screenY:e.screenY},offset:{x:i.touch_capable?o.changedTouches[0].pageX-o.changedTouches[0].target.offsetLeft:e.offsetX,y:i.touch_capable?o.changedTouches[0].pageY-o.changedTouches[0].target.offsetTop:e.offsetY},time:Date.now(),target:e.target};r.time-s=-i.tap_pixel_range&&g<=i.tap_pixel_range&&d>=-i.tap_pixel_range&&d<=i.tap_pixel_range)){for(var f=e.originalEvent,v=[],w=0;wl.y&&u.y-l.y>g&&(a="swipeup"),u.xp&&(a="swiperight"),u.yg&&(a="swipedown"),u.x>l.x&&u.x-l.x>p&&(a="swipeleft"),void 0!=a&&r){u.x=0,u.y=0,l.x=0,l.y=0,r=!1;var d=t.originalEvent;endEvnt={position:{x:i.touch_capable?d.touches[0].screenX:t.screenX,y:i.touch_capable?d.touches[0].screenY:t.screenY},offset:{x:i.touch_capable?d.touches[0].pageX-d.touches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?d.touches[0].pageY-d.touches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target};var f=Math.abs(o.position.x-endEvnt.position.x),v=Math.abs(o.position.y-endEvnt.position.y),w={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:f,yAmount:v,duration:endEvnt.time-o.time};h=!0,c.trigger("swipe",w).trigger(a,w)}}function n(t){c=e(t.currentTarget);var a="";if(c.data("callee3",arguments.callee),h){var n=c.data("xthreshold"),s=c.data("ythreshold"),u="undefined"!=typeof n&&n!==!1&&parseInt(n)?parseInt(n):i.swipe_h_threshold,l="undefined"!=typeof s&&s!==!1&&parseInt(s)?parseInt(s):i.swipe_v_threshold,p=t.originalEvent;endEvnt={position:{x:i.touch_capable?p.changedTouches[0].screenX:t.screenX,y:i.touch_capable?p.changedTouches[0].screenY:t.screenY},offset:{x:i.touch_capable?p.changedTouches[0].pageX-p.changedTouches[0].target.offsetLeft:t.offsetX,y:i.touch_capable?p.changedTouches[0].pageY-p.changedTouches[0].target.offsetTop:t.offsetY},time:Date.now(),target:t.target},o.position.y>endEvnt.position.y&&o.position.y-endEvnt.position.y>l&&(a="swipeup"),o.position.xu&&(a="swiperight"),o.position.yl&&(a="swipedown"),o.position.x>endEvnt.position.x&&o.position.x-endEvnt.position.x>u&&(a="swipeleft");var g=Math.abs(o.position.x-endEvnt.position.x),d=Math.abs(o.position.y-endEvnt.position.y),f={startEvnt:o,endEvnt:endEvnt,direction:a.replace("swipe",""),xAmount:g,yAmount:d,duration:endEvnt.time-o.time};c.trigger("swipeend",f)}r=!1,h=!1}var o,s=this,c=e(s),r=!1,h=!1,u={x:0,y:0},l={x:0,y:0};c.on(i.startevent,t),c.on(i.moveevent,a),c.on(i.endevent,n)},remove:function(){e(this).off(i.startevent,e(this).data.callee1).off(i.moveevent,e(this).data.callee2).off(i.endevent,e(this).data.callee3)}},e.event.special.scrollstart={setup:function(){function t(e,t){n=t,a(s,n?"scrollstart":"scrollend",e)}var n,o,s=this,c=e(s);c.on(i.scrollevent,function(e){c.data("callee",arguments.callee),n||t(e,!0),clearTimeout(o),o=setTimeout(function(){t(e,!1)},50)})},remove:function(){e(this).off(i.scrollevent,e(this).data.callee)}};var s,c,r,h,u,l=e(window),p={0:!0,180:!0};if(i.orientation_support){var g=window.innerWidth||l.width(),d=window.innerHeight||l.height(),f=50;h=g>d&&g-d>f,u=p[window.orientation],(h&&u||!h&&!u)&&(p={"-90":!0,90:!0})}e.event.special.orientationchange=s={setup:function(){return i.orientation_support?!1:(r=c(),l.on("throttledresize",t),!0)},teardown:function(){return i.orientation_support?!1:(l.off("throttledresize",t),!0)},add:function(e){var t=e.handler;e.handler=function(e){return e.orientation=c(),t.apply(this,arguments)}}},e.event.special.orientationchange.orientation=c=function(){var e=!0,t=document.documentElement;return e=i.orientation_support?p[window.orientation]:t&&t.clientWidth/t.clientHeight<1.1,e?"portrait":"landscape"},e.event.special.throttledresize={setup:function(){e(this).on("resize",m)},teardown:function(){e(this).off("resize",m)}};var v,w,_,T=250,m=function(){w=Date.now(),_=w-x,_>=T?(x=w,e(this).trigger("throttledresize")):(v&&window.clearTimeout(v),v=window.setTimeout(t,T-_))},x=0;e.each({scrollend:"scrollstart",swipeup:"swipe",swiperight:"swipe",swipedown:"swipe",swipeleft:"swipe",swipeend:"swipe",tap2:"tap"},function(t,a){e.event.special[t]={setup:function(){e(this).on(a,e.noop)}}})}(jQuery); diff --git a/js/vendor/jquery.ui.touch-punch-custom.js b/js/vendor/jquery.ui.touch-punch-custom.js new file mode 100644 index 0000000000..2fc70604e1 --- /dev/null +++ b/js/vendor/jquery.ui.touch-punch-custom.js @@ -0,0 +1,184 @@ +/*! + * jQuery UI Touch Punch 0.2.3 + * + * Copyright 2011–2014, Dave Furfero + * Dual licensed under the MIT or GPL Version 2 licenses. + * + * Modified for ownCloud Gallery by Olivier Paroz to convert taphold events into clicks instead of + * using touchstart + * @see https://stackoverflow.com/questions/34027761/jquery-ui-sortable-hold-and-drag-for-mobile + * + * Depends: + * jquery.ui.widget.js + * jquery.ui.mouse.js + */ +(function ($) { + + // Detect touch support + $.support.touch = 'ontouchend' in document; + + // Ignore browsers without touch support + if (!$.support.touch) { + return; + } + + var mouseProto = $.ui.mouse.prototype, + _mouseInit = mouseProto._mouseInit, + _mouseDestroy = mouseProto._mouseDestroy, + touchHandled; + + /** + * Simulate a mouse event based on a corresponding touch event + * @param {Object} event A touch event + * @param {String} simulatedType The corresponding mouse event + */ + function simulateMouseEvent (event, simulatedType) { + + // Ignore multi-touch events + if (event.originalEvent.touches.length > 1) { + return; + } + + event.preventDefault(); + + var touch = event.originalEvent.changedTouches[0], + simulatedEvent = document.createEvent('MouseEvents'); + + // Initialize the simulated mouse event using the touch event's coordinates + simulatedEvent.initMouseEvent( + simulatedType, // type + true, // bubbles + true, // cancelable + window, // view + 1, // detail + touch.screenX, // screenX + touch.screenY, // screenY + touch.clientX, // clientX + touch.clientY, // clientY + false, // ctrlKey + false, // altKey + false, // shiftKey + false, // metaKey + 0, // button + null // relatedTarget + ); + + // Dispatch the simulated event to the target element + event.target.dispatchEvent(simulatedEvent); + } + + /** + * Handle the jQuery UI widget's touchstart events + * @param {Object} event The widget element's touchstart event + */ + mouseProto._touchStart = function (event) { + + var self = this; + + // Ignore the event if another widget is already being handled + if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { + return; + } + + // Set the flag to prevent other widgets from inheriting the touch event + touchHandled = true; + + // Track movement to determine if interaction was a click + self._touchMoved = false; + + // Simulate the mouseover event + simulateMouseEvent(event, 'mouseover'); + + // Simulate the mousemove event + simulateMouseEvent(event, 'mousemove'); + + // Simulate the mousedown event + simulateMouseEvent(event, 'mousedown'); + }; + + /** + * Handle the jQuery UI widget's touchmove events + * @param {Object} event The document's touchmove event + */ + mouseProto._touchMove = function (event) { + + // Ignore event if not handled + if (!touchHandled) { + return; + } + + // Interaction was not a click + this._touchMoved = true; + + // Simulate the mousemove event + simulateMouseEvent(event, 'mousemove'); + }; + + /** + * Handle the jQuery UI widget's touchend events + * @param {Object} event The document's touchend event + */ + mouseProto._touchEnd = function (event) { + + // Ignore event if not handled + if (!touchHandled) { + return; + } + + // Simulate the mouseup event + simulateMouseEvent(event, 'mouseup'); + + // Simulate the mouseout event + simulateMouseEvent(event, 'mouseout'); + + // If the touch interaction did not move, it should trigger a click + if (!this._touchMoved) { + + // Simulate the click event + simulateMouseEvent(event, 'click'); + } + + // Unset the flag to allow other widgets to inherit the touch event + touchHandled = false; + }; + + /** + * A duck punch of the $.ui.mouse _mouseInit method to support touch events. + * This method extends the widget with bound touch event handlers that + * translate touch events to mouse events and pass them to the widget's + * original mouse event handling methods. + */ + mouseProto._mouseInit = function () { + + var self = this; + + // Delegate the touch handlers to the widget's element + self.element.bind({ + taphold: $.proxy(self, '_touchStart'), + touchmove: $.proxy(self, '_touchMove'), + touchend: $.proxy(self, '_touchEnd') + }); + + // Call the original $.ui.mouse init method + _mouseInit.call(self); + }; + + /** + * Remove the touch event handlers + */ + mouseProto._mouseDestroy = function () { + + var self = this; + + // Delegate the touch handlers to the widget's element + self.element.unbind({ + taphold: $.proxy(self, '_touchStart'), + touchmove: $.proxy(self, '_touchMove'), + touchend: $.proxy(self, '_touchEnd') + }); + + // Call the original $.ui.mouse destroy method + _mouseDestroy.call(self); + }; + +})(jQuery); \ No newline at end of file diff --git a/js/vendor/jqueryui-touch-punch/README.md b/js/vendor/jqueryui-touch-punch/README.md new file mode 100644 index 0000000000..cff7baad70 --- /dev/null +++ b/js/vendor/jqueryui-touch-punch/README.md @@ -0,0 +1,41 @@ +# jQuery UI Touch Punch +## Touch Event Support for jQuery UI + +> **jQuery UI Touch Punch is a small hack that enables the use of touch events on sites using the jQuery UI user interface library.** + +_[Visit the official Touch Punch website](http://touchpunch.furf.com)._ + +Currently, [jQuery UI](http://jqueryui.com/) user interface library does not support the use of touch events in their widgets and interactions. This means that the slick UI you designed and tested in your desktop browser will fail on most, if not all, touch-enabled mobile devices, because jQuery UI listens to mouse events—mouseover, mousemove and mouseout—not touch events—touchstart, touchmove and touchend. + +That's where jQuery UI Touch Punch comes in. Touch Punch works by using [simulated events](https://developer.mozilla.org/en/DOM/document.createEvent) to map [touch events](http://www.html5rocks.com/en/mobile/touch/) to their mouse event analogs. Simply include the script on your page and your touch events will be turned into their corresponding mouse events to which jQuery UI will respond as expected. + +As I said, Touch Punch is a hack. It [duck punches](http://en.wikipedia.org/wiki/Monkey_patch) some of jQuery UI's core functionality to handle the mapping of touch events. Touch Punch works with all basic implementations of jQuery UI's interactions and widgets. However, you may find more complex cases where Touch Punch fails. If so, scroll down to learn how you can file and/or fix issues. + +This code is dual licensed under the MIT or GPL Version 2 licenses and is therefore free to use, modify and/or distribute, but if you include Touch Punch in other software packages or plugins, please include an attribution to the original software and a link to [this Touch Punch website](http://touchpunch.furf.com/). + +## Using Touch Punch is as easy as 1, 2… + +Just follow these simple steps to enable touch events in your jQuery UI app: + +1. Include jQuery and jQuery UI on your page. + + ```html + + + ``` + +2. Include Touch Punch after jQuery UI and before its first use. + + Please note that if you are using jQuery UI's components, Touch Punch must be included after jquery.ui.mouse.js, as Touch Punch modifies its behavior. + + ```html + + ``` + +3. There is no 3. Just use jQuery UI as expected and watch it work at the touch of a finger. + + ```html + + ``` + +_Tested on iPad, iPhone, Android and other touch-enabled mobile devices._ diff --git a/js/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.js b/js/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.js new file mode 100644 index 0000000000..16ce41d1ed --- /dev/null +++ b/js/vendor/jqueryui-touch-punch/jquery.ui.touch-punch.js @@ -0,0 +1,180 @@ +/*! + * jQuery UI Touch Punch 0.2.3 + * + * Copyright 2011–2014, Dave Furfero + * Dual licensed under the MIT or GPL Version 2 licenses. + * + * Depends: + * jquery.ui.widget.js + * jquery.ui.mouse.js + */ +(function ($) { + + // Detect touch support + $.support.touch = 'ontouchend' in document; + + // Ignore browsers without touch support + if (!$.support.touch) { + return; + } + + var mouseProto = $.ui.mouse.prototype, + _mouseInit = mouseProto._mouseInit, + _mouseDestroy = mouseProto._mouseDestroy, + touchHandled; + + /** + * Simulate a mouse event based on a corresponding touch event + * @param {Object} event A touch event + * @param {String} simulatedType The corresponding mouse event + */ + function simulateMouseEvent (event, simulatedType) { + + // Ignore multi-touch events + if (event.originalEvent.touches.length > 1) { + return; + } + + event.preventDefault(); + + var touch = event.originalEvent.changedTouches[0], + simulatedEvent = document.createEvent('MouseEvents'); + + // Initialize the simulated mouse event using the touch event's coordinates + simulatedEvent.initMouseEvent( + simulatedType, // type + true, // bubbles + true, // cancelable + window, // view + 1, // detail + touch.screenX, // screenX + touch.screenY, // screenY + touch.clientX, // clientX + touch.clientY, // clientY + false, // ctrlKey + false, // altKey + false, // shiftKey + false, // metaKey + 0, // button + null // relatedTarget + ); + + // Dispatch the simulated event to the target element + event.target.dispatchEvent(simulatedEvent); + } + + /** + * Handle the jQuery UI widget's touchstart events + * @param {Object} event The widget element's touchstart event + */ + mouseProto._touchStart = function (event) { + + var self = this; + + // Ignore the event if another widget is already being handled + if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) { + return; + } + + // Set the flag to prevent other widgets from inheriting the touch event + touchHandled = true; + + // Track movement to determine if interaction was a click + self._touchMoved = false; + + // Simulate the mouseover event + simulateMouseEvent(event, 'mouseover'); + + // Simulate the mousemove event + simulateMouseEvent(event, 'mousemove'); + + // Simulate the mousedown event + simulateMouseEvent(event, 'mousedown'); + }; + + /** + * Handle the jQuery UI widget's touchmove events + * @param {Object} event The document's touchmove event + */ + mouseProto._touchMove = function (event) { + + // Ignore event if not handled + if (!touchHandled) { + return; + } + + // Interaction was not a click + this._touchMoved = true; + + // Simulate the mousemove event + simulateMouseEvent(event, 'mousemove'); + }; + + /** + * Handle the jQuery UI widget's touchend events + * @param {Object} event The document's touchend event + */ + mouseProto._touchEnd = function (event) { + + // Ignore event if not handled + if (!touchHandled) { + return; + } + + // Simulate the mouseup event + simulateMouseEvent(event, 'mouseup'); + + // Simulate the mouseout event + simulateMouseEvent(event, 'mouseout'); + + // If the touch interaction did not move, it should trigger a click + if (!this._touchMoved) { + + // Simulate the click event + simulateMouseEvent(event, 'click'); + } + + // Unset the flag to allow other widgets to inherit the touch event + touchHandled = false; + }; + + /** + * A duck punch of the $.ui.mouse _mouseInit method to support touch events. + * This method extends the widget with bound touch event handlers that + * translate touch events to mouse events and pass them to the widget's + * original mouse event handling methods. + */ + mouseProto._mouseInit = function () { + + var self = this; + + // Delegate the touch handlers to the widget's element + self.element.bind({ + touchstart: $.proxy(self, '_touchStart'), + touchmove: $.proxy(self, '_touchMove'), + touchend: $.proxy(self, '_touchEnd') + }); + + // Call the original $.ui.mouse init method + _mouseInit.call(self); + }; + + /** + * Remove the touch event handlers + */ + mouseProto._mouseDestroy = function () { + + var self = this; + + // Delegate the touch handlers to the widget's element + self.element.unbind({ + touchstart: $.proxy(self, '_touchStart'), + touchmove: $.proxy(self, '_touchMove'), + touchend: $.proxy(self, '_touchEnd') + }); + + // Call the original $.ui.mouse destroy method + _mouseDestroy.call(self); + }; + +})(jQuery); \ No newline at end of file diff --git a/templates/part.content.php b/templates/part.content.php index 1e1ecad4e3..eb24d1f0b1 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -9,6 +9,8 @@ $_['appName'], [ 'app', + 'vendor/jquery-touch-events/src/1.0.1/jquery.mobile-events.min', + 'vendor/jquery.ui.touch-punch-custom', 'gallery', 'galleryutility', 'galleryconfig',