any-touch
Advanced tools
Comparing version 0.0.24 to 0.0.25
@@ -87,2 +87,123 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i; | ||
@@ -523,123 +644,2 @@ var IS_MOBILE = MOBILE_REGEX.test(navigator.userAgent); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var STATUS_POSSIBLE = 'possible'; | ||
@@ -789,3 +789,2 @@ var STATUS_START = 'start'; | ||
}()); | ||
Recognizer.prototype.eventBus = new EventEmitter(); | ||
@@ -1110,6 +1109,8 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout; | ||
function AnyTouch(el, options) { | ||
this.version = '0.0.12'; | ||
var _this = this; | ||
this.version = '0.0.25'; | ||
this.el = el; | ||
this.isMobile = IS_MOBILE; | ||
this.options = __assign({}, this.default, options); | ||
this.eventBus = new EventEmitter(); | ||
this.recognizers = [ | ||
@@ -1123,5 +1124,8 @@ new TapRecognizer(), | ||
]; | ||
Recognizer.prototype.el = el; | ||
Recognizer.prototype.$root = this; | ||
Recognizer.prototype.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.forEach(function (recognizer) { | ||
recognizer.eventBus = _this.eventBus; | ||
recognizer.el = el; | ||
recognizer.$root = _this; | ||
recognizer.hasDomEvents = _this.options.hasDomEvents; | ||
}); | ||
this.update(); | ||
@@ -1184,2 +1188,6 @@ this.unbinders = this._bindRecognizers(this.el); | ||
AnyTouch.prototype.add = function (recognizer) { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = this.el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.push(recognizer); | ||
@@ -1217,3 +1225,3 @@ this.update(); | ||
if (!event.cancelable) { | ||
Recognizer.prototype.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
this.eventBus.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
} | ||
@@ -1244,6 +1252,6 @@ if (this.options.isPreventDefault) { | ||
AnyTouch.prototype.on = function (type, listener) { | ||
Recognizer.prototype.on(type, listener); | ||
this.eventBus.on(type, listener); | ||
}; | ||
AnyTouch.prototype.off = function (type, listener) { | ||
Recognizer.prototype.off(type, listener); | ||
this.eventBus.off(type, listener); | ||
}; | ||
@@ -1250,0 +1258,0 @@ AnyTouch.prototype.destroy = function () { |
@@ -85,2 +85,123 @@ /*! ***************************************************************************** | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i; | ||
@@ -521,123 +642,2 @@ var IS_MOBILE = MOBILE_REGEX.test(navigator.userAgent); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var STATUS_POSSIBLE = 'possible'; | ||
@@ -787,3 +787,2 @@ var STATUS_START = 'start'; | ||
}()); | ||
Recognizer.prototype.eventBus = new EventEmitter(); | ||
@@ -1108,6 +1107,8 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout; | ||
function AnyTouch(el, options) { | ||
this.version = '0.0.12'; | ||
var _this = this; | ||
this.version = '0.0.25'; | ||
this.el = el; | ||
this.isMobile = IS_MOBILE; | ||
this.options = __assign({}, this.default, options); | ||
this.eventBus = new EventEmitter(); | ||
this.recognizers = [ | ||
@@ -1121,5 +1122,8 @@ new TapRecognizer(), | ||
]; | ||
Recognizer.prototype.el = el; | ||
Recognizer.prototype.$root = this; | ||
Recognizer.prototype.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.forEach(function (recognizer) { | ||
recognizer.eventBus = _this.eventBus; | ||
recognizer.el = el; | ||
recognizer.$root = _this; | ||
recognizer.hasDomEvents = _this.options.hasDomEvents; | ||
}); | ||
this.update(); | ||
@@ -1182,2 +1186,6 @@ this.unbinders = this._bindRecognizers(this.el); | ||
AnyTouch.prototype.add = function (recognizer) { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = this.el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.push(recognizer); | ||
@@ -1215,3 +1223,3 @@ this.update(); | ||
if (!event.cancelable) { | ||
Recognizer.prototype.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
this.eventBus.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
} | ||
@@ -1242,6 +1250,6 @@ if (this.options.isPreventDefault) { | ||
AnyTouch.prototype.on = function (type, listener) { | ||
Recognizer.prototype.on(type, listener); | ||
this.eventBus.on(type, listener); | ||
}; | ||
AnyTouch.prototype.off = function (type, listener) { | ||
Recognizer.prototype.off(type, listener); | ||
this.eventBus.off(type, listener); | ||
}; | ||
@@ -1248,0 +1256,0 @@ AnyTouch.prototype.destroy = function () { |
@@ -91,2 +91,123 @@ (function (global, factory) { | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i; | ||
@@ -527,123 +648,2 @@ var IS_MOBILE = MOBILE_REGEX.test(navigator.userAgent); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __values$1(o) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; | ||
if (m) return m.call(o); | ||
return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
} | ||
function __read$1(o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
} | ||
function __spread$1() { | ||
for (var ar = [], i = 0; i < arguments.length; i++) | ||
ar = ar.concat(__read$1(arguments[i])); | ||
return ar; | ||
} | ||
var EventEmitter = (function () { | ||
function EventEmitter() { | ||
this._listenersMap = {}; | ||
} | ||
EventEmitter.prototype.on = function (eventName, listener) { | ||
if (undefined === this._listenersMap[eventName]) { | ||
this._listenersMap[eventName] = []; | ||
} | ||
this._listenersMap[eventName].push(listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.once = function (eventName, listener) { | ||
listener.isOnce = true; | ||
this.on(eventName, listener); | ||
return this; | ||
}; | ||
EventEmitter.prototype.off = function (eventName, listener) { | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners) { | ||
if (undefined === listener) { | ||
delete this._listenersMap[eventName]; | ||
} | ||
else { | ||
var index = listeners.findIndex(function (fn) { return fn === listener; }); | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
return this; | ||
}; | ||
EventEmitter.prototype.emit = function (eventName) { | ||
var payload = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
payload[_i - 1] = arguments[_i]; | ||
} | ||
var e_1, _a; | ||
var listeners = this._listenersMap[eventName]; | ||
if (undefined !== listeners && 0 < listeners.length) { | ||
try { | ||
for (var _b = __values$1(listeners.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var _d = __read$1(_c.value, 2), index = _d[0], listener = _d[1]; | ||
if (listener.isOnce) { | ||
var listenerClone = listener; | ||
listeners.splice(index, 1); | ||
listenerClone.apply(void 0, __spread$1(payload)); | ||
} | ||
else { | ||
listener.apply(void 0, __spread$1(payload)); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
return true; | ||
} | ||
else { | ||
return false; | ||
} | ||
}; | ||
EventEmitter.prototype.has = function (eventName) { | ||
return undefined !== this._listenersMap[eventName] && 0 < this._listenersMap[eventName].length; | ||
}; | ||
EventEmitter.prototype.destroy = function () { | ||
this._listenersMap = {}; | ||
}; | ||
return EventEmitter; | ||
}()); | ||
var STATUS_POSSIBLE = 'possible'; | ||
@@ -793,3 +793,2 @@ var STATUS_START = 'start'; | ||
}()); | ||
Recognizer.prototype.eventBus = new EventEmitter(); | ||
@@ -1114,6 +1113,8 @@ var setTimeout = window.setTimeout, clearTimeout$1 = window.clearTimeout; | ||
function AnyTouch(el, options) { | ||
this.version = '0.0.12'; | ||
var _this = this; | ||
this.version = '0.0.25'; | ||
this.el = el; | ||
this.isMobile = IS_MOBILE; | ||
this.options = __assign({}, this.default, options); | ||
this.eventBus = new EventEmitter(); | ||
this.recognizers = [ | ||
@@ -1127,5 +1128,8 @@ new TapRecognizer(), | ||
]; | ||
Recognizer.prototype.el = el; | ||
Recognizer.prototype.$root = this; | ||
Recognizer.prototype.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.forEach(function (recognizer) { | ||
recognizer.eventBus = _this.eventBus; | ||
recognizer.el = el; | ||
recognizer.$root = _this; | ||
recognizer.hasDomEvents = _this.options.hasDomEvents; | ||
}); | ||
this.update(); | ||
@@ -1188,2 +1192,6 @@ this.unbinders = this._bindRecognizers(this.el); | ||
AnyTouch.prototype.add = function (recognizer) { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = this.el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.push(recognizer); | ||
@@ -1221,3 +1229,3 @@ this.update(); | ||
if (!event.cancelable) { | ||
Recognizer.prototype.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
this.eventBus.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
} | ||
@@ -1248,6 +1256,6 @@ if (this.options.isPreventDefault) { | ||
AnyTouch.prototype.on = function (type, listener) { | ||
Recognizer.prototype.on(type, listener); | ||
this.eventBus.on(type, listener); | ||
}; | ||
AnyTouch.prototype.off = function (type, listener) { | ||
Recognizer.prototype.off(type, listener); | ||
this.eventBus.off(type, listener); | ||
}; | ||
@@ -1254,0 +1262,0 @@ AnyTouch.prototype.destroy = function () { |
@@ -32,2 +32,3 @@ import { EventHandler } from './interface'; | ||
options: Options; | ||
eventBus: any; | ||
constructor(el: HTMLElement, options?: Options); | ||
@@ -34,0 +35,0 @@ updateTouchAction(el: HTMLElement): void; |
@@ -42,2 +42,3 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import AnyEvent from 'any-event'; | ||
import { IS_MOBILE, } from './const'; | ||
@@ -47,3 +48,2 @@ import inputManage from './inputManage'; | ||
import computeTouchAction from './untils/computeTouchAction'; | ||
import Recognizer from './recognitions/Base'; | ||
import TapRecognizer from './recognitions/Tap'; | ||
@@ -59,6 +59,8 @@ import PressRecognizer from './recognitions/Press'; | ||
function AnyTouch(el, options) { | ||
this.version = '0.0.12'; | ||
var _this = this; | ||
this.version = '0.0.25'; | ||
this.el = el; | ||
this.isMobile = IS_MOBILE; | ||
this.options = __assign({}, this.default, options); | ||
this.eventBus = new AnyEvent(); | ||
this.recognizers = [ | ||
@@ -72,5 +74,8 @@ new TapRecognizer(), | ||
]; | ||
Recognizer.prototype.el = el; | ||
Recognizer.prototype.$root = this; | ||
Recognizer.prototype.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.forEach(function (recognizer) { | ||
recognizer.eventBus = _this.eventBus; | ||
recognizer.el = el; | ||
recognizer.$root = _this; | ||
recognizer.hasDomEvents = _this.options.hasDomEvents; | ||
}); | ||
this.update(); | ||
@@ -138,2 +143,6 @@ this.unbinders = this._bindRecognizers(this.el); | ||
AnyTouch.prototype.add = function (recognizer) { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = this.el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.push(recognizer); | ||
@@ -175,3 +184,3 @@ this.update(); | ||
if (!event.cancelable) { | ||
Recognizer.prototype.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
this.eventBus.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
} | ||
@@ -203,7 +212,7 @@ if (this.options.isPreventDefault) { | ||
AnyTouch.prototype.on = function (type, listener) { | ||
Recognizer.prototype.on(type, listener); | ||
this.eventBus.on(type, listener); | ||
}; | ||
; | ||
AnyTouch.prototype.off = function (type, listener) { | ||
Recognizer.prototype.off(type, listener); | ||
this.eventBus.off(type, listener); | ||
}; | ||
@@ -210,0 +219,0 @@ ; |
@@ -31,3 +31,2 @@ var __assign = (this && this.__assign) || function () { | ||
}; | ||
import AnyEvent from 'any-event'; | ||
import { INPUT_CANCEL, INPUT_END, INPUT_MOVE } from '../const'; | ||
@@ -190,3 +189,2 @@ import { STATUS_POSSIBLE, STATUS_START, STATUS_MOVE, STATUS_END, STATUS_CANCELLED, STATUS_FAILED, STATUS_RECOGNIZED } from '../const/recognizerStatus'; | ||
; | ||
Recognizer.prototype.eventBus = new AnyEvent(); | ||
//# sourceMappingURL=Base.js.map |
{ | ||
"name": "any-touch", | ||
"version": "0.0.24", | ||
"version": "0.0.25", | ||
"description": "一个手势库", | ||
@@ -5,0 +5,0 @@ "unpkg": "dist/AnyTouch.umd.js", |
@@ -19,2 +19,3 @@ /** | ||
*/ | ||
import AnyEvent from 'any-event'; | ||
import { EventHandler, Computed } from './interface'; | ||
@@ -65,2 +66,4 @@ import { | ||
eventBus: any; | ||
/** | ||
@@ -71,6 +74,9 @@ * @param {Element} el | ||
constructor(el: HTMLElement, options?: Options) { | ||
this.version = '0.0.12'; | ||
this.version = '0.0.25'; | ||
this.el = el; | ||
this.isMobile = IS_MOBILE; | ||
this.options = { ...this.default, ...options }; | ||
// eventBus | ||
this.eventBus = new AnyEvent(); | ||
// 识别器 | ||
this.recognizers = [ | ||
@@ -84,14 +90,12 @@ new TapRecognizer(), | ||
]; | ||
// 注入el到识别器原型 | ||
// 注入el | ||
// 后面模拟浏览器时间需要用到el | ||
Recognizer.prototype.el = el; | ||
Recognizer.prototype.$root = this; | ||
Recognizer.prototype.hasDomEvents = this.options.hasDomEvents; | ||
// 识别器注入update方法 | ||
// Object.setPrototypeOf(Recognizer, {$root:AnyTouch}) | ||
this.recognizers.forEach(recognizer => { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
}); | ||
// console.log(Object.getPrototypeOf(Recognizer).$root); | ||
// Recognizer.prototype.$root = 123; | ||
// Recognizer.pro('update', this.update.bind(this)); | ||
// 应用设置 | ||
@@ -161,2 +165,7 @@ this.update(); | ||
add(recognizer: any): void { | ||
recognizer.eventBus = this.eventBus; | ||
recognizer.el = this.el; | ||
recognizer.$root = this; | ||
recognizer.hasDomEvents = this.options.hasDomEvents; | ||
this.recognizers.push(recognizer); | ||
@@ -199,3 +208,3 @@ this.update(); | ||
if (!event.cancelable) { | ||
Recognizer.prototype.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
this.eventBus.emit('error', { code: 0, message: '页面滚动的时候, 请暂时不要操作元素!' }); | ||
} | ||
@@ -211,5 +220,5 @@ | ||
// 当是鼠标事件的时候, mouseup阶段的input和computed为空 | ||
for(let recognizer of this.recognizers) { | ||
for (let recognizer of this.recognizers) { | ||
// const isValidEvent = Recognizer.prototype.eventBus.has(recognizer.name); | ||
if(recognizer.disabled) continue; | ||
if (recognizer.disabled) continue; | ||
recognizer.recognize(computed); | ||
@@ -227,3 +236,3 @@ // recognizer.emit('input', { ...computed, type: 'input' }); | ||
on(type: string, listener: EventHandler): void { | ||
Recognizer.prototype.on(type, listener); | ||
this.eventBus.on(type, listener); | ||
}; | ||
@@ -237,3 +246,3 @@ | ||
off(type: string, listener?: EventHandler): void { | ||
Recognizer.prototype.off(type, listener); | ||
this.eventBus.off(type, listener); | ||
}; | ||
@@ -240,0 +249,0 @@ |
@@ -6,3 +6,2 @@ /* | ||
* */ | ||
import AnyEvent from 'any-event'; | ||
import { Computed } from '../interface'; | ||
@@ -86,3 +85,3 @@ import { Options } from '../../types/recognition'; | ||
/** | ||
* 对eventBus进行封装 | ||
* 对$root.进行封装 | ||
* @param type | ||
@@ -269,2 +268,1 @@ * @param payload | ||
Recognizer.prototype.eventBus = new AnyEvent(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
309558
6938