Widget: Style updates

Closes gh-1597
This commit is contained in:
Scott González 2015-09-16 12:21:43 -04:00
parent 2c064b4d50
commit d31e342e1d
2 changed files with 73 additions and 48 deletions

View File

@ -6,7 +6,6 @@
"expr": true, "expr": true,
"immed": true, "immed": true,
"noarg": true, "noarg": true,
"onevar": true,
"quotmark": "double", "quotmark": "double",
"smarttabs": true, "smarttabs": true,
"trailing": true, "trailing": true,

View File

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