From eef633e32a20ad93355060a8eef4b2129cf0bc5c Mon Sep 17 00:00:00 2001 From: Alex Rhea Date: Tue, 3 Jan 2012 13:00:02 -0500 Subject: Bug fix for isLocal function in jQuery Tabs. isLocal function was not compatible with HTML5 push state as the url could have changed since the page was loaded as in cases with Backbone.js --- ui/jquery.ui.tabs.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 5c9fc1326..3e022af4a 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -18,18 +18,13 @@ function getNextTabId() { return ++tabId; } -var isLocal = (function() { - var rhash = /#.*$/, - currentPage = location.href.replace( rhash, "" ); - - return function( anchor ) { - // clone the node to work around IE 6 not normalizing the href property - // if it's manually set, i.e., a.href = "#foo" kills the normalization - anchor = anchor.cloneNode( false ); - return anchor.hash.length > 1 && - anchor.href.replace( rhash, "" ) === currentPage; - }; -})(); +var isLocal = function( anchor ) { + var rhash = /#.*$/; + // clone the node to work around IE 6 not normalizing the href property + // if it's manually set, i.e., a.href = "#foo" kills the normalization + anchor = anchor.cloneNode( false ); + return anchor.hash.length > 1 && anchor.href.replace( rhash, "" ) === location.href.replace( rhash, "" ); +}; $.widget( "ui.tabs", { version: "@VERSION", -- cgit v1.2.3 From 3c4e40d8d770ac117969b2cb011ac3d7402a134a Mon Sep 17 00:00:00 2001 From: Alex Rhea Date: Tue, 3 Jan 2012 13:18:13 -0500 Subject: Removed regex from function and split return into two lines. --- ui/jquery.ui.tabs.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 3e022af4a..0429363f2 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -13,17 +13,19 @@ */ (function( $, undefined ) { -var tabId = 0; +var tabId = 0, + rhash = /#.*$/; + function getNextTabId() { return ++tabId; } var isLocal = function( anchor ) { - var rhash = /#.*$/; // clone the node to work around IE 6 not normalizing the href property // if it's manually set, i.e., a.href = "#foo" kills the normalization anchor = anchor.cloneNode( false ); - return anchor.hash.length > 1 && anchor.href.replace( rhash, "" ) === location.href.replace( rhash, "" ); + return anchor.hash.length > 1 && + anchor.href.replace( rhash, "" ) === location.href.replace( rhash, "" ); }; $.widget( "ui.tabs", { -- cgit v1.2.3 From 0cf6bc042938a11abc09ed4e575c8792585607ac Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 21 Jan 2012 08:04:39 -0500 Subject: Tabs: Move logic for finding the tab list into its own function to allow overriding for rare usage scenarios. --- ui/jquery.ui.tabs.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ui/jquery.ui.tabs.js') diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 0429363f2..168aa0ee5 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -209,7 +209,7 @@ $.widget( "ui.tabs", { _processTabs: function() { var self = this; - this.list = this.element.find( "ol,ul" ).eq( 0 ); + this.list = this._getList(); this.lis = $( " > li:has(a[href])", this.list ); this.anchors = this.lis.map(function() { return $( "a", this )[ 0 ]; @@ -241,6 +241,11 @@ $.widget( "ui.tabs", { }); }, + // allow overriding how to find the list for rare usage scenarios (#7715) + _getList: function() { + return this.element.find( "ol,ul" ).eq( 0 ); + }, + _createPanel: function( id ) { return $( "
" ) .attr( "id", id ) -- cgit v1.2.3 From 6800e1a2f97a7d8aaf20d065aa2ce517528e5068 Mon Sep 17 00:00:00 2001 From: Scott González Date: Sat, 21 Jan 2012 08:46:02 -0500 Subject: Tabs: Pass tab and panel in create event. Fixes #7868 - Tabs: Provide tab and panel details in create event. --- tests/unit/tabs/tabs_events.js | 39 +++++++++++++++++++++++++++++++++++++++ ui/jquery.ui.tabs.js | 7 +++++++ 2 files changed, 46 insertions(+) (limited to 'ui/jquery.ui.tabs.js') diff --git a/tests/unit/tabs/tabs_events.js b/tests/unit/tabs/tabs_events.js index f5cde180b..333578907 100644 --- a/tests/unit/tabs/tabs_events.js +++ b/tests/unit/tabs/tabs_events.js @@ -2,6 +2,45 @@ module( "tabs: events" ); +test( "create", function() { + expect( 10 ); + + var element = $( "#tabs1" ), + tabs = element.find( "ul a" ), + panels = element.children( "div" ); + + element.tabs({ + create: function( event, ui ) { + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tabs[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panels[ 0 ], "panel" ); + } + }); + element.tabs( "destroy" ); + + element.tabs({ + active: 2, + create: function( event, ui ) { + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tabs[ 2 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panels[ 2 ], "panel" ); + } + }); + element.tabs( "destroy" ); + + element.tabs({ + active: false, + collapsible: true, + create: function( event, ui ) { + equals( ui.tab.size(), 0, "tab size" ); + equals( ui.panel.size(), 0, "panel size" ); + } + }); + element.tabs( "destroy" ); +}); + test( "beforeActivate", function() { expect( 38 ); diff --git a/ui/jquery.ui.tabs.js b/ui/jquery.ui.tabs.js index 168aa0ee5..7a701405c 100644 --- a/ui/jquery.ui.tabs.js +++ b/ui/jquery.ui.tabs.js @@ -120,6 +120,13 @@ $.widget( "ui.tabs", { } }, + _getCreateEventData: function() { + return { + tab: this.active, + panel: !this.active.length ? $() : this._getPanelForTab( this.active ) + }; + }, + _setOption: function( key, value ) { if ( key == "active" ) { // _activate() will handle invalid values and update this.options -- cgit v1.2.3