Skip to content

Commit d31e342

Browse files
committed
Widget: Style updates
Closes jquerygh-1597
1 parent 2c064b4 commit d31e342

File tree

2 files changed

+73
-48
lines changed

2 files changed

+73
-48
lines changed

ui/.jshintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"expr": true,
77
"immed": true,
88
"noarg": true,
9-
"onevar": true,
109
"quotmark": "double",
1110
"smarttabs": true,
1211
"trailing": true,

ui/widget.js

Lines changed: 73 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
}
2626
}( function( $ ) {
2727

28-
var widgetUuid = 0,
29-
widgetSlice = Array.prototype.slice;
28+
var widgetUuid = 0;
29+
var widgetSlice = Array.prototype.slice;
3030

3131
$.cleanData = ( function( orig ) {
3232
return function( elems ) {
@@ -48,15 +48,15 @@ $.cleanData = ( function( orig ) {
4848
} )( $.cleanData );
4949

5050
$.widget = function( name, base, prototype ) {
51-
var fullName, existingConstructor, constructor, basePrototype,
51+
var existingConstructor, constructor, basePrototype;
5252

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 = {};
5756

57+
var namespace = name.split( "." )[ 0 ];
5858
name = name.split( "." )[ 1 ];
59-
fullName = namespace + "-" + name;
59+
var fullName = namespace + "-" + name;
6060

6161
if ( !prototype ) {
6262
prototype = base;
@@ -113,16 +113,18 @@ $.widget = function( name, base, prototype ) {
113113
return;
114114
}
115115
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+
122124
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;
126128

127129
this._super = _super;
128130
this._superApply = _superApply;
@@ -159,7 +161,8 @@ $.widget = function( name, base, prototype ) {
159161

160162
// Redefine the child widget using the same prototype that was
161163
// 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 );
163166
} );
164167

165168
// Remove the list of existing child constructors from the old constructor
@@ -175,11 +178,12 @@ $.widget = function( name, base, prototype ) {
175178
};
176179

177180
$.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+
183187
for ( ; inputIndex < inputLength; inputIndex++ ) {
184188
for ( key in input[ inputIndex ] ) {
185189
value = input[ inputIndex ][ key ];
@@ -206,26 +210,31 @@ $.widget.extend = function( target ) {
206210
$.widget.bridge = function( name, object ) {
207211
var fullName = object.prototype.widgetFullName || name;
208212
$.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;
212216

213217
if ( isMethodCall ) {
214218
this.each( function() {
215-
var methodValue,
216-
instance = $.data( this, fullName );
219+
var methodValue;
220+
var instance = $.data( this, fullName );
221+
217222
if ( options === "instance" ) {
218223
returnValue = instance;
219224
return false;
220225
}
226+
221227
if ( !instance ) {
222228
return $.error( "cannot call methods on " + name + " prior to initialization; " +
223229
"attempted to call method '" + options + "'" );
224230
}
231+
225232
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
226233
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
227234
}
235+
228236
methodValue = instance[ options ].apply( instance, args );
237+
229238
if ( methodValue !== instance && methodValue !== undefined ) {
230239
returnValue = methodValue && methodValue.jquery ?
231240
returnValue.pushStack( methodValue.get() ) :
@@ -264,13 +273,15 @@ $.Widget.prototype = {
264273
widgetName: "widget",
265274
widgetEventPrefix: "",
266275
defaultElement: "<div>",
276+
267277
options: {
268278
classes: {},
269279
disabled: false,
270280

271281
// Callbacks
272282
create: null
273283
},
284+
274285
_createWidget: function( options, element ) {
275286
element = $( element || this.defaultElement || this )[ 0 ];
276287
this.element = $( element );
@@ -310,9 +321,13 @@ $.Widget.prototype = {
310321
this._trigger( "create", null, this._getCreateEventData() );
311322
this._init();
312323
},
324+
313325
_getCreateOptions: $.noop,
326+
314327
_getCreateEventData: $.noop,
328+
315329
_create: $.noop,
330+
316331
_init: $.noop,
317332

318333
destroy: function() {
@@ -335,17 +350,18 @@ $.Widget.prototype = {
335350
// Clean up events and states
336351
this.bindings.off( this.eventNamespace );
337352
},
353+
338354
_destroy: $.noop,
339355

340356
widget: function() {
341357
return this.element;
342358
},
343359

344360
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;
349365

350366
if ( arguments.length === 0 ) {
351367

@@ -382,6 +398,7 @@ $.Widget.prototype = {
382398

383399
return this;
384400
},
401+
385402
_setOptions: function( options ) {
386403
var key;
387404

@@ -391,6 +408,7 @@ $.Widget.prototype = {
391408

392409
return this;
393410
},
411+
394412
_setOption: function( key, value ) {
395413
if ( key === "classes" ) {
396414
this._setOptionClasses( value );
@@ -410,6 +428,7 @@ $.Widget.prototype = {
410428

411429
return this;
412430
},
431+
413432
_setOptionClasses: function( value ) {
414433
var classKey, elements, currentElements;
415434

@@ -444,13 +463,14 @@ $.Widget.prototype = {
444463
enable: function() {
445464
return this._setOptions( { disabled: false } );
446465
},
466+
447467
disable: function() {
448468
return this._setOptions( { disabled: true } );
449469
},
450470

451471
_classes: function( options ) {
452-
var full = [],
453-
that = this;
472+
var full = [];
473+
var that = this;
454474

455475
options = $.extend( {
456476
element: this.element,
@@ -506,8 +526,8 @@ $.Widget.prototype = {
506526
},
507527

508528
_on: function( suppressDisabledCheck, element, handlers ) {
509-
var delegateElement,
510-
instance = this;
529+
var delegateElement;
530+
var instance = this;
511531

512532
// No suppressDisabledCheck flag, shuffle arguments
513533
if ( typeof suppressDisabledCheck !== "boolean" ) {
@@ -547,9 +567,10 @@ $.Widget.prototype = {
547567
handler.guid || handlerProxy.guid || $.guid++;
548568
}
549569

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+
553574
if ( selector ) {
554575
delegateElement.on( eventName, selector, handlerProxy );
555576
} else {
@@ -603,8 +624,8 @@ $.Widget.prototype = {
603624
},
604625

605626
_trigger: function( type, event, data ) {
606-
var prop, orig,
607-
callback = this.options[ type ];
627+
var prop, orig;
628+
var callback = this.options[ type ];
608629

609630
data = data || {};
610631
event = $.Event( event );
@@ -638,21 +659,26 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
638659
if ( typeof options === "string" ) {
639660
options = { effect: options };
640661
}
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+
647670
options = options || {};
648671
if ( typeof options === "number" ) {
649672
options = { duration: options };
650673
}
674+
651675
hasOptions = !$.isEmptyObject( options );
652676
options.complete = callback;
677+
653678
if ( options.delay ) {
654679
element.delay( options.delay );
655680
}
681+
656682
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
657683
element[ method ]( options );
658684
} else if ( effectName !== method && element[ effectName ] ) {

0 commit comments

Comments
 (0)