-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaktion.js
947 lines (777 loc) · 33.5 KB
/
aktion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
/**
* Define Aktion data attributes.
*
* @attr data-aktion-name Unique action name (default: autogenerated)
* @attr data-aktion-type Action type (can be: 'set'|'toggle'|'add'|'remove'|'trigger-event', default: 'toggle')
* @attr data-aktion-value String value which will affect the attribute value of the destination DOM element(s) (required)
* @attr data-aktion-value-type The attribute value of the destination DOM element(s) can be a "static" string,
* or the name of an "attribute" of the source DOM element which stores the value, or the name of an "event" which will be triggered
* on the destination DOM element (can be 'static'|'attribute')
* @attr data-aktion-event Native/custom event fires up action (default: 'click')
* @attr data-aktion-event-threshold Custom event (swipe) threshold value (default: 10)
* @attr data-aktion-source-selector A valid DOM selector which determines the source DOM element(s) (default: this)
* @attr data-aktion-destination-selector A valid DOM selector which determines the destination DOM element(s) (default: this)
* @attr data-aktion-trigger-before Action will trigger before this named action, which has the same source selector (default: false)
* @attr data-aktion-trigger-after Action will trigger after this named action, which has the same source selector (default: false)
* @attr data-aktion-attribute The attribute of the destination DOM element, which will be affected (if data-aktion-value-type is not "event") (default: 'class')
* @attr data-aktion-interval-time Time of the function calling interval (in milliseconds). Used at custom scroll event checking (default: 100).
* @attr data-aktion-extra-condition Function call which determines extra condition for the execution of the action (default: true)
**/
var Aktion = (function(customConfig) {
/**
* MinJS
*
* https://github.com/remy/min.js
*
* Upgraded by megant
*
**/
var $ = (function (document, window, $) {
// Node covers all elements, but also the document objects
var node = Node.prototype,
nodeList = NodeList.prototype,
forEach = 'forEach',
trigger = 'trigger',
each = [][forEach],
// note: createElement requires a string in Firefox
dummy = document.createElement('i'),
event_idx;
nodeList[forEach] = each;
// we have to explicitly add a window.on as it's not included
// in the Node object.
window.on = node.on = function (events, fn) {
events = events.split(" ");
for (event_idx in events) {
this.addEventListener(events[event_idx], fn, false);
}
// allow for chaining
return this;
};
nodeList.on = function (events, fn) {
events = events.split(" ");
this[forEach](function (el) {
for (event_idx in events) {
el.on(events[event_idx], fn);
}
});
return this;
};
// we save a few bytes (but none really in compression)
// by using [trigger] - really it's for consistency in the
// source code.
window[trigger] = node[trigger] = function (type, data) {
// construct an HTML event. This could have
// been a real custom event
var event = document.createEvent('HTMLEvents');
event.initEvent(type, true, true);
event.data = data || {};
event.eventName = type;
event.target = this;
this.dispatchEvent(event);
return this;
};
nodeList[trigger] = function (event) {
this[forEach](function (el) {
el[trigger](event);
});
return this;
};
$ = function (s) {
var r = document.querySelectorAll(s || '☺'),
length = r.length;
return length == 1 ? r[0] : r;
};
// $.on and $.trigger allow for pub/sub type global
// custom events.
$.on = node.on.bind(dummy);
$[trigger] = node[trigger].bind(dummy);
return $;
})(document, this);
Node.prototype.delegate=function(a,b,c){var d=this.mozMatchesSelector||this.webkitMatchesSelector||this.oMatchesSelector||this.matchesSelector||function(a){var b=this,c=$(a),d=!1;return c instanceof NodeList?c.forEach(function(a){a===b&&(d=!0)}):c===b&&(d=!0),d};return this.on(b,function(b){d.call(b.target,a)&&c.call(b.target,b)}),this};
/**
* Main Aktion object
*
* @constructor
* @param {object} customConfig Public configuration object
* @returns {object} Public API object
*/
var AktionBase = function(customConfig) {
/** "Private" properties **/
/** Scroll position checker interval **/
var scrollInterval = null;
/** Collection of elements with custom scroll events **/
var scrollElements = [];
/** Aktion-wide indicators */
var indicators = {
isIOS: false,
actionCheckInProgress: false,
// data-action-name counter (if data-action-name is not present)
elementNameCounter: 0,
// 0: inactive, 1: active, 2: in progress, 3: stopped
scrollStatus: 0
};
/** Touch position indicators for mobile events */
var touchPositions = {
startX: null,
startY: null,
currentX: null,
currentY: null
};
/** Default configuration options */
var defaultConfig = {
dataAttributePrefix: "aktion",
autoActivate: true,
debugMode: false
};
/** Instance configuration options */
var config = {};
/** data-action-* attribute defaults */
var elementDefaults = {
type: 'toggle',
source_selector: null,
destination_selector: null,
event: 'click',
event_threshold: 10,
attribute: 'class',
value: null,
value_type: 'static',
trigger_before: false,
trigger_after: false,
interval_time: 100,
extra_condition: (function () {return true})
};
/** currently triggering aktions queue */
var actionQueue = {};
/** aktion order container array */
var actionOrder = [];
/** Helper methods **/
var Helpers = {
/**
* Log to the console
*
* @param {string} message Log message
* @param {object} data Log data object
* @returns {boolean} false if debug mode is disabled
*/
log: function(message, data) {
if (!config.debugMode) {
return false;
}
console.log(message, data);
},
/**
* Create a new object by combining two or more objects
*
* @returns {object} extended object
*/
extend: function () {
// Variables
var extended = {};
var deep = false;
var i = 0;
var length = arguments.length;
// Check if a deep merge
if (Object.prototype.toString.call(arguments[0]) === '[object Boolean]') {
deep = arguments[0];
i++;
}
// Merge the object into the extended object
var merge = function (obj) {
for (var prop in obj) {
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
// If deep merge and property is an object, merge properties
if (deep && Object.prototype.toString.call(obj[prop]) === '[object Object]') {
extended[prop] = extend(true, extended[prop], obj[prop]);
} else {
extended[prop] = obj[prop];
}
}
}
};
// Loop through each object and conduct a merge
for (; i < length; i++) {
var obj = arguments[i];
merge(obj);
}
return extended;
},
/**
* Cross-browser pointer event getter
*
* @param {Event} event Event object
* @returns {Event} Browser compatible pointer event object
*/
getPointerEvent: function (event) {
return event.targetTouches ? event.targetTouches[0] : event;
},
/**
* Get height of an element
*
* @param {DOM object} el DOM object
* @returns {number} Height in pixels
*/
getHeight: function (el) {
var height;
if (el == window) {
height = el.innerHeight;
} else if (el == document) {
height = this.getDocumentDimension('height');
} else {
height = el.offsetHeight;
var style = getComputedStyle(el);
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
}
return height;
},
/**
* Cross-browser document height getter
*
* @param {string} dimension name of the searched dimension
* @returns {number} dimension in pixels
*/
getDocumentDimension: function (dimension) {
var D = document;
dimension = dimension.charAt(0).toUpperCase() + dimension.slice(1);
return Math.max(
D.body['scroll' + dimension], D.documentElement['scroll' + dimension],
D.body['offset' + dimension], D.documentElement['offset' + dimension],
D.body['client' + dimension], D.documentElement['client' + dimension]
);
},
/**
* iOS platform check
*
* @returns {boolean} True if platform is iOS
*/
checkIOS: function () {
return /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
},
/**
* Get delegator DOM element (if needed)
*
* @param {string} source_selector Source element selector string
* @returns {DOM object} Delegator DOM object
*/
getDelegatorDOMElement: function (source_selector) {
if (source_selector == 'window') {
return false;
} else {
return $('body');
}
},
/**
* Get aktion attribute value
*
* @param {DOM element}
* @param {string} attr attribute of Aktion
*
* @returns Aktion attribute
*/
getAttr: function (elm, attr) {
var fullAttribute = this.getAttrName(attr);
return elm.getAttribute(fullAttribute);
},
/**
* Get full aktion data attribute name
*
* @param {string} attr Short attribute name
* @returns {string} Full aktion data attribute name
*/
getAttrName: function (attr) {
return 'data-' + config.dataAttributePrefix + '-' + attr;
},
/**
* Cross-browser foreach method for old browsers
*
* @oaram {array} array Array which will be looped thru
* @param {function} callback Callback function
* @param {object} scope Optional scope object
*/
forEach: function (array, callback, scope) {
if (undefined === array.length) {
array = [array];
}
for (var i = 0; i < array.length; i++) {
callback.call(scope, array[i], i); // passes back stuff we need
}
},
/**
* Get window scroll top property
*
* @returns {integer} Scroll top property in pixels
*/
getWindowScrollTop: function() {
return (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
}
}
/**
* Object init
*/
var init = function () {
config = Helpers.extend(defaultConfig, customConfig)
indicators.isIOS = Helpers.checkIOS();
if (config.autoActivate) _activate();
};
/**
* Activate aktion events
*/
var _activate = function () {
var $aktions = $('[' + Helpers.getAttrName('value') + ']');
// No aktion elements has been found
if ($aktions.length < 1) return false;
// CSS3 animation and transition events
initCrossPlatformEvents($aktions);
Helpers.forEach($aktions, function ($aktion, index) {
// Element data object
var element = setElementData($aktion);
handleActionTriggering(element);
});
}
/**
* Cross-platform event initialization
*/
var initCrossPlatformEvents = function () {
// Cross-browser transition end event trigger
$('['+Helpers.getAttrName('event')+'="trans-end"]').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function (event) {
event.target.trigger('trans-end');
});
// Cross-browser animation end event trigger
$('['+Helpers.getAttrName('event')+'="anim-end"]').on('animationend webkitAnimationEnd oAnimationEnd MSAnimationEnd', function (event) {
event.target.trigger('anim-end');
});
}
/**
* Trigger custom swipe events
* @param {object} element Element data object
*/
var handleSwipeEvent = function (element) {
var touchStarted = false;
var _events = [];
element.sourceElm.on('touchstart', function (e) {
var pointer = Helpers.getPointerEvent(e);
// caching the current x
touchPositions.startX = touchPositions.currentX = pointer.pageX;
touchPositions.startY = touchPositions.currentY = pointer.pageY;
// a touch event is detected
touchStarted = true;
// detecting if after 200ms the finger is still in the same position
setTimeout(function () {
if ((touchPositions.startX === touchPositions.currentX) && !touchStarted && (touchPositions.startY === touchPositions.currentY)) {
touchStarted = false;
}
}, 200);
});
element.sourceElm.on('touchmove', function (e) {
var pointer = Helpers.getPointerEvent(e);
_events = [];
touchPositions.currentX = pointer.pageX;
touchPositions.currentY = pointer.pageY;
if (touchPositions.currentX + element.event_threshold < touchPositions.startX) {
_events.push('swipeleft');
} else if (touchPositions.currentX - element.event_threshold > touchPositions.startX) {
_events.push('swiperight');
}
if (touchPositions.currentY + element.event_threshold < touchPositions.startY) {
_events.push('swipeup');
} else if (touchPositions.currentY - element.event_threshold > touchPositions.startY) {
_events.push('swipedown');
}
});
element.sourceElm.on('touchend touchcancel', function (e) {
if (touchStarted && _events.length) {
var event_idx = _events.indexOf(element.event);
if (event_idx > -1 && element.extra_condition()) {
element.sourceElm.trigger(_events[event_idx]);
}
}
// here we can consider finished the touch event
touchStarted = false;
_events = [];
});
}
/**
* Custom scroll event checking
*
* @param {integer} index The index of the current scroll_element (from scrollElements)
* @param {string} event_type Event type name
* @return {boolean} True if scroll event condition is fulfilled, false if not
*/
var checkScrollEvent = function (index, event_type) {
var condition, direction;
var element = scrollElements[index];
if (element.sourceElm == window) {
element.scrollContainer.scrollTop = Helpers.getWindowScrollTop();
}
if (null !== element.lastY && element.lastY < element.scrollContainer.scrollTop) {
direction = 1;
} else if (element.lastY > element.scrollContainer.scrollTop) {
direction = -1;
} else {
direction = null;
}
var scroll_status = indicators.scrollStatus;
var scroll_stopped = (scroll_status > 1 && null === direction);
if (scroll_stopped && (element.lastDirection === null || (element.event == 'scroll-reached-bottom' || element.event == 'scroll-reached-top'))) {
if (event_type == "scrollstart") {
element.scrollContainer.trigger('scrollend');
}
return false;
}
// Browser's top position bouncing is not a scroll event
if (element.scrollContainer.scrollTop < 0 || element.scrollContainer.scrollTop + Helpers.getHeight(element.scrollContainer) > Helpers.getDocumentDimension('height')) {
return false;
}
switch (element.event) {
case 'scroll-start':
condition = (scroll_status == 1 && element.scrollContainer.scrollTop > 0);
break;
case 'scroll-stop':
condition = (scroll_status > 1 && null === direction);
break;
case 'scroll':
condition = (scroll_status > 1 && null !== direction);
break;
case 'scroll-up':
condition = (scroll_status > 1 && direction == -1);
break;
case 'scroll-down':
condition = (scroll_status > 1 && direction == 1);
break;
case 'scroll-dir-change':
condition = (scroll_status > 1 && ((element.lastDirection == -1 && direction == 1) || (element.lastDirection == 1 && direction == -1)));
break;
case 'scroll-dir-change-up':
condition = (scroll_status > 1 && element.lastDirection == 1 && direction == -1);
break;
case 'scroll-dir-change-down':
condition = (scroll_status > 1 && element.lastDirection == -1 && direction == 1);
break;
case 'scroll-reached-top':
condition = (scroll_status > 1 && element.lastDirection != 1 && element.scrollContainer.scrollTop == 0);
break;
case 'scroll-reached-bottom':
condition = (scroll_status > 1 && element.lastDirection != -1 && element.scrollContainer.scrollTop + Helpers.getHeight(element.scrollContainer) == Helpers.getHeight(element.scrollContent));
break;
}
scrollElements[index].lastDirection = direction;
scrollElements[index].lastY = element.scrollContainer.scrollTop;
if (scroll_status == 1 && null !== direction) {
indicators.scrollStatus = 2;
}
return (element.extra_condition() && condition);
}
/**
* Add an action to the queue
*
* @param {object|int} element The element object/index of the current scroll_element (from scrollElements)
* @param {object} _this The DOM element of the current source element
*/
var addToActionQueue = function (element, _this) {
actionQueue[element.name] = {
_this: _this,
element: element
};
actionOrder.push(element.name);
// The "call after all events" hack
window.setTimeout(function () {
if (!indicators.actionCheckInProgress && actionOrder.length > 0) {
indicators.actionCheckInProgress = true;
sortActions();
}
}, 0);
}
/**
* Reset action queue and order
*/
var resetActionQueue = function () {
actionQueue = {};
actionOrder = [];
indicators.actionCheckInProgress = false;
}
/**
* Sort triggering actions
*
*/
var sortActions = function () {
var element_name, element;
for (var idx in actionOrder) {
element_name = actionOrder[idx];
element = actionQueue[element_name].element;
if (element.trigger_before && actionOrder.indexOf(element.trigger_before) > -1 && actionOrder.indexOf(element_name) > actionOrder.indexOf(element.trigger_before)) {
delete actionOrder[idx];
actionOrder.splice(actionOrder.indexOf(element.trigger_before), 0, element_name);
}
else if (element.trigger_after && actionOrder.indexOf(element.trigger_after) > -1 && actionOrder.indexOf(element_name) < actionOrder.indexOf(element.trigger_after)) {
delete actionOrder[idx];
actionOrder.splice(actionOrder.indexOf(element.trigger_after) + 1, 0, element_name);
}
}
triggerActions();
}
/**
* Trigger all actions from the queue
*
*/
var triggerActions = function () {
var action, callback;
var callbackQueue = [];
for (var idx in actionOrder) {
action = actionQueue[actionOrder[idx]];
callback = triggerAction(action.element, action._this);
if (false !== callback) {
callbackQueue.push(callback);
}
}
resetActionQueue();
if (callbackQueue.length) {
Helpers.forEach(callbackQueue, function(cb, idx) {
cb();
});
}
}
/**
* Trigger an action
*
* @param {object|int} element The element object/index of the current scroll_element (from scrollElements)
* @param {object} _this The DOM element of the current source element
*
* @returns {function|boolean} Callback function or false if no callback present
*/
var triggerAction = function (element, _this) {
Helpers.log(element.name + ' action is running.', element);
if (typeof element != 'object') {
element = scrollElements[element];
}
var $this,
attr,
values,
value,
current_values,
current_idx,
action_value,
affected_elements;
// get value from source's attribute if present
if (element.value_type == 'attribute') {
value_data = _this.getAttribute(element.value);
} else {
value_data = element.value;
}
if (element.type != 'trigger-event') {
values = value_data.split(",");
var boolean_attributes = ['checked', 'selected', 'disabled'];
if (element.destination_selector === null && element.destElm.length > 1) {
affected_elements = _this;
} else {
affected_elements = element.destElm;
}
for (var idx in values) {
value = values[idx].trim();
Helpers.forEach(affected_elements, function (elm, index) {
attr = elm.getAttribute(element.attribute);
if (null !== attr) {
current_values = attr.split(" ");
current_idx = current_values.indexOf(value);
} else {
current_values = null;
current_idx = -1;
}
if (element.type != 'set') {
if (element.type != 'remove' && current_idx < 0) {
action_value = ((attr !== null && attr.length > 0) ? attr + ' ' : '') + value;
} else if (element.type != 'add' && current_idx > -1) {
if (boolean_attributes.indexOf(element.attribute) > -1) {
elm[element.attribute] = false;
return;
}
current_values.splice(current_idx, 1);
action_value = current_values.join(" ");
} else {
return false;
}
} else {
action_value = value;
}
elm.setAttribute(element.attribute, action_value);
});
}
return false;
} else {
return function() {
$((element.destination_selector === null) ? element.source_selector : element.destination_selector).trigger(value_data)
};
}
}
/**
* Element data object creator
*
* @param {DOM object} $el DOM element of an aktion element
* @returns {object}
*/
var setElementData = function ($el) {
var data_attribute_value, value;
if (Helpers.getAttr($el, 'name')) {
var element_name = Helpers.getAttr($el, 'name');
}
else {
var element_name = 'action' + indicators.elementNameCounter;
indicators.elementNameCounter++;
}
var element = {name: element_name};
// set element object properties
for (var attribute in elementDefaults) {
data_attribute_value = Helpers.getAttr($el, attribute.replace('_', '-'));
if (data_attribute_value) {
switch (typeof elementDefaults[attribute]) {
case 'number':
value = parseInt(data_attribute_value);
break;
case 'function':
value = window[data_attribute_value];
break;
default:
value = data_attribute_value;
break;
}
}
else {
value = elementDefaults[attribute];
}
element[attribute] = value;
}
// Handle special selectors (window/document)
switch (element.source_selector) {
case 'window':
element.sourceElm = window;
break;
case 'document':
element.sourceElm = document;
break;
case null:
element.sourceElm = $el;
break;
default:
element.sourceElm = $(element.source_selector);
}
// iOS click trigger hack
if (indicators.isIOS && element.source_selector != 'window' && element.source_selector != 'document' && element.event == 'click') {
element.sourceElm.style.cursor = 'pointer';
}
element.destElm = (element.destination_selector !== null) ? $(element.destination_selector) : element.sourceElm;
return element;
}
/**
* Handle action triggering according to action type
*
* @param {object} element Aktion element data object
*/
var handleActionTriggering = function (element) {
// Scroll event
if (element.event.indexOf('scroll') > -1) {
handleScrollActions(element);
} else if (element.event.indexOf('swipe') > -1) {
handleSwipeActions(element);
} else {
handleCommonActions(element);
}
}
/**
* Handle scroll action triggering
*
* @param {object} element Aktion element data object
*/
var handleScrollActions = function(element) {
// Scroll event
element.lastY = null;
element.direction = null;
var sourceElements = (element.source_selector == 'window' || element.source_selector == 'document') ? [window] : element.sourceElm;
Helpers.forEach(sourceElements, function(elm, idx) {
if (undefined !== elm.parentNode) {
element.scrollContainer = elm.parentNode;
} else {
element.scrollContainer = elm;
}
element.scrollContent = (element.source_selector == 'window' || element.source_selector == 'document') ? document : elm;
element.scrollContainer.on('touchstart mousedown scrollstart', function (evt) {
if (null === scrollInterval) {
indicators.scrollStatus = 1;
scrollInterval = setInterval(function () {
for (var index in scrollElements) {
if (checkScrollEvent(index, evt.type)) {
addToActionQueue(scrollElements[index], scrollElements[index].sourceElm);
}
}
}, element.interval_time);
}
});
element.scrollContainer.on('touchend touchcancel mouseup scrollend', function (evt) {
if (null !== scrollInterval) {
clearInterval(scrollInterval);
scrollInterval = null;
element.lastY = null;
indicators.scrollStatus = 0;
}
});
element.scrollContainer.on('scroll', function(evt) {
if (null === scrollInterval) {
element.scrollContainer.trigger('scrollstart');
}
});
scrollElements.push(element);
});
}
/**
* Handle swipe action triggering
*
* @param {object} element Aktion element data object
*/
var handleSwipeActions = function(element) {
handleSwipeEvent(element);
if (null !== element.source_selector &&
(delegator = Helpers.getDelegatorDOMElement(element.source_selector))) {
delegator.delegate(element.source_selector, element.event, function (event) {
addToActionQueue(element, event.target);
});
} else {
element.sourceElm.on(element.event, function (event) {
addToActionQueue(element, event.target);
});
}
}
/**
* Handle common action triggering
*
* @param {object} element Aktion element data object
*/
var handleCommonActions = function(element) {
// Native events
if (null !== element.source_selector &&
(delegator = Helpers.getDelegatorDOMElement(element.source_selector))) {
delegator.delegate(element.source_selector, element.event, function (event) {
if (element.extra_condition()) {
addToActionQueue(element, event.target);
}
});
} else {
element.sourceElm.on(element.event, function (event) {
if (element.extra_condition()) {
addToActionQueue(element, event.target);
}
});
}
}
/** Public methods and properties **/
var api = {
/**
* Activate Aktion
*
* @returns {function} _activate private method
*/
activate: function() {
return _activate();
}
};
init();
return api;
}
return AktionBase;
})();