From 995518c10fa03703754af3fe272fb1a7021a285b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Mon, 4 Apr 2011 17:06:13 -0400 Subject: [PATCH] Tabs: cleanup. --- tests/unit/tabs/tabs_defaults.js | 30 +++++------ tests/unit/tabs/tabs_defaults_deprecated.js | 56 ++++++++++----------- tests/unit/tabs/tabs_deprecated.js | 2 +- tests/unit/tabs/tabs_events.js | 7 ++- tests/unit/tabs/tabs_tickets.js | 4 +- ui/jquery.ui.tabs.js | 27 ++++++---- 6 files changed, 61 insertions(+), 65 deletions(-) diff --git a/tests/unit/tabs/tabs_defaults.js b/tests/unit/tabs/tabs_defaults.js index 0f33cc28c..d64316f9f 100644 --- a/tests/unit/tabs/tabs_defaults.js +++ b/tests/unit/tabs/tabs_defaults.js @@ -1,17 +1,13 @@ -/* - * tabs_defaults.js - */ - -var tabs_defaults = { - activate: null, - beforeload: null, - beforeActivate: null, - collapsible: false, - disabled: false, - event: "click", - fx: null, - load: null -}; - -// FAIL: falsy values break the cookie option -commonWidgetTests( "tabs", { defaults: tabs_defaults } ); +commonWidgetTests( "tabs", { + defaults: { + activate: null, +// active: null, + beforeLoad: null, + beforeActivate: null, + collapsible: false, + disabled: false, + event: "click", + fx: null, + load: null + } +}); diff --git a/tests/unit/tabs/tabs_defaults_deprecated.js b/tests/unit/tabs/tabs_defaults_deprecated.js index 03ee13d3d..c496e72f5 100644 --- a/tests/unit/tabs/tabs_defaults_deprecated.js +++ b/tests/unit/tabs/tabs_defaults_deprecated.js @@ -1,30 +1,26 @@ -/* - * tabs_defaults.js - */ - -var tabs_defaults = { - activate: null, - add: null, - ajaxOptions: null, - beforeload: null, - beforeActivate: null, - cache: false, - collapsible: false, - cookie: null, - disable: null, - disabled: false, - enable: null, - event: "click", - fx: null, - idPrefix: "ui-tabs-", - load: null, - panelTemplate: "
", - remove: null, - select: null, - show: null, - spinner: "Loading…", - tabTemplate: "
  • #{label}
  • " -}; - -// FAIL: falsy values break the cookie option -commonWidgetTests( "tabs", { defaults: tabs_defaults } ); +commonWidgetTests( "tabs", { + defaults: { + activate: null, +// active: null, + add: null, + ajaxOptions: null, + beforeLoad: null, + beforeActivate: null, + cache: false, + collapsible: false, + cookie: null, + disable: null, + disabled: false, + enable: null, + event: "click", + fx: null, + idPrefix: "ui-tabs-", + load: null, + panelTemplate: "
    ", + remove: null, + select: null, + show: null, + spinner: "Loading…", + tabTemplate: "
  • #{label}
  • " + } +}); diff --git a/tests/unit/tabs/tabs_deprecated.js b/tests/unit/tabs/tabs_deprecated.js index b784c724e..c4a27026d 100644 --- a/tests/unit/tabs/tabs_deprecated.js +++ b/tests/unit/tabs/tabs_deprecated.js @@ -7,7 +7,7 @@ test( "#4581 - title attribute for remote tabs does not support foreign language $( "#tabs2" ).tabs({ selected: 3, - beforeload: function( event, ui ) { + beforeLoad: function( event, ui ) { event.preventDefault(); equal( ui.panel.id, "∫ßáö_Սե", "proper title" ); } diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index c578e5db7..9c9fe0cd9 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -139,14 +139,14 @@ test( "activate", function() { element.tabs( "option", "active", 1 ); }); -test('beforeload', function() { +test( "beforeLoad", function() { expect( 5 ); - el = $('#tabs2'); + el = $( "#tabs2" ); el.tabs({ active: 2, - beforeload: function( event, ui ) { + beforeLoad: function( event, ui ) { ok( $.isFunction( ui.jqXHR.promise ), 'contain jqXHR object'); equals( ui.settings.url, "data/test.html", 'contain ajax settings url'); equals( ui.tab, el.find('a')[ 2 ], 'contain tab as DOM anchor element'); @@ -155,7 +155,6 @@ test('beforeload', function() { event.preventDefault(); } }); - }); test('load', function() { diff --git a/tests/unit/tabs/tabs_tickets.js b/tests/unit/tabs/tabs_tickets.js index 36ddd6e84..503f96260 100644 --- a/tests/unit/tabs/tabs_tickets.js +++ b/tests/unit/tabs/tabs_tickets.js @@ -44,7 +44,7 @@ test('#3627 - Ajax tab with url containing a fragment identifier fails to load', el = $('#tabs2').tabs({ active: 2, - beforeload: function( event, ui ) { + beforeLoad: function( event, ui ) { event.preventDefault(); ok(/test.html$/.test( ui.settings.url ), 'should ignore fragment identifier'); } @@ -58,7 +58,7 @@ test('#4033 - IE expands hash to full url and misinterprets tab as ajax', functi el = $('
    '); el.appendTo('#main'); el.tabs({ - beforeload: function( event, ui ) { + beforeLoad: function( event, ui ) { event.preventDefault(); ok( false, 'should not be an ajax tab'); } diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 7544d0302..b350f309e 100755 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -27,10 +27,11 @@ function getNextListId() { $.widget( "ui.tabs", { options: { activate: null, - beforeload: null, + // TODO: uncomment (requires fixing code related to active option) +// active: null, + beforeLoad: null, beforeActivate: null, collapsible: false, - disabled: false, event: "click", fx: null, // e.g. { height: 'toggle', opacity: 'toggle', duration: 200 } load: null @@ -118,13 +119,13 @@ $.widget( "ui.tabs", { _setOption: function( key, value ) { if ( key == "active" ) { - // _activate() will handle invalid values and update this.option + // _activate() will handle invalid values and update this.options this._activate( value ); - return - } else { - this.options[ key ] = value; - this.refresh(); + return; } + + this.options[ key ] = value; + this.refresh(); }, _tabId: function( a ) { @@ -573,8 +574,9 @@ $.widget( "ui.tabs", { this.xhr = $.ajax({ url: url, beforeSend: function( jqXHR, settings ) { - return self._trigger( "beforeload", null, - $.extend( { jqXHR: jqXHR, settings: settings }, eventData ) ); + // TODO: pass relevant event + return self._trigger( "beforeLoad", null, + $.extend( { jqXHR : jqXHR, settings: settings }, eventData ) ); } }); @@ -609,8 +611,12 @@ $.widget( "ui.tabs", { self.element.dequeue( "tabs" ); return this; - } + }, + _getPanelForTab: function( tab ) { + var id = $( tab ).attr( "aria-controls" ); + return this.element.find( this._sanitizeSelector( "#" + id ) ); + } }); $.extend( $.ui.tabs, { @@ -619,7 +625,6 @@ $.extend( $.ui.tabs, { // DEPRECATED if ( $.uiBackCompat !== false ) { - // ajaxOptions and cache options (function( $, prototype ) { $.extend( prototype.options, { -- 2.39.5