From d6e71ffe38bfbe674d226851bccc020af3558559 Mon Sep 17 00:00:00 2001 From: Tina Quach Date: Tue, 30 Aug 2016 13:59:07 -0700 Subject: [PATCH] scrollable block lib, fix bug for repeated alert about unsaved changes (#612) --- .../block_library_controller.js | 29 ++++++++++++++----- demos/blocklyfactory/factory.css | 5 ++++ demos/blocklyfactory/factory_utils.js | 2 +- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/demos/blocklyfactory/block_library_controller.js b/demos/blocklyfactory/block_library_controller.js index 7f7a19ed1..e7548488d 100644 --- a/demos/blocklyfactory/block_library_controller.js +++ b/demos/blocklyfactory/block_library_controller.js @@ -161,7 +161,8 @@ BlockLibraryController.prototype.saveToBlockLibrary = function() { // main workspace. this.openBlock(blockType); - this.addOptionSelectHandlers(); + // Add select handler to the new option. + this.addOptionSelectHandler(blockType); }; /** @@ -254,10 +255,13 @@ BlockLibraryController.prototype.setNoneSelected = function() { }; /** - * Add select handlers to each option to update the view and the selected - * blocks accordingly. + * Add select handler for an option of a given block type. The handler will to + * update the view and the selected block accordingly. + * + * @param {!string} blockType - The type of block represented by the option is + * for. */ -BlockLibraryController.prototype.addOptionSelectHandlers = function() { +BlockLibraryController.prototype.addOptionSelectHandler = function(blockType) { var self = this; // Click handler for a block option. Sets the block option as the selected @@ -287,12 +291,21 @@ BlockLibraryController.prototype.addOptionSelectHandlers = function() { }; }; + // Assign a click handler to the block option. + var blockOption = this.view.optionMap[blockType]; + // Use an additional closure to correctly assign the tab callback. + blockOption.addEventListener( + 'click', makeOptionSelectHandler_(blockOption)); +}; + +/** + * Add select handlers to each option to update the view and the selected + * blocks accordingly. + */ +BlockLibraryController.prototype.addOptionSelectHandlers = function() { // Assign a click handler to each block option. for (var blockType in this.view.optionMap) { - var blockOption = this.view.optionMap[blockType]; - // Use an additional closure to correctly assign the tab callback. - blockOption.addEventListener( - 'click', makeOptionSelectHandler_(blockOption)); + this.addOptionSelectHandler(blockType); } }; diff --git a/demos/blocklyfactory/factory.css b/demos/blocklyfactory/factory.css index 46a1d3d30..f212b1d49 100644 --- a/demos/blocklyfactory/factory.css +++ b/demos/blocklyfactory/factory.css @@ -304,6 +304,11 @@ button, .buttonStyle { /* Block Library */ +#dropdownDiv_blockLib { + max-height: 65%; + overflow-y: scroll; +} + #button_blockLib { border-color: darkgrey; font-size: large; diff --git a/demos/blocklyfactory/factory_utils.js b/demos/blocklyfactory/factory_utils.js index 1a16488de..416015362 100644 --- a/demos/blocklyfactory/factory_utils.js +++ b/demos/blocklyfactory/factory_utils.js @@ -994,7 +994,7 @@ FactoryUtils.warnIfUnsavedChanges = function() { if (!BlockFactory.isStarterBlock() && !FactoryUtils.savedBlockChanges(self.blockLibraryController)) { return confirm('You have unsaved changes. By proceeding without saving ' + - ' your block first, you will lose these changes.'); + ' your block first, you will lose these changes.'); } return true; };