1 define(function(require) {
 
   5 var $ = require('libs/jquery'),
 
   6     _ = require('libs/underscore'),
 
   7     Backbone = require('libs/backbone'),
 
   8     gutterBoxTemplate = require('libs/text!./gutterBox.html');
 
  11 var GutterView = function(gutter) {
 
  12     gutter.on('show', function(group) {
 
  14             this.groupView.remove();
 
  16         this.groupView = new GutterGroupView(this, group);
 
  17         this.dom.append(this.groupView.dom);
 
  18         this.groupView.dom.css({top: group.getOffsetHint()});
 
  19         this.groupView.show();
 
  21     this.dom = $('<div class="gutter"></div>');
 
  25 var GutterGroupView = function(gutterView, group) {
 
  26     this.gutterView = gutterView;
 
  30     this.dom = $(gutterBoxTemplate);
 
  32     this.dom.on('click', function() {
 
  33         if(!this.dom.hasClass('focused')) {
 
  34             var canvas = this.group.meta.canvas;
 
  35             canvas.setCurrentElement(this.group.meta);
 
  39     this.group.views.forEach(function(view) {
 
  40         this.onViewAdded(view);
 
  43     this.group.on('viewAdded', this.onViewAdded, this);
 
  44     this.group.on('focusToggled', this.onFocusToggled, this);
 
  45     this.group.on('removed', this.remove, this);
 
  47 $.extend(GutterGroupView.prototype, {
 
  49         this.group.off('viewAdded', this.onViewAdded);
 
  50         this.group.off('focusToggled', this.onFocusToggled);
 
  51         this.group.off('removed', this.removed);
 
  54     onViewAdded: function(view) {
 
  55         this.views.push(view);
 
  56         this.dom.append(view.dom);
 
  59         this.dom.addClass('focused');
 
  60         this.views.forEach(function(view) {
 
  61             if(view.onActivated) {
 
  72 var ViewGroup = function(params, gutter, meta) {
 
  76     this.view = $(gutterBoxTemplate);
 
  79 $.extend(ViewGroup.prototype, Backbone.Events, {
 
  80     getOffsetHint: function() {
 
  81         return _.isFunction(this.params.offsetHint) ? this.params.offsetHint() : this.params.offsetHint;
 
  83     addView: function(view) {
 
  84         this.views.push(view);
 
  85         this.trigger('viewAdded', view);
 
  88         this.gutter.show(this);
 
  91         this.trigger('removed');
 
  96 var Gutter = function() {
 
  99 _.extend(Gutter.prototype, Backbone.Events, {
 
 100     createViewGroup: function(params, meta) {
 
 101         return new ViewGroup(params, this, meta);
 
 103     show: function(group) {
 
 104         this.trigger('show', group);
 
 113     GutterView: GutterView,
 
 114     GutterGroupView: GutterGroupView