File tree 1 file changed +28
-9
lines changed
1 file changed +28
-9
lines changed Original file line number Diff line number Diff line change 117
117
}
118
118
} ) ;
119
119
120
- $ . fn . timeago = function ( ) {
121
- var self = this ;
122
- self . each ( refresh ) ;
120
+ // functions that can be called via $(el).timeago('action')
121
+ // init is default when no action is given
122
+ // functions are called with context of a single element
123
+ var functions = {
124
+ init : function ( ) {
125
+ var refresh_el = $ . proxy ( refresh , this ) ;
126
+ refresh_el ( ) ;
127
+ var $s = $t . settings ;
128
+ if ( $s . refreshMillis > 0 ) {
129
+ setInterval ( refresh_el , $s . refreshMillis ) ;
130
+ }
131
+ } ,
132
+ update : function ( time ) {
133
+ $ ( this ) . data ( 'timeago' , { datetime : $t . parse ( time ) } ) ;
134
+ refresh . apply ( this ) ;
135
+ }
136
+ } ;
123
137
124
- var $s = $t . settings ;
125
- if ( $s . refreshMillis > 0 ) {
126
- setInterval ( function ( ) { self . each ( refresh ) ; } , $s . refreshMillis ) ;
127
- }
128
- return self ;
129
- } ;
138
+ $ . fn . timeago = function ( action , options ) {
139
+ var fn = action ? functions [ action ] : functions . init ;
140
+ if ( ! fn ) {
141
+ throw new Error ( "Unknown function name '" + action + "' for timeago" ) ;
142
+ }
143
+ // each over objects here and call the requested function
144
+ this . each ( function ( ) {
145
+ fn . call ( this , options ) ;
146
+ } ) ;
147
+ return this ;
148
+ } ;
130
149
131
150
function refresh ( ) {
132
151
var data = prepareData ( this ) ;
You can’t perform that action at this time.
0 commit comments