12
12
* jquery.ui.widget.js
13
13
*/
14
14
( function ( $ , undefined ) {
15
+
16
+ var itemClasses = "ui-ticker-content ui-widget-content ui-helper-reset ui-state-default ui-corner-all" ;
15
17
16
18
$ . widget ( "ui.ticker" , {
17
19
options : {
20
+ active : true ,
18
21
initialTimeout : 4000 ,
19
22
mouseOnTimeout : 8000 ,
20
23
mouseOffTimeout : 4000 ,
@@ -27,6 +30,8 @@ $.widget( "ui.ticker", {
27
30
var self = this ,
28
31
options = self . options ;
29
32
33
+ self . timeoutId = null ;
34
+
30
35
self . speed = options . mouseOffTimeout ;
31
36
32
37
self . element
@@ -36,50 +41,44 @@ $.widget( "ui.ticker", {
36
41
return ;
37
42
}
38
43
self . speed = options . mouseOnTimeout ;
39
- if ( self . timeoutId !== undefined ) {
40
- window . clearTimeout ( timeoutId ) ;
41
- self . timeoutId = window . setTimeout ( function ( ) { self . rotate ( ) ; } , self . speed ) ;
44
+ if ( options . active && self . timeoutId !== null ) {
45
+ window . clearTimeout ( self . timeoutId ) ;
46
+ self . timeoutId = window . setTimeout ( function ( ) { self . _scroll ( ) ; } , self . speed ) ;
42
47
}
43
48
} )
44
49
. bind ( "mouseleave.ticker" , function ( ) {
45
50
if ( options . disabled ) {
46
51
return ;
47
52
}
48
53
self . speed = options . mouseOffTimeout ;
49
- if ( self . timeoutId !== undefined ) {
50
- window . clearTimeout ( timeoutId ) ;
51
- self . timeoutId = window . setTimeout ( function ( ) { self . rotate ( ) ; } , self . speed ) ;
54
+ if ( options . active && self . timeoutId !== null ) {
55
+ window . clearTimeout ( self . timeoutId ) ;
56
+ self . timeoutId = window . setTimeout ( function ( ) { self . _scroll ( ) ; } , self . speed ) ;
52
57
}
53
58
} ) ;
54
59
55
- self . _addItemClasses ( self . element . children ( "li" ) ) ;
60
+ self . element . children ( "li" ) . addClass ( itemClasses ) ;
56
61
self . _addItemBindings ( self . element . children ( "li" ) ) ;
57
62
} ,
58
63
59
64
_init : function ( ) {
60
65
var self = this ,
61
66
options = self . options ;
62
67
63
- window . setTimeout ( function ( ) { self . rotate ( ) } , options . initialTimeout ) ;
68
+ if ( options . active ) {
69
+ self . timeoutId = window . setTimeout ( function ( ) { self . _scroll ( ) } , options . initialTimeout ) ;
70
+ }
64
71
} ,
65
72
66
73
destroy : function ( ) {
67
74
this . element . unbind ( ".ticker" ) ;
68
75
this . element . children ( "li" ) . unbind ( ".ticker" ) ;
69
76
this . element . removeClass ( "ui-ticker ui-widget ui-corner-all" ) ;
70
- this . _removeItemClasses ( this . element . children ( "li" ) ) ;
77
+ this . element . children ( "li" ) . removeClass ( itemClasses + " ui-state-hover ui-state-focus" ) ;
71
78
72
79
return $ . Widget . prototype . destroy . call ( this ) ;
73
80
} ,
74
81
75
- _addItemClasses : function ( item ) {
76
- item . addClass ( "ui-ticker-content ui-widget-content ui-helper-reset ui-state-default ui-corner-all" )
77
- } ,
78
-
79
- _removeItemClasses : function ( item ) {
80
- item . removeClass ( "ui-ticker-content ui-widget-content ui-helper-reset ui-state-default ui-state-hover ui-state-focus ui-corner-all" )
81
- } ,
82
-
83
82
_addItemBindings : function ( item ) {
84
83
var options = this . options ;
85
84
@@ -110,34 +109,59 @@ $.widget( "ui.ticker", {
110
109
} ) ;
111
110
} ,
112
111
113
- rotate : function ( ) {
112
+ _scroll : function ( ) {
114
113
var self = this ,
115
114
options = self . options ,
116
115
newItem ,
117
116
lastItem ;
118
117
119
- lastItem = lastItem = self . element . children ( ) . last ( ) . clone ( ) ;
120
- self . _removeItemClasses ( lastItem ) ;
121
-
122
- newItem = $ ( self . options . next ( lastItem . get ( ) ) ) ;
118
+ lastItem = self . element . children ( ) . last ( ) . clone ( ) ;
119
+ lastItem . removeClass ( itemClasses + " ui-state-hover ui-state-focus" ) ;
123
120
124
- if ( newItem !== null ) {
125
- self . _addItemClasses ( newItem ) ;
126
- self . _addItemBindings ( newItem ) ;
127
- newItem
128
- . hide ( )
129
- . prependTo ( self . element )
130
- . css ( 'visibility' , 'hidden' )
131
- . slideDown ( options . slidingTime , function ( ) {
132
- $ ( this ) . fadeTo ( 0 , 0 ) . css ( 'visibility' , 'visible' ) . fadeTo ( options . fadeInTime , 1 ) ;
133
- } ) ;
121
+ if ( self . options . next !== null ) {
122
+ newItem = $ ( self . options . next ( lastItem . get ( ) ) ) ;
123
+
124
+ if ( newItem . length > 0 ) {
125
+ newItem . addClass ( itemClasses ) ;
126
+ self . _addItemBindings ( newItem ) ;
127
+ newItem
128
+ . hide ( )
129
+ . prependTo ( self . element )
130
+ . css ( 'visibility' , 'hidden' )
131
+ . slideDown ( options . slidingTime , function ( ) {
132
+ $ ( this ) . fadeTo ( 0 , 0 ) . css ( 'visibility' , 'visible' ) . fadeTo ( options . fadeInTime , 1 ) ;
133
+ } ) ;
134
134
135
- self . element . children ( ) . last ( ) . slideUp ( options . slidingTime , function ( ) {
136
- $ ( this ) . remove ( ) ;
137
- } ) ;
135
+ self . element . children ( ) . last ( ) . slideUp ( options . slidingTime , function ( ) {
136
+ $ ( this ) . remove ( ) ;
137
+ } ) ;
138
+ }
138
139
}
139
140
140
- self . timeoutId = window . setTimeout ( function ( ) { self . rotate ( ) ; } , self . speed ) ;
141
+ if ( options . active ) {
142
+ self . timeoutId = window . setTimeout ( function ( ) { self . _scroll ( ) ; } , self . speed ) ;
143
+ }
144
+ } ,
145
+
146
+ stop : function ( ) {
147
+ var self = this ,
148
+ options = self . options ;
149
+
150
+ options . active = false ;
151
+ if ( self . timeoutId !== null ) {
152
+ window . clearTimeout ( self . timeoutId ) ;
153
+ self . timeoutId = null ;
154
+ }
155
+ } ,
156
+
157
+ start : function ( ) {
158
+ var self = this ,
159
+ options = self . options ;
160
+
161
+ options . active = true ;
162
+ if ( self . timeoutId === null ) {
163
+ self . timeoutId = window . setTimeout ( function ( ) { self . _scroll ( ) ; } , self . speed ) ;
164
+ }
141
165
}
142
166
} ) ;
143
167
0 commit comments