control.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. DrawingBoard.Control = function(drawingBoard, opts) {
  2. this.board = drawingBoard;
  3. this.opts = $.extend({}, this.defaults, opts);
  4. this.$el = $(document.createElement('div')).addClass('drawing-board-control');
  5. if (this.name)
  6. this.$el.addClass('drawing-board-control-' + this.name);
  7. this.board.ev.bind('board:reset', $.proxy(this.onBoardReset, this));
  8. this.initialize.apply(this, arguments);
  9. return this;
  10. };
  11. DrawingBoard.Control.prototype = {
  12. name: '',
  13. defaults: {},
  14. initialize: function() {
  15. },
  16. addToBoard: function() {
  17. this.board.addControl(this);
  18. },
  19. onBoardReset: function(opts) {
  20. }
  21. };
  22. //extend directly taken from backbone.js
  23. DrawingBoard.Control.extend = function(protoProps, staticProps) {
  24. var parent = this;
  25. var child;
  26. if (protoProps && protoProps.hasOwnProperty('constructor')) {
  27. child = protoProps.constructor;
  28. } else {
  29. child = function(){ return parent.apply(this, arguments); };
  30. }
  31. $.extend(child, parent, staticProps);
  32. var Surrogate = function(){ this.constructor = child; };
  33. Surrogate.prototype = parent.prototype;
  34. child.prototype = new Surrogate();
  35. if (protoProps) $.extend(child.prototype, protoProps);
  36. child.__super__ = parent.prototype;
  37. return child;
  38. };