2011-05-13 03:30:49 +02:00
|
|
|
(function($) {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-01-09 05:22:28 +01:00
|
|
|
$.entwine('ss', function($) {
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
// setup jquery.entwine
|
|
|
|
$.entwine.warningLevel = $.entwine.WARN_LEVEL_BESTPRACTISE;
|
|
|
|
|
|
|
|
/**
|
2015-01-09 05:22:28 +01:00
|
|
|
* Horizontal collapsible panel. Generic enough to work with CMS menu as well as various "filter" panels.
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2011-05-13 03:30:49 +02:00
|
|
|
* 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)
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2011-05-13 03:30:49 +02:00
|
|
|
* 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({
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
WidthExpanded: null,
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
WidthCollapsed: null,
|
2015-05-19 03:43:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @func canSetCookie
|
|
|
|
* @return {boolean}
|
|
|
|
* @desc Before trying to set a cookie, make sure $.cookie and the element's id are both defined.
|
|
|
|
*/
|
|
|
|
canSetCookie: function () {
|
|
|
|
return $.cookie !== void 0 && this.attr('id') !== void 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func getPersistedCollapsedState
|
|
|
|
* @return {boolean|undefined} - Returns true if the panel is collapsed, false if expanded. Returns undefined if there is no cookie set.
|
|
|
|
* @desc Get the collapsed state of the panel according to the cookie.
|
|
|
|
*/
|
|
|
|
getPersistedCollapsedState: function () {
|
|
|
|
var isCollapsed, cookieValue;
|
|
|
|
|
|
|
|
if (this.canSetCookie()) {
|
|
|
|
cookieValue = $.cookie('cms-panel-collapsed-' + this.attr('id'));
|
|
|
|
|
|
|
|
if (cookieValue !== void 0 && cookieValue !== null) {
|
|
|
|
isCollapsed = cookieValue === 'true';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return isCollapsed;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func setPersistedCollapsedState
|
|
|
|
* @param {boolean} newState - Pass true if you want the panel to be collapsed, false for expanded.
|
|
|
|
* @desc Set the collapsed value of the panel, stored in cookies.
|
|
|
|
*/
|
|
|
|
setPersistedCollapsedState: function (newState) {
|
|
|
|
if (this.canSetCookie()) {
|
|
|
|
$.cookie('cms-panel-collapsed-' + this.attr('id'), newState, { path: '/', expires: 31 });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func clearPersistedState
|
|
|
|
* @desc Remove the cookie responsible for maintaing the collapsed state.
|
|
|
|
*/
|
|
|
|
clearPersistedCollapsedState: function () {
|
|
|
|
if (this.canSetCookie()) {
|
|
|
|
$.cookie('cms-panel-collapsed-' + this.attr('id'), '', { path: '/', expires: -1 });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func getInitialCollapsedState
|
|
|
|
* @return {boolean} - Returns true if the the panel is collapsed, false if expanded.
|
|
|
|
* @desc Get the initial collapsed state of the panel. Check if a cookie value is set then fall back to checking CSS classes.
|
|
|
|
*/
|
|
|
|
getInitialCollapsedState: function () {
|
|
|
|
var isCollapsed = this.getPersistedCollapsedState();
|
|
|
|
|
|
|
|
// Fallback to getting the state from the default CSS class
|
|
|
|
if (isCollapsed === void 0) {
|
|
|
|
isCollapsed = this.hasClass('collapsed');
|
|
|
|
}
|
|
|
|
|
|
|
|
return isCollapsed;
|
|
|
|
},
|
|
|
|
|
2013-08-12 04:18:18 +02:00
|
|
|
onadd: function() {
|
2015-05-19 03:43:43 +02:00
|
|
|
var collapsedContent, container;
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
if(!this.find('.cms-panel-content').length) throw new Exception('Content panel for ".cms-panel" not found');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-10-29 02:01:06 +02:00
|
|
|
// Create default controls unless they already exist.
|
|
|
|
if(!this.find('.cms-panel-toggle').length) {
|
2015-05-19 03:43:43 +02:00
|
|
|
container = $("<div class='cms-panel-toggle south'></div>")
|
2011-10-29 02:01:06 +02:00
|
|
|
.append('<a class="toggle-expand" href="#"><span>»</span></a>')
|
|
|
|
.append('<a class="toggle-collapse" href="#"><span>«</span></a>');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-10-29 02:01:06 +02:00
|
|
|
this.append(container);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
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());
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-01-09 05:22:28 +01:00
|
|
|
// Assumes the collapsed width is indicated by the toggle, or by an optionally collapsed view
|
2015-05-19 03:43:43 +02:00
|
|
|
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-05-01 13:01:00 +02:00
|
|
|
// Toggle visibility
|
2015-05-19 03:43:43 +02:00
|
|
|
this.togglePanel(!this.getInitialCollapsedState(), true, false);
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2015-05-19 03:43:43 +02:00
|
|
|
|
2012-02-15 14:17:35 +01:00
|
|
|
/**
|
2015-05-19 03:43:43 +02:00
|
|
|
* @func togglePanel
|
|
|
|
* @param doExpand {boolean} - true to expand, false to collapse.
|
|
|
|
* @param silent {boolean} - true means that events won't be fired, which is useful for the component initialization phase.
|
|
|
|
* @param doSaveState - if false, the panel's state will not be persisted via cookies.
|
|
|
|
* @desc Toggle the expanded / collapsed state of the panel.
|
2012-02-15 14:17:35 +01:00
|
|
|
*/
|
2015-05-19 03:43:43 +02:00
|
|
|
togglePanel: function(doExpand, silent, doSaveState) {
|
|
|
|
var newWidth, collapsedContent;
|
|
|
|
|
2012-02-16 11:45:07 +01:00
|
|
|
if(!silent) {
|
2015-05-19 03:43:43 +02:00
|
|
|
this.trigger('beforetoggle.sspanel', doExpand);
|
|
|
|
this.trigger(doExpand ? 'beforeexpand' : 'beforecollapse');
|
2012-02-16 11:45:07 +01:00
|
|
|
}
|
2012-02-15 14:17:35 +01:00
|
|
|
|
2015-05-19 03:43:43 +02:00
|
|
|
this.toggleClass('collapsed', !doExpand);
|
|
|
|
newWidth = doExpand ? this.getWidthExpanded() : this.getWidthCollapsed();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.width(newWidth); // the content panel width always stays in "expanded state" to avoid floating elements
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
// If an alternative collapsed view exists, toggle it as well
|
2015-05-19 03:43:43 +02:00
|
|
|
collapsedContent = this.find('.cms-panel-content-collapsed');
|
2011-05-13 03:30:49 +02:00
|
|
|
if(collapsedContent.length) {
|
2015-05-19 03:43:43 +02:00
|
|
|
this.find('.cms-panel-content')[doExpand ? 'show' : 'hide']();
|
|
|
|
this.find('.cms-panel-content-collapsed')[doExpand ? 'hide' : 'show']();
|
2011-05-13 03:30:49 +02:00
|
|
|
}
|
2012-01-06 16:39:32 +01:00
|
|
|
|
2015-05-19 03:43:43 +02:00
|
|
|
if (doSaveState !== false) {
|
|
|
|
this.setPersistedCollapsedState(!doExpand);
|
|
|
|
}
|
2013-08-12 04:18:18 +02:00
|
|
|
|
2012-02-28 18:07:28 +01:00
|
|
|
// TODO Fix redraw order (inner to outer), and re-enable silent flag
|
|
|
|
// to avoid multiple expensive redraws on a single load.
|
|
|
|
// if(!silent) {
|
2015-05-19 03:43:43 +02:00
|
|
|
this.trigger('toggle', doExpand);
|
|
|
|
this.trigger(doExpand ? 'expand' : 'collapse');
|
2012-02-28 18:07:28 +01:00
|
|
|
// }
|
2011-05-13 03:30:49 +02:00
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
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);
|
|
|
|
},
|
2016-01-06 00:34:58 +01:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
2012-02-14 21:46:50 +01:00
|
|
|
|
2013-07-30 05:02:26 +02:00
|
|
|
$('.cms-panel.collapsed .cms-panel-toggle').entwine({
|
2012-02-14 21:46:50 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
this.expandPanel();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
$('.cms-panel *').entwine({
|
|
|
|
getPanel: function() {
|
|
|
|
return this.parents('.cms-panel:first');
|
|
|
|
}
|
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
$('.cms-panel .toggle-expand').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
e.preventDefault();
|
2015-05-19 03:43:43 +02:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.getPanel().expandPanel();
|
2015-05-19 03:43:43 +02:00
|
|
|
|
|
|
|
this._super(e);
|
2011-05-13 03:30:49 +02:00
|
|
|
}
|
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
$('.cms-panel .toggle-collapse').entwine({
|
|
|
|
onclick: function(e) {
|
2015-05-19 03:43:43 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2011-05-13 03:30:49 +02:00
|
|
|
this.getPanel().collapsePanel();
|
2015-05-19 03:43:43 +02:00
|
|
|
|
|
|
|
this._super(e);
|
2011-05-13 03:30:49 +02:00
|
|
|
}
|
|
|
|
});
|
2015-01-09 05:22:28 +01:00
|
|
|
|
|
|
|
$('.cms-content-tools.collapsed').entwine({
|
|
|
|
// Expand CMS' centre pane, when the pane itself is clicked somewhere
|
|
|
|
onclick: function(e) {
|
2015-08-24 07:36:29 +02:00
|
|
|
this.expandPanel();
|
2015-05-19 03:43:43 +02:00
|
|
|
this._super(e);
|
2015-01-09 05:22:28 +01:00
|
|
|
}
|
|
|
|
});
|
2011-05-13 03:30:49 +02:00
|
|
|
});
|
2012-05-14 01:43:36 +02:00
|
|
|
}(jQuery));
|