]> source.dussan.org Git - jquery-ui.git/commitdiff
Tabs: Rename show event to activate. Fixes #7137 Tabs: Rename show event to activate
authorDavid Petersen <public@petersendidit.com>
Sun, 27 Mar 2011 20:55:05 +0000 (16:55 -0400)
committerDavid Petersen <public@petersendidit.com>
Sun, 27 Mar 2011 20:55:05 +0000 (16:55 -0400)
tests/unit/tabs/tabs_defaults.js
tests/unit/tabs/tabs_defaults_deprecated.js
tests/unit/tabs/tabs_deprecated.js
tests/unit/tabs/tabs_events.js
ui/jquery.ui.tabs.js

index 98cb99fb597cc56ccba298efab396669d6da1f20..e155a3dac5b7ba01d6b21120fd9da7e45fa13cea 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 var tabs_defaults = {
+       activate: null,
        beforeload: null,
        collapsible: false,
        cookie: null,
@@ -10,8 +11,7 @@ var tabs_defaults = {
        event: "click",
        fx: null,
        load: null,
-       select: null,
-       show: null
+       select: null
 };
 
 // FAIL: falsy values break the cookie option
index 73e9ffedeabc219e1137d2bf3b2c1cfbe8e73212..47fd75d8f1b1b9b14e3248e8e1f1c569f11a641b 100644 (file)
@@ -3,6 +3,7 @@
  */
 
 var tabs_defaults = {
+       activate: null,
        add: null,
        ajaxOptions: null,
        beforeload: null,
index 8b6b50d7e4e86d15f8ac143efd7112f32fa7d1b3..ba1a778b09af3a8ca1b6b7736357de443b132bb6 100644 (file)
@@ -168,6 +168,26 @@ test('remove', function() {
        ok(false, "missing test - untested code is broken code.");
 });
 
+test('show', function() {
+       expect(5);
+
+       var uiObj, eventObj;
+       el = $('#tabs1').tabs({
+               show: function(event, ui) {
+                       uiObj = ui;
+                       eventObj = event;
+               }
+       });
+       ok(uiObj !== undefined, 'trigger callback after initialization');
+       equals(uiObj.tab, $('a', el)[0], 'contain tab as DOM anchor element');
+       equals(uiObj.panel, $('div', el)[0], 'contain panel as DOM div element');
+       equals(uiObj.index, 0, 'contain index');
+
+       el.find( "li:eq(1) a" ).simulate( "click" );
+       equals( eventObj.originalEvent.type, "click", "show triggered by click" );
+
+});
+
 module("tabs (deprecated): methods");
 
 test('add', function() {
index 04f2821571c548f7fd206b72b02284273f3beb11..60affd7ff49fb98ebbd5cfb552fb4b4aeba1257c 100644 (file)
@@ -49,12 +49,12 @@ test('load', function() {
        ok(false, "missing test - untested code is broken code.");
 });
 
-test('show', function() {
+test('activate', function() {
        expect(5);
 
        var uiObj, eventObj;
        el = $('#tabs1').tabs({
-               show: function(event, ui) {
+               activate: function(event, ui) {
                        uiObj = ui;
                        eventObj = event;
                }
index d76565a2ae004ab7f953c44e23a9c1e0a410ae89..d605b2d48d2a46093e7eb50c2ce10cb0d645bca6 100755 (executable)
@@ -26,6 +26,7 @@ function getNextListId() {
 
 $.widget( "ui.tabs", {
        options: {
+               activate: null,
                beforeload: null,
                cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true }
                collapsible: false,
@@ -33,8 +34,7 @@ $.widget( "ui.tabs", {
                event: "click",
                fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 }
                load: null,
-               select: null,
-               show: null
+               select: null
        },
 
        _create: function() {
@@ -103,9 +103,9 @@ $.widget( "ui.tabs", {
 
                        this.lis.eq( o.active ).addClass( "ui-tabs-selected ui-state-active" );
 
-                       // seems to be expected behavior that the show callback is fired
+                       // seems to be expected behavior that the activate callback is fired
                        self.element.queue( "tabs", function() {
-                               self._trigger( "show", null, self._ui( tab, panel[ 0 ] ) );
+                               self._trigger( "activate", null, self._ui( tab, panel[ 0 ] ) );
                        });
 
                        this.load( o.active );
@@ -304,11 +304,11 @@ $.widget( "ui.tabs", {
                                .animate( showFx, showFx.duration || "normal", function() {
                                        self._resetStyle( show, showFx );
                                        self.running = false;
-                                       self._trigger( "show", event, self._ui( clicked, show[ 0 ] ) );
+                                       self._trigger( "activate", event, self._ui( clicked, show[ 0 ] ) );
                                });
                } else {
                        show.removeClass( "ui-tabs-hide" );
-                       self._trigger( "show", event, self._ui( clicked, show[ 0 ] ) );
+                       self._trigger( "activate", event, self._ui( clicked, show[ 0 ] ) );
                }
        },
 
@@ -815,7 +815,7 @@ if ( $.uiBackCompat !== false ) {
                                $li.addClass( "ui-tabs-selected ui-state-active" );
                                $panel.removeClass( "ui-tabs-hide" );
                                this.element.queue( "tabs", function() {
-                                       self._trigger( "show", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
+                                       self._trigger( "activate", null, self._ui( self.anchors[ 0 ], self.panels[ 0 ] ) );
                                });
 
                                this.load( 0 );
@@ -926,6 +926,24 @@ if ( $.uiBackCompat !== false ) {
                        this.options.selected = this.options.active ;
                };
        }( jQuery, jQuery.ui.tabs.prototype ) );
+
+       // show event
+       (function( $, prototype ) {
+               $.extend( prototype.options, {
+                       show: null
+               });
+               var _trigger = prototype._trigger;
+
+               prototype._trigger = function( type, event, data ) {
+                       var ret = _trigger.apply( this, arguments );
+                       if ( !ret ) {
+                               return false;
+                       }
+                       if ( type === "activate" ) {
+                               ret = _trigger.call( this, "show", event, data );
+                       }
+               };
+       }( jQuery, jQuery.ui.tabs.prototype ) );
 }
 
 })( jQuery );