2009-11-21 03:22:52 +01:00
|
|
|
(function($){
|
2010-04-13 07:45:29 +02:00
|
|
|
$.entwine('ss', function($){
|
2009-11-21 03:33:06 +01:00
|
|
|
/**
|
|
|
|
* Lightweight wrapper around jQuery UI tabs.
|
|
|
|
*/
|
2010-04-13 07:45:29 +02:00
|
|
|
$('.ss-tabset').entwine({
|
2012-11-21 22:01:02 +01:00
|
|
|
|
|
|
|
/*Custom functionality for special action tabsets*/
|
|
|
|
actionTabs: function(){
|
|
|
|
this.tabs(
|
|
|
|
'option',
|
|
|
|
'collapsible',
|
|
|
|
true
|
|
|
|
).tabs('option', 'active', false);
|
|
|
|
|
|
|
|
//Apply special behaviour to the cms actions row
|
|
|
|
if(this.hasClass('cms-actions-row')){
|
|
|
|
|
|
|
|
/* If actions panel is within the tree, apply active class
|
|
|
|
to help animate open/close on hover
|
|
|
|
Position must be reset else anyone coming from main sitetree
|
|
|
|
will see broken tabs */
|
|
|
|
var container = this.parent().parent();
|
|
|
|
if($(container).hasClass('cms-tree-view-sidebar')){
|
|
|
|
$('.ui-tabs-nav li').hover(function(){
|
|
|
|
$(this).parent().find('li .active').removeClass('active');
|
|
|
|
$(this).find('a').addClass('active');
|
|
|
|
});
|
|
|
|
|
|
|
|
this.tabs({
|
|
|
|
beforeActivate:function(event, ui){
|
|
|
|
var activePanel = ui.newPanel;
|
|
|
|
$(activePanel).attr("style","left : auto; right: auto");
|
|
|
|
$(this).closest('.ss-ui-action-tabset').removeClass('tabset-open').removeClass('tabset-open-last');
|
|
|
|
|
|
|
|
if($(activePanel).length > 0){
|
|
|
|
$(activePanel).parent().addClass('tabset-open');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else{
|
|
|
|
/* If the tabs are in the full site tree view, do some
|
|
|
|
positioning so tabPanel stays with relevent tab */
|
|
|
|
this.tabs({
|
|
|
|
beforeActivate:function(event, ui){
|
|
|
|
var activePanel = ui.newPanel;
|
|
|
|
var activeTab = ui.newTab;
|
|
|
|
$(this).closest('.ss-ui-action-tabset').removeClass('tabset-open').removeClass('tabset-open-last');
|
|
|
|
if($(activePanel).length > 0){
|
|
|
|
if($(activeTab).hasClass("last")){
|
|
|
|
$(activePanel).attr("style","left : auto; right: 0px");
|
|
|
|
$(activePanel).parent().addClass('tabset-open-last');//last needs to be styled differently when open
|
|
|
|
}else{
|
|
|
|
$(activePanel).attr("style","left: "+activeTab.position().left+"px");
|
|
|
|
if($(activeTab).hasClass("first")){
|
|
|
|
$(activePanel).attr("style","left: 0px");
|
|
|
|
$(activePanel).parent().addClass('tabset-open');
|
|
|
|
}else{
|
|
|
|
$(activePanel).attr("style","left: "+activeTab.position().left+"px");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-11-29 04:26:50 +01:00
|
|
|
}else if(this.parents('.cms-content-actions')){
|
|
|
|
var that = this;
|
|
|
|
var closeHandler = function(event){
|
|
|
|
if (!$(event.target).closest(that).length) {
|
|
|
|
that.tabs('option', 'active', false);
|
|
|
|
var frame = $('.cms').find('iframe');
|
|
|
|
frame.each(function(index, iframe){
|
|
|
|
$(iframe).contents().off('click', closeHandler);
|
|
|
|
});
|
|
|
|
$(document).off('click', closeHandler);
|
|
|
|
};
|
|
|
|
}
|
2012-11-21 22:01:02 +01:00
|
|
|
this.tabs({
|
|
|
|
beforeActivate:function(event, ui){
|
|
|
|
var activePanel = ui.newPanel;
|
2012-11-29 04:26:50 +01:00
|
|
|
var activeTab = ui.newTab;
|
|
|
|
var frame = $('.cms').find('iframe');
|
2012-11-21 22:01:02 +01:00
|
|
|
if($(activePanel).length > 0){
|
|
|
|
$(activePanel).attr("style","left: "+activeTab.position().left+"px");
|
2012-11-29 04:26:50 +01:00
|
|
|
}
|
|
|
|
$(document).on('click', closeHandler);
|
|
|
|
//Make sure iframe click also closes tab
|
|
|
|
if(frame.length > 0){
|
|
|
|
frame.each(function(index, iframe){
|
|
|
|
$(iframe).contents().on('click', closeHandler);
|
|
|
|
});
|
|
|
|
}
|
2012-11-21 22:01:02 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
//Check if tabs should open upwards, and adjust
|
|
|
|
this.riseUp();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2011-07-21 18:39:26 +02:00
|
|
|
// Can't name redraw() as it clashes with other CMS entwine classes
|
|
|
|
this.redrawTabs();
|
2011-07-15 10:37:46 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
2012-11-06 22:53:34 +01:00
|
|
|
if(this.data('uiTabs')) this.tabs('destroy');
|
2012-05-11 07:36:18 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-11-21 22:01:02 +01:00
|
|
|
riseUp: function(){
|
|
|
|
/* Function checks to see if a tab should be opened upwards
|
|
|
|
(based on space concerns. If true, the rise-up class is applied
|
|
|
|
and the position is calculated and applied to the element */
|
|
|
|
var elHeight = $(this).find('.ui-tabs-panel').outerHeight();
|
|
|
|
var trigger = $(this).find('.ui-tabs-nav').outerHeight();
|
|
|
|
var endOfWindow = ($(window).height() + $(document).scrollTop()) - trigger;
|
|
|
|
var elPos = $(this).find('.ui-tabs-nav').offset().top;
|
2012-11-29 04:26:50 +01:00
|
|
|
var that = this;
|
2012-11-21 22:01:02 +01:00
|
|
|
if(elPos + elHeight >= endOfWindow && elPos - elHeight > 0){
|
|
|
|
this.addClass('rise-up');
|
|
|
|
|
|
|
|
/* Apply position to tab */
|
|
|
|
this.tabs({
|
|
|
|
activate:function(event, ui){
|
|
|
|
var activePanel = ui.newPanel;
|
|
|
|
var activeTab = ui.newTab;
|
2012-11-29 04:26:50 +01:00
|
|
|
if(activeTab.position() != null){
|
|
|
|
var topPosition = -activePanel.outerHeight();
|
2012-11-21 22:01:02 +01:00
|
|
|
var containerSouth = activePanel.parents('.south');
|
|
|
|
if(containerSouth){
|
2012-11-29 04:26:50 +01:00
|
|
|
//If container is the southern panel, make tab appear from the top of the container
|
|
|
|
var padding = activeTab.offset().top - containerSouth.offset().top;
|
|
|
|
topPosition = topPosition-padding;
|
|
|
|
}
|
2012-11-21 22:01:02 +01:00
|
|
|
|
2012-11-29 04:26:50 +01:00
|
|
|
$(activePanel).css('top',topPosition+"px");
|
2012-11-21 22:01:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}else{
|
|
|
|
this.removeClass('rise-up');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2011-07-21 18:39:26 +02:00
|
|
|
redrawTabs: function() {
|
2009-11-21 03:32:38 +01:00
|
|
|
this.rewriteHashlinks();
|
2012-04-17 17:40:37 +02:00
|
|
|
this.tabs();
|
2012-11-21 22:01:02 +01:00
|
|
|
|
|
|
|
//Apply special behaviour to action tabs: closed by default, and collapsible
|
|
|
|
if(this.hasClass('ss-ui-action-tabset')){
|
|
|
|
this.actionTabs();
|
|
|
|
}
|
2009-11-21 03:32:38 +01:00
|
|
|
},
|
2009-11-21 03:33:06 +01:00
|
|
|
|
2009-11-21 03:32:38 +01:00
|
|
|
/**
|
2012-11-06 15:28:09 +01:00
|
|
|
* Ensure hash links are prefixed with the current page URL,
|
|
|
|
* otherwise jQuery interprets them as being external.
|
2009-11-21 03:32:38 +01:00
|
|
|
*/
|
|
|
|
rewriteHashlinks: function() {
|
|
|
|
$(this).find('ul a').each(function() {
|
2012-12-04 05:59:33 +01:00
|
|
|
if (!$(this).attr('href')) return;
|
|
|
|
|
2012-11-06 15:28:09 +01:00
|
|
|
var matches = $(this).attr('href').match(/#.*/);
|
|
|
|
if(!matches) return;
|
|
|
|
$(this).attr('href', document.location.href.replace(/#.*/, '') + matches[0]);
|
2009-11-21 03:32:38 +01:00
|
|
|
});
|
|
|
|
}
|
2009-11-21 03:33:06 +01:00
|
|
|
});
|
2009-11-21 03:22:52 +01:00
|
|
|
});
|
2012-05-11 07:36:18 +02:00
|
|
|
})(jQuery);
|