Skip to content

Commit b5f0fae

Browse files
committed
Widget: Style updates
Ref #14246 Ref gh-1588
1 parent 1f71646 commit b5f0fae

File tree

2 files changed

+54
-37
lines changed

2 files changed

+54
-37
lines changed

demos/widget/default.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
green: 0,
3131
blue: 0,
3232

33-
// callbacks
33+
// Callbacks
3434
change: null,
3535
random: null
3636
},
3737

38-
// the constructor
38+
// The constructor
3939
_create: function() {
4040
this.element
4141
// add a class for theming
@@ -50,27 +50,27 @@
5050
.appendTo( this.element )
5151
.button();
5252

53-
// bind click events on the changer button to the random method
53+
// Bind click events on the changer button to the random method
5454
this._on( this.changer, {
5555
// _on won't call random when widget is disabled
5656
click: "random"
5757
});
5858
this._refresh();
5959
},
6060

61-
// called when created, and later when changing options
61+
// Called when created, and later when changing options
6262
_refresh: function() {
6363
this.element.css( "background-color", "rgb(" +
6464
this.options.red +"," +
6565
this.options.green + "," +
6666
this.options.blue + ")"
6767
);
6868

69-
// trigger a callback/event
69+
// Trigger a callback/event
7070
this._trigger( "change" );
7171
},
7272

73-
// a public method to change the color to a random value
73+
// A public method to change the color to a random value
7474
// can be called directly via .colorize( "random" )
7575
random: function( event ) {
7676
var colors = {
@@ -79,13 +79,13 @@
7979
blue: Math.floor( Math.random() * 256 )
8080
};
8181

82-
// trigger an event, check if it's canceled
82+
// Trigger an event, check if it's canceled
8383
if ( this._trigger( "random", event, colors ) !== false ) {
8484
this.option( colors );
8585
}
8686
},
8787

88-
// events bound via _on are removed automatically
88+
// Events bound via _on are removed automatically
8989
// revert other modifications here
9090
_destroy: function() {
9191
// remove generated elements
@@ -115,16 +115,16 @@
115115
}
116116
});
117117

118-
// initialize with default options
118+
// Initialize with default options
119119
$( "#my-widget1" ).colorize();
120120

121-
// initialize with two customized options
121+
// Initialize with two customized options
122122
$( "#my-widget2" ).colorize({
123123
red: 60,
124124
blue: 60
125125
});
126126

127-
// initialize with custom green value
127+
// Initialize with custom green value
128128
// and a random callback to allow only colors with enough green
129129
$( "#my-widget3" ).colorize( {
130130
green: 128,
@@ -133,7 +133,7 @@
133133
}
134134
});
135135

136-
// click to toggle enabled/disabled
136+
// Click to toggle enabled/disabled
137137
$( "#disable" ).on( "click", function() {
138138
// use the custom selector created for each widget to find all instances
139139
// all instances are toggled together, so we can check the state from the first
@@ -144,7 +144,7 @@
144144
}
145145
});
146146

