Elffuss BraidHub

kikocis/iscroll public

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