@@ -3,33 +3,48 @@ var $ = require('jquery'),
3
3
4
4
function loader ( option ) {
5
5
require ( './loader.css' ) ;
6
- var _this = this ,
7
- o = {
8
- number : 4 , //bars numbers
9
- speed : 100 ,
10
- style : {
11
- width : '8px' ,
12
- height : '4px' ,
13
- backgroundColor : '#CCC' ,
14
- activeBackgroundColor : '#EA578C'
15
- }
16
- } ;
17
- $ . extend ( o , option ) ;
18
- var barsHtml = new Array ( o . number ) . join ( '<i></i>' ) ;
6
+ var _this = this ;
7
+ var defaults = {
8
+ number : 4 , //bars numbers
9
+ speed : 100 ,
10
+ style : {
11
+ width : '8px' ,
12
+ height : '4px' ,
13
+ backgroundColor : '#CCC' ,
14
+ activeBackgroundColor : '#EA578C'
15
+ }
16
+ } ;
17
+ _this . o = { } ;
18
+ $ . extend ( _this . o , defaults , option ) ;
19
+
20
+ // custom style
21
+ var style = [ ] ;
22
+ for ( var i in _this . o . style ) {
23
+ if ( this . o . style [ i ] !== defaults . style [ i ] ) {
24
+ style . push ( i + ':' + this . o . style [ i ] ) ;
25
+ }
26
+ }
27
+ style = style . join ( ';' ) . replace ( 'backgroundColor' , 'background-color' ) ;
28
+ var barsHtml = new Array ( _this . o . number ) . join ( '<i style="' + style + '"></i>' ) ;
29
+
19
30
this . overlay = new Overlay ( {
20
- template : '<span class="mk-loading"><i class="mk-loading-active"></i>' + barsHtml + '</span>' ,
21
- align : o . align ,
31
+ template : '<span class="mk-loading"><i class="mk-loading-active" style="' + style + '"></i>' + barsHtml + '</span>' ,
22
32
align : {
23
33
selfXY : [ '50%' , '50%' ] ,
24
34
baseElement : option . target ,
25
35
baseXY : [ '50%' , '50%' ]
26
36
}
27
37
} ) ;
38
+ this . play ( ) ;
39
+ return this ;
40
+ }
28
41
42
+ loader . prototype . play = function ( ) {
29
43
var $loading = this . overlay . element ,
30
44
$items = $loading . find ( 'i' ) ,
31
- length = $items . length ;
32
- var playInterval = setInterval ( function ( ) {
45
+ length = $items . length ,
46
+ _this = this ;
47
+ setInterval ( function ( ) {
33
48
var $active = $loading . find ( '.mk-loading-active' ) ,
34
49
thisone = $active . index ( ) + 1 ,
35
50
lastone = thisone - 1 ;
@@ -38,8 +53,9 @@ function loader(option) {
38
53
lastone = length - 1 ;
39
54
}
40
55
$items . eq ( lastone ) . removeClass ( 'mk-loading-active' ) . end ( ) . eq ( thisone ) . addClass ( 'mk-loading-active' ) ;
41
- } , o . speed ) ;
42
- }
56
+ } , _this . o . speed ) ;
57
+ return this ;
58
+ } ;
43
59
44
60
loader . prototype . show = function ( ) {
45
61
this . overlay . show ( ) ;
0 commit comments