147-
// click to set options after initialization
147+
// Click to set options after initialization
148148
$( "#green" ).on( "click", function() {
149149
$( ":custom-colorize" ).colorize( "option", {
150150
red: 64,

ui/widget.js

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $.cleanData = ( function( orig ) {
4040
$( elem ).triggerHandler( "remove" );
4141
}
4242

43-
// http://bugs.jquery.com/ticket/8235
43+
// Http://bugs.jquery.com/ticket/8235
4444
} catch ( e ) {}
4545
}
4646
orig( elems );
@@ -49,7 +49,8 @@ $.cleanData = ( function( orig ) {
4949

5050
$.widget = function( name, base, prototype ) {
5151
var fullName, existingConstructor, constructor, basePrototype,
52-
// proxiedPrototype allows the provided prototype to remain unmodified
52+
53+
// ProxiedPrototype allows the provided prototype to remain unmodified
5354
// so that it can be used as a mixin for multiple widgets (#8876)
5455
proxiedPrototype = {},
5556
namespace = name.split( "." )[ 0 ];
@@ -66,38 +67,43 @@ $.widget = function( name, base, prototype ) {
6667
prototype = $.extend.apply( null, [ {} ].concat( prototype ) );
6768
}
6869

69-
// create selector for plugin
70+
// Create selector for plugin
7071
$.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) {
7172
return !!$.data( elem, fullName );
7273
};
7374

7475
$[ namespace ] = $[ namespace ] || {};
7576
existingConstructor = $[ namespace ][ name ];
7677
constructor = $[ namespace ][ name ] = function( options, element ) {
77-
// allow instantiation without "new" keyword
78+
79+
// Allow instantiation without "new" keyword
7880
if ( !this._createWidget ) {
7981
return new constructor( options, element );
8082
}
8183

82-
// allow instantiation without initializing for simple inheritance
84+
// Allow instantiation without initializing for simple inheritance
8385
// must use "new" keyword (the code above always passes args)
8486
if ( arguments.length ) {
8587
this._createWidget( options, element );
8688
}
8789
};
88-
// extend with the existing constructor to carry over any static properties
90+
91+
// Extend with the existing constructor to carry over any static properties
8992
$.extend( constructor, existingConstructor, {
9093
version: prototype.version,
91-
// copy the object used to create the prototype in case we need to
94+
95+
// Copy the object used to create the prototype in case we need to
9296
// redefine the widget later
9397
_proto: $.extend( {}, prototype ),
94-
// track widgets that inherit from this widget in case this widget is
98+
99+
// Track widgets that inherit from this widget in case this widget is
95100
// redefined after a widget inherits from it
96101
_childConstructors: []
97102
} );
98103

99104
basePrototype = new base();
100-
// we need to make the options hash a property directly on the new instance
105+
106+
// We need to make the options hash a property directly on the new instance
101107
// otherwise we'll modify the options hash on the prototype that we're
102108
// inheriting from
103109
basePrototype.options = $.widget.extend( {}, basePrototype.options );
@@ -131,6 +137,7 @@ $.widget = function( name, base, prototype ) {
131137
} )();
132138
} );
133139
constructor.prototype = $.widget.extend( basePrototype, {
140+
134141
// TODO: remove support for widgetEventPrefix
135142
// always use the name + a colon as the prefix, e.g., draggable:start
136143
// don't prefix for widgets that aren't DOM-based
@@ -150,11 +157,12 @@ $.widget = function( name, base, prototype ) {
150157
$.each( existingConstructor._childConstructors, function( i, child ) {
151158
var childPrototype = child.prototype;
152159

153-
// redefine the child widget using the same prototype that was
160+
// Redefine the child widget using the same prototype that was
154161
// originally used, but inherit from the new version of the base
155162
$.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
156163
} );
157-
// remove the list of existing child constructors from the old constructor
164+
165+
// Remove the list of existing child constructors from the old constructor
158166
// so the old child constructors can be garbage collected
159167
delete existingConstructor._childConstructors;
160168
} else {
@@ -176,12 +184,15 @@ $.widget.extend = function( target ) {
176184
for ( key in input[ inputIndex ] ) {
177185
value = input[ inputIndex ][ key ];
178186
if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) {
187+
179188
// Clone objects
180189
if ( $.isPlainObject( value ) ) {
181190
target[ key ] = $.isPlainObject( target[ key ] ) ?
182191
$.widget.extend( {}, target[ key ], value ) :
192+
183193
// Don't extend strings, arrays, etc. with objects
184194
$.widget.extend( {}, value );
195+
185196
// Copy everything else by reference
186197
} else {
187198
target[ key ] = value;
@@ -257,7 +268,7 @@ $.Widget.prototype = {
257268
classes: {},
258269
disabled: false,
259270

260-
// callbacks
271+
// Callbacks
261272
create: null
262273
},
263274
_createWidget: function( options, element ) {
@@ -281,9 +292,11 @@ $.Widget.prototype = {
281292
}
282293
} );
283294
this.document = $( element.style ?
284-
// element within the document
295+
296+
// Element within the document
285297
element.ownerDocument :
286-
// element is window or document
298+
299+
// Element is window or document
287300
element.document || element );
288301
this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow );
289302
}
@@ -310,7 +323,7 @@ $.Widget.prototype = {
310323
that._removeClass( value, key );
311324
} );
312325

313-
// we can probably remove the unbind calls in 2.0
326+
// We can probably remove the unbind calls in 2.0
314327
// all event bindings should go through this._on()
315328
this.element
316329
.off( this.eventNamespace )
@@ -319,7 +332,7 @@ $.Widget.prototype = {
319332
.off( this.eventNamespace )
320333
.removeAttr( "aria-disabled" );
321334

322-
// clean up events and states
335+
// Clean up events and states
323336
this.bindings.off( this.eventNamespace );
324337
},
325338
_destroy: $.noop,
@@ -335,12 +348,14 @@ $.Widget.prototype = {
335348
i;
336349

337350
if ( arguments.length === 0 ) {
338-
// don't return a reference to the internal hash
351+
352+
// Don't return a reference to the internal hash
339353
return $.widget.extend( {}, this.options );
340354
}
341355

342356
if ( typeof key === "string" ) {
343-
// handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
357+
358+
// Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } }
344359
options = {};
345360
parts = key.split( "." );
346361
key = parts.shift();
@@ -494,14 +509,14 @@ $.Widget.prototype = {
494509
var delegateElement,
495510
instance = this;
496511

497-
// no suppressDisabledCheck flag, shuffle arguments
512+
// No suppressDisabledCheck flag, shuffle arguments
498513
if ( typeof suppressDisabledCheck !== "boolean" ) {
499514
handlers = element;
500515
element = suppressDisabledCheck;
501516
suppressDisabledCheck = false;
502517
}
503518

504-
// no element argument, shuffle and use this.element
519+
// No element argument, shuffle and use this.element
505520
if ( !handlers ) {
506521
handlers = element;
507522
element = this.element;
@@ -513,7 +528,8 @@ $.Widget.prototype = {
513528

514529
$.each( handlers, function( event, handler ) {
515530
function handlerProxy() {
516-
// allow widgets to customize the disabled handling
531+
532+
// Allow widgets to customize the disabled handling
517533
// - disabled as an array instead of boolean
518534
// - disabled class as method for disabling individual parts
519535
if ( !suppressDisabledCheck &&
@@ -525,7 +541,7 @@ $.Widget.prototype = {
525541
.apply( instance, arguments );
526542
}
527543

528-
// copy the guid so direct unbinding works
544+
// Copy the guid so direct unbinding works
529545
if ( typeof handler !== "string" ) {
530546
handlerProxy.guid = handler.guid =
531547
handler.guid || handlerProxy.guid || $.guid++;
@@ -595,11 +611,12 @@ $.Widget.prototype = {
595611
event.type = ( type === this.widgetEventPrefix ?
596612
type :
597613
this.widgetEventPrefix + type ).toLowerCase();
598-
// the original event may come from any element
614+
615+
// The original event may come from any element
599616
// so we need to reset the target on the new event
600617
event.target = this.element[ 0 ];
601618

602-
// copy original event properties over to the new event
619+
// Copy original event properties over to the new event
603620
orig = event.originalEvent;
604621
if ( orig ) {
605622
for ( prop in orig ) {

0 commit comments

Comments
 (0)