Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENHANCEMENT Using jQuery UI tabs in TabSet form field. Using custom j…
…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
Showing
2 changed files
with
61 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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); |