navigation.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. DrawingBoard.Control.Navigation = DrawingBoard.Control.extend({
  2. name: 'navigation',
  3. defaults: {
  4. back: true,
  5. forward: true,
  6. reset: true,
  7. uploadimg: false
  8. },
  9. initialize: function() {
  10. var el = '';
  11. if (this.opts.back) el += '<button class="drawing-board-control-navigation-back">&larr;</button>';
  12. if (this.opts.forward) el += '<button class="drawing-board-control-navigation-forward">&rarr;</button>';
  13. if (this.opts.reset) el += '<button class="drawing-board-control-navigation-reset">&times;</button>';
  14. if (this.opts.uploadimg) el += '<button class="drawing-board-control-navigation-uploadimg">上传图片</button>';
  15. this.$el.append(el);
  16. if (this.opts.back) {
  17. var $back = this.$el.find('.drawing-board-control-navigation-back');
  18. this.board.ev.bind('historyNavigation', $.proxy(function(pos) {
  19. if (pos === 1)
  20. $back.attr('disabled', 'disabled');
  21. else
  22. $back.removeAttr('disabled');
  23. }, this));
  24. this.$el.on('click', '.drawing-board-control-navigation-back', $.proxy(function(e) {
  25. this.board.goBackInHistory();
  26. e.preventDefault();
  27. }, this));
  28. }
  29. if (this.opts.forward) {
  30. var $forward = this.$el.find('.drawing-board-control-navigation-forward');
  31. this.board.ev.bind('historyNavigation', $.proxy(function(pos) {
  32. if (pos === this.board.history.values.length)
  33. $forward.attr('disabled', 'disabled');
  34. else
  35. $forward.removeAttr('disabled');
  36. }, this));
  37. this.$el.on('click', '.drawing-board-control-navigation-forward', $.proxy(function(e) {
  38. this.board.goForthInHistory();
  39. e.preventDefault();
  40. }, this));
  41. }
  42. if (this.opts.reset) {
  43. this.$el.on('click', '.drawing-board-control-navigation-reset', $.proxy(function(e) {
  44. this.board.reset({ background: true });
  45. e.preventDefault();
  46. }, this));
  47. }
  48. if (this.opts.uploadimg) {
  49. this.$el.on('click', '.drawing-board-control-navigation-uploadimg', $.proxy(function(e) {
  50. this.board.uploadImg();
  51. e.preventDefault();
  52. }, this));
  53. }
  54. }
  55. });