2011-05-15 05:43:21 +02:00
|
|
|
(function($) {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-15 05:43:21 +02:00
|
|
|
$.entwine('ss', function($){
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
/**
|
2016-01-06 00:34:58 +01:00
|
|
|
* Vertical CMS menu with two levels, built from a nested unordered list.
|
2011-05-26 12:02:44 +02:00
|
|
|
* The (optional) second level is collapsible, hiding its children.
|
|
|
|
* The whole menu (including second levels) is collapsible as well,
|
|
|
|
* exposing only a preview for every menu item in order to save space.
|
|
|
|
* In this "preview/collapsed" mode, the secondary menu hovers over the menu item,
|
|
|
|
* rather than expanding it.
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2011-05-26 12:02:44 +02:00
|
|
|
* Example:
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2011-05-26 12:02:44 +02:00
|
|
|
* <ul class="cms-menu-list">
|
|
|
|
* <li><a href="#">Item 1</a></li>
|
|
|
|
* <li class="current opened">
|
|
|
|
* <a href="#">Item 2</a>
|
|
|
|
* <ul>
|
|
|
|
* <li class="current opened"><a href="#">Item 2.1</a></li>
|
|
|
|
* <li><a href="#">Item 2.2</a></li>
|
|
|
|
* </ul>
|
|
|
|
* </li>
|
|
|
|
* </ul>
|
2016-01-06 00:34:58 +01:00
|
|
|
*
|
2011-12-15 12:23:32 +01:00
|
|
|
* Custom Events:
|
|
|
|
* - 'select': Fires when a menu item is selected (on any level).
|
2011-05-26 12:02:44 +02:00
|
|
|
*/
|
2012-02-14 21:45:38 +01:00
|
|
|
$('.cms-panel.cms-menu').entwine({
|
2015-05-19 03:43:43 +02:00
|
|
|
togglePanel: function(doExpand, silent, doSaveState) {
|
2012-02-14 21:45:38 +01:00
|
|
|
//apply or unapply the flyout formatting, should only apply to cms-menu-list when the current collapsed panal is the cms menu.
|
|
|
|
$('.cms-menu-list').children('li').each(function(){
|
2015-05-19 03:43:43 +02:00
|
|
|
if (doExpand) { //expand
|
2012-02-14 21:45:38 +01:00
|
|
|
$(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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-19 03:43:43 +02:00
|
|
|
this.toggleFlyoutState(doExpand);
|
2012-02-14 21:45:38 +01:00
|
|
|
|
2015-05-19 03:43:43 +02:00
|
|
|
this._super(doExpand, silent, doSaveState);
|
2012-02-14 21:45:38 +01:00
|
|
|
},
|
|
|
|
toggleFlyoutState: function(bool) {
|
|
|
|
if (bool) { //expand
|
|
|
|
//show the flyout
|
|
|
|
$('.collapsed').find('li').show();
|
|
|
|
|
|
|
|
//hide all the flyout-indicator
|
|
|
|
$('.cms-menu-list').find('.child-flyout-indicator').hide();
|
|
|
|
} 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();
|
|
|
|
});
|
|
|
|
|
|
|
|
//show all the flyout-indicators
|
|
|
|
var par = $('.cms-menu-list ul.collapsed-flyout').parent();
|
2012-02-21 17:46:58 +01:00
|
|
|
if (par.children('.child-flyout-indicator').length === 0) par.append('<span class="child-flyout-indicator"></span>').fadeIn();
|
2012-02-14 21:45:38 +01:00
|
|
|
par.children('.child-flyout-indicator').fadeIn();
|
|
|
|
}
|
2015-05-19 03:43:43 +02:00
|
|
|
},
|
|
|
|
siteTreePresent: function () {
|
|
|
|
return $('#cms-content-tools-CMSMain').length > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func getPersistedStickyState
|
|
|
|
* @return {boolean|undefined} - Returns true if the menu is sticky, false if unsticky. Returns undefined if there is no cookie set.
|
|
|
|
* @desc Get the sticky state of the menu according to the cookie.
|
|
|
|
*/
|
|
|
|
getPersistedStickyState: function () {
|
|
|
|
var persistedState, cookieValue;
|
|
|
|
|
|
|
|
if ($.cookie !== void 0) {
|
|
|
|
cookieValue = $.cookie('cms-menu-sticky');
|
|
|
|
|
|
|
|
if (cookieValue !== void 0 && cookieValue !== null) {
|
|
|
|
persistedState = cookieValue === 'true';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return persistedState;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func setPersistedStickyState
|
|
|
|
* @param {boolean} isSticky - Pass true if you want the panel to be sticky, false for unsticky.
|
|
|
|
* @desc Set the collapsed value of the panel, stored in cookies.
|
|
|
|
*/
|
|
|
|
setPersistedStickyState: function (isSticky) {
|
|
|
|
if ($.cookie !== void 0) {
|
|
|
|
$.cookie('cms-menu-sticky', isSticky, { path: '/', expires: 31 });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func getEvaluatedCollapsedState
|
|
|
|
* @return {boolean} - Returns true if the menu should be collapsed, false if expanded.
|
|
|
|
* @desc Evaluate whether the menu should be collapsed.
|
|
|
|
* The basic rule is "If the SiteTree (middle column) is present, collapse the menu, otherwise expand the menu".
|
|
|
|
* This reason behind this is to give the content area more real estate when the SiteTree is present.
|
|
|
|
* The user may wish to override this automatic behaviour and have the menu expanded or collapsed at all times.
|
|
|
|
* So unlike manually toggling the menu, the automatic behaviour never updates the menu's cookie value.
|
|
|
|
* Here we use the manually set state and the automatic behaviour to evaluate what the collapsed state should be.
|
|
|
|
*/
|
|
|
|
getEvaluatedCollapsedState: function () {
|
|
|
|
var shouldCollapse,
|
|
|
|
manualState = this.getPersistedCollapsedState(),
|
|
|
|
menuIsSticky = $('.cms-menu').getPersistedStickyState(),
|
|
|
|
automaticState = this.siteTreePresent();
|
|
|
|
|
|
|
|
if (manualState === void 0) {
|
|
|
|
// There is no manual state, use automatic state.
|
|
|
|
shouldCollapse = automaticState;
|
|
|
|
} else if (manualState !== automaticState && menuIsSticky) {
|
|
|
|
// The manual and automatic statea conflict, use manual state.
|
|
|
|
shouldCollapse = manualState;
|
|
|
|
} else {
|
|
|
|
// Use automatic state.
|
|
|
|
shouldCollapse = automaticState;
|
|
|
|
}
|
|
|
|
|
|
|
|
return shouldCollapse;
|
|
|
|
},
|
|
|
|
|
|
|
|
onadd: function () {
|
|
|
|
var self = this;
|
|
|
|
|
2015-05-25 06:06:47 +02:00
|
|
|
setTimeout(function () {
|
|
|
|
// Use a timeout so this happens after the redraw.
|
|
|
|
// Triggering a toggle before redraw will result in an incorrect
|
|
|
|
// menu 'expanded width' being calculated when then menu
|
|
|
|
// is added in a collapsed state.
|
|
|
|
self.togglePanel(!self.getEvaluatedCollapsedState(), false, false);
|
|
|
|
}, 0);
|
|
|
|
|
2015-05-19 03:43:43 +02:00
|
|
|
// Setup automatic expand / collapse behaviour.
|
|
|
|
$(window).on('ajaxComplete', function (e) {
|
|
|
|
setTimeout(function () { // Use a timeout so this happens after the redraw
|
|
|
|
self.togglePanel(!self.getEvaluatedCollapsedState(), false, false);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
|
|
|
|
this._super();
|
2012-02-17 15:04:58 +01:00
|
|
|
}
|
2012-02-14 21:45:38 +01:00
|
|
|
});
|
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
$('.cms-menu-list').entwine({
|
|
|
|
onmatch: function() {
|
2011-06-09 03:49:52 +02:00
|
|
|
var self = this;
|
2011-12-20 17:06:40 +01:00
|
|
|
|
2011-09-19 22:27:34 +02:00
|
|
|
// Select default element (which might reveal children in hidden parents)
|
|
|
|
this.find('li.current').select();
|
2011-10-29 02:01:06 +02:00
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
this.updateItems();
|
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
this._super();
|
2011-12-14 18:01:03 +01:00
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
|
|
|
updateMenuFromResponse: function(xhr) {
|
|
|
|
var controller = xhr.getResponseHeader('X-Controller');
|
|
|
|
if(controller) {
|
2015-07-15 16:33:00 +02:00
|
|
|
var item = this.find('li#Menu-' + controller.replace(/\\/g, '-').replace(/[^a-zA-Z0-9\-_:.]+/, ''));
|
2012-06-12 12:48:08 +02:00
|
|
|
if(!item.hasClass('current')) item.select();
|
|
|
|
}
|
|
|
|
this.updateItems();
|
|
|
|
},
|
|
|
|
|
|
|
|
'from .cms-container': {
|
|
|
|
onafterstatechange: function(e, data){
|
|
|
|
this.updateMenuFromResponse(data.xhr);
|
|
|
|
},
|
|
|
|
onaftersubmitform: function(e, data){
|
|
|
|
this.updateMenuFromResponse(data.xhr);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
'from .cms-edit-form': {
|
|
|
|
onrelodeditform: function(e, data){
|
|
|
|
this.updateMenuFromResponse(data.xmlhttp);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
getContainingPanel: function(){
|
|
|
|
return this.closest('.cms-panel');
|
|
|
|
},
|
|
|
|
|
|
|
|
fromContainingPanel: {
|
|
|
|
ontoggle: function(e){
|
|
|
|
this.toggleClass('collapsed', $(e.target).hasClass('collapsed'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
updateItems: function() {
|
|
|
|
// Hide "edit page" commands unless the section is activated
|
|
|
|
var editPageItem = this.find('#Menu-CMSMain');
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
editPageItem[editPageItem.is('.current') ? 'show' : 'hide']();
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-20 14:10:39 +01:00
|
|
|
// Update the menu links to reflect the page ID if the page has changed the URL.
|
2011-12-17 03:48:47 +01:00
|
|
|
var currentID = $('.cms-content input[name=ID]').val();
|
|
|
|
if(currentID) {
|
2011-12-20 17:06:40 +01:00
|
|
|
this.find('li').each(function() {
|
|
|
|
if($.isFunction($(this).setRecordID)) $(this).setRecordID(currentID);
|
2011-12-17 03:48:47 +01:00
|
|
|
});
|
|
|
|
}
|
2011-05-26 12:02:44 +02:00
|
|
|
}
|
|
|
|
});
|
2012-02-14 21:45:38 +01: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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
//slight delay to prevent flyout closing from "sloppy mouse movement"
|
|
|
|
$('.cms-menu-list li').hoverIntent(function(){$(this).toggleFlyout(true);},function(){$(this).toggleFlyout(false);});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
$('.cms-menu-list .toggle').entwine({
|
2011-05-20 01:38:36 +02:00
|
|
|
onclick: function(e) {
|
2011-05-26 12:02:44 +02:00
|
|
|
this.getMenuItem().toggle();
|
2011-05-20 01:38:36 +02:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2011-05-15 05:43:21 +02:00
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
$('.cms-menu-list li').entwine({
|
2012-01-05 17:03:38 +01:00
|
|
|
onmatch: function() {
|
|
|
|
if(this.find('ul').length) {
|
|
|
|
this.find('a:first').append('<span class="toggle-children"><span class="toggle-children-icon"></span></span>');
|
|
|
|
}
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2012-01-05 17:03:38 +01:00
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2011-05-26 12:02:44 +02:00
|
|
|
toggle: function() {
|
|
|
|
this[this.hasClass('opened') ? 'close' : 'open']();
|
|
|
|
},
|
2012-01-05 17:03:38 +01:00
|
|
|
/**
|
|
|
|
* "Open" is just a visual state, and unrelated to "current".
|
|
|
|
* More than one item can be open at the same time.
|
|
|
|
*/
|
2011-05-26 12:02:44 +02:00
|
|
|
open: function() {
|
|
|
|
var parent = this.getMenuItem();
|
|
|
|
if(parent) parent.open();
|
|
|
|
this.addClass('opened').find('ul').show();
|
2012-01-05 17:03:38 +01:00
|
|
|
this.find('.toggle-children').addClass('opened');
|
2011-05-26 12:02:44 +02:00
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
this.removeClass('opened').find('ul').hide();
|
2012-01-05 17:03:38 +01:00
|
|
|
this.find('.toggle-children').removeClass('opened');
|
2011-05-26 12:02:44 +02:00
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
var parent = this.getMenuItem();
|
|
|
|
this.addClass('current').open();
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
// Remove "current" class from all siblings and their children
|
|
|
|
this.siblings().removeClass('current').close();
|
|
|
|
this.siblings().find('li').removeClass('current');
|
2012-01-05 17:03:38 +01:00
|
|
|
if(parent) {
|
|
|
|
var parentSiblings = parent.siblings();
|
|
|
|
parent.addClass('current');
|
|
|
|
parentSiblings.removeClass('current').close();
|
|
|
|
parentSiblings.find('li').removeClass('current').close();
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
this.getMenu().updateItems();
|
2011-12-15 12:23:32 +01:00
|
|
|
|
2011-07-15 10:36:59 +02:00
|
|
|
this.trigger('select');
|
2011-05-26 12:02:44 +02:00
|
|
|
}
|
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
$('.cms-menu-list *').entwine({
|
|
|
|
getMenu: function() {
|
|
|
|
return this.parents('.cms-menu-list:first');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
$('.cms-menu-list li *').entwine({
|
|
|
|
getMenuItem: function() {
|
|
|
|
return this.parents('li:first');
|
|
|
|
}
|
|
|
|
});
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
/**
|
|
|
|
* Both primary and secondary nav.
|
|
|
|
*/
|
|
|
|
$('.cms-menu-list li a').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
// Only catch left clicks, in order to allow opening in tabs.
|
|
|
|
// Ignore external links, fallback to standard link behaviour
|
2012-03-30 15:22:40 +02:00
|
|
|
var isExternal = $.path.isExternal(this.attr('href'));
|
|
|
|
if(e.which > 1 || isExternal) return;
|
2013-10-02 08:06:54 +02:00
|
|
|
|
2016-01-06 00:34:58 +01:00
|
|
|
// if the developer has this to open in a new window, handle
|
2013-10-02 08:06:54 +02:00
|
|
|
// that
|
|
|
|
if(this.attr('target') == "_blank") {
|
|
|
|
return;
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
e.preventDefault();
|
2011-12-15 12:23:32 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
var item = this.getMenuItem();
|
2011-12-14 16:13:13 +01:00
|
|
|
|
|
|
|
var url = this.attr('href');
|
2012-03-30 15:22:40 +02:00
|
|
|
if(!isExternal) url = $('base').attr('href') + url;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
var children = item.find('li');
|
|
|
|
if(children.length) {
|
|
|
|
children.first().find('a').click();
|
2011-12-14 16:13:13 +01:00
|
|
|
} else {
|
2011-12-15 12:23:32 +01:00
|
|
|
// Load URL, but give the loading logic an opportunity to veto the action
|
|
|
|
// (e.g. because of unsaved changes)
|
2016-01-06 00:34:58 +01:00
|
|
|
if(!$('.cms-container').loadPanel(url)) return false;
|
2011-05-26 12:02:44 +02:00
|
|
|
}
|
2011-12-15 12:23:32 +01:00
|
|
|
|
|
|
|
item.select();
|
2011-05-15 05:43:21 +02:00
|
|
|
}
|
|
|
|
});
|
2011-12-20 17:06:40 +01:00
|
|
|
|
2012-01-05 17:03:38 +01:00
|
|
|
$('.cms-menu-list li .toggle-children').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
var li = this.closest('li');
|
|
|
|
li.toggle();
|
|
|
|
return false; // prevent wrapping link event to fire
|
|
|
|
}
|
|
|
|
});
|
2012-10-08 04:02:01 +02:00
|
|
|
|
|
|
|
$('.cms .profile-link').entwine({
|
|
|
|
onclick: function() {
|
|
|
|
$('.cms-container').loadPanel(this.attr('href'));
|
2016-01-06 00:34:58 +01:00
|
|
|
$('.cms-menu-list li').removeClass('current').close();
|
2012-10-08 04:02:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2015-05-19 03:43:43 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggles the manual override of the left menu's automatic expand / collapse behaviour.
|
|
|
|
*/
|
|
|
|
$('.cms-menu .sticky-toggle').entwine({
|
|
|
|
|
|
|
|
onadd: function () {
|
|
|
|
var isSticky = $('.cms-menu').getPersistedStickyState() ? true : false;
|
|
|
|
|
|
|
|
this.toggleCSS(isSticky);
|
|
|
|
this.toggleIndicator(isSticky);
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func toggleCSS
|
|
|
|
* @param {boolean} isSticky - The current state of the menu.
|
|
|
|
* @desc Toggles the 'active' CSS class of the element.
|
|
|
|
*/
|
|
|
|
toggleCSS: function (isSticky) {
|
|
|
|
this[isSticky ? 'addClass' : 'removeClass']('active');
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @func toggleIndicator
|
|
|
|
* @param {boolean} isSticky - The current state of the menu.
|
|
|
|
* @desc Updates the indicator's text based on the sticky state of the menu.
|
|
|
|
*/
|
|
|
|
toggleIndicator: function (isSticky) {
|
|
|
|
this.next('.sticky-status-indicator').text(isSticky ? 'fixed' : 'auto');
|
|
|
|
},
|
|
|
|
|
|
|
|
onclick: function () {
|
|
|
|
var $menu = this.closest('.cms-menu'),
|
|
|
|
persistedCollapsedState = $menu.getPersistedCollapsedState(),
|
|
|
|
persistedStickyState = $menu.getPersistedStickyState(),
|
|
|
|
newStickyState = persistedStickyState === void 0 ? !this.hasClass('active') : !persistedStickyState;
|
|
|
|
|
|
|
|
// Update the persisted collapsed state
|
|
|
|
if (persistedCollapsedState === void 0) {
|
|
|
|
// If there is no persisted menu state currently set, then set it to the menu's current state.
|
|
|
|
// This will be the case if the user has never manually expanded or collapsed the menu,
|
|
|
|
// or the menu has previously been made unsticky.
|
|
|
|
$menu.setPersistedCollapsedState($menu.hasClass('collapsed'));
|
|
|
|
} else if (persistedCollapsedState !== void 0 && newStickyState === false) {
|
|
|
|
// If there is a persisted state and the menu has been made unsticky, remove the persisted state.
|
|
|
|
$menu.clearPersistedCollapsedState();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Persist the sticky state of the menu
|
|
|
|
$menu.setPersistedStickyState(newStickyState);
|
|
|
|
|
|
|
|
this.toggleCSS(newStickyState);
|
|
|
|
this.toggleIndicator(newStickyState);
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
2011-05-15 05:43:21 +02:00
|
|
|
});
|
2012-05-11 06:07:07 +02:00
|
|
|
}(jQuery));
|