25
25
}
26
26
} ( function ( $ ) {
27
27
28
- var widgetUuid = 0 ,
29
- widgetSlice = Array . prototype . slice ;
28
+ var widgetUuid = 0 ;
29
+ var widgetSlice = Array . prototype . slice ;
30
30
31
31
$ . cleanData = ( function ( orig ) {
32
32
return function ( elems ) {
@@ -48,15 +48,15 @@ $.cleanData = ( function( orig ) {
48
48
} ) ( $ . cleanData ) ;
49
49
50
50
$ . widget = function ( name , base , prototype ) {
51
- var fullName , existingConstructor , constructor , basePrototype ,
51
+ var existingConstructor , constructor , basePrototype ;
52
52
53
- // ProxiedPrototype allows the provided prototype to remain unmodified
54
- // so that it can be used as a mixin for multiple widgets (#8876)
55
- proxiedPrototype = { } ,
56
- namespace = name . split ( "." ) [ 0 ] ;
53
+ // ProxiedPrototype allows the provided prototype to remain unmodified
54
+ // so that it can be used as a mixin for multiple widgets (#8876)
55
+ var proxiedPrototype = { } ;
57
56
57
+ var namespace = name . split ( "." ) [ 0 ] ;
58
58
name = name . split ( "." ) [ 1 ] ;
59
- fullName = namespace + "-" + name ;
59
+ var fullName = namespace + "-" + name ;
60
60
61
61
if ( ! prototype ) {
62
62
prototype = base ;
@@ -113,16 +113,18 @@ $.widget = function( name, base, prototype ) {
113
113
return ;
114
114
}
115
115
proxiedPrototype [ prop ] = ( function ( ) {
116
- var _super = function ( ) {
117
- return base . prototype [ prop ] . apply ( this , arguments ) ;
118
- } ,
119
- _superApply = function ( args ) {
120
- return base . prototype [ prop ] . apply ( this , args ) ;
121
- } ;
116
+ function _super ( ) {
117
+ return base . prototype [ prop ] . apply ( this , arguments ) ;
118
+ }
119
+
120
+ function _superApply ( args ) {
121
+ return base . prototype [ prop ] . apply ( this , args ) ;
122
+ }
123
+
122
124
return function ( ) {
123
- var __super = this . _super ,
124
- __superApply = this . _superApply ,
125
- returnValue ;
125
+ var __super = this . _super ;
126
+ var __superApply = this . _superApply ;
127
+ var returnValue ;
126
128
127
129
this . _super = _super ;
128
130
this . _superApply = _superApply ;
@@ -159,7 +161,8 @@ $.widget = function( name, base, prototype ) {
159
161
160
162
// Redefine the child widget using the same prototype that was
161
163
// originally used, but inherit from the new version of the base
162
- $ . widget ( childPrototype . namespace + "." + childPrototype . widgetName , constructor , child . _proto ) ;
164
+ $ . widget ( childPrototype . namespace + "." + childPrototype . widgetName , constructor ,
165
+ child . _proto ) ;
163
166
} ) ;
164
167
165
168
// Remove the list of existing child constructors from the old constructor
@@ -175,11 +178,12 @@ $.widget = function( name, base, prototype ) {
175
178
} ;
176
179
177
180
$ . widget . extend = function ( target ) {
178
- var input = widgetSlice . call ( arguments , 1 ) ,
179
- inputIndex = 0 ,
180
- inputLength = input . length ,
181
- key ,
182
- value ;
181
+ var input = widgetSlice . call ( arguments , 1 ) ;
182
+ var inputIndex = 0 ;
183
+ var inputLength = input . length ;
184
+ var key ;
185
+ var value ;
186
+
183
187
for ( ; inputIndex < inputLength ; inputIndex ++ ) {
184
188
for ( key in input [ inputIndex ] ) {
185
189
value = input [ inputIndex ] [ key ] ;
@@ -206,26 +210,31 @@ $.widget.extend = function( target ) {
206
210
$ . widget . bridge = function ( name , object ) {
207
211
var fullName = object . prototype . widgetFullName || name ;
208
212
$ . fn [ name ] = function ( options ) {
209
- var isMethodCall = typeof options === "string" ,
210
- args = widgetSlice . call ( arguments , 1 ) ,
211
- returnValue = this ;
213
+ var isMethodCall = typeof options === "string" ;
214
+ var args = widgetSlice . call ( arguments , 1 ) ;
215
+ var returnValue = this ;
212
216
213
217
if ( isMethodCall ) {
214
218
this . each ( function ( ) {
215
- var methodValue ,
216
- instance = $ . data ( this , fullName ) ;
219
+ var methodValue ;
220
+ var instance = $ . data ( this , fullName ) ;
221
+
217
222
if ( options === "instance" ) {
218
223
returnValue = instance ;
219
224
return false ;
220
225
}
226
+
221
227
if ( ! instance ) {
222
228
return $ . error ( "cannot call methods on " + name + " prior to initialization; " +
223
229
"attempted to call method '" + options + "'" ) ;
224
230
}
231
+
225
232
if ( ! $ . isFunction ( instance [ options ] ) || options . charAt ( 0 ) === "_" ) {
226
233
return $ . error ( "no such method '" + options + "' for " + name + " widget instance" ) ;
227
234
}
235
+
228
236
methodValue = instance [ options ] . apply ( instance , args ) ;
237
+
229
238
if ( methodValue !== instance && methodValue !== undefined ) {
230
239
returnValue = methodValue && methodValue . jquery ?
231
240
returnValue . pushStack ( methodValue . get ( ) ) :
@@ -264,13 +273,15 @@ $.Widget.prototype = {
264
273
widgetName : "widget" ,
265
274
widgetEventPrefix : "" ,
266
275
defaultElement : "<div>" ,
276
+
267
277
options : {
268
278
classes : { } ,
269
279
disabled : false ,
270
280
271
281
// Callbacks
272
282
create : null
273
283
} ,
284
+
274
285
_createWidget : function ( options , element ) {
275
286
element = $ ( element || this . defaultElement || this ) [ 0 ] ;
276
287
this . element = $ ( element ) ;
@@ -310,9 +321,13 @@ $.Widget.prototype = {
310
321
this . _trigger ( "create" , null , this . _getCreateEventData ( ) ) ;
311
322
this . _init ( ) ;
312
323
} ,
324
+
313
325
_getCreateOptions : $ . noop ,
326
+
314
327
_getCreateEventData : $ . noop ,
328
+
315
329
_create : $ . noop ,
330
+
316
331
_init : $ . noop ,
317
332
318
333
destroy : function ( ) {
@@ -335,17 +350,18 @@ $.Widget.prototype = {
335
350
// Clean up events and states
336
351
this . bindings . off ( this . eventNamespace ) ;
337
352
} ,
353
+
338
354
_destroy : $ . noop ,
339
355
340
356
widget : function ( ) {
341
357
return this . element ;
342
358
} ,
343
359
344
360
option : function ( key , value ) {
345
- var options = key ,
346
- parts ,
347
- curOption ,
348
- i ;
361
+ var options = key ;
362
+ var parts ;
363
+ var curOption ;
364
+ var i ;
349
365
350
366
if ( arguments . length === 0 ) {
351
367
@@ -382,6 +398,7 @@ $.Widget.prototype = {
382
398
383
399
return this ;
384
400
} ,
401
+
385
402
_setOptions : function ( options ) {
386
403
var key ;
387
404
@@ -391,6 +408,7 @@ $.Widget.prototype = {
391
408
392
409
return this ;
393
410
} ,
411
+
394
412
_setOption : function ( key , value ) {
395
413
if ( key === "classes" ) {
396
414
this . _setOptionClasses ( value ) ;
@@ -410,6 +428,7 @@ $.Widget.prototype = {
410
428
411
429
return this ;
412
430
} ,
431
+
413
432
_setOptionClasses : function ( value ) {
414
433
var classKey , elements , currentElements ;
415
434
@@ -444,13 +463,14 @@ $.Widget.prototype = {
444
463
enable : function ( ) {
445
464
return this . _setOptions ( { disabled : false } ) ;
446
465
} ,
466
+
447
467
disable : function ( ) {
448
468
return this . _setOptions ( { disabled : true } ) ;
449
469
} ,
450
470
451
471
_classes : function ( options ) {
452
- var full = [ ] ,
453
- that = this ;
472
+ var full = [ ] ;
473
+ var that = this ;
454
474
455
475
options = $ . extend ( {
456
476
element : this . element ,
@@ -506,8 +526,8 @@ $.Widget.prototype = {
506
526
} ,
507
527
508
528
_on : function ( suppressDisabledCheck , element , handlers ) {
509
- var delegateElement ,
510
- instance = this ;
529
+ var delegateElement ;
530
+ var instance = this ;
511
531
512
532
// No suppressDisabledCheck flag, shuffle arguments
513
533
if ( typeof suppressDisabledCheck !== "boolean" ) {
@@ -547,9 +567,10 @@ $.Widget.prototype = {
547
567
handler . guid || handlerProxy . guid || $ . guid ++ ;
548
568
}
549
569
550
- var match = event . match ( / ^ ( [ \w : - ] * ) \s * ( .* ) $ / ) ,
551
- eventName = match [ 1 ] + instance . eventNamespace ,
552
- selector = match [ 2 ] ;
570
+ var match = event . match ( / ^ ( [ \w : - ] * ) \s * ( .* ) $ / ) ;
571
+ var eventName = match [ 1 ] + instance . eventNamespace ;
572
+ var selector = match [ 2 ] ;
573
+
553
574
if ( selector ) {
554
575
delegateElement . on ( eventName , selector , handlerProxy ) ;
555
576
} else {
@@ -603,8 +624,8 @@ $.Widget.prototype = {
603
624
} ,
604
625
605
626
_trigger : function ( type , event , data ) {
606
- var prop , orig ,
607
- callback = this . options [ type ] ;
627
+ var prop , orig ;
628
+ var callback = this . options [ type ] ;
608
629
609
630
data = data || { } ;
610
631
event = $ . Event ( event ) ;
@@ -638,21 +659,26 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
638
659
if ( typeof options === "string" ) {
639
660
options = { effect : options } ;
640
661
}
641
- var hasOptions ,
642
- effectName = ! options ?
643
- method :
644
- options === true || typeof options === "number" ?
645
- defaultEffect :
646
- options . effect || defaultEffect ;
662
+
663
+ var hasOptions ;
664
+ var effectName = ! options ?
665
+ method :
666
+ options === true || typeof options === "number" ?
667
+ defaultEffect :
668
+ options . effect || defaultEffect ;
669
+
647
670
options = options || { } ;
648
671
if ( typeof options === "number" ) {
649
672
options = { duration : options } ;
650
673
}
674
+
651
675
hasOptions = ! $ . isEmptyObject ( options ) ;
652
676
options . complete = callback ;
677
+
653
678
if ( options . delay ) {
654
679
element . delay ( options . delay ) ;
655
680
}
681
+
656
682
if ( hasOptions && $ . effects && $ . effects . effect [ effectName ] ) {
657
683
element [ method ] ( options ) ;
658
684
} else if ( effectName !== method && element [ effectName ] ) {
0 commit comments