-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathbreadcrumbs-view.js
More file actions
47 lines (44 loc) · 1.54 KB
/
breadcrumbs-view.js
File metadata and controls
47 lines (44 loc) · 1.54 KB
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
/**
* A Backbone view that renders breadcrumbs-type tiered navigation.
*
* Initialize the view by passing in the following attributes:
*
*~~~ javascript
* var view = new BreadcrumbsView({
* el: $('selector for element that will contain breadcrumbs'),
* model: new BreadcrumbsModel({
* breadcrumbs: [{url: '/', title: 'Overview'}]
* }),
* events: {
* 'click nav.breadcrumbs a.nav-item': function (event) {
* event.preventDefault();
* window.location = $(event.currentTarget).attr('href');
* }
* }
* });
*~~~
* @module BreadcrumbsView
*/
(function(define) {
'use strict';
define(['backbone', 'edx-ui-toolkit/js/utils/html-utils', 'text!./breadcrumbs.underscore'],
function(Backbone, HtmlUtils, breadcrumbsTemplate) {
var BreadcrumbsView = Backbone.View.extend({
initialize: function() {
this.template = HtmlUtils.template(breadcrumbsTemplate);
this.listenTo(this.model, 'change', this.render);
this.render();
},
render: function() {
var json = this.model.attributes;
HtmlUtils.setHtml(this.$el, this.template(json));
return this;
}
});
return BreadcrumbsView;
});
}).call(
this,
// Use the default 'define' function if available, else use 'RequireJS.define'
typeof define === 'function' && define.amd ? define : RequireJS.define
);