123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 'use strict';
- goog.provide('Blockly.ZoomControls');
- goog.require('Blockly.Touch');
- goog.require('goog.dom');
- Blockly.ZoomControls = function(workspace) {
- this.workspace_ = workspace;
- };
- Blockly.ZoomControls.prototype.WIDTH_ = 32;
- Blockly.ZoomControls.prototype.HEIGHT_ = 110;
- Blockly.ZoomControls.prototype.MARGIN_BOTTOM_ = 20;
- Blockly.ZoomControls.prototype.MARGIN_SIDE_ = 20;
- Blockly.ZoomControls.prototype.svgGroup_ = null;
- Blockly.ZoomControls.prototype.left_ = 0;
- Blockly.ZoomControls.prototype.top_ = 0;
- Blockly.ZoomControls.prototype.createDom = function() {
- var workspace = this.workspace_;
-
- this.svgGroup_ = Blockly.createSvgElement('g',
- {'class': 'blocklyZoom'}, null);
- var rnd = String(Math.random()).substring(2);
- var clip = Blockly.createSvgElement('clipPath',
- {'id': 'blocklyZoomoutClipPath' + rnd},
- this.svgGroup_);
- Blockly.createSvgElement('rect',
- {'width': 32, 'height': 32, 'y': 77},
- clip);
- var zoomoutSvg = Blockly.createSvgElement('image',
- {'width': Blockly.SPRITE.width,
- 'height': Blockly.SPRITE.height, 'x': -64,
- 'y': -15,
- 'clip-path': 'url(#blocklyZoomoutClipPath' + rnd + ')'},
- this.svgGroup_);
- zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
- workspace.options.pathToMedia + Blockly.SPRITE.url);
- var clip = Blockly.createSvgElement('clipPath',
- {'id': 'blocklyZoominClipPath' + rnd},
- this.svgGroup_);
- Blockly.createSvgElement('rect',
- {'width': 32, 'height': 32, 'y': 43},
- clip);
- var zoominSvg = Blockly.createSvgElement('image',
- {'width': Blockly.SPRITE.width,
- 'height': Blockly.SPRITE.height,
- 'x': -32,
- 'y': -49,
- 'clip-path': 'url(#blocklyZoominClipPath' + rnd + ')'},
- this.svgGroup_);
- zoominSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
- workspace.options.pathToMedia + Blockly.SPRITE.url);
- var clip = Blockly.createSvgElement('clipPath',
- {'id': 'blocklyZoomresetClipPath' + rnd},
- this.svgGroup_);
- Blockly.createSvgElement('rect',
- {'width': 32, 'height': 32},
- clip);
- var zoomresetSvg = Blockly.createSvgElement('image',
- {'width': Blockly.SPRITE.width,
- 'height': Blockly.SPRITE.height, 'y': -92,
- 'clip-path': 'url(#blocklyZoomresetClipPath' + rnd + ')'},
- this.svgGroup_);
- zoomresetSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
- workspace.options.pathToMedia + Blockly.SPRITE.url);
-
- Blockly.bindEventWithChecks_(zoomresetSvg, 'mousedown', null, function(e) {
- workspace.markFocused();
- workspace.setScale(workspace.options.zoomOptions.startScale);
- workspace.scrollCenter();
- Blockly.Touch.clearTouchIdentifier();
- e.stopPropagation();
- e.preventDefault();
- });
- Blockly.bindEventWithChecks_(zoominSvg, 'mousedown', null, function(e) {
- workspace.markFocused();
- workspace.zoomCenter(1);
- Blockly.Touch.clearTouchIdentifier();
- e.stopPropagation();
- e.preventDefault();
- });
- Blockly.bindEventWithChecks_(zoomoutSvg, 'mousedown', null, function(e) {
- workspace.markFocused();
- workspace.zoomCenter(-1);
- Blockly.Touch.clearTouchIdentifier();
- e.stopPropagation();
- e.preventDefault();
- });
- return this.svgGroup_;
- };
- Blockly.ZoomControls.prototype.init = function(bottom) {
- this.bottom_ = this.MARGIN_BOTTOM_ + bottom;
- return this.bottom_ + this.HEIGHT_;
- };
- Blockly.ZoomControls.prototype.dispose = function() {
- if (this.svgGroup_) {
- goog.dom.removeNode(this.svgGroup_);
- this.svgGroup_ = null;
- }
- this.workspace_ = null;
- };
- Blockly.ZoomControls.prototype.position = function() {
- var metrics = this.workspace_.getMetrics();
- if (!metrics) {
-
- return;
- }
- if (this.workspace_.RTL) {
- this.left_ = this.MARGIN_SIDE_ + Blockly.Scrollbar.scrollbarThickness;
- if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
- this.left_ += metrics.flyoutWidth;
- if (this.workspace_.toolbox_) {
- this.left_ += metrics.absoluteLeft;
- }
- }
- } else {
- this.left_ = metrics.viewWidth + metrics.absoluteLeft -
- this.WIDTH_ - this.MARGIN_SIDE_ - Blockly.Scrollbar.scrollbarThickness;
- if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
- this.left_ -= metrics.flyoutWidth;
- }
- }
- this.top_ = metrics.viewHeight + metrics.absoluteTop -
- this.HEIGHT_ - this.bottom_;
- if (metrics.toolboxPosition == Blockly.TOOLBOX_AT_BOTTOM) {
- this.top_ -= metrics.flyoutHeight;
- }
- this.svgGroup_.setAttribute('transform',
- 'translate(' + this.left_ + ',' + this.top_ + ')');
- };
|