| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
|
|
| 'use strict';
|
|
|
| goog.provide('Blockly.Comment');
|
|
|
| goog.require('Blockly.Bubble');
|
| goog.require('Blockly.Events.BlockChange');
|
| goog.require('Blockly.Events.Ui');
|
| goog.require('Blockly.Icon');
|
| goog.require('goog.userAgent');
|
|
|
|
|
| |
| |
| |
| |
| |
|
|
| Blockly.Comment = function(block) {
|
| Blockly.Comment.superClass_.constructor.call(this, block);
|
| this.createIcon();
|
| };
|
| goog.inherits(Blockly.Comment, Blockly.Icon);
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.text_ = '';
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.width_ = 160;
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.height_ = 80;
|
|
|
| |
| |
| |
| |
|
|
| Blockly.Comment.prototype.drawIcon_ = function(group) {
|
|
|
| Blockly.utils.createSvgElement('circle',
|
| {'class': 'blocklyIconShape', 'r': '8', 'cx': '8', 'cy': '8'},
|
| group);
|
|
|
|
|
|
|
| Blockly.utils.createSvgElement('path',
|
| {
|
| 'class': 'blocklyIconSymbol',
|
| 'd': 'm6.8,10h2c0.003,-0.617 0.271,-0.962 0.633,-1.266 2.875,-2.405' +
|
| '0.607,-5.534 -3.765,-3.874v1.7c3.12,-1.657 3.698,0.118 2.336,1.25' +
|
| '-1.201,0.998 -1.201,1.528 -1.204,2.19z'
|
| },
|
| group);
|
|
|
| Blockly.utils.createSvgElement('rect',
|
| {
|
| 'class': 'blocklyIconSymbol',
|
| 'x': '6.8',
|
| 'y': '10.78',
|
| 'height': '2',
|
| 'width': '2'
|
| },
|
| group);
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.Comment.prototype.createEditor_ = function() {
|
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| this.foreignObject_ = Blockly.utils.createSvgElement('foreignObject',
|
| {'x': Blockly.Bubble.BORDER_WIDTH, 'y': Blockly.Bubble.BORDER_WIDTH},
|
| null);
|
| var body = document.createElementNS(Blockly.HTML_NS, 'body');
|
| body.setAttribute('xmlns', Blockly.HTML_NS);
|
| body.className = 'blocklyMinimalBody';
|
| var textarea = document.createElementNS(Blockly.HTML_NS, 'textarea');
|
| textarea.className = 'blocklyCommentTextarea';
|
| textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR');
|
| body.appendChild(textarea);
|
| this.textarea_ = textarea;
|
| this.foreignObject_.appendChild(body);
|
| Blockly.bindEventWithChecks_(textarea, 'mouseup', this, this.textareaFocus_);
|
|
|
| Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) {
|
| e.stopPropagation();
|
| });
|
| Blockly.bindEventWithChecks_(textarea, 'change', this, function(_e) {
|
| if (this.text_ != textarea.value) {
|
| Blockly.Events.fire(new Blockly.Events.BlockChange(
|
| this.block_, 'comment', null, this.text_, textarea.value));
|
| this.text_ = textarea.value;
|
| }
|
| });
|
| setTimeout(function() {
|
| textarea.focus();
|
| }, 0);
|
| return this.foreignObject_;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.updateEditable = function() {
|
| if (this.isVisible()) {
|
|
|
| this.setVisible(false);
|
| this.setVisible(true);
|
| }
|
|
|
| Blockly.Icon.prototype.updateEditable.call(this);
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.Comment.prototype.resizeBubble_ = function() {
|
| if (this.isVisible()) {
|
| var size = this.bubble_.getBubbleSize();
|
| var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH;
|
| this.foreignObject_.setAttribute('width', size.width - doubleBorderWidth);
|
| this.foreignObject_.setAttribute('height', size.height - doubleBorderWidth);
|
| this.textarea_.style.width = (size.width - doubleBorderWidth - 4) + 'px';
|
| this.textarea_.style.height = (size.height - doubleBorderWidth - 4) + 'px';
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.setVisible = function(visible) {
|
| if (visible == this.isVisible()) {
|
|
|
| return;
|
| }
|
| Blockly.Events.fire(
|
| new Blockly.Events.Ui(this.block_, 'commentOpen', !visible, visible));
|
| if ((!this.block_.isEditable() && !this.textarea_) || goog.userAgent.IE) {
|
|
|
|
|
|
|
|
|
| Blockly.Warning.prototype.setVisible.call(this, visible);
|
| return;
|
| }
|
|
|
| var text = this.getText();
|
| var size = this.getBubbleSize();
|
| if (visible) {
|
|
|
| this.bubble_ = new Blockly.Bubble(
|
| (this.block_.workspace),
|
| this.createEditor_(), this.block_.svgPath_,
|
| this.iconXY_, this.width_, this.height_);
|
|
|
| this.bubble_.setSvgId(this.block_.id);
|
| this.bubble_.registerResizeEvent(this.resizeBubble_.bind(this));
|
| this.updateColour();
|
| } else {
|
|
|
| this.bubble_.dispose();
|
| this.bubble_ = null;
|
| this.textarea_ = null;
|
| this.foreignObject_ = null;
|
| }
|
|
|
| this.setText(text);
|
| this.setBubbleSize(size.width, size.height);
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.Comment.prototype.textareaFocus_ = function(_e) {
|
|
|
|
|
|
|
|
|
| if (this.bubble_.promote_()) {
|
|
|
|
|
| this.textarea_.focus();
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.getBubbleSize = function() {
|
| if (this.isVisible()) {
|
| return this.bubble_.getBubbleSize();
|
| } else {
|
| return {width: this.width_, height: this.height_};
|
| }
|
| };
|
|
|
| |
| |
| |
| |
|
|
| Blockly.Comment.prototype.setBubbleSize = function(width, height) {
|
| if (this.textarea_) {
|
| this.bubble_.setBubbleSize(width, height);
|
| } else {
|
| this.width_ = width;
|
| this.height_ = height;
|
| }
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.getText = function() {
|
| return this.textarea_ ? this.textarea_.value : this.text_;
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.Comment.prototype.setText = function(text) {
|
| if (this.text_ != text) {
|
| Blockly.Events.fire(new Blockly.Events.BlockChange(
|
| this.block_, 'comment', null, this.text_, text));
|
| this.text_ = text;
|
| }
|
| if (this.textarea_) {
|
| this.textarea_.value = text;
|
| }
|
| };
|
|
|
| |
| |
|
|
| Blockly.Comment.prototype.dispose = function() {
|
| if (Blockly.Events.isEnabled()) {
|
| this.setText('');
|
| }
|
| this.block_.comment = null;
|
| Blockly.Icon.prototype.dispose.call(this);
|
| };
|
|
|