|
469 | 469 | target.typeCount++;
|
470 | 470 | }
|
471 | 471 |
|
472 |
| - if (indexOf(target.events[type], listener) === -1) { |
| 472 | + if (!contains(target.events[type], listener)) { |
473 | 473 | var ret;
|
474 | 474 |
|
475 | 475 | if (useAttachEvent) {
|
|
591 | 591 | return -1;
|
592 | 592 | }
|
593 | 593 |
|
| 594 | + function contains (array, target) { |
| 595 | + return indexOf(array, target) !== -1; |
| 596 | + } |
| 597 | + |
594 | 598 | function preventDef () {
|
595 | 599 | this.returnValue = false;
|
596 | 600 | }
|
|
1089 | 1093 | action = 'resize';
|
1090 | 1094 | }
|
1091 | 1095 |
|
1092 |
| - return (options.snapEnabled && indexOf(options.snap.actions, action) !== -1); |
| 1096 | + return (options.snapEnabled && contains(options.snap.actions, action)); |
1093 | 1097 | }
|
1094 | 1098 |
|
1095 | 1099 | function checkRestrict (interactable, action) {
|
|
2718 | 2722 | else if (target) {
|
2719 | 2723 | var prevTargetChildren = prevTargetElement.querySelectorAll('*');
|
2720 | 2724 |
|
2721 |
| - if (indexOf(prevTargetChildren, eventTarget) !== -1) { |
| 2725 | + if (contains(prevTargetChildren, eventTarget)) { |
2722 | 2726 |
|
2723 | 2727 | // reset the elements of the matches to the old target
|
2724 | 2728 | for (var i = 0; i < matches.length; i++) {
|
|
2824 | 2828 | // check if inertia should be started
|
2825 | 2829 | inertiaPossible = (options.inertiaEnabled
|
2826 | 2830 | && prepared !== 'gesture'
|
2827 |
| - && indexOf(inertiaOptions.actions, prepared) !== -1 |
| 2831 | + && contains(inertiaOptions.actions, prepared) |
2828 | 2832 | && event !== inertiaStatus.startEvent);
|
2829 | 2833 |
|
2830 | 2834 | inertia = (inertiaPossible
|
|
2834 | 2838 |
|
2835 | 2839 | if (inertiaPossible && !inertia
|
2836 | 2840 | && ((options.snapEnabled && options.snap.endOnly
|
2837 |
| - && indexOf(options.snap.actions, prepared) !== -1) |
| 2841 | + && contains(options.snap.actions, prepared)) |
2838 | 2842 | || (options.restrictEnabled && options.restrict.endOnly))) {
|
2839 | 2843 |
|
2840 | 2844 | var snapRestrict = {};
|
|
2905 | 2909 | dx = dy = 0;
|
2906 | 2910 |
|
2907 | 2911 | if (options.snapEnabled && options.snap.endOnly
|
2908 |
| - && indexOf(options.snap.actions, prepared) !== -1) { |
| 2912 | + && contains(options.snap.actions, prepared)) { |
2909 | 2913 |
|
2910 | 2914 | var snap = setSnapping(event, statusObject);
|
2911 | 2915 |
|
|
4248 | 4252 | = (Interactable) this Interactable
|
4249 | 4253 | \*/
|
4250 | 4254 | fire: function (iEvent) {
|
4251 |
| - if (!(iEvent && iEvent.type) || indexOf(eventTypes, iEvent.type) === -1) { |
| 4255 | + if (!(iEvent && iEvent.type) || !contains(eventTypes, iEvent.type)) { |
4252 | 4256 | return this;
|
4253 | 4257 | }
|
4254 | 4258 |
|
|
4333 | 4337 | // convert to boolean
|
4334 | 4338 | useCapture = useCapture? true: false;
|
4335 | 4339 |
|
4336 |
| - if (indexOf(eventTypes, eventType) !== -1) { |
| 4340 | + if (contains(eventTypes, eventType)) { |
4337 | 4341 | // if this type of event was never bound to this Interactable
|
4338 | 4342 | if (!(eventType in this._iEvents)) {
|
4339 | 4343 | this._iEvents[eventType] = [listener];
|
4340 | 4344 | }
|
4341 | 4345 | // 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)) { |
4343 | 4347 | this._iEvents[eventType].push(listener);
|
4344 | 4348 | }
|
4345 | 4349 | }
|
|
4408 | 4412 | }
|
4409 | 4413 |
|
4410 | 4414 | // if it is an action event type
|
4411 |
| - if (indexOf(eventTypes, eventType) !== -1) { |
| 4415 | + if (contains(eventTypes, eventType)) { |
4412 | 4416 | eventList = this._iEvents[eventType];
|
4413 | 4417 |
|
4414 | 4418 | if (eventList && (index = indexOf(eventList, listener)) !== -1) {
|
|
4597 | 4601 | \*/
|
4598 | 4602 | interact.on = function (type, listener, useCapture) {
|
4599 | 4603 | // if it is an InteractEvent type, add listener to globalEvents
|
4600 |
| - if (indexOf(eventTypes, type) !== -1) { |
| 4604 | + if (contains(eventTypes, type)) { |
4601 | 4605 | // if this type of event was never bound
|
4602 | 4606 | if (!globalEvents[type]) {
|
4603 | 4607 | globalEvents[type] = [listener];
|
4604 | 4608 | }
|
4605 | 4609 |
|
4606 | 4610 | // 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)) { |
4608 | 4612 |
|
4609 | 4613 | globalEvents[type].push(listener);
|
4610 | 4614 | }
|
|
4629 | 4633 | = (object) interact
|
4630 | 4634 | \*/
|
4631 | 4635 | interact.off = function (type, listener, useCapture) {
|
4632 |
| - if (indexOf(eventTypes, type) === -1) { |
| 4636 | + if (!contains(eventTypes, type)) { |
4633 | 4637 | events.remove(docTarget, type, listener, useCapture);
|
4634 | 4638 | }
|
4635 | 4639 | else {
|
|
5293 | 5297 | return -1;
|
5294 | 5298 | }
|
5295 | 5299 |
|
| 5300 | + function contains (array, target) { |
| 5301 | + return indexOf(array, target) !== -1; |
| 5302 | + } |
| 5303 | + |
5296 | 5304 | // For IE's lack of Event#preventDefault
|
5297 | 5305 | events.add(docTarget, 'selectstart', function (event) {
|
5298 | 5306 | if (dragging || resizing || gesturing) {
|
|
0 commit comments