Skip to content

Commit

Permalink
Use goog.global instead of this or window.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser committed Dec 24, 2014
1 parent 0f8d012 commit 4973db4
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 83 deletions.
46 changes: 23 additions & 23 deletions blockly_compressed.js

Large diffs are not rendered by default.

47 changes: 26 additions & 21 deletions blockly_uncompressed.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,15 @@ Blockly.Block.prototype.setHelpUrl = function(url) {
this.helpUrl = url;
};

/**
* Change the tooltip text for a block.
* @param {string|!Function} newTip Text for tooltip or a parent element to
* link to for its tooltip. May be a function that returns a string.
*/
Blockly.Block.prototype.setTooltip = function(newTip) {
this.tooltip = newTip;
};

/**
* Get the colour of a block.
* @return {number} HSV hue value.
Expand Down Expand Up @@ -605,15 +614,6 @@ Blockly.Block.prototype.setTitleValue = function(newValue, name) {
this.setFieldValue(newValue, name);
};

/**
* Change the tooltip text for a block.
* @param {string|!Function} newTip Text for tooltip or a parent element to
* link to for its tooltip. May be a function that returns a string.
*/
Blockly.Block.prototype.setTooltip = function(newTip) {
this.tooltip = newTip;
};

/**
* Set whether this block can chain onto the bottom of another block.
* @param {boolean} newBoolean True if there can be a previous statement.
Expand Down
4 changes: 2 additions & 2 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ Blockly.BlockSvg.disposeUiStep_ = function(clone) {
var closure = function() {
Blockly.BlockSvg.disposeUiStep_(clone);
};
window.setTimeout(closure, 10);
setTimeout(closure, 10);
}
};

Expand Down Expand Up @@ -1040,7 +1040,7 @@ Blockly.BlockSvg.connectionUiStep_ = function(ripple) {
var closure = function() {
Blockly.BlockSvg.connectionUiStep_(ripple);
};
window.setTimeout(closure, 10);
setTimeout(closure, 10);
}
};

Expand Down
12 changes: 6 additions & 6 deletions core/blockly.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ Blockly.removeAllRanges = function() {
var sel = window.getSelection();
if (sel && sel.removeAllRanges) {
sel.removeAllRanges();
window.setTimeout(function() {
setTimeout(function() {
try {
window.getSelection().removeAllRanges();
} catch (e) {
Expand Down Expand Up @@ -767,9 +767,9 @@ Blockly.getMainWorkspace = function() {
};

// Export symbols that would otherwise be renamed by Closure compiler.
if (!this['Blockly']) {
this['Blockly'] = {};
if (!goog.global['Blockly']) {
goog.global['Blockly'] = {};
}
this['Blockly']['getMainWorkspace'] = Blockly.getMainWorkspace;
this['Blockly']['addChangeListener'] = Blockly.addChangeListener;
this['Blockly']['removeChangeListener'] = Blockly.removeChangeListener;
goog.global['Blockly']['getMainWorkspace'] = Blockly.getMainWorkspace;
goog.global['Blockly']['addChangeListener'] = Blockly.addChangeListener;
goog.global['Blockly']['removeChangeListener'] = Blockly.removeChangeListener;
4 changes: 2 additions & 2 deletions core/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
}
if (orphanBlock) {
// Unable to reattach orphan. Bump it off to the side.
window.setTimeout(function() {
setTimeout(function() {
orphanBlock.outputConnection.bumpAwayFrom_(otherConnection);
}, Blockly.BUMP_DELAY);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ Blockly.Connection.prototype.connect = function(otherConnection) {
}
if (orphanBlock) {
// Unable to reattach orphan. Bump it off to the side.
window.setTimeout(function() {
setTimeout(function() {
orphanBlock.previousConnection.bumpAwayFrom_(otherConnection);
}, Blockly.BUMP_DELAY);
}
Expand Down
6 changes: 4 additions & 2 deletions core/realtime-client-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ rtclient.FOLDER_KEY = 'folderId';
* @return {!Object} Parameter object.
*/
rtclient.getParams = function() {
// Be careful with regards to node.js which has no window or location.
var location = goog.global['location'] || {};
var params = {};
function parseParams(fragment) {
// Split up the query string and store in an object.
Expand All @@ -88,12 +90,12 @@ rtclient.getParams = function() {
params[decodeURIComponent(paramStr[0])] = decodeURIComponent(paramStr[1]);
}
}
var hashFragment = this.location && this.location.hash;
var hashFragment = location.hash;
if (hashFragment) {
parseParams(hashFragment);
}
// Opening from Drive will encode the state in a query search parameter.
var searchFragment = this.location && this.location.search;
var searchFragment = location.search;
if (searchFragment) {
parseParams(searchFragment);
}
Expand Down
2 changes: 1 addition & 1 deletion core/realtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ Blockly.Realtime.afterAuth_ = function() {
// This is a workaround for the fact that the code in realtime-client-utils.js
// doesn't deal with auth timeouts correctly. So we explicitly reauthorize at
// regular intervals.
window.setTimeout(
setTimeout(
function() {
Blockly.Realtime.realtimeLoader_.authorizer.authorize(
Blockly.Realtime.afterAuth_);
Expand Down
2 changes: 1 addition & 1 deletion core/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ Blockly.Toolbox.TreeControl.prototype.handleTouchEvent_ = function(e) {
if (node && e.type === goog.events.EventType.TOUCHSTART) {
// Fire asynchronously since onMouseDown takes long enough that the browser
// would fire the default mouse event before this method returns.
window.setTimeout(function() {
setTimeout(function() {
node.onMouseDown(e); // Same behaviour for click and touch.
}, 1);
}
Expand Down
12 changes: 6 additions & 6 deletions core/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Blockly.Tooltip.onMouseOver_ = function(e) {
Blockly.Tooltip.element_ = element;
}
// Forget about any immediately preceeding mouseOut event.
window.clearTimeout(Blockly.Tooltip.mouseOutPid_);
clearTimeout(Blockly.Tooltip.mouseOutPid_);
};

/**
Expand All @@ -195,12 +195,12 @@ Blockly.Tooltip.onMouseOut_ = function(e) {
// a mouseOut followed instantly by a mouseOver. Fork off the mouseOut
// event and kill it if a mouseOver is received immediately.
// This way the task only fully executes if mousing into the void.
Blockly.Tooltip.mouseOutPid_ = window.setTimeout(function() {
Blockly.Tooltip.mouseOutPid_ = setTimeout(function() {
Blockly.Tooltip.element_ = null;
Blockly.Tooltip.poisonedElement_ = null;
Blockly.Tooltip.hide();
}, 1);
window.clearTimeout(Blockly.Tooltip.showPid_);
clearTimeout(Blockly.Tooltip.showPid_);
};

/**
Expand Down Expand Up @@ -232,11 +232,11 @@ Blockly.Tooltip.onMouseMove_ = function(e) {
}
} else if (Blockly.Tooltip.poisonedElement_ != Blockly.Tooltip.element_) {
// The mouse moved, clear any previously scheduled tooltip.
window.clearTimeout(Blockly.Tooltip.showPid_);
clearTimeout(Blockly.Tooltip.showPid_);
// Maybe this time the mouse will stay put. Schedule showing of tooltip.
Blockly.Tooltip.lastXY_ = Blockly.mouseToSvg(e);
Blockly.Tooltip.showPid_ =
window.setTimeout(Blockly.Tooltip.show_, Blockly.Tooltip.HOVER_MS);
setTimeout(Blockly.Tooltip.show_, Blockly.Tooltip.HOVER_MS);
}
};

Expand All @@ -250,7 +250,7 @@ Blockly.Tooltip.hide = function() {
Blockly.Tooltip.svgGroup_.style.display = 'none';
}
}
window.clearTimeout(Blockly.Tooltip.showPid_);
clearTimeout(Blockly.Tooltip.showPid_);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,11 @@ Blockly.WorkspaceSvg.prototype.fireChangeEvent = function() {
return;
}
if (this.fireChangeEventPid_) {
window.clearTimeout(this.fireChangeEventPid_);
clearTimeout(this.fireChangeEventPid_);
}
var canvas = this.svgBlockCanvas_;
if (canvas) {
this.fireChangeEventPid_ = window.setTimeout(function() {
this.fireChangeEventPid_ = setTimeout(function() {
Blockly.fireUiEvent(canvas, 'blocklyWorkspaceChange');
}, 0);
}
Expand Down
16 changes: 8 additions & 8 deletions core/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,13 +416,13 @@ Blockly.Xml.deleteNext = function(xmlBlock) {
};

// Export symbols that would otherwise be renamed by Closure compiler.
if (!this['Blockly']) {
this['Blockly'] = {};
if (!goog.global['Blockly']) {
goog.global['Blockly'] = {};
}
if (!this['Blockly']['Xml']) {
this['Blockly']['Xml'] = {};
if (!goog.global['Blockly']['Xml']) {
goog.global['Blockly']['Xml'] = {};
}
this['Blockly']['Xml']['domToText'] = Blockly.Xml.domToText;
this['Blockly']['Xml']['domToWorkspace'] = Blockly.Xml.domToWorkspace;
this['Blockly']['Xml']['textToDom'] = Blockly.Xml.textToDom;
this['Blockly']['Xml']['workspaceToDom'] = Blockly.Xml.workspaceToDom;
goog.global['Blockly']['Xml']['domToText'] = Blockly.Xml.domToText;
goog.global['Blockly']['Xml']['domToWorkspace'] = Blockly.Xml.domToWorkspace;
goog.global['Blockly']['Xml']['textToDom'] = Blockly.Xml.textToDom;
goog.global['Blockly']['Xml']['workspaceToDom'] = Blockly.Xml.workspaceToDom;

0 comments on commit 4973db4

Please sign in to comment.