YH.slide.js
2.82 KB
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
var me = require('./YH.base');
var slide = function (options) {
this.__lastTime = null;
this.__isStop = false;
options = me.extend(this.defaults, options);
slide.superclass.constructor.call(this, options);
}
me.inherit(slide, me.assembly);
slide.prototype.oninit = function () {
var __self = this, _o = __self.options;
if (_o.auto) {
__self.play();
}
__self.go(_o.index);
return this;
}
slide.prototype.go = function (_to, _from) {
var __self = this, _o = __self.options;
if (__self.__lastTime) {
clearTimeout(__self.__lastTime);
__self.__lastTime = null;
}
_from = "undefined" == typeof _from ? _o.index : _from;
var _direction = _to === _from ? 0 : _to > _from ? 1 : -1;
var _loop = _o.loop, _index = _o.length - 1, _originalto = _to;
if (_loop) {
if (_to > _index) {
_to = _to - _index - 1;
} else {
if (0 > _to) {
_to = _to + _index + 1;
} else {
_to = _to;
}
}
} else {
if (_to > _index) {
_to = _index;
} else {
if (0 > _to) {
_to = 0;
} else {
_to = _to;
}
}
}
var _current = _o.index = _to;
var o = {
from: _from,
to: _to,
originalto: _originalto,
direction: _direction
}
for (var key in __self.registerEvent) {
if (__self.registerEvent[key].length > 0) {
for (_e in __self.registerEvent[key]) {
__self.registerEvent[key][_e](o);
}
}
}
if (_current !== _index || _to) {
if (!__self.__isStop && _o.auto) {
__self.play();
}
} else {
if (__self.__lastTime) {
clearTimeout(__self.__lastTime);
}
}
}
slide.prototype.play = function () {
var __self = this, _o = __self.options;
__self.__lastTime = setTimeout(function () {
__self.next();
}, 1000 * _o.timeout);
return this;
}
slide.prototype.next = function () {
var __self = this, _o = __self.options;
var _from = _o.index;
var _to = _from + _o.step;
__self.go(_to, _from);
}
slide.prototype.prev = function () {
var __self = this, _o = __self.options;
var _from = _o.index;
var _to = _from - _o.step;
__self.go(_to, _from);
}
slide.prototype.pause = function () {
var __self = this, _o = __self.options;
if (__self.__lastTime) {
clearTimeout(__self.__lastTime);
}
__self.__isStop = true;
}
slide.prototype.resume = function () {
var __self = this, _o = __self.options;
__self.__isStop = false;
__self.play();
}
slide.prototype.defaults = {
index: 0,
timeout: 5,
step: 1,
per: 1,
auto: false,
loop: false
}
module.exports =slide;