Skip to content

Commit 6d1df4d

Browse files
committed
Revert "De-singleton Blockly. Part 1."
This reverts commit 3122c8a.
1 parent 29976c4 commit 6d1df4d

File tree

7 files changed

+141
-164
lines changed

7 files changed

+141
-164
lines changed

core/block.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ Blockly.Block.prototype.getFieldValue = function(name) {
622622
* @deprecated December 2013
623623
*/
624624
Blockly.Block.prototype.getTitleValue = function(name) {
625-
console.warn('Deprecated call to getTitleValue, use getFieldValue instead.');
625+
console.log('Deprecated call to getTitleValue, use getFieldValue instead.');
626626
return this.getFieldValue(name);
627627
};
628628

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

core/block_svg.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ Blockly.BlockSvg.prototype.showHelp_ = function() {
484484
* @private
485485
*/
486486
Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
487-
if (this.workspace.options.readOnly || !this.contextMenu) {
487+
if (Blockly.readOnly || !this.contextMenu) {
488488
return;
489489
}
490490
// Save the current block in a variable for use in closures.
@@ -505,8 +505,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
505505
}
506506
options.push(duplicateOption);
507507

508-
if (this.isEditable() && !this.collapsed_ &&
509-
this.workspace.options.comments) {
508+
if (this.isEditable() && !this.collapsed_ && Blockly.comments) {
510509
// Option to add/remove a comment.
511510
var commentOption = {enabled: true};
512511
if (this.comment) {
@@ -540,7 +539,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
540539
}
541540
}
542541

543-
if (this.workspace.options.collapse) {
542+
if (Blockly.collapse) {
544543
// Option to collapse/expand block.
545544
if (this.collapsed_) {
546545
var expandOption = {enabled: true};
@@ -559,7 +558,7 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) {
559558
}
560559
}
561560

562-
if (this.workspace.options.disable) {
561+
if (Blockly.disable) {
563562
// Option to disable/enable block.
564563
var disableOption = {
565564
text: this.disabled ?

core/blockly.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ goog.require('goog.color');
5454
goog.require('goog.userAgent');
5555

5656

57+
/**
58+
* Path to Blockly's media directory. Can be relative, absolute, or remote.
59+
* Used for loading sounds and sprites. Defaults to demo server.
60+
*/
61+
Blockly.pathToMedia = 'https://blockly-demo.appspot.com/static/media/';
62+
5763
/**
5864
* Required name space for SVG elements.
5965
* @const
@@ -377,6 +383,7 @@ Blockly.onKeyDown_ = function(e) {
377383
// When focused on an HTML text input widget, don't trap any keys.
378384
return;
379385
}
386+
// TODO: Add keyboard support for cursoring around the context menu.
380387
if (e.keyCode == 27) {
381388
// Pressing esc closes the context menu.
382389
Blockly.hideChaff();
@@ -487,18 +494,17 @@ Blockly.copy_ = function(block) {
487494
* @private
488495
*/
489496
Blockly.showContextMenu_ = function(e) {
490-
var workspace = Blockly.mainWorkspace;
491-
if (workspace.options.readOnly) {
497+
if (Blockly.readOnly) {
492498
return;
493499
}
494500
var options = [];
495501
// Add a little animation to collapsing and expanding.
496502
var COLLAPSE_DELAY = 10;
497503

498-
if (workspace.options.collapse) {
504+
if (Blockly.collapse) {
499505
var hasCollapsedBlocks = false;
500506
var hasExpandedBlocks = false;
501-
var topBlocks = workspace.getTopBlocks(false);
507+
var topBlocks = Blockly.mainWorkspace.getTopBlocks(false);
502508
for (var i = 0; i < topBlocks.length; i++) {
503509
var block = topBlocks[i];
504510
while (block) {
@@ -696,20 +702,19 @@ Blockly.playAudio = function(name, opt_volume) {
696702
* @private
697703
*/
698704
Blockly.getMainWorkspaceMetrics_ = function() {
699-
var mainWorkspace = Blockly.mainWorkspace;
700705
var svgSize = Blockly.svgSize();
701-
if (mainWorkspace.toolbox_) {
702-
svgSize.width -= mainWorkspace.toolbox_.width;
706+
if (Blockly.mainWorkspace.toolbox_) {
707+
svgSize.width -= Blockly.mainWorkspace.toolbox_.width;
703708
}
704709
var viewWidth = svgSize.width - Blockly.Scrollbar.scrollbarThickness;
705710
var viewHeight = svgSize.height - Blockly.Scrollbar.scrollbarThickness;
706711
try {
707-
var blockBox = mainWorkspace.getCanvas().getBBox();
712+
var blockBox = Blockly.mainWorkspace.getCanvas().getBBox();
708713
} catch (e) {
709714
// Firefox has trouble with hidden elements (Bug 528969).
710715
return null;
711716
}
712-
if (mainWorkspace.scrollbar) {
717+
if (Blockly.mainWorkspace.scrollbar) {
713718
// Add a border around the content that is at least half a screenful wide.
714719
// Ensure border is wide enough that blocks can scroll over entire screen.
715720
var MARGIN = 5;
@@ -731,16 +736,16 @@ Blockly.getMainWorkspaceMetrics_ = function() {
731736
var bottomEdge = topEdge + blockBox.height;
732737
}
733738
var absoluteLeft = 0;
734-
if (!Blockly.RTL && mainWorkspace.toolbox_) {
735-
absoluteLeft = mainWorkspace.toolbox_.width;
739+
if (!Blockly.RTL && Blockly.mainWorkspace.toolbox_) {
740+
absoluteLeft = Blockly.mainWorkspace.toolbox_.width;
736741
}
737742
var metrics = {
738743
viewHeight: svgSize.height,
739744
viewWidth: svgSize.width,
740745
contentHeight: bottomEdge - topEdge,
741746
contentWidth: rightEdge - leftEdge,
742-
viewTop: -mainWorkspace.scrollY,
743-
viewLeft: -mainWorkspace.scrollX,
747+
viewTop: -Blockly.mainWorkspace.scrollY,
748+
viewLeft: -Blockly.mainWorkspace.scrollX,
744749
contentTop: topEdge,
745750
contentLeft: leftEdge,
746751
absoluteTop: 0,
@@ -756,24 +761,23 @@ Blockly.getMainWorkspaceMetrics_ = function() {
756761
* @private
757762
*/
758763
Blockly.setMainWorkspaceMetrics_ = function(xyRatio) {
759-
var mainWorkspace = Blockly.mainWorkspace;
760-
if (!mainWorkspace.scrollbar) {
764+
if (!Blockly.mainWorkspace.scrollbar) {
761765
throw 'Attempt to set main workspace scroll without scrollbars.';
762766
}
763767
var metrics = Blockly.getMainWorkspaceMetrics_();
764768
if (goog.isNumber(xyRatio.x)) {
765-
mainWorkspace.scrollX = -metrics.contentWidth * xyRatio.x -
769+
Blockly.mainWorkspace.scrollX = -metrics.contentWidth * xyRatio.x -
766770
metrics.contentLeft;
767771
}
768772
if (goog.isNumber(xyRatio.y)) {
769-
mainWorkspace.scrollY = -metrics.contentHeight * xyRatio.y -
773+
Blockly.mainWorkspace.scrollY = -metrics.contentHeight * xyRatio.y -
770774
metrics.contentTop;
771775
}
772-
var x = mainWorkspace.scrollX + metrics.absoluteLeft;
773-
var y = mainWorkspace.scrollY + metrics.absoluteTop;
774-
mainWorkspace.translate(x, y);
775-
mainWorkspace.gridPattern_.setAttribute('x', x);
776-
mainWorkspace.gridPattern_.setAttribute('y', y);
776+
var x = Blockly.mainWorkspace.scrollX + metrics.absoluteLeft;
777+
var y = Blockly.mainWorkspace.scrollY + metrics.absoluteTop;
778+
Blockly.mainWorkspace.translate(x, y);
779+
Blockly.mainWorkspacePattern_.setAttribute('x', x);
780+
Blockly.mainWorkspacePattern_.setAttribute('y', y);
777781
};
778782

779783
/**

core/css.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,15 @@ Blockly.Css.mediaPath_ = '';
6666
* a) It loads synchronously and doesn't force a redraw later.
6767
* b) It speeds up loading by not blocking on a separate HTTP transfer.
6868
* c) The CSS content may be made dynamic depending on init options.
69-
* @param {boolean} hasCss If false, don't inject CSS
70-
* (providing CSS becomes the document's responsibility).
71-
* @param {string} pathToMedia Path from page to the Blockly media directory.
7269
*/
73-
Blockly.Css.inject = function(hasCss, pathToMedia) {
70+
Blockly.Css.inject = function() {
7471
// Placeholder for cursor rule. Must be first rule (index 0).
7572
var text = '.blocklyDraggable {}\n';
76-
if (hasCss) {
73+
if (Blockly.hasCss) {
7774
text += Blockly.Css.CONTENT.join('\n');
7875
}
7976
// Strip off any trailing slash (either Unix or Windows).
80-
Blockly.Css.mediaPath_ = pathToMedia.replace(/[\\\/]$/, '');
77+
Blockly.Css.mediaPath_ = Blockly.pathToMedia.replace(/[\\\/]$/, '');
8178
text = text.replace(/<<<PATH>>>/g, Blockly.Css.mediaPath_);
8279
Blockly.Css.styleSheet_ = goog.cssom.addCssText(text).sheet;
8380
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);

0 commit comments

Comments
 (0)