scratch – Blame information for rev 84

Subversion Repositories:
Rev:
Rev Author Line No. Line
84 office 1 DrawingBoard.Control.DrawingMode = DrawingBoard.Control.extend({
2  
3 name: 'drawingmode',
4  
5 defaults: {
6 pencil: true,
7 eraser: true,
8 filler: true
9 },
10  
11 initialize: function() {
12  
13 this.prevMode = this.board.getMode();
14  
15 $.each(["pencil", "eraser", "filler"], $.proxy(function(k, value) {
16 if (this.opts[value]) {
17 this.$el.append('<button class="drawing-board-control-drawingmode-' + value + '-button" data-mode="' + value + '"></button>');
18 }
19 }, this));
20  
21 this.$el.on('click', 'button[data-mode]', $.proxy(function(e) {
22 var value = $(e.currentTarget).attr('data-mode');
23 var mode = this.board.getMode();
24 if (mode !== value) this.prevMode = mode;
25 var newMode = mode === value ? this.prevMode : value;
26 this.board.setMode( newMode );
27 e.preventDefault();
28 }, this));
29  
30 this.board.ev.bind('board:mode', $.proxy(function(mode) {
31 this.toggleButtons(mode);
32 }, this));
33  
34 this.toggleButtons( this.board.getMode() );
35 },
36  
37 toggleButtons: function(mode) {
38 this.$el.find('button[data-mode]').each(function(k, item) {
39 var $item = $(item);
40 $item.toggleClass('active', mode === $item.attr('data-mode'));
41 });
42 }
43  
44 });