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

Version Path
admin_it-1.3.8 client/src/js/views/menu.js
admin_it-1.3.7 client/src/js/views/menu.js
admin_it-1.3.6 client/src/js/views/menu.js
admin_it-1.3.5 client/src/js/views/menu.js
admin_it-1.3.4 client/src/js/views/menu.js
admin_it-1.3.3 client/src/js/views/menu.js
admin_it-1.3.2 client/src/js/views/menu.js
admin_it-1.3.1 client/src/js/views/menu.js
admin_it-1.3.0 client/src/js/views/menu.js
admin_it-1.2.8 client/src/js/views/menu.js
admin_it-1.2.7 client/src/js/views/menu.js