123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- (function ($) {
-
- $.support.touch = 'ontouchend' in document;
-
- if (!$.support.touch) {
- return;
- }
- var mouseProto = $.ui.mouse.prototype,
- _mouseInit = mouseProto._mouseInit,
- _mouseDestroy = mouseProto._mouseDestroy,
- touchHandled;
-
- function simulateMouseEvent (event, simulatedType) {
-
- if (event.originalEvent.touches.length > 1) {
- return;
- }
- event.preventDefault();
- var touch = event.originalEvent.changedTouches[0],
- simulatedEvent = document.createEvent('MouseEvents');
-
-
- simulatedEvent.initMouseEvent(
- simulatedType,
- true,
- true,
- window,
- 1,
- touch.screenX,
- touch.screenY,
- touch.clientX,
- touch.clientY,
- false,
- false,
- false,
- false,
- 0,
- null
- );
-
- event.target.dispatchEvent(simulatedEvent);
- }
-
- mouseProto._touchStart = function (event) {
- var self = this;
-
- if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
- return;
- }
-
- touchHandled = true;
-
- self._touchMoved = false;
-
- simulateMouseEvent(event, 'mouseover');
-
- simulateMouseEvent(event, 'mousemove');
-
- simulateMouseEvent(event, 'mousedown');
- };
-
- mouseProto._touchMove = function (event) {
-
- if (!touchHandled) {
- return;
- }
-
- this._touchMoved = true;
-
- simulateMouseEvent(event, 'mousemove');
- };
-
- mouseProto._touchEnd = function (event) {
-
- if (!touchHandled) {
- return;
- }
-
- simulateMouseEvent(event, 'mouseup');
-
- simulateMouseEvent(event, 'mouseout');
-
- if (!this._touchMoved) {
-
- simulateMouseEvent(event, 'click');
- }
-
- touchHandled = false;
- };
-
- mouseProto._mouseInit = function () {
-
- var self = this;
-
- self.element.bind({
- touchstart: $.proxy(self, '_touchStart'),
- touchmove: $.proxy(self, '_touchMove'),
- touchend: $.proxy(self, '_touchEnd')
- });
-
- _mouseInit.call(self);
- };
-
- mouseProto._mouseDestroy = function () {
-
- var self = this;
-
- self.element.unbind({
- touchstart: $.proxy(self, '_touchStart'),
- touchmove: $.proxy(self, '_touchMove'),
- touchend: $.proxy(self, '_touchEnd')
- });
-
- _mouseDestroy.call(self);
- };
- })(jQuery);
|