diff --git a/core/block.js b/core/block.js index c1e43e58c..36fb5ac28 100644 --- a/core/block.js +++ b/core/block.js @@ -41,7 +41,6 @@ goog.require('Blockly.Workspace'); goog.require('Blockly.Xml'); goog.require('goog.array'); goog.require('goog.math.Coordinate'); -goog.require('goog.string'); /** @@ -1055,12 +1054,14 @@ Blockly.Block.prototype.toString = function(opt_maxLength, opt_emptyToken) { } } } - text = goog.string.trim(text.join(' ')) || '???'; + text = text.join(' ').trim() || '???'; if (opt_maxLength) { // TODO: Improve truncation so that text from this block is given priority. // E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not "1+2+3+4+5...". // E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...". - text = goog.string.truncate(text, opt_maxLength); + if (text.length > opt_maxLength) { + text = text.substring(0, opt_maxLength - 3) + '...'; + } } return text; }; @@ -1260,7 +1261,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { } // Add last dummy input if needed. if (elements.length && (typeof elements[elements.length - 1] == 'string' || - goog.string.startsWith( + Blockly.utils.startsWith( elements[elements.length - 1]['type'], 'field_'))) { var dummyInput = {type: 'input_dummy'}; if (lastDummyAlign) { diff --git a/core/field_variable.js b/core/field_variable.js index 467586f0e..b742ff1d9 100644 --- a/core/field_variable.js +++ b/core/field_variable.js @@ -30,7 +30,6 @@ goog.require('Blockly.FieldDropdown'); goog.require('Blockly.Msg'); goog.require('Blockly.VariableModel'); goog.require('Blockly.Variables'); -goog.require('goog.string'); /** diff --git a/core/gesture.js b/core/gesture.js index f8b3aa260..7fe357a4b 100644 --- a/core/gesture.js +++ b/core/gesture.js @@ -505,8 +505,9 @@ Blockly.Gesture.prototype.doStart = function(e) { return; } - if (goog.string.caseInsensitiveEquals(e.type, 'touchstart') || - (goog.string.caseInsensitiveEquals(e.type, 'pointerdown') && e.pointerType != 'mouse')) { + if ((e.type.toLowerCase() == 'touchstart' || + e.type.toLowerCase() == 'pointerdown') && + e.pointerType != 'mouse') { Blockly.longStart_(e, this); } diff --git a/core/touch.js b/core/touch.js index d5b8c0a36..85c704302 100644 --- a/core/touch.js +++ b/core/touch.js @@ -32,7 +32,6 @@ goog.provide('Blockly.Touch'); goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); -goog.require('goog.string'); /** @@ -198,7 +197,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) { * @param {!Event} e A touch event. */ Blockly.Touch.setClientFromTouch = function(e) { - if (goog.string.startsWith(e.type, 'touch')) { + if (Blockly.utils.startsWith(e.type, 'touch')) { // Map the touch event's properties to the event. var touchPoint = e.changedTouches[0]; e.clientX = touchPoint.clientX; @@ -212,9 +211,9 @@ Blockly.Touch.setClientFromTouch = function(e) { * @return {boolean} true if it is a mouse or touch event; false otherwise. */ Blockly.Touch.isMouseOrTouchEvent = function(e) { - return goog.string.startsWith(e.type, 'touch') || - goog.string.startsWith(e.type, 'mouse') || - goog.string.startsWith(e.type, 'pointer'); + return Blockly.utils.startsWith(e.type, 'touch') || + Blockly.utils.startsWith(e.type, 'mouse') || + Blockly.utils.startsWith(e.type, 'pointer'); }; /** @@ -223,8 +222,8 @@ Blockly.Touch.isMouseOrTouchEvent = function(e) { * @return {boolean} true if it is a touch event; false otherwise. */ Blockly.Touch.isTouchEvent = function(e) { - return goog.string.startsWith(e.type, 'touch') || - goog.string.startsWith(e.type, 'pointer'); + return Blockly.utils.startsWith(e.type, 'touch') || + Blockly.utils.startsWith(e.type, 'pointer'); }; /** diff --git a/core/utils.js b/core/utils.js index 543761c39..478c07228 100644 --- a/core/utils.js +++ b/core/utils.js @@ -525,7 +525,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, // BKY_ is the prefix used to namespace the strings used in Blockly // core files and the predefined blocks in ../blocks/. These strings // are defined in ../msgs/ files. - var bklyKey = goog.string.startsWith(keyUpper, 'BKY_') ? + var bklyKey = Blockly.utils.startsWith(keyUpper, 'BKY_') ? keyUpper.substring(4) : null; if (bklyKey && bklyKey in Blockly.Msg) { var rawValue = Blockly.Msg[bklyKey]; @@ -901,3 +901,14 @@ Blockly.utils.getViewportBBox = function() { left: scrollOffset.x }; }; + +/** + * Fast prefix-checker. + * Copied from Closure's goog.string.startsWith. + * @param {string} str The string to check. + * @param {string} prefix A string to look for at the start of `str`. + * @return {boolean} True if `str` begins with `prefix`. + */ +Blockly.utils.startsWith = function(str, prefix) { + return str.lastIndexOf(prefix, 0) == 0; +}; diff --git a/core/variable_model.js b/core/variable_model.js index 339620532..a047b18e7 100644 --- a/core/variable_model.js +++ b/core/variable_model.js @@ -28,8 +28,6 @@ goog.provide('Blockly.VariableModel'); goog.require('Blockly.Events.VarCreate'); -goog.require('goog.string'); - /** * Class for a variable model. @@ -97,5 +95,13 @@ Blockly.VariableModel.prototype.getId = function() { * @package */ Blockly.VariableModel.compareByName = function(var1, var2) { - return goog.string.caseInsensitiveCompare(var1.name, var2.name); + var name1 = var1.name.toLowerCase(); + var name2 = var2.name.toLowerCase(); + if (name1 < name2) { + return -1; + } else if (name1 == name2) { + return 0; + } else { + return 1; + } }; diff --git a/core/variables_dynamic.js b/core/variables_dynamic.js index 7cf3e6430..7ee4d8787 100644 --- a/core/variables_dynamic.js +++ b/core/variables_dynamic.js @@ -33,7 +33,6 @@ goog.require('Blockly.constants'); goog.require('Blockly.VariableModel'); // TODO Fix circular dependencies // goog.require('Blockly.Workspace'); -goog.require('goog.string'); Blockly.VariablesDynamic.onCreateVariableButtonClick_String = function(button) {