-
Notifications
You must be signed in to change notification settings - Fork 4
/
Navigation.js
74 lines (59 loc) · 1.9 KB
/
Navigation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
define( function( require ) {
/**
* This view will draw the nav menu...
*/
var Backbone = require( 'backbone' ),
_ = require( 'underscore' ),
AppInstance;
return Backbone.View.extend( {
/**
* @property {String} nav this will be a nav element
*/
tagName: 'ul',
/**
*
* @returns {Object}
*/
events: function() {
return {
'click a': 'onAnchorClick'
}
},
/**
* @chainable
* @returns {Backbone.View}
*/
render: function() {
var template = _.template( '<li><a href="<%= url %>"><%= label %></a></li>' ),
links = [
{ url: '#', label: 'Home' },
{ url: '#red', label: 'Red Module' },
{ url: '#blue', label: 'Blue Module' }
];
_.each(
links,
function( link ) {
this.$el.append( template( link ) );
},
this
);
return this;
},
/**
*
* @param {Event} event
* @returns {Boolean}
*/
onAnchorClick: function( event ) {
// May not be compatible with older IE versions
var href = event.currentTarget.href,
hash = '#' + _.last( href.split( '#' ) );
AppInstance = require( 'AppInstance' );
// Let Backbone route this for you. Triggering forces
// the router to load a new page
AppInstance.Router.navigate( hash, { trigger: true } );
// returning false cancels the event
return false;
}
} );
} );