Skip to content

Commit

Permalink
Revert "De-singleton Blockly. Part 1."
Browse files Browse the repository at this point in the history
This reverts commit 3122c8a.
  • Loading branch information
NeilFraser committed Apr 8, 2015
1 parent 29976c4 commit 6d1df4d
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 164 deletions.
4 changes: 2 additions & 2 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ Blockly.Block.prototype.getFieldValue = function(name) {
* @deprecated December 2013
*/
Blockly.Block.prototype.getTitleValue = function(name) {
console.warn('Deprecated call to getTitleValue, use getFieldValue instead.');
console.log('Deprecated call to getTitleValue, use getFieldValue instead.');
return this.getFieldValue(name);
};

Expand All @@ -644,7 +644,7 @@ Blockly.Block.prototype.setFieldValue = function(newValue, name) {
* @deprecated December 2013
*/
Blockly.Block.prototype.setTitleValue = function(newValue, name) {
console.warn('Deprecated call to setTitleValue, use setFieldValue instead.');
console.log('Deprecated call to setTitleValue, use setFieldValue instead.');
this.setFieldValue(newValue, name);
};

Expand Down
9 changes: 4 additions & 5 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ Blockly.BlockSvg.prototype.showHelp_ = function() {
* @private
*/
Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
if (this.workspace.options.readOnly || !this.contextMenu) {
if (Blockly.readOnly || !this.contextMenu) {
return;
}
// Save the current block in a variable for use in closures.
Expand All @@ -505,8 +505,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
}
options.push(duplicateOption);

if (this.isEditable() && !this.collapsed_ &&
this.workspace.options.comments) {
if (this.isEditable() && !this.collapsed_ && Blockly.comments) {
// Option to add/remove a comment.
var commentOption = {enabled: true};
if (this.comment) {
Expand Down Expand Up @@ -540,7 +539,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
}
}

if (this.workspace.options.collapse) {
if (Blockly.collapse) {
// Option to collapse/expand block.
if (this.collapsed_) {
var expandOption = {enabled: true};
Expand All @@ -559,7 +558,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
}
}

if (this.workspace.options.disable) {
if (Blockly.disable) {
// Option to disable/enable block.
var disableOption = {
text: this.disabled ?
Expand Down
48 changes: 26 additions & 22 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ goog.require('goog.color');
goog.require('goog.userAgent');


/**
* Path to Blockly's media directory. Can be relative, absolute, or remote.
* Used for loading sounds and sprites. Defaults to demo server.
*/
Blockly.pathToMedia = 'https://blockly-demo.appspot.com/static/media/';

/**
* Required name space for SVG elements.
* @const
Expand Down Expand Up @@ -377,6 +383,7 @@ Blockly.onKeyDown_ = function(e) {
// When focused on an HTML text input widget, don't trap any keys.
return;
}
// TODO: Add keyboard support for cursoring around the context menu.
if (e.keyCode == 27) {
// Pressing esc closes the context menu.
Blockly.hideChaff();
Expand Down Expand Up @@ -487,18 +494,17 @@ Blockly.copy_ = function(block) {
* @private
*/
Blockly.showContextMenu_ = function(e) {
var workspace = Blockly.mainWorkspace;
if (workspace.options.readOnly) {
if (Blockly.readOnly) {
return;
}
var options = [];
// Add a little animation to collapsing and expanding.
var COLLAPSE_DELAY = 10;

if (workspace.options.collapse) {
if (Blockly.collapse) {
var hasCollapsedBlocks = false;
var hasExpandedBlocks = false;
var topBlocks = workspace.getTopBlocks(false);
var topBlocks = Blockly.mainWorkspace.getTopBlocks(false);
for (var i = 0; i < topBlocks.length; i++) {
var block = topBlocks[i];
while (block) {
Expand Down Expand Up @@ -696,20 +702,19 @@ Blockly.playAudio = function(name, opt_volume) {
* @private
*/
Blockly.getMainWorkspaceMetrics_ = function() {
var mainWorkspace = Blockly.mainWorkspace;
var svgSize = Blockly.svgSize();
if (mainWorkspace.toolbox_) {
svgSize.width -= mainWorkspace.toolbox_.width;
if (Blockly.mainWorkspace.toolbox_) {
svgSize.width -= Blockly.mainWorkspace.toolbox_.width;
}
var viewWidth = svgSize.width - Blockly.Scrollbar.scrollbarThickness;
var viewHeight = svgSize.height - Blockly.Scrollbar.scrollbarThickness;
try {
var blockBox = mainWorkspace.getCanvas().getBBox();
var blockBox = Blockly.mainWorkspace.getCanvas().getBBox();
} catch (e) {
// Firefox has trouble with hidden elements (Bug 528969).
return null;
}
if (mainWorkspace.scrollbar) {
if (Blockly.mainWorkspace.scrollbar) {
// Add a border around the content that is at least half a screenful wide.
// Ensure border is wide enough that blocks can scroll over entire screen.
var MARGIN = 5;
Expand All @@ -731,16 +736,16 @@ Blockly.getMainWorkspaceMetrics_ = function() {
var bottomEdge = topEdge + blockBox.height;
}
var absoluteLeft = 0;
if (!Blockly.RTL && mainWorkspace.toolbox_) {
absoluteLeft = mainWorkspace.toolbox_.width;
if (!Blockly.RTL && Blockly.mainWorkspace.toolbox_) {
absoluteLeft = Blockly.mainWorkspace.toolbox_.width;
}
var metrics = {
viewHeight: svgSize.height,
viewWidth: svgSize.width,
contentHeight: bottomEdge - topEdge,
contentWidth: rightEdge - leftEdge,
viewTop: -mainWorkspace.scrollY,
viewLeft: -mainWorkspace.scrollX,
viewTop: -Blockly.mainWorkspace.scrollY,
viewLeft: -Blockly.mainWorkspace.scrollX,
contentTop: topEdge,
contentLeft: leftEdge,
absoluteTop: 0,
Expand All @@ -756,24 +761,23 @@ Blockly.getMainWorkspaceMetrics_ = function() {
* @private
*/
Blockly.setMainWorkspaceMetrics_ = function(xyRatio) {
var mainWorkspace = Blockly.mainWorkspace;
if (!mainWorkspace.scrollbar) {
if (!Blockly.mainWorkspace.scrollbar) {
throw 'Attempt to set main workspace scroll without scrollbars.';
}
var metrics = Blockly.getMainWorkspaceMetrics_();
if (goog.isNumber(xyRatio.x)) {
mainWorkspace.scrollX = -metrics.contentWidth * xyRatio.x -
Blockly.mainWorkspace.scrollX = -metrics.contentWidth * xyRatio.x -
metrics.contentLeft;
}
if (goog.isNumber(xyRatio.y)) {
mainWorkspace.scrollY = -metrics.contentHeight * xyRatio.y -
Blockly.mainWorkspace.scrollY = -metrics.contentHeight * xyRatio.y -
metrics.contentTop;
}
var x = mainWorkspace.scrollX + metrics.absoluteLeft;
var y = mainWorkspace.scrollY + metrics.absoluteTop;
mainWorkspace.translate(x, y);
mainWorkspace.gridPattern_.setAttribute('x', x);
mainWorkspace.gridPattern_.setAttribute('y', y);
var x = Blockly.mainWorkspace.scrollX + metrics.absoluteLeft;
var y = Blockly.mainWorkspace.scrollY + metrics.absoluteTop;
Blockly.mainWorkspace.translate(x, y);
Blockly.mainWorkspacePattern_.setAttribute('x', x);
Blockly.mainWorkspacePattern_.setAttribute('y', y);
};

/**
Expand Down
9 changes: 3 additions & 6 deletions core/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ Blockly.Css.mediaPath_ = '';
* a) It loads synchronously and doesn't force a redraw later.
* b) It speeds up loading by not blocking on a separate HTTP transfer.
* c) The CSS content may be made dynamic depending on init options.
* @param {boolean} hasCss If false, don't inject CSS
* (providing CSS becomes the document's responsibility).
* @param {string} pathToMedia Path from page to the Blockly media directory.
*/
Blockly.Css.inject = function(hasCss, pathToMedia) {
Blockly.Css.inject = function() {
// Placeholder for cursor rule. Must be first rule (index 0).
var text = '.blocklyDraggable {}\n';
if (hasCss) {
if (Blockly.hasCss) {
text += Blockly.Css.CONTENT.join('\n');
}
// Strip off any trailing slash (either Unix or Windows).
Blockly.Css.mediaPath_ = pathToMedia.replace(/[\\\/]$/, '');
Blockly.Css.mediaPath_ = Blockly.pathToMedia.replace(/[\\\/]$/, '');
text = text.replace(/<<<PATH>>>/g, Blockly.Css.mediaPath_);
Blockly.Css.styleSheet_ = goog.cssom.addCssText(text).sheet;
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
Expand Down
Loading

0 comments on commit 6d1df4d

Please # to comment.