2011-05-15 05:43:21 +02:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
$.entwine('ss', function($){
|
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
/**
|
|
|
|
* Vertical CMS menu with two levels, built from a nested unordered list.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
|
|
|
* <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>
|
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
|
|
|
*/
|
|
|
|
$('.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
|
|
|
|
|
|
|
var updateMenuFromResponse = function(xhr) {
|
|
|
|
var controller = xhr.getResponseHeader('X-Controller');
|
2011-07-15 10:36:59 +02:00
|
|
|
if(controller) {
|
|
|
|
var item = self.find('li#Menu-' + controller);
|
|
|
|
if(!item.hasClass('current')) item.select();
|
|
|
|
}
|
2011-12-14 18:01:03 +01:00
|
|
|
self.updateItems();
|
2011-12-20 17:06:40 +01:00
|
|
|
};
|
|
|
|
$('.cms-container').live('afterstatechange', function(e, data) {
|
|
|
|
updateMenuFromResponse(data.xhr);
|
|
|
|
});
|
|
|
|
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
|
|
|
updateMenuFromResponse(data.xmlhttp);
|
2011-06-09 03:49:52 +02:00
|
|
|
});
|
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
// Sync collapsed state with parent panel
|
|
|
|
this.parents('.cms-panel:first').bind('toggle', function(e) {
|
|
|
|
self.toggleClass('collapsed', $(this).hasClass('collapsed'));
|
|
|
|
});
|
|
|
|
|
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
|
|
|
},
|
|
|
|
|
|
|
|
updateItems: function() {
|
|
|
|
// Hide "edit page" commands unless the section is activated
|
|
|
|
var editPageItem = this.find('#Menu-CMSMain');
|
2011-12-17 03:48:47 +01:00
|
|
|
|
2011-12-14 18:01:03 +01:00
|
|
|
editPageItem[editPageItem.is('.current') ? 'show' : 'hide']();
|
2011-12-17 03:48:47 +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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.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
|
|
|
});
|
|
|
|
|
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>');
|
|
|
|
}
|
|
|
|
},
|
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();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
if(e.which > 1 || this.is(':external')) return;
|
|
|
|
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');
|
|
|
|
if(this.is(':internal')) url = $('base').attr('href') + url;
|
2011-05-26 12:02:44 +02:00
|
|
|
|
|
|
|
var children = item.find('li');
|
2011-12-17 04:06:56 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
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)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
});
|
2011-12-20 17:06:40 +01:00
|
|
|
|
|
|
|
$('.cms-menu-list #Menu-CMSPageSettingsController, .cms-menu-list #Menu-CMSPageHistoryController, .cms-menu-list #Menu-CMSPageEditController').entwine({
|
|
|
|
setRecordID: function(id) {
|
2012-01-05 17:03:38 +01:00
|
|
|
// Only applies to edit forms relating to page elements
|
|
|
|
if(!$('.cms-content').is('.CMSMain')) return;
|
|
|
|
|
2011-12-20 17:06:40 +01:00
|
|
|
var link = this.find('a:first'), href = link.attr("href").split('/')
|
|
|
|
// Assumes that current ID will always be the last URL segment (and not a query parameter)
|
|
|
|
href[href.length -1] = id;
|
|
|
|
link.attr('href', href.join('/'));
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
$('.cms-menu-list #Menu-CMSPageAddController').entwine({
|
|
|
|
setRecordID: function(id) {
|
2012-01-05 17:03:38 +01:00
|
|
|
// Only applies to edit forms relating to page elements
|
|
|
|
if(!$('.cms-content').is('.CMSMain')) return;
|
|
|
|
|
|
|
|
var link = this.find('a:first'), href = link.attr('href');
|
|
|
|
if(!href.match(/\?/)) href += '?';
|
|
|
|
link.attr('href', href.replace(/\?.*$/, '?ParentID=' + id));
|
2011-12-20 17:06:40 +01:00
|
|
|
}
|
|
|
|
});
|
2011-05-15 05:43:21 +02:00
|
|
|
|
|
|
|
});
|
2011-12-14 16:13:13 +01:00
|
|
|
|
2011-05-26 12:02:44 +02:00
|
|
|
// Internal Helper
|
|
|
|
$.expr[':'].internal = function(obj){return obj.href.match(/^mailto\:/) || (obj.hostname == location.hostname);};
|
|
|
|
$.expr[':'].external = function(obj){return !$(obj).is(':internal')};
|
2011-05-15 05:43:21 +02:00
|
|
|
}(jQuery));
|