aboutsummaryrefslogtreecommitdiffstats
path: root/ui/widget.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2015-09-16 12:21:43 -0400
committerScott González <scott.gonzalez@gmail.com>2015-09-16 12:45:54 -0400
commitd31e342e1d1268947eb624d2e79c83e58706c31c (patch)
tree2a837946fef383682dd44efb2f45a9ea98e89cc8 /ui/widget.js
parent2c064b4d508661ece869b569eccf81238bc51201 (diff)
downloadjquery-ui-d31e342e1d1268947eb624d2e79c83e58706c31c.tar.gz
jquery-ui-d31e342e1d1268947eb624d2e79c83e58706c31c.zip
Widget: Style updates
Closes gh-1597
Diffstat (limited to 'ui/widget.js')
-rw-r--r--ui/widget.js120
1 files changed, 73 insertions, 47 deletions
diff --git a/ui/widget.js b/ui/widget.js
index 183d455b6..eabeb3981 100644
--- a/ui/widget.js
+++ b/ui/widget.js
@@ -25,8 +25,8 @@
}
}( function( $ ) {
-var widgetUuid = 0,
- widgetSlice = Array.prototype.slice;
+var widgetUuid = 0;
+var widgetSlice = Array.prototype.slice;
$.cleanData = ( function( orig ) {
return function( elems ) {
@@ -48,15 +48,15 @@ $.cleanData = ( function( orig ) {
} )( $.cleanData );
$.widget = function( name, base, prototype ) {
- var fullName, existingConstructor, constructor, basePrototype,
+ var existingConstructor, constructor, basePrototype;
- // ProxiedPrototype allows the provided prototype to remain unmodified
- // so that it can be used as a mixin for multiple widgets (#8876)
- proxiedPrototype = {},
- namespace = name.split( "." )[ 0 ];
+ // ProxiedPrototype allows the provided prototype to remain unmodified
+ // so that it can be used as a mixin for multiple widgets (#8876)
+ var proxiedPrototype = {};
+ var namespace = name.split( "." )[ 0 ];
name = name.split( "." )[ 1 ];
- fullName = namespace + "-" + name;
+ var fullName = namespace + "-" + name;
if ( !prototype ) {
prototype = base;
@@ -113,16 +113,18 @@ $.widget = function( name, base, prototype ) {
return;
}
proxiedPrototype[ prop ] = ( function() {
- var _super = function() {
- return base.prototype[ prop ].apply( this, arguments );
- },
- _superApply = function( args ) {
- return base.prototype[ prop ].apply( this, args );
- };
+ function _super() {
+ return base.prototype[ prop ].apply( this, arguments );
+ }
+
+ function _superApply( args ) {
+ return base.prototype[ prop ].apply( this, args );
+ }
+
return function() {
- var __super = this._super,
- __superApply = this._superApply,
- returnValue;
+ var __super = this._super;
+ var __superApply = this._superApply;
+ var returnValue;
this._super = _super;
this._superApply = _superApply;
@@ -159,7 +161,8 @@ $.widget = function( name, base, prototype ) {
// Redefine the child widget using the same prototype that was
// originally used, but inherit from the new version of the base
- $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, child._proto );
+ $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor,
+ child._proto );
} );
// Remove the list of existing child constructors from the old constructor
@@ -175,11 +178,12 @@ $.widget = function( name, base, prototype ) {
};
$.widget.extend = function( target ) {
- var input = widgetSlice.call( arguments, 1 ),
- inputIndex = 0,
- inputLength = input.length,
- key,
- value;
+ var input = widgetSlice.call( arguments, 1 );
+ var inputIndex = 0;
+ var inputLength = input.length;
+ var key;
+ var value;
+
for ( ; inputIndex < inputLength; inputIndex++ ) {
for ( key in input[ inputIndex ] ) {
value = input[ inputIndex ][ key ];
@@ -206,26 +210,31 @@ $.widget.extend = function( target ) {
$.widget.bridge = function( name, object ) {
var fullName = object.prototype.widgetFullName || name;
$.fn[ name ] = function( options ) {
- var isMethodCall = typeof options === "string",
- args = widgetSlice.call( arguments, 1 ),
- returnValue = this;
+ var isMethodCall = typeof options === "string";
+ var args = widgetSlice.call( arguments, 1 );
+ var returnValue = this;
if ( isMethodCall ) {
this.each( function() {
- var methodValue,
- instance = $.data( this, fullName );
+ var methodValue;
+ var instance = $.data( this, fullName );
+
if ( options === "instance" ) {
returnValue = instance;
return false;
}
+
if ( !instance ) {
return $.error( "cannot call methods on " + name + " prior to initialization; " +
"attempted to call method '" + options + "'" );
}
+
if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
+
methodValue = instance[ options ].apply( instance, args );
+
if ( methodValue !== instance && methodValue !== undefined ) {
returnValue = methodValue && methodValue.jquery ?
returnValue.pushStack( methodValue.get() ) :
@@ -264,6 +273,7 @@ $.Widget.prototype = {
widgetName: "widget",
widgetEventPrefix: "",
defaultElement: "<div>",
+
options: {
classes: {},
disabled: false,
@@ -271,6 +281,7 @@ $.Widget.prototype = {
// Callbacks
create: null
},
+
_createWidget: function( options, element ) {
element = $( element || this.defaultElement || this )[ 0 ];
this.element = $( element );
@@ -310,9 +321,13 @@ $.Widget.prototype = {
this._trigger( "create", null, this._getCreateEventData() );
this._init();
},
+
_getCreateOptions: $.noop,
+
_getCreateEventData: $.noop,
+
_create: $.noop,
+
_init: $.noop,
destroy: function() {
@@ -335,6 +350,7 @@ $.Widget.prototype = {
// Clean up events and states
this.bindings.off( this.eventNamespace );
},
+
_destroy: $.noop,
widget: function() {
@@ -342,10 +358,10 @@ $.Widget.prototype = {
},
option: function( key, value ) {
- var options = key,
- parts,
- curOption,
- i;
+ var options = key;
+ var parts;
+ var curOption;
+ var i;
if ( arguments.length === 0 ) {
@@ -382,6 +398,7 @@ $.Widget.prototype = {
return this;
},
+
_setOptions: function( options ) {
var key;
@@ -391,6 +408,7 @@ $.Widget.prototype = {
return this;
},
+
_setOption: function( key, value ) {
if ( key === "classes" ) {
this._setOptionClasses( value );
@@ -410,6 +428,7 @@ $.Widget.prototype = {
return this;
},
+
_setOptionClasses: function( value ) {
var classKey, elements, currentElements;
@@ -444,13 +463,14 @@ $.Widget.prototype = {
enable: function() {
return this._setOptions( { disabled: false } );
},
+
disable: function() {
return this._setOptions( { disabled: true } );
},
_classes: function( options ) {
- var full = [],
- that = this;
+ var full = [];
+ var that = this;
options = $.extend( {
element: this.element,
@@ -506,8 +526,8 @@ $.Widget.prototype = {
},
_on: function( suppressDisabledCheck, element, handlers ) {
- var delegateElement,
- instance = this;
+ var delegateElement;
+ var instance = this;
// No suppressDisabledCheck flag, shuffle arguments
if ( typeof suppressDisabledCheck !== "boolean" ) {
@@ -547,9 +567,10 @@ $.Widget.prototype = {
handler.guid || handlerProxy.guid || $.guid++;
}
- var match = event.match( /^([\w:-]*)\s*(.*)$/ ),
- eventName = match[ 1 ] + instance.eventNamespace,
- selector = match[ 2 ];
+ var match = event.match( /^([\w:-]*)\s*(.*)$/ );
+ var eventName = match[ 1 ] + instance.eventNamespace;
+ var selector = match[ 2 ];
+
if ( selector ) {
delegateElement.on( eventName, selector, handlerProxy );
} else {
@@ -603,8 +624,8 @@ $.Widget.prototype = {
},
_trigger: function( type, event, data ) {
- var prop, orig,
- callback = this.options[ type ];
+ var prop, orig;
+ var callback = this.options[ type ];
data = data || {};
event = $.Event( event );
@@ -638,21 +659,26 @@ $.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) {
if ( typeof options === "string" ) {
options = { effect: options };
}
- var hasOptions,
- effectName = !options ?
- method :
- options === true || typeof options === "number" ?
- defaultEffect :
- options.effect || defaultEffect;
+
+ var hasOptions;
+ var effectName = !options ?
+ method :
+ options === true || typeof options === "number" ?
+ defaultEffect :
+ options.effect || defaultEffect;
+
options = options || {};
if ( typeof options === "number" ) {
options = { duration: options };
}
+
hasOptions = !$.isEmptyObject( options );
options.complete = callback;
+
if ( options.delay ) {
element.delay( options.delay );
}
+
if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) {
element[ method ]( options );
} else if ( effectName !== method && element[ effectName ] ) {