DaveGoosem
8/13/2012 - 1:44 AM

sample module no comments

sample module no comments

;(function($) { 
  window.ProjectName.SomeModule = window.ProjectName.SomeModule || window.ProjectName.BaseModule(function() {
    var $el;
    var _self;
    var _template = _.template('<div><%= name %></div>');

    var _people = [
      { name: 'Fry' },
      { name: 'Bender' },
      { name: 'Leela' }
    ];
    var _currentPerson = 0;

    var _getCurrentPerson() {
      return _people[_currentPerson];
    }

    return {
      init: function() {
        _self = this;
        $el = $('#some-module');
        this.attachEvents();
        this.render();
      },
      render: function() {
        var person = _getCurrentPerson();
        var html = _template(person);
        $el.html(html);
      },
      attachEvents: function() {
        $el.on('click', '.some-link', this.events.clickSomeLink);
        $el.on('change', '.some-input', this.events.changeSomeInput);
      },
      events: {
        clickSomeLink: function(e) {
          e.preventDefault();
          console.log('Some link has been clicked');
        },
        changeSomeInput: function(e) {
          console.log('Some input has been changed');
        }
      },
      people: _people
    }
  }());
})(jQuery);