Skip to content

Commit 9f540d9

Browse files
committed
Add 'contains' for checking if element is in array
1 parent d312ddc commit 9f540d9

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

interact.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@
469469
target.typeCount++;
470470
}
471471

472-
if (indexOf(target.events[type], listener) === -1) {
472+
if (!contains(target.events[type], listener)) {
473473
var ret;
474474

475475
if (useAttachEvent) {
@@ -591,6 +591,10 @@
591591
return -1;
592592
}
593593

594+
function contains (array, target) {
595+
return indexOf(array, target) !== -1;
596+
}
597+
594598
function preventDef () {
595599
this.returnValue = false;
596600
}
@@ -1089,7 +1093,7 @@
10891093
action = 'resize';
10901094
}
10911095

1092-
return (options.snapEnabled && indexOf(options.snap.actions, action) !== -1);
1096+
return (options.snapEnabled && contains(options.snap.actions, action));
10931097
}
10941098

10951099
function checkRestrict (interactable, action) {
@@ -2718,7 +2722,7 @@
27182722
else if (target) {
27192723
var prevTargetChildren = prevTargetElement.querySelectorAll('*');
27202724

2721-
if (indexOf(prevTargetChildren, eventTarget) !== -1) {
2725+
if (contains(prevTargetChildren, eventTarget)) {
27222726

27232727
// reset the elements of the matches to the old target
27242728
for (var i = 0; i < matches.length; i++) {
@@ -2824,7 +2828,7 @@
28242828
// check if inertia should be started
28252829
inertiaPossible = (options.inertiaEnabled
28262830
&& prepared !== 'gesture'
2827-
&& indexOf(inertiaOptions.actions, prepared) !== -1
2831+
&& contains(inertiaOptions.actions, prepared)
28282832
&& event !== inertiaStatus.startEvent);
28292833

28302834
inertia = (inertiaPossible
@@ -2834,7 +2838,7 @@
28342838

28352839
if (inertiaPossible && !inertia
28362840
&& ((options.snapEnabled && options.snap.endOnly
2837-
&& indexOf(options.snap.actions, prepared) !== -1)
2841+
&& contains(options.snap.actions, prepared))
28382842
|| (options.restrictEnabled && options.restrict.endOnly))) {
28392843

28402844
var snapRestrict = {};
@@ -2905,7 +2909,7 @@
29052909
dx = dy = 0;
29062910

29072911
if (options.snapEnabled && options.snap.endOnly
2908-
&& indexOf(options.snap.actions, prepared) !== -1) {
2912+
&& contains(options.snap.actions, prepared)) {
29092913

29102914
var snap = setSnapping(event, statusObject);
29112915

@@ -4248,7 +4252,7 @@
42484252
= (Interactable) this Interactable
42494253
\*/
42504254
fire: function (iEvent) {
4251-
if (!(iEvent && iEvent.type) || indexOf(eventTypes, iEvent.type) === -1) {
4255+
if (!(iEvent && iEvent.type) || !contains(eventTypes, iEvent.type)) {
42524256
return this;
42534257
}
42544258

@@ -4333,13 +4337,13 @@
43334337
// convert to boolean
43344338
useCapture = useCapture? true: false;
43354339

4336-
if (indexOf(eventTypes, eventType) !== -1) {
4340+
if (contains(eventTypes, eventType)) {
43374341
// if this type of event was never bound to this Interactable
43384342
if (!(eventType in this._iEvents)) {
43394343
this._iEvents[eventType] = [listener];
43404344
}
43414345
// if the event listener is not already bound for this type
4342-
else if (indexOf(this._iEvents[eventType], listener) === -1) {
4346+
else if (!contains(this._iEvents[eventType], listener)) {
43434347
this._iEvents[eventType].push(listener);
43444348
}
43454349
}
@@ -4408,7 +4412,7 @@
44084412
}
44094413

44104414
// if it is an action event type
4411-
if (indexOf(eventTypes, eventType) !== -1) {
4415+
if (contains(eventTypes, eventType)) {
44124416
eventList = this._iEvents[eventType];
44134417

44144418
if (eventList && (index = indexOf(eventList, listener)) !== -1) {
@@ -4597,14 +4601,14 @@
45974601
\*/
45984602
interact.on = function (type, listener, useCapture) {
45994603
// if it is an InteractEvent type, add listener to globalEvents
4600-
if (indexOf(eventTypes, type) !== -1) {
4604+
if (contains(eventTypes, type)) {
46014605
// if this type of event was never bound
46024606
if (!globalEvents[type]) {
46034607
globalEvents[type] = [listener];
46044608
}
46054609

46064610
// if the event listener is not already bound for this type
4607-
else if (indexOf(globalEvents[type], listener) === -1) {
4611+
else if (!contains(globalEvents[type], listener)) {
46084612

46094613
globalEvents[type].push(listener);
46104614
}
@@ -4629,7 +4633,7 @@
46294633
= (object) interact
46304634
\*/
46314635
interact.off = function (type, listener, useCapture) {
4632-
if (indexOf(eventTypes, type) === -1) {
4636+
if (!contains(eventTypes, type)) {
46334637
events.remove(docTarget, type, listener, useCapture);
46344638
}
46354639
else {
@@ -5293,6 +5297,10 @@
52935297
return -1;
52945298
}
52955299

5300+
function contains (array, target) {
5301+
return indexOf(array, target) !== -1;
5302+
}
5303+
52965304
// For IE's lack of Event#preventDefault
52975305
events.add(docTarget, 'selectstart', function (event) {
52985306
if (dragging || resizing || gesturing) {

0 commit comments

Comments
 (0)