Zoom.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. // wrapped by build app
  2. define("dojox/drawing/ui/dom/Zoom", ["dijit","dojo","dojox","dojo/require!dojox/drawing/plugins/_Plugin"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.drawing.ui.dom.Zoom");
  4. dojo.require("dojox.drawing.plugins._Plugin");
  5. dojox.drawing.ui.dom.Zoom = dojox.drawing.util.oo.declare(
  6. // NOTE:
  7. // dojox.drawing.ui.dom.Zoom is DEPRECATED.
  8. // This was a temporary DOM solution. Use the non-dom
  9. // tools for Toobar and Plugins.
  10. //
  11. // summary:
  12. // A plugin that allows for zooming the canvas in and out. An
  13. // action-tool is added to the toolbar with plus, minus and 100%
  14. // buttons.
  15. // example:
  16. // | <div dojoType="dojox.drawing.Toolbar" drawingId="drawingNode" class="drawingToolbar vertical">
  17. // | <div tool="dojox.drawing.tools.Line" selected="true">Line</div>
  18. // | <div plugin="dojox.drawing.ui.dom.Zoom" options="{zoomInc:.1,minZoom:.5,maxZoom:2}">Zoom</div>
  19. // | </div>
  20. //
  21. dojox.drawing.plugins._Plugin,
  22. function(options){
  23. var cls = options.node.className;
  24. var txt = options.node.innerHTML;
  25. this.domNode = dojo.create("div", {id:"btnZoom", "class":"toolCombo"}, options.node, "replace");
  26. this.makeButton("ZoomIn", this.topClass);
  27. this.makeButton("Zoom100", this.midClass);
  28. this.makeButton("ZoomOut", this.botClass);
  29. },
  30. {
  31. type:"dojox.drawing.ui.dom.Zoom",
  32. //
  33. // zoomInc: Float
  34. // The amount of zoom that will occur upon each click.
  35. zoomInc:.1,
  36. //
  37. // maxZoom: Number
  38. // The maximum the canvas can be zoomed in. 10 = 1000%
  39. maxZoom:10,
  40. //
  41. // minZoom: Float
  42. // The most the canvas can be zoomed out. .1 = 10%
  43. minZoom:.1,
  44. //
  45. // zoomFactor: [readonly] Float
  46. // The current zoom amount
  47. zoomFactor:1,
  48. //
  49. // baseClass: String
  50. // The CSS class added to the Toolbar buttons
  51. baseClass:"drawingButton",
  52. //
  53. // topClass: String
  54. // The CSS class added to the top (or left) Toolbar button
  55. topClass:"toolComboTop",
  56. //
  57. // midClass: String
  58. // The CSS class added to the middle Toolbar button
  59. midClass:"toolComboMid",
  60. //
  61. // botClass: String
  62. // The CSS class added to the bottom (or right) Toolbar button
  63. botClass:"toolComboBot",
  64. //
  65. makeButton: function(name, cls){
  66. // summary:
  67. // Internal. Creates one of the buttons in the zoom-button set.
  68. //
  69. var node = dojo.create("div", {id:"btn"+name, "class":this.baseClass+" "+cls,
  70. innerHTML:'<div title="Zoom In" class="icon icon'+name+'"></div>'}, this.domNode);
  71. dojo.connect(document, "mouseup", function(evt){
  72. dojo.stopEvent(evt);
  73. dojo.removeClass(node, "active");
  74. });
  75. dojo.connect(node, "mouseup", this, function(evt){
  76. dojo.stopEvent(evt);
  77. dojo.removeClass(node, "active");
  78. this["on"+name](); // this is what calls the methods below
  79. });
  80. dojo.connect(node, "mouseover", function(evt){
  81. dojo.stopEvent(evt);
  82. dojo.addClass(node, "hover");
  83. });
  84. dojo.connect(node, "mousedown", this, function(evt){
  85. dojo.stopEvent(evt);
  86. dojo.addClass(node, "active");
  87. });
  88. dojo.connect(node, "mouseout", this, function(evt){
  89. dojo.stopEvent(evt);
  90. dojo.removeClass(node, "hover");
  91. });
  92. },
  93. onZoomIn: function(/*Mouse Event*/evt){
  94. // summary:
  95. // Handles zoom in.
  96. //
  97. this.zoomFactor += this.zoomInc;
  98. this.zoomFactor = Math.min(this.zoomFactor, this.maxZoom);
  99. this.canvas.setZoom(this.zoomFactor);
  100. this.mouse.setZoom(this.zoomFactor);
  101. },
  102. onZoom100: function(/*Mouse Event*/evt){
  103. // summary:
  104. // Zooms to 100%
  105. //
  106. this.zoomFactor = 1;
  107. this.canvas.setZoom(this.zoomFactor);
  108. this.mouse.setZoom(this.zoomFactor);
  109. },
  110. onZoomOut: function(/*Mouse Event*/evt){
  111. // summary:
  112. // Handles zoom out.
  113. //
  114. this.zoomFactor -= this.zoomInc;
  115. this.zoomFactor = Math.max(this.zoomFactor, this.minZoom);
  116. this.canvas.setZoom(this.zoomFactor);
  117. this.mouse.setZoom(this.zoomFactor);
  118. }
  119. }
  120. );
  121. //dojox.drawing.register(dojox.drawing.plugins.tools.Pan, "plugin");
  122. });