2011-05-13 03:30:49 +02:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
$.entwine('ss', function($){
|
|
|
|
|
|
|
|
// setup jquery.entwine
|
|
|
|
$.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Vertically collapsible panel. Generic enough to work with CMS menu as well as various "filter" panels.
|
|
|
|
*
|
|
|
|
* A panel consists of the following parts:
|
|
|
|
* - Container div: The outer element, with class ".cms-panel"
|
|
|
|
* - Header (optional)
|
|
|
|
* - Content
|
|
|
|
* - Expand and collapse toggle anchors (optional)
|
|
|
|
*
|
|
|
|
* Sample HTML:
|
|
|
|
* <div class="cms-panel">
|
|
|
|
* <div class="cms-panel-header">your header</div>
|
|
|
|
* <div class="cms-panel-content">your content here</div>
|
2011-10-29 02:01:06 +02:00
|
|
|
* <div class="cms-panel-toggle">
|
|
|
|
* <a href="#" class="toggle-expande">your toggle text</a>
|
|
|
|
* <a href="#" class="toggle-collapse">your toggle text</a>
|
|
|
|
* </div>
|
2011-05-13 03:30:49 +02:00
|
|
|
* </div>
|
|
|
|
*/
|
|
|
|
$('.cms-panel').entwine({
|
|
|
|
|
|
|
|
WidthExpanded: null,
|
|
|
|
|
|
|
|
WidthCollapsed: null,
|
|
|
|
|
|
|
|
onmatch: function() {
|
|
|
|
if(!this.find('.cms-panel-content').length) throw new Exception('Content panel for ".cms-panel" not found');
|
|
|
|
|
2011-10-29 02:01:06 +02:00
|
|
|
// Create default controls unless they already exist.
|
|
|
|
if(!this.find('.cms-panel-toggle').length) {
|
|
|
|
var container = $("<div class='cms-panel-toggle south'></div>")
|
|
|
|
.append('<a class="toggle-expand" href="#"><span>»</span></a>')
|
|
|
|
.append('<a class="toggle-collapse" href="#"><span>«</span></a>');
|
|
|
|
|
|
|
|
this.append(container);
|
|
|
|
}
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
// Set panel width same as the content panel it contains. Assumes the panel has overflow: hidden.
|
2011-08-09 07:52:13 +02:00
|
|
|
this.setWidthExpanded(this.find('.cms-panel-content').innerWidth());
|
2011-05-13 03:30:49 +02:00
|
|
|
|
|
|
|
// Assumes the collasped width is indicated by the toggle, or by an optional collapsed view
|
|
|
|
var collapsedContent = this.find('.cms-panel-content-collapsed');
|
2011-08-09 07:52:13 +02:00
|
|
|
this.setWidthCollapsed(collapsedContent.length ? collapsedContent.innerWidth() : this.find('.toggle-expand').innerWidth());
|
2011-05-13 03:30:49 +02:00
|
|
|
|
2012-01-06 16:39:32 +01:00
|
|
|
// Set inital collapsed state, either from cookie or from default CSS classes
|
|
|
|
var collapsed, cookieCollapsed;
|
|
|
|
if($.cookie && this.attr('id')) {
|
|
|
|
cookieCollapsed = $.cookie('cms-panel-collapsed-' + this.attr('id'));
|
|
|
|
if(typeof cookieCollapsed != 'undefined') collapsed = (cookieCollapsed == 'true');
|
|
|
|
}
|
|
|
|
if(typeof collapsed == 'undefined') collapsed = jQuery(this).hasClass('collapsed');
|
|
|
|
this.togglePanel(!collapsed);
|
2011-05-13 03:30:49 +02:00
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
onclick: function(e) {
|
|
|
|
// By default, the whole collapsed area serves as a trigger
|
|
|
|
if(this.data('expandOnClick') && jQuery(this).hasClass('collapsed')) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.expandPanel();
|
|
|
|
}
|
|
|
|
},
|
2011-10-07 06:48:53 +02:00
|
|
|
|
2011-10-10 02:24:27 +02:00
|
|
|
toggleFlyoutState: function(bool) {
|
2011-10-07 06:48:53 +02:00
|
|
|
if (bool) { //expand
|
|
|
|
//show the flyout
|
|
|
|
$('.collapsed').find('li').show();
|
|
|
|
|
2011-10-10 02:24:27 +02:00
|
|
|
//hide all the flyout-indicator
|
|
|
|
$('.cms-menu-list').find('.child-flyout-indicator').hide();
|
2011-10-07 06:48:53 +02:00
|
|
|
} else { //collapse
|
|
|
|
//hide the flyout only if it is not the current section
|
|
|
|
$('.collapsed-flyout').find('li').each(function() {
|
|
|
|
//if (!$(this).hasClass('current'))
|
|
|
|
$(this).hide();
|
|
|
|
});
|
|
|
|
|
2011-10-10 02:24:27 +02:00
|
|
|
//show all the flyout-indicators
|
2011-10-07 06:48:53 +02:00
|
|
|
var par = $('.cms-menu-list ul.collapsed-flyout').parent();
|
2011-10-10 02:24:27 +02:00
|
|
|
if (par.children('.child-flyout-indicator').length == 0) par.append('<span class="child-flyout-indicator"></span>').fadeIn();
|
|
|
|
par.children('.child-flyout-indicator').fadeIn();
|
2011-10-07 06:48:53 +02:00
|
|
|
}
|
2011-10-10 02:24:27 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
togglePanel: function(bool) {
|
|
|
|
|
|
|
|
//apply or unapply the flyout formatting
|
|
|
|
$('.cms-menu-list').children('li').each(function(){
|
|
|
|
if (bool) { //expand
|
|
|
|
$(this).children('ul').each(function() {
|
|
|
|
$(this).removeClass('collapsed-flyout');
|
|
|
|
if ($(this).data('collapse')) {
|
|
|
|
$(this).removeData('collapse');
|
|
|
|
$(this).addClass('collapse');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else { //collapse
|
|
|
|
$(this).children('ul').each(function() {
|
|
|
|
$(this).addClass('collapsed-flyout');
|
|
|
|
$(this).hasClass('collapse');
|
|
|
|
$(this).removeClass('collapse');
|
|
|
|
$(this).data('collapse', true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.toggleFlyoutState(bool);
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.toggleClass('collapsed', !bool);
|
|
|
|
var newWidth = bool ? this.getWidthExpanded() : this.getWidthCollapsed();
|
|
|
|
|
|
|
|
this.trigger('beforetoggle');
|
|
|
|
this.width(newWidth); // the content panel width always stays in "expanded state" to avoid floating elements
|
|
|
|
this.find('.toggle-collapse')[bool ? 'show' : 'hide']();
|
|
|
|
this.find('.toggle-expand')[bool ? 'hide' : 'show']();
|
|
|
|
|
|
|
|
// If an alternative collapsed view exists, toggle it as well
|
|
|
|
var collapsedContent = this.find('.cms-panel-content-collapsed');
|
|
|
|
if(collapsedContent.length) {
|
|
|
|
this.find('.cms-panel-content')[bool ? 'show' : 'hide']();
|
|
|
|
this.find('.cms-panel-content-collapsed')[bool ? 'hide' : 'show']();
|
|
|
|
}
|
2012-01-06 16:39:32 +01:00
|
|
|
|
|
|
|
// Save collapsed state in cookie
|
|
|
|
if($.cookie && this.attr('id')) $.cookie('cms-panel-collapsed-' + this.attr('id'), !bool, {path: '/', expires: 31});
|
2011-05-13 03:30:49 +02:00
|
|
|
|
|
|
|
this.trigger('toggle');
|
|
|
|
},
|
|
|
|
|
2011-12-15 17:22:59 +01:00
|
|
|
expandPanel: function(force) {
|
|
|
|
if(!force && !this.hasClass('collapsed')) return;
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.togglePanel(true);
|
|
|
|
},
|
|
|
|
|
2011-12-15 17:22:59 +01:00
|
|
|
collapsePanel: function(force) {
|
|
|
|
if(!force && this.hasClass('collapsed')) return;
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.togglePanel(false);
|
|
|
|
}
|
|
|
|
});
|
2011-10-07 06:48:53 +02:00
|
|
|
|
|
|
|
/** Toggle the flyout panel to appear/disappear when mouse over */
|
|
|
|
$('.cms-menu-list li').entwine({
|
|
|
|
toggleFlyout: function(bool) {
|
|
|
|
fly = $(this);
|
|
|
|
if (fly.children('ul').first().hasClass('collapsed-flyout')) {
|
|
|
|
if (bool) { //expand
|
|
|
|
fly.children('ul').find('li').fadeIn('fast');
|
|
|
|
} else { //collapse
|
|
|
|
fly.children('ul').find('li').hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-10-10 03:00:47 +02:00
|
|
|
//slight delay to prevent flyout closing from "sloppy mouse movement"
|
|
|
|
$('.cms-menu-list li').hoverIntent(function(){$(this).toggleFlyout(true);},function(){$(this).toggleFlyout(false);});
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
|
|
|
|
$('.cms-panel *').entwine({
|
|
|
|
getPanel: function() {
|
|
|
|
return this.parents('.cms-panel:first');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-panel .toggle-expand').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.getPanel().expandPanel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.cms-panel .toggle-collapse').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
this.getPanel().collapsePanel();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}(jQuery));
|