2013-06-25 01:41:59 +02:00
|
|
|
|
'use strict';
|
|
|
|
|
define(['marionette'], function (Marionette) {
|
|
|
|
|
var MainMenuView = Marionette.ItemView.extend({
|
2013-02-27 04:31:35 +01:00
|
|
|
|
events: {
|
|
|
|
|
'click a': 'onClick'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onClick: function (event) {
|
|
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
var target = $(event.target);
|
|
|
|
|
|
|
|
|
|
//look down for <a/>
|
2013-04-23 06:55:08 +02:00
|
|
|
|
var href = event.target.getAttribute('href');
|
2013-02-27 04:31:35 +01:00
|
|
|
|
|
|
|
|
|
//if couldn't find it look up
|
|
|
|
|
if (!href && target.parent('a') && target.parent('a')[0]) {
|
|
|
|
|
|
|
|
|
|
var linkElement = target.parent('a')[0];
|
|
|
|
|
|
|
|
|
|
href = linkElement.getAttribute('href');
|
|
|
|
|
this.setActive(linkElement);
|
|
|
|
|
} else {
|
|
|
|
|
this.setActive(event.target);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setActive: function (element) {
|
2013-04-23 02:35:04 +02:00
|
|
|
|
//Todo: Set active on first load
|
2013-02-27 04:31:35 +01:00
|
|
|
|
this.$('a').removeClass('active');
|
|
|
|
|
$(element).addClass('active');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
this.setElement($('#main-menu-region'));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2013-06-07 01:05:06 +02:00
|
|
|
|
return new MainMenuView();
|
2013-02-27 04:31:35 +01:00
|
|
|
|
|
|
|
|
|
});
|