Navigation Menu

Skip to content

Commit

Permalink
ENHANCEMENT Using jQuery UI tabs in TabSet form field. Using custom j…
Browse files Browse the repository at this point in the history
…avascript to ensure sizing of tabs within layout-managed containers.

API CHANGE Changed CSS-class in TabSet template from "tabstrip" to "ss-tabset".

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92483 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed Nov 21, 2009
1 parent 70deaa4 commit 2a74a8b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 46 deletions.
13 changes: 1 addition & 12 deletions forms/TabSet.php
Expand Up @@ -54,21 +54,10 @@ public function FieldHolder() {
Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/jquery-ui.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/jquery-ui.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/ui.core.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/ui.core.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/ui.tabs.js'); Requirements::javascript(THIRDPARTY_DIR . '/jquery/ui/ui.tabs.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/fitheighttoparent/jquery.fitheighttoparent.js'); Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');

Requirements::css(THIRDPARTY_DIR . '/jquery/themes/smoothness/ui.all.css'); Requirements::css(THIRDPARTY_DIR . '/jquery/themes/smoothness/ui.all.css');
Requirements::css(THIRDPARTY_DIR . '/jquery/themes/smoothness/ui.tabs.css'); Requirements::css(THIRDPARTY_DIR . '/jquery/themes/smoothness/ui.tabs.css');


// concrete
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.class.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.selector.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.selector.specifity.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.selector.matches.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.dat.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/concrete/jquery.concrete.js');

Requirements::javascript(SAPPHIRE_DIR . '/javascript/TabSet.js');

return $this->renderWith("TabSetFieldHolder"); return $this->renderWith("TabSetFieldHolder");
} }


Expand Down
94 changes: 60 additions & 34 deletions javascript/TabSet.js
@@ -1,37 +1,63 @@
(function($){ jQuery(document).ready(function () {
/** /**
* Lightweight wrapper around jQuery UI tabs. * Replace prefixes for all hashlinks in tabs.
* Ensures that anchor links are set properly, * SSViewer rewrites them from "#Root_MyTab" to
* and any nested tabs are scrolled if they have * e.g. "/admin/#Root_MyTab" which makes them
* their height explicitly set. This is important * unusable for jQuery UI.
* for forms inside the CMS layout.
*/ */
$('.ss-tabset').concrete({ jQuery('.ss-tabset > ul a').each(function() {
onmatch: function() { var href = jQuery(this).attr('href').replace(/.*(#.*)/, '$1');
this.rewriteHashlinks(); jQuery(this).attr('href', href);

})
// Initialize jQuery UI tabs
this.tabs(); // Initialize tabset
}, jQuery('.ss-tabset').tabs();

/**
* Adjust height of nested tabset panels contained
* in jQuery.layout panels to allow scrolling.
*/
var ss_tabset_fixHeight = function(e) {
console.debug(jQuery('.ss-tabset .tab'));
jQuery('.ss-tabset .tab').each(function() {
console.debug(this);
var $tabPane = jQuery(this);
var $layoutPane = $tabPane.parents('.ui-layout-pane:first');

// don't apply resizing if tabset is not contained in a layout pane
if(!$layoutPane) return;

// substract heights of unrelated tab elements
var $tabSets = $tabPane.parents('.ss-tabset');
var $tabBars = $tabSets.children('.ui-tabs-nav');
var tabPaneHeight = $layoutPane.height();
console.log('total', tabPaneHeight);
// each tabset has certain padding and borders
$tabSets.each(function() {
console.log('tabset',jQuery(this).outerHeight(true) - jQuery(this).innerHeight());
tabPaneHeight -= jQuery(this).outerHeight(true) - jQuery(this).innerHeight();
});
// get all "parent" tab navigation bars to substract their heights
// from the total panel height
$tabBars.each(function() {
console.log('tabbar', jQuery(this).outerHeight(true));
// substract height of every tab bar from the total panel height
tabPaneHeight -= jQuery(this).outerHeight(true);
});
// Remove any margins from the tab pane
console.log('tabpane', $tabPane.outerHeight(true) - $tabPane.innerHeight());
tabPaneHeight -= $tabPane.outerHeight(true) - $tabPane.innerHeight();
console.log('final', tabPaneHeight);
$tabPane.height(tabPaneHeight);


/** // if tab has no nested tabs, set overflow to auto
* Replace prefixes for all hashlinks in tabs. if(!$tabPane.find('.tab').length) {
* SSViewer rewrites them from "#Root_MyTab" to $tabPane.css('overflow', 'auto');
* e.g. "/admin/#Root_MyTab" which makes them }
* unusable for jQuery UI. });
*/ }
rewriteHashlinks: function() {
$(this).find('ul a').each(function() { ss_tabset_fixHeight();
var href = $(this).attr('href').replace(/.*(#.*)/, '$1');
if(href) $(this).attr('href', href); jQuery(window).bind('resize', ss_tabset_fixHeight);
}) });
},

/**
* If tab has no nested tabs, set overflow to auto
*/
setOverflows: function() {
$(this).find('.tab').not(':has(.tab)').css('overflow', 'auto');
}
});
})(jQuery);

0 comments on commit 2a74a8b

Please sign in to comment.