cloud-blocks
Version:
Cloud Blocks is a library for building scratch computing interfaces with Luxrobo MODI.
150 lines (134 loc) • 3.87 kB
JavaScript
/**
* @license
* Visual Blocks Editor
*
* Copyright 2011 Google Inc.
* https://developers.google.com/blockly/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @fileoverview Toolbox from whence to create blocks.
* @author fraser@google.com (Neil Fraser)
*/
'use strict';
goog.provide('Blockly.CodeSketchToolbox');
goog.require('Blockly.CodeSketchVerticalFlyout');
/**
* overrides createFlyout_, position
*/
/**
* Class for a Toolbox.
* Creates the toolbox's DOM.
* @param {!Blockly.Workspace} workspace The workspace in which to create new
* blocks.
* @constructor
*/
Blockly.CodeSketchToolbox = function (workspace) {
Blockly.CodeSketchToolbox.superClass_.constructor.call(this, workspace);
};
goog.inherits(Blockly.CodeSketchToolbox, Blockly.Toolbox);
/**
* Create and configure a flyout based on the main workspace's options.
* @private
*/
Blockly.CodeSketchToolbox.prototype.createFlyout_ = function () {
var workspace = this.workspace_;
var options = {
disabledPatternId: workspace.options.disabledPatternId,
parentWorkspace: workspace,
RTL: workspace.RTL,
oneBasedIndex: workspace.options.oneBasedIndex,
horizontalLayout: workspace.horizontalLayout,
toolboxPosition: workspace.options.toolboxPosition,
stackGlowFilterId: workspace.options.stackGlowFilterId
};
if (workspace.horizontalLayout) {
this.flyout_ = new Blockly.HorizontalFlyout(options);
} else {
this.flyout_ = new Blockly.CodeSketchVerticalFlyout(options);
}
this.flyout_.setParentToolbox(this);
goog.dom.insertSiblingAfter(
this.flyout_.createDom('svg'),
this.workspace_.getParentSvg()
);
this.flyout_.init(workspace);
};
/**
* Move the toolbox to the edge.
*/
Blockly.CodeSketchToolbox.prototype.position = function () {
var treeDiv = this.HtmlDiv;
if (!treeDiv) {
// Not initialized yet.
return;
}
var svg = this.workspace_.getParentSvg();
var svgSize = Blockly.svgSize(svg);
if (this.horizontalLayout_) {
treeDiv.style.left = '0';
treeDiv.style.height = 'auto';
treeDiv.style.width = svgSize.width + 'px';
this.height = treeDiv.offsetHeight;
if (this.toolboxPosition == Blockly.TOOLBOX_AT_TOP) {
// Top
treeDiv.style.top = '0';
} else {
// Bottom
treeDiv.style.bottom = '0';
}
} else {
if (this.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
// Right
treeDiv.style.right = '0';
} else {
// Left
treeDiv.style.left = '0';
}
/**
* @author Tom
*/
var videoOptions = this.getVideoOptions();
if (videoOptions) {
var videoHeight = videoOptions.videoHeight;
var collapseHeight = videoOptions.collapseHeight;
this.setHeight(videoHeight + collapseHeight);
} else {
this.setHeight();
}
}
this.flyout_.position();
};
/**
* @author Tom
*/
Blockly.CodeSketchToolbox.prototype.getVideoOptions = function () {
var workspaceOptions = this.workspace_.options;
if (workspaceOptions) {
return workspaceOptions.videoOptions;
} else {
return undefined;
}
};
/**
* @author Tom
*/
Blockly.CodeSketchToolbox.prototype.setHeight = function (height = 0) {
var treeDiv = this.HtmlDiv;
if (!treeDiv) {
// Not initialized yet.
return;
}
treeDiv.style.height = `-webkit-calc(100% - ${height}px)`;
};