Elffuss BraidHub

kikocis/iscroll public

master · 2.4 KiBRawPermalink
1
2 _initIndicators: function () {
3 var interactive = this.options.interactiveScrollbars,
4 customStyle = typeof this.options.scrollbars != 'string',
5 indicators = [],
6 indicator;
7
8 var that = this;
9
10 this.indicators = [];
11
12 if ( this.options.scrollbars ) {
13 // Vertical scrollbar
14 if ( this.options.scrollY ) {
15 indicator = {
16 el: createDefaultScrollbar('v', interactive, this.options.scrollbars),
17 interactive: interactive,
18 defaultScrollbars: true,
19 customStyle: customStyle,
20 resize: this.options.resizeScrollbars,
21 shrink: this.options.shrinkScrollbars,
22 fade: this.options.fadeScrollbars,
23 listenX: false
24 };
25
26 this.wrapper.appendChild(indicator.el);
27 indicators.push(indicator);
28 }
29
30 // Horizontal scrollbar
31 if ( this.options.scrollX ) {
32 indicator = {
33 el: createDefaultScrollbar('h', interactive, this.options.scrollbars),
34 interactive: interactive,
35 defaultScrollbars: true,
36 customStyle: customStyle,
37 resize: this.options.resizeScrollbars,
38 shrink: this.options.shrinkScrollbars,
39 fade: this.options.fadeScrollbars,
40 listenY: false
41 };
42
43 this.wrapper.appendChild(indicator.el);
44 indicators.push(indicator);
45 }
46 }
47
48 if ( this.options.indicators ) {
49 // TODO: check concat compatibility
50 indicators = indicators.concat(this.options.indicators);
51 }
52
53 for ( var i = indicators.length; i--; ) {
54 this.indicators.push( new Indicator(this, indicators[i]) );
55 }
56
57 // TODO: check if we can use array.map (wide compatibility and performance issues)
58 function _indicatorsMap (fn) {
59 for ( var i = that.indicators.length; i--; ) {
60 fn.call(that.indicators[i]);
61 }
62 }
63
64 if ( this.options.fadeScrollbars ) {
65 this.on('scrollEnd', function () {
66 _indicatorsMap(function () {
67 this.fade();
68 });
69 });
70
71 this.on('scrollCancel', function () {
72 _indicatorsMap(function () {
73 this.fade();
74 });
75 });
76
77 this.on('scrollStart', function () {
78 _indicatorsMap(function () {
79 this.fade(1);
80 });
81 });
82
83 this.on('beforeScrollStart', function () {
84 _indicatorsMap(function () {
85 this.fade(1, true);
86 });
87 });
88 }
89
90
91 this.on('refresh', function () {
92 _indicatorsMap(function () {
93 this.refresh();
94 });
95 });
96
97 this.on('destroy', function () {
98 _indicatorsMap(function () {
99 this.destroy();
100 });
101
102 delete this.indicators;
103 });
104 },