Various nits

This commit is contained in:
Eric Rosenbaum 2017-09-21 11:54:42 -04:00
parent 4bedaa458a
commit 865fbec3a3
3 changed files with 18 additions and 8 deletions

View file

@ -118,6 +118,14 @@ Blockly.Flyout = function(workspaceOptions) {
* @private
*/
this.parentToolbox_ = null;
/**
* The target position for the flyout scroll animation in pixels.
* Is a number while animating, null otherwise.
* @type {?number}
* @package
*/
this.scrollTarget = null;
};
/**
@ -458,7 +466,7 @@ Blockly.Flyout.prototype.show = function(xmlList) {
// Handle dynamic categories, represented by a name instead of a list of XML.
// Look up the correct category generation function and call that to get a
// valid XML list.
if (typeof xmlList[i] === 'string') {
if (typeof xml === 'string') {
var fnToApply = this.workspace_.targetWorkspace.getToolboxCategoryCallback(
xmlList[i]);
var newList = fnToApply(this.workspace_.targetWorkspace);
@ -554,15 +562,15 @@ Blockly.Flyout.prototype.recordCategoryScrollPositions_ = function() {
/**
* Select a category using the scroll position.
* @param {number} pos The scroll position.
* @param {number} pos The scroll position in pixels.
* @package
*/
Blockly.Flyout.prototype.selectCategoryByScrollPosition = function(pos) {
var scaledPos = pos / this.workspace_.scale;
var workspacePos = pos / this.workspace_.scale;
// Traverse the array of scroll positions in reverse, so we can select the furthest
// category that the scroll position is beyond
// category that the scroll position is beyond.
for (var i = this.categoryScrollPositions.length - 1; i >= 0; i--) {
if (scaledPos > this.categoryScrollPositions[i].position) {
if (workspacePos > this.categoryScrollPositions[i].position) {
this.parentToolbox_.selectCategoryByName(this.categoryScrollPositions[i].categoryName);
return;
}

View file

@ -33,6 +33,7 @@ goog.require('Blockly.FlyoutButton');
goog.require('Blockly.Flyout');
goog.require('Blockly.WorkspaceSvg');
goog.require('goog.dom');
goog.require('goog.dom.animationFrame.polyfill');
goog.require('goog.events');
goog.require('goog.math.Rect');
goog.require('goog.userAgent');
@ -247,6 +248,7 @@ Blockly.HorizontalFlyout.prototype.scrollToStart = function() {
/**
* Scroll the flyout to a position.
* @param {number} pos The targeted scroll position.
* @package
*/
Blockly.HorizontalFlyout.prototype.scrollTo = function(pos) {
this.scrollTarget = pos * this.workspace_.scale;

View file

@ -34,11 +34,10 @@ goog.require('Blockly.FlyoutButton');
goog.require('Blockly.utils');
goog.require('Blockly.WorkspaceSvg');
goog.require('goog.dom');
goog.require('goog.dom.animationFrame.polyfill');
goog.require('goog.events');
goog.require('goog.math.Rect');
goog.require('goog.userAgent');
goog.require('goog.dom.animationFrame.polyfill');
/**
* Class for a flyout.
@ -334,7 +333,8 @@ Blockly.VerticalFlyout.prototype.scrollToStart = function() {
/**
* Scroll the flyout to a position.
* @param {number} pos The targeted scroll position.
* @param {number} pos The targeted scroll position in workspace coordinates.
* @package
*/
Blockly.VerticalFlyout.prototype.scrollTo = function(pos) {
this.scrollTarget = pos * this.workspace_.scale;