@@ -39,6 +39,27 @@ Blockly.ZoomControls = function(workspace) {
39
39
this . workspace_ = workspace ;
40
40
} ;
41
41
42
+ /**
43
+ * Zoom in icon path.
44
+ * @type {string }
45
+ * @private
46
+ */
47
+ Blockly . ZoomControls . prototype . ZOOM_IN_PATH = 'zoom-in.svg' ;
48
+
49
+ /**
50
+ * Zoom out icon path.
51
+ * @type {string }
52
+ * @private
53
+ */
54
+ Blockly . ZoomControls . prototype . ZOOM_OUT_PATH = 'zoom-out.svg' ;
55
+
56
+ /**
57
+ * Zoom reset icon path.
58
+ * @type {string }
59
+ * @private
60
+ */
61
+ Blockly . ZoomControls . prototype . ZOOM_RESET_PATH = 'zoom-reset.svg' ;
62
+
42
63
/**
43
64
* Width of the zoom controls.
44
65
* @type {number }
@@ -51,7 +72,14 @@ Blockly.ZoomControls.prototype.WIDTH_ = 32;
51
72
* @type {number }
52
73
* @private
53
74
*/
54
- Blockly . ZoomControls . prototype . HEIGHT_ = 110 ;
75
+ Blockly . ZoomControls . prototype . HEIGHT_ = 112 ;
76
+
77
+ /**
78
+ * Distance between each zoom control.
79
+ * @type {number }
80
+ * @private
81
+ */
82
+ Blockly . ZoomControls . prototype . MARGIN_BETWEEN_ = 8 ;
55
83
56
84
/**
57
85
* Distance between zoom controls and bottom edge of workspace.
@@ -95,92 +123,98 @@ Blockly.ZoomControls.prototype.top_ = 0;
95
123
Blockly . ZoomControls . prototype . createDom = function ( ) {
96
124
var workspace = this . workspace_ ;
97
125
/* Here's the markup that will be generated:
98
- <g class="blocklyZoom">
99
- <clippath id="blocklyZoomoutClipPath837493">
100
- <rect width="32" height="32" y="77"></rect>
101
- </clippath>
102
- <image width="96" height="124" x="-64" y="-15" xlink:href="media/sprites.png"
103
- clip-path="url(#blocklyZoomoutClipPath837493)"></image>
104
- <clippath id="blocklyZoominClipPath837493">
105
- <rect width="32" height="32" y="43"></rect>
106
- </clippath>
107
- <image width="96" height="124" x="-32" y="-49" xlink:href="media/sprites.png"
108
- clip-path="url(#blocklyZoominClipPath837493)"></image>
109
- <clippath id="blocklyZoomresetClipPath837493">
110
- <rect width="32" height="32"></rect>
111
- </clippath>
112
- <image width="96" height="124" y="-92" xlink:href="media/sprites.png"
113
- clip-path="url(#blocklyZoomresetClipPath837493)"></image>
126
+ <g class="blocklyZoom" transform="translate(822,594)">
127
+ <image width="32" height="32" y="0" xlink:href="../media/zoom-in.svg">
128
+ </image>
129
+ <image width="32" height="32" y="40" xlink:href="../media/zoom-out.svg">
130
+ </image>
131
+ <image width="32" height="32" y="80" xlink:href="../media/zoom-reset.svg">
132
+ </image>
114
133
</g>
115
134
*/
116
- this . svgGroup_ = Blockly . utils . createSvgElement ( 'g' ,
117
- { 'class' : 'blocklyZoom' } , null ) ;
135
+ this . svgGroup_ = Blockly . utils . createSvgElement (
136
+ 'g' ,
137
+ { 'class' : 'blocklyZoom' } ,
138
+ null
139
+ ) ;
118
140
var rnd = String ( Math . random ( ) ) . substring ( 2 ) ;
119
141
120
- var clip = Blockly . utils . createSvgElement ( 'clipPath' ,
121
- { 'id' : 'blocklyZoomoutClipPath' + rnd } ,
122
- this . svgGroup_ ) ;
123
- Blockly . utils . createSvgElement ( 'rect' ,
124
- { 'width' : 32 , 'height' : 32 , 'y' : 77 } ,
125
- clip ) ;
126
- var zoomoutSvg = Blockly . utils . createSvgElement ( 'image' ,
127
- { 'width' : Blockly . SPRITE . width ,
128
- 'height' : Blockly . SPRITE . height , 'x' : - 64 ,
129
- 'y' : - 15 ,
130
- 'clip-path' : 'url(#blocklyZoomoutClipPath' + rnd + ')' } ,
131
- this . svgGroup_ ) ;
132
- zoomoutSvg . setAttributeNS ( 'http://www.w3.org/1999/xlink' , 'xlink:href' ,
133
- workspace . options . pathToMedia + Blockly . SPRITE . url ) ;
134
-
135
- var clip = Blockly . utils . createSvgElement ( 'clipPath' ,
136
- { 'id' : 'blocklyZoominClipPath' + rnd } ,
137
- this . svgGroup_ ) ;
138
- Blockly . utils . createSvgElement ( 'rect' ,
139
- { 'width' : 32 , 'height' : 32 , 'y' : 43 } ,
140
- clip ) ;
141
- var zoominSvg = Blockly . utils . createSvgElement ( 'image' ,
142
- { 'width' : Blockly . SPRITE . width ,
143
- 'height' : Blockly . SPRITE . height ,
144
- 'x' : - 32 ,
145
- 'y' : - 49 ,
146
- 'clip-path' : 'url(#blocklyZoominClipPath' + rnd + ')' } ,
147
- this . svgGroup_ ) ;
148
- zoominSvg . setAttributeNS ( 'http://www.w3.org/1999/xlink' , 'xlink:href' ,
149
- workspace . options . pathToMedia + Blockly . SPRITE . url ) ;
150
-
151
- var clip = Blockly . utils . createSvgElement ( 'clipPath' ,
152
- { 'id' : 'blocklyZoomresetClipPath' + rnd } ,
153
- this . svgGroup_ ) ;
154
- Blockly . utils . createSvgElement ( 'rect' ,
155
- { 'width' : 32 , 'height' : 32 } ,
156
- clip ) ;
157
- var zoomresetSvg = Blockly . utils . createSvgElement ( 'image' ,
158
- { 'width' : Blockly . SPRITE . width ,
159
- 'height' : Blockly . SPRITE . height , 'y' : - 92 ,
160
- 'clip-path' : 'url(#blocklyZoomresetClipPath' + rnd + ')' } ,
161
- this . svgGroup_ ) ;
162
- zoomresetSvg . setAttributeNS ( 'http://www.w3.org/1999/xlink' , 'xlink:href' ,
163
- workspace . options . pathToMedia + Blockly . SPRITE . url ) ;
142
+ /**
143
+ * Zoom in control.
144
+ * @type {SVGElement }
145
+ */
146
+ var zoominSvg = Blockly . utils . createSvgElement (
147
+ 'image' ,
148
+ {
149
+ 'width' : this . WIDTH_ ,
150
+ 'height' : this . WIDTH_ ,
151
+ 'y' : 0
152
+ } ,
153
+ this . svgGroup_
154
+ ) ;
155
+ zoominSvg . setAttributeNS (
156
+ 'http://www.w3.org/1999/xlink' ,
157
+ 'xlink:href' ,
158
+ workspace . options . pathToMedia + this . ZOOM_IN_PATH
159
+ ) ;
160
+
161
+ /**
162
+ * Zoom out control.
163
+ * @type {SVGElement }
164
+ */
165
+ var zoomoutSvg = Blockly . utils . createSvgElement (
166
+ 'image' ,
167
+ {
168
+ 'width' : this . WIDTH_ ,
169
+ 'height' : this . WIDTH_ ,
170
+ 'y' : ( this . WIDTH_ * 1 ) + ( this . MARGIN_BETWEEN_ * 1 )
171
+ } ,
172
+ this . svgGroup_
173
+ ) ;
174
+ zoomoutSvg . setAttributeNS (
175
+ 'http://www.w3.org/1999/xlink' ,
176
+ 'xlink:href' ,
177
+ workspace . options . pathToMedia + this . ZOOM_OUT_PATH
178
+ ) ;
179
+
180
+ /**
181
+ * Zoom reset control.
182
+ * @type {SVGElement }
183
+ */
184
+ var zoomresetSvg = Blockly . utils . createSvgElement (
185
+ 'image' ,
186
+ {
187
+ 'width' : this . WIDTH_ ,
188
+ 'height' : this . WIDTH_ ,
189
+ 'y' : ( this . WIDTH_ * 2 ) + ( this . MARGIN_BETWEEN_ * 2 )
190
+ } ,
191
+ this . svgGroup_
192
+ ) ;
193
+ zoomresetSvg . setAttributeNS (
194
+ 'http://www.w3.org/1999/xlink' ,
195
+ 'xlink:href' ,
196
+ workspace . options . pathToMedia + this . ZOOM_RESET_PATH
197
+ ) ;
164
198
165
199
// Attach event listeners.
166
- Blockly . bindEventWithChecks_ ( zoomresetSvg , 'mousedown' , null , function ( e ) {
200
+ Blockly . bindEventWithChecks_ ( zoominSvg , 'mousedown' , null , function ( e ) {
167
201
workspace . markFocused ( ) ;
168
- workspace . setScale ( workspace . options . zoomOptions . startScale ) ;
169
- workspace . scrollCenter ( ) ;
202
+ workspace . zoomCenter ( 1 ) ;
170
203
Blockly . Touch . clearTouchIdentifier ( ) ; // Don't block future drags.
171
204
e . stopPropagation ( ) ; // Don't start a workspace scroll.
172
205
e . preventDefault ( ) ; // Stop double-clicking from selecting text.
173
206
} ) ;
174
- Blockly . bindEventWithChecks_ ( zoominSvg , 'mousedown' , null , function ( e ) {
207
+ Blockly . bindEventWithChecks_ ( zoomoutSvg , 'mousedown' , null , function ( e ) {
175
208
workspace . markFocused ( ) ;
176
- workspace . zoomCenter ( 1 ) ;
209
+ workspace . zoomCenter ( - 1 ) ;
177
210
Blockly . Touch . clearTouchIdentifier ( ) ; // Don't block future drags.
178
211
e . stopPropagation ( ) ; // Don't start a workspace scroll.
179
212
e . preventDefault ( ) ; // Stop double-clicking from selecting text.
180
213
} ) ;
181
- Blockly . bindEventWithChecks_ ( zoomoutSvg , 'mousedown' , null , function ( e ) {
214
+ Blockly . bindEventWithChecks_ ( zoomresetSvg , 'mousedown' , null , function ( e ) {
182
215
workspace . markFocused ( ) ;
183
- workspace . zoomCenter ( - 1 ) ;
216
+ workspace . setScale ( workspace . options . zoomOptions . startScale ) ;
217
+ workspace . scrollCenter ( ) ;
184
218
Blockly . Touch . clearTouchIdentifier ( ) ; // Don't block future drags.
185
219
e . stopPropagation ( ) ; // Don't start a workspace scroll.
186
220
e . preventDefault ( ) ; // Stop double-clicking from selecting text.
0 commit comments