-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflow.js
executable file
·77 lines (56 loc) · 1.56 KB
/
flow.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
(function( window ) {
window.Flow = window.Flow || (function() {
function Flow( slides, params ) {
var that = this;
that.params = {
startPosition: null
};
for ( var item in params ) {
that.params[ item ] = params[ item ];
}
if ( typeof slides === 'string' ) {
that.slides = window.document.querySelectorAll( slides );
} else {
that.slides = slides;
}
if ( typeof that.params.startPosition === 'number' ) {
that.show( that.params.startPosition );
}
};
var FlowProto = Flow.prototype;
FlowProto.show = function( position ) {
if ( typeof position === "number" && !isNaN( position ) ) {
return this.movement( this.currentPosition = position );
} else {
throw TypeError("Flow.show( position ) - position isn't a number");
}
};
FlowProto.movement = function( position ) {
var l = this.slides.length,
i = 0;
for ( ; i < l; i++ ) {
this.slides[ i ].style.display = 'none';
}
// @TODO: Need to set native display value instead of 'block'
this.slides[ position ].style.display = 'block';
};
// Controllers
FlowProto.next = function() {
return this.show( this.currentPosition + 1 === this.size() ? 0 : this.currentPosition + 1 );
};
FlowProto.prev = function() {
return this.show( this.currentPosition === 0 ? this.size() - 1 : this.currentPosition - 1 );
};
FlowProto.first = function() {
return this.show( 0 );
};
FlowProto.last = function() {
return this.show( this.size() - 1 );
};
// Secondary
FlowProto.size = function() {
return this.slides.length;
};
return Flow;
})();
})( this );