diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.accordion.js | 29 | ||||
-rw-r--r-- | ui/jquery.ui.dialog.js | 16 | ||||
-rwxr-xr-x | ui/jquery.ui.tabs.js | 33 | ||||
-rw-r--r-- | ui/jquery.ui.widget.js | 73 |
4 files changed, 76 insertions, 75 deletions
diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index 9d74557de..6c257c8c0 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -36,32 +36,11 @@ $.widget( "ui.accordion", { self.element.addClass( "ui-accordion ui-widget ui-helper-reset" ); self.headers = self.element.find( options.header ) - .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" ) - .bind( "mouseenter.accordion", function() { - if ( options.disabled ) { - return; - } - $( this ).addClass( "ui-state-hover" ); - }) - .bind( "mouseleave.accordion", function() { - if ( options.disabled ) { - return; - } - $( this ).removeClass( "ui-state-hover" ); - }) - .bind( "focus.accordion", function() { - if ( options.disabled ) { - return; - } - $( this ).addClass( "ui-state-focus" ); - }) - .bind( "blur.accordion", function() { - if ( options.disabled ) { - return; - } - $( this ).removeClass( "ui-state-focus" ); - }); + .addClass( "ui-accordion-header ui-helper-reset ui-state-default ui-corner-all" ); + self._hoverable( self.headers ); + self._focusable( self.headers ); + self.headers.next() .addClass( "ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom" ); self.headers.find( ":first-child" ).addClass( "ui-accordion-heading" ); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 5d18b9b21..0183dd801 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -125,20 +125,6 @@ $.widget("ui.dialog", { uiDialogTitlebarClose = $( "<a href='#'></a>" ) .addClass( "ui-dialog-titlebar-close ui-corner-all" ) .attr( "role", "button" ) - .hover( - function() { - uiDialogTitlebarClose.addClass( "ui-state-hover" ); - }, - function() { - uiDialogTitlebarClose.removeClass( "ui-state-hover" ); - } - ) - .focus(function() { - uiDialogTitlebarClose.addClass( "ui-state-focus" ); - }) - .blur(function() { - uiDialogTitlebarClose.removeClass( "ui-state-focus" ); - }) .click(function( event ) { event.preventDefault(); self.close( event ); @@ -157,6 +143,8 @@ $.widget("ui.dialog", { .prependTo( uiDialogTitlebar ); uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection(); + this._hoverable( uiDialogTitlebarClose ); + this._focusable( uiDialogTitlebarClose ); if ( options.draggable && $.fn.draggable ) { self._makeDraggable(); diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 8ab3bdf40..21ad6ddec 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -254,28 +254,8 @@ $.widget( "ui.tabs", { // remove all handlers before, tabify may run on existing tabs after add or option change this.lis.add( this.anchors ).unbind( ".tabs" ); - if ( o.event !== "mouseover" ) { - var addState = function( state, el ) { - if ( el.is( ":not(.ui-state-disabled)" ) ) { - el.addClass( "ui-state-" + state ); - } - }; - var removeState = function( state, el ) { - el.removeClass( "ui-state-" + state ); - }; - this.lis.bind( "mouseover.tabs" , function() { - addState( "hover", $( this ) ); - }); - this.lis.bind( "mouseout.tabs", function() { - removeState( "hover", $( this ) ); - }); - this.anchors.bind( "focus.tabs", function() { - addState( "focus", $( this ).closest( "li" ) ); - }); - this.anchors.bind( "blur.tabs", function() { - removeState( "focus", $( this ).closest( "li" ) ); - }); - } + this._focusable( this.lis ); + this._hoverable( this.lis ); // set up animations var hideFx, showFx; @@ -431,15 +411,12 @@ $.widget( "ui.tabs", { return index; }, - destroy: function() { + _destroy: function() { var o = this.options; this.abort(); - this.element - .unbind( ".tabs" ) - .removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" ) - .removeData( "tabs" ); + this.element.removeClass( "ui-tabs ui-widget ui-widget-content ui-corner-all ui-tabs-collapsible" ); this.list.removeClass( "ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" ); @@ -463,8 +440,6 @@ $.widget( "ui.tabs", { "ui-corner-top", "ui-tabs-selected", "ui-state-active", - "ui-state-hover", - "ui-state-focus", "ui-state-disabled", "ui-tabs-panel", "ui-widget-content", diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index ece6e9e16..c8e5348ac 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -139,14 +139,16 @@ $.Widget.prototype = { this.options, this._getCreateOptions(), options ); - if (element !== this) { - $.data(element, this.widgetName, this); - - var self = this; - this.element.bind("remove." + this.widgetName, function(){ - self.destroy(); - }); + + this.bindings = $(); + this.hoverable = $(); + this.focusable = $(); + + if ( element !== this ) { + $.data( element, this.widgetName, this ); + this._bind({ remove: "destroy" }); } + this._create(); this._trigger( "create" ); this._init(); @@ -166,6 +168,8 @@ $.Widget.prototype = { destroy: function() { this._destroy(); + // we can probably remove the unbind calls in 2.0 + // all event bindings should go through this._bind() this.element .unbind( "." + this.widgetName ) .removeData( this.widgetName ); @@ -175,6 +179,11 @@ $.Widget.prototype = { .removeClass( this.widgetBaseClass + "-disabled " + "ui-state-disabled" ); + + // clean up events and states + this.bindings.unbind( "." + this.widgetName ); + this.hoverable.removeClass( "ui-state-hover" ); + this.focusable.removeClass( "ui-state-focus" ); }, _destroy: $.noop, @@ -217,6 +226,8 @@ $.Widget.prototype = { this.widget() .toggleClass( this.widgetBaseClass + "-disabled ui-state-disabled", !!value ) .attr( "aria-disabled", value ); + this.hoverable.removeClass( "ui-state-hover" ); + this.focusable.removeClass( "ui-state-focus" ); } return this; @@ -229,6 +240,54 @@ $.Widget.prototype = { return this._setOption( "disabled", true ); }, + _bind: function( element, handlers ) { + // no element argument, shuffle and use this.element + if ( !handlers ) { + handlers = element; + element = this.element; + } else { + this.bindings = this.bindings.add( element ); + } + var instance = this; + $.each( handlers, function( event, handler ) { + element.bind( event + "." + instance.widgetName, function() { + // allow widgets to customize the disabled handling + // - disabled as an array instead of boolean + // - disabled class as method for disabling individual parts + if ( instance.options.disabled === true || + $( this ).hasClass( "ui-state-disabled" ) ) { + return; + } + return ( typeof handler === "string" ? instance[ handler ] : handler ) + .apply( instance, arguments ); + }); + }); + }, + + _hoverable: function( element ) { + this.hoverable = this.hoverable.add( element ); + this._bind( element, { + mouseenter: function( event ) { + $( event.currentTarget ).addClass( "ui-state-hover" ); + }, + mouseleave: function( event ) { + $( event.currentTarget ).removeClass( "ui-state-hover" ); + } + }); + }, + + _focusable: function( element ) { + this.focusable = this.focusable.add( element ); + this._bind( element, { + focusin: function( event ) { + $( event.currentTarget ).addClass( "ui-state-focus" ); + }, + focusout: function( event ) { + $( event.currentTarget ).removeClass( "ui-state-focus" ); + } + }); + }, + _trigger: function( type, event, data ) { var callback = this.options[ type ]; |