Sha256: b70bfd8466c511ac6b6240082183998856289f0be4fe302c9f2361f26c61a95e
Contents?: true
Size: 1.29 KB
Versions: 11
Compression:
Stored size: 1.29 KB
Contents
define( ['jquery', 'underscore', 'backbone', 'admin_it/views/base'], function($, _, Backbone, Base) { 'use strict'; var Menu = Base.extend({ events: { 'click .admin-it-main-menu-item': 'select' }, initialize: function(opts) { Base.prototype.initialize.apply(this, arguments); this.selected = null; this.listenTo(this.collection, 'reset add change', this.render); }, render: function() { if (!this.el) return this; this.$el.html(this.template.render( { items: this.collection.toJSON() }, { icon: this.app.templates.icon } )); return this; }, select: function(index) { if (!index) index = 0; var model = null; if (index instanceof $.Event) { index.preventDefault(); index = $(index.currentTarget).data('id'); } if (_.isNumber(index)) { if (index < 0 || index >= this.collection.length) index = 0; model = this.collection.at(index); } else if (_.isString(index)) { model = this.collection.get(index); } if (!model) return; console.log(this); this.$('.active').removeClass('active'); this.$('[data-id="' + model.id + '"]').addClass('active'); this.trigger('selected', model); } }); return Menu });
Version data entries
11 entries across 11 versions & 1 rubygems