From 8b0c3618bdebddd98d4c09e77d14c50c4f4d3190 Mon Sep 17 00:00:00 2001 From: David Petersen Date: Sun, 27 Mar 2011 17:02:58 -0400 Subject: [PATCH] Tabs: Rename select event to beforeActivate. Fixes #7136 Tabs: Rename select event to beforeActivate --- tests/unit/tabs/tabs_defaults.js | 4 ++-- tests/unit/tabs/tabs_defaults_deprecated.js | 1 + tests/unit/tabs/tabs_deprecated.js | 21 +++++++++++++++++++++ tests/unit/tabs/tabs_events.js | 10 +++++----- ui/jquery.ui.tabs.js | 17 ++++++++++------- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/tests/unit/tabs/tabs_defaults.js b/tests/unit/tabs/tabs_defaults.js index e155a3dac..194d2b76c 100644 --- a/tests/unit/tabs/tabs_defaults.js +++ b/tests/unit/tabs/tabs_defaults.js @@ -5,13 +5,13 @@ var tabs_defaults = { activate: null, beforeload: null, + beforeActivate: null, collapsible: false, cookie: null, disabled: false, event: "click", fx: null, - load: null, - select: null + load: null }; // FAIL: falsy values break the cookie option diff --git a/tests/unit/tabs/tabs_defaults_deprecated.js b/tests/unit/tabs/tabs_defaults_deprecated.js index 47fd75d8f..03ee13d3d 100644 --- a/tests/unit/tabs/tabs_defaults_deprecated.js +++ b/tests/unit/tabs/tabs_defaults_deprecated.js @@ -7,6 +7,7 @@ var tabs_defaults = { add: null, ajaxOptions: null, beforeload: null, + beforeActivate: null, cache: false, collapsible: false, cookie: null, diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index ba1a778b0..38fa6db71 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -188,6 +188,27 @@ test('show', function() { }); +test('select', function() { + expect(7); + + var eventObj; + el = $('#tabs1').tabs({ + select: function(event, ui) { + ok(true, 'select triggered after initialization'); + equals(this, el[0], "context of callback"); + equals(event.type, 'tabsselect', 'event type in callback'); + equals(ui.tab, el.find('a')[1], 'contain tab as DOM anchor element'); + equals(ui.panel, el.find('div')[1], 'contain panel as DOM div element'); + equals(ui.index, 1, 'contain index'); + evenObj = event; + } + }); + el.tabs('select', 1); + + el.find( "li:eq(1) a" ).simulate( "click" ); + equals( evenObj.originalEvent.type, "click", "select triggered by click" ); +}); + module("tabs (deprecated): methods"); test('add', function() { diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index 60affd7ff..4fedde842 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -5,15 +5,15 @@ module("tabs: events"); -test('select', function() { +test('beforeActivate', function() { expect(7); var eventObj; el = $('#tabs1').tabs({ - select: function(event, ui) { - ok(true, 'select triggered after initialization'); + beforeActivate: function(event, ui) { + ok(true, 'beforeActivate triggered after initialization'); equals(this, el[0], "context of callback"); - equals(event.type, 'tabsselect', 'event type in callback'); + equals(event.type, 'tabsbeforeactivate', 'event type in callback'); equals(ui.tab, el.find('a')[1], 'contain tab as DOM anchor element'); equals(ui.panel, el.find('div')[1], 'contain panel as DOM div element'); equals(ui.index, 1, 'contain index'); @@ -23,7 +23,7 @@ test('select', function() { el.tabs('select', 1); el.find( "li:eq(1) a" ).simulate( "click" ); - equals( evenObj.originalEvent.type, "click", "select triggered by click" ); + equals( evenObj.originalEvent.type, "click", "beforeActivate triggered by click" ); }); test('beforeload', function() { diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index d605b2d48..8508f0adb 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -28,13 +28,13 @@ $.widget( "ui.tabs", { options: { activate: null, beforeload: null, + beforeActivate: null, cookie: null, // e.g. { expires: 7, path: '/', domain: 'jquery.com', secure: true } collapsible: false, disabled: false, event: "click", fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 } - load: null, - select: null + load: null }, _create: function() { @@ -363,8 +363,8 @@ $.widget( "ui.tabs", { $li.hasClass( "ui-state-disabled" ) || // tab is already loading $li.hasClass( "ui-state-processing" ) || - // allow canceling by select event - self._trigger( "select", event, self._ui( el, $show[ 0 ] ) ) === false ) { + // allow canceling by beforeActivate event + self._trigger( "beforeActivate", event, self._ui( el, $show[ 0 ] ) ) === false ) { el.blur(); return; } @@ -927,10 +927,11 @@ if ( $.uiBackCompat !== false ) { }; }( jQuery, jQuery.ui.tabs.prototype ) ); - // show event + // show and select event (function( $, prototype ) { $.extend( prototype.options, { - show: null + show: null, + select: null }); var _trigger = prototype._trigger; @@ -939,7 +940,9 @@ if ( $.uiBackCompat !== false ) { if ( !ret ) { return false; } - if ( type === "activate" ) { + if ( type === "beforeActivate" ) { + ret = _trigger.call( this, "select", event, data ); + } else if ( type === "activate" ) { ret = _trigger.call( this, "show", event, data ); } }; -- 2.39.5