scratch – Blame information for rev 92
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
84 | office | 1 | DrawingBoard.Control.Navigation = DrawingBoard.Control.extend({ |
2 | |||
3 | name: 'navigation', |
||
4 | |||
5 | defaults: { |
||
6 | back: true, |
||
7 | forward: true, |
||
8 | reset: true |
||
9 | }, |
||
10 | |||
11 | initialize: function() { |
||
12 | var el = ''; |
||
13 | if (this.opts.back) el += '<button class="drawing-board-control-navigation-back">←</button>'; |
||
14 | if (this.opts.forward) el += '<button class="drawing-board-control-navigation-forward">→</button>'; |
||
15 | if (this.opts.reset) el += '<button class="drawing-board-control-navigation-reset">×</button>'; |
||
16 | this.$el.append(el); |
||
17 | |||
18 | if (this.opts.back) { |
||
19 | var $back = this.$el.find('.drawing-board-control-navigation-back'); |
||
20 | this.board.ev.bind('historyNavigation', $.proxy(this.updateBack, this, $back)); |
||
21 | this.$el.on('click', '.drawing-board-control-navigation-back', $.proxy(function(e) { |
||
22 | this.board.goBackInHistory(); |
||
23 | e.preventDefault(); |
||
24 | }, this)); |
||
25 | |||
26 | this.updateBack($back); |
||
27 | } |
||
28 | |||
29 | if (this.opts.forward) { |
||
30 | var $forward = this.$el.find('.drawing-board-control-navigation-forward'); |
||
31 | this.board.ev.bind('historyNavigation', $.proxy(this.updateForward, this, $forward)); |
||
32 | this.$el.on('click', '.drawing-board-control-navigation-forward', $.proxy(function(e) { |
||
33 | this.board.goForthInHistory(); |
||
34 | e.preventDefault(); |
||
35 | }, this)); |
||
36 | |||
37 | this.updateForward($forward); |
||
38 | } |
||
39 | |||
40 | if (this.opts.reset) { |
||
41 | this.$el.on('click', '.drawing-board-control-navigation-reset', $.proxy(function(e) { |
||
42 | this.board.reset({ background: true }); |
||
43 | e.preventDefault(); |
||
44 | }, this)); |
||
45 | } |
||
46 | }, |
||
47 | |||
48 | updateBack: function($back) { |
||
49 | if (this.board.history.canUndo()) { |
||
50 | $back.removeAttr('disabled'); |
||
51 | } else { |
||
52 | $back.attr('disabled', 'disabled'); |
||
53 | } |
||
54 | }, |
||
55 | |||
56 | updateForward: function($forward) { |
||
57 | if (this.board.history.canRedo()) { |
||
58 | $forward.removeAttr('disabled'); |
||
59 | } else { |
||
60 | $forward.attr('disabled', 'disabled'); |
||
61 | } |
||
62 | } |
||
63 | }); |