2010-09-15 02:03:24 +00:00
|
|
|
/*
|
|
|
|
|
* Collapsible tabs jQuery Plugin
|
|
|
|
|
*/
|
2010-10-01 18:05:55 +00:00
|
|
|
( function( $ ) {
|
|
|
|
|
$.fn.collapsibleTabs = function( options ) {
|
|
|
|
|
// return if the function is called on an empty jquery object
|
|
|
|
|
if( !this.length ) return this;
|
|
|
|
|
//merge options into the defaults
|
|
|
|
|
var $settings = $.extend( {}, $.collapsibleTabs.defaults, options );
|
2011-08-12 21:48:10 +00:00
|
|
|
|
2010-10-01 18:05:55 +00:00
|
|
|
this.each( function() {
|
|
|
|
|
var $this = $( this );
|
|
|
|
|
// add the element to our array of collapsible managers
|
|
|
|
|
$.collapsibleTabs.instances = ( $.collapsibleTabs.instances.length == 0 ?
|
|
|
|
|
$this : $.collapsibleTabs.instances.add( $this ) );
|
|
|
|
|
// attach the settings to the elements
|
|
|
|
|
$this.data( 'collapsibleTabsSettings', $settings );
|
|
|
|
|
// attach data to our collapsible elements
|
|
|
|
|
$this.children( $settings.collapsible ).each( function() {
|
|
|
|
|
$.collapsibleTabs.addData( $( this ) );
|
|
|
|
|
} );
|
2010-09-15 02:03:24 +00:00
|
|
|
} );
|
2011-08-12 21:48:10 +00:00
|
|
|
|
2010-10-01 18:05:55 +00:00
|
|
|
// if we haven't already bound our resize hanlder, bind it now
|
|
|
|
|
if( !$.collapsibleTabs.boundEvent ) {
|
|
|
|
|
$( window )
|
2011-12-02 21:47:46 +00:00
|
|
|
.delayedBind( '500', 'resize', function( ) { $.collapsibleTabs.handleResize(); } );
|
2010-09-15 02:03:24 +00:00
|
|
|
}
|
2010-10-01 18:05:55 +00:00
|
|
|
// call our resize handler to setup the page
|
|
|
|
|
$.collapsibleTabs.handleResize();
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
$.collapsibleTabs = {
|
|
|
|
|
instances: [],
|
|
|
|
|
boundEvent: null,
|
|
|
|
|
defaults: {
|
|
|
|
|
expandedContainer: '#p-views ul',
|
|
|
|
|
collapsedContainer: '#p-cactions ul',
|
|
|
|
|
collapsible: 'li.collapsible',
|
|
|
|
|
shifting: false,
|
|
|
|
|
expandCondition: function( eleWidth ) {
|
|
|
|
|
return ( $( '#left-navigation' ).position().left + $( '#left-navigation' ).width() )
|
|
|
|
|
< ( $( '#right-navigation' ).position().left - eleWidth );
|
|
|
|
|
},
|
|
|
|
|
collapseCondition: function() {
|
|
|
|
|
return ( $( '#left-navigation' ).position().left + $( '#left-navigation' ).width() )
|
|
|
|
|
> $( '#right-navigation' ).position().left;
|
2010-09-15 02:03:24 +00:00
|
|
|
}
|
2010-10-01 18:05:55 +00:00
|
|
|
},
|
|
|
|
|
addData: function( $collapsible ) {
|
|
|
|
|
var $settings = $collapsible.parent().data( 'collapsibleTabsSettings' );
|
2011-04-25 10:17:30 +00:00
|
|
|
if ( $settings != null ) {
|
2011-04-21 14:39:45 +00:00
|
|
|
$collapsible.data( 'collapsibleTabsSettings', {
|
|
|
|
|
'expandedContainer': $settings.expandedContainer,
|
|
|
|
|
'collapsedContainer': $settings.collapsedContainer,
|
|
|
|
|
'expandedWidth': $collapsible.width(),
|
|
|
|
|
'prevElement': $collapsible.prev()
|
|
|
|
|
} );
|
|
|
|
|
}
|
2010-10-01 18:05:55 +00:00
|
|
|
},
|
|
|
|
|
getSettings: function( $collapsible ) {
|
|
|
|
|
var $settings = $collapsible.data( 'collapsibleTabsSettings' );
|
|
|
|
|
if ( typeof $settings == 'undefined' ) {
|
|
|
|
|
$.collapsibleTabs.addData( $collapsible );
|
|
|
|
|
$settings = $collapsible.data( 'collapsibleTabsSettings' );
|
2010-09-15 02:03:24 +00:00
|
|
|
}
|
2010-10-01 18:05:55 +00:00
|
|
|
return $settings;
|
|
|
|
|
},
|
|
|
|
|
handleResize: function( e ){
|
|
|
|
|
$.collapsibleTabs.instances.each( function() {
|
|
|
|
|
var $this = $( this ), data = $.collapsibleTabs.getSettings( $this );
|
|
|
|
|
if( data.shifting ) return;
|
2011-08-12 21:48:10 +00:00
|
|
|
|
2010-10-01 18:05:55 +00:00
|
|
|
// if the two navigations are colliding
|
|
|
|
|
if( $this.children( data.collapsible ).length > 0 && data.collapseCondition() ) {
|
2011-08-12 21:48:10 +00:00
|
|
|
|
2010-10-01 18:05:55 +00:00
|
|
|
$this.trigger( "beforeTabCollapse" );
|
|
|
|
|
// move the element to the dropdown menu
|
|
|
|
|
$.collapsibleTabs.moveToCollapsed( $this.children( data.collapsible + ':last' ) );
|
|
|
|
|
}
|
2011-08-12 21:48:10 +00:00
|
|
|
|
2010-10-01 18:05:55 +00:00
|
|
|
// if there are still moveable items in the dropdown menu,
|
|
|
|
|
// and there is sufficient space to place them in the tab container
|
|
|
|
|
if( $( data.collapsedContainer + ' ' + data.collapsible ).length > 0
|
|
|
|
|
&& data.expandCondition( $.collapsibleTabs.getSettings( $( data.collapsedContainer ).children(
|
|
|
|
|
data.collapsible+":first" ) ).expandedWidth ) ) {
|
|
|
|
|
//move the element from the dropdown to the tab
|
|
|
|
|
$this.trigger( "beforeTabExpand" );
|
|
|
|
|
$.collapsibleTabs
|
|
|
|
|
.moveToExpanded( data.collapsedContainer + " " + data.collapsible + ':first' );
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
moveToCollapsed: function( ele ) {
|
|
|
|
|
var $moving = $( ele );
|
|
|
|
|
var data = $.collapsibleTabs.getSettings( $moving );
|
|
|
|
|
var dataExp = $.collapsibleTabs.getSettings( data.expandedContainer );
|
|
|
|
|
dataExp.shifting = true;
|
|
|
|
|
$moving
|
2011-04-21 14:39:45 +00:00
|
|
|
.detach()
|
2010-10-01 18:05:55 +00:00
|
|
|
.prependTo( data.collapsedContainer )
|
|
|
|
|
.data( 'collapsibleTabsSettings', data );
|
|
|
|
|
dataExp.shifting = false;
|
|
|
|
|
$.collapsibleTabs.handleResize();
|
|
|
|
|
},
|
|
|
|
|
moveToExpanded: function( ele ) {
|
|
|
|
|
var $moving = $( ele );
|
|
|
|
|
var data = $.collapsibleTabs.getSettings( $moving );
|
|
|
|
|
var dataExp = $.collapsibleTabs.getSettings( data.expandedContainer );
|
|
|
|
|
dataExp.shifting = true;
|
|
|
|
|
// remove this element from where it's at and put it in the dropdown menu
|
2011-04-21 14:39:45 +00:00
|
|
|
$moving.detach().insertAfter( data.prevElement ).data( 'collapsibleTabsSettings', data );
|
2010-10-01 18:05:55 +00:00
|
|
|
dataExp.shifting = false;
|
|
|
|
|
$.collapsibleTabs.handleResize();
|
|
|
|
|
}
|
|
|
|
|
};
|
2011-04-25 10:17:30 +00:00
|
|
|
} )( jQuery );
|