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>
|
|
|
|
*/
|
|
|
|
$('.cms-menu-list').entwine({
|
|
|
|
onmatch: function() {
|
2011-06-09 03:49:52 +02:00
|
|
|
var self = this;
|
|
|
|
|
2011-07-05 14:34:31 +02:00
|
|
|
$('.cms-container').bind('afterstatechange', function(e, data) {
|
2011-06-09 03:49:52 +02:00
|
|
|
var controller = data.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-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-05-26 12:02:44 +02:00
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.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({
|
|
|
|
toggle: function() {
|
|
|
|
this[this.hasClass('opened') ? 'close' : 'open']();
|
|
|
|
},
|
|
|
|
open: function() {
|
|
|
|
var parent = this.getMenuItem();
|
|
|
|
if(parent) parent.open();
|
|
|
|
this.addClass('opened').find('ul').show();
|
|
|
|
},
|
|
|
|
close: function() {
|
|
|
|
this.removeClass('opened').find('ul').hide();
|
|
|
|
},
|
|
|
|
select: function() {
|
|
|
|
var parent = this.getMenuItem();
|
|
|
|
this.addClass('current').open();
|
|
|
|
// Remove "current" class from all siblings and their children
|
|
|
|
this.siblings().removeClass('current').close();
|
|
|
|
this.siblings().find('li').removeClass('current');
|
|
|
|
if(parent) parent.addClass('current').siblings().removeClass('current');
|
2011-07-15 10:36:59 +02:00
|
|
|
|
|
|
|
this.trigger('select');
|
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();
|
|
|
|
|
|
|
|
// Expand this, and collapse all other items
|
|
|
|
var item = this.getMenuItem();
|
|
|
|
item.select();
|
|
|
|
|
|
|
|
var children = item.find('li');
|
|
|
|
if(children.length) {
|
|
|
|
children.first().find('a').click();
|
|
|
|
} else {
|
2011-06-09 03:49:52 +02:00
|
|
|
// Active menu item is set based on X-Controller ajax header,
|
|
|
|
// which matches one class on the menu
|
2011-05-26 12:02:44 +02:00
|
|
|
window.History.pushState({}, '', this.attr('href'));
|
|
|
|
}
|
2011-05-15 05:43:21 +02: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));
|