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, tutorial) {
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>');
22 var tutorialHolder = $('<div/>').attr('data-toggle', 'tutorial').attr('data-tutorial', tutorial.index)
23 .attr('data-placement', 'bottom').attr('data-content', tutorial.text);
24 this.dom.append(tutorialHolder);
28 var GutterGroupView = function(gutterView, group) {
29 this.gutterView = gutterView;
33 this.dom = $(gutterBoxTemplate);
35 this.dom.on('click', function() {
36 if(!this.dom.hasClass('focused')) {
37 var canvas = this.group.meta.canvas;
38 canvas.setCurrentElement(this.group.meta);
42 this.group.views.forEach(function(view) {
43 this.onViewAdded(view);
46 this.group.on('viewAdded', this.onViewAdded, this);
47 this.group.on('focusToggled', this.onFocusToggled, this);
48 this.group.on('removed', this.remove, this);
50 $.extend(GutterGroupView.prototype, {
52 this.group.off('viewAdded', this.onViewAdded);
53 this.group.off('focusToggled', this.onFocusToggled);
54 this.group.off('removed', this.removed);
57 onViewAdded: function(view) {
58 this.views.push(view);
59 this.dom.append(view.dom);
62 this.dom.addClass('focused');
63 this.views.forEach(function(view) {
64 if(view.onActivated) {
75 var ViewGroup = function(params, gutter, meta) {
79 this.view = $(gutterBoxTemplate);
82 $.extend(ViewGroup.prototype, Backbone.Events, {
83 getOffsetHint: function() {
84 return _.isFunction(this.params.offsetHint) ? this.params.offsetHint() : this.params.offsetHint;
86 addView: function(view) {
87 this.views.push(view);
88 this.trigger('viewAdded', view);
91 this.gutter.show(this);
94 this.trigger('removed');
99 var Gutter = function() {
102 _.extend(Gutter.prototype, Backbone.Events, {
103 createViewGroup: function(params, meta) {
104 return new ViewGroup(params, this, meta);
106 show: function(group) {
107 this.trigger('show', group);
116 GutterView: GutterView,
117 GutterGroupView: GutterGroupView