diff --git a/accessible/media/accessible.css b/accessible/media/accessible.css index 77918fa90..d068253bf 100644 --- a/accessible/media/accessible.css +++ b/accessible/media/accessible.css @@ -49,7 +49,7 @@ .blocklyModal { background-color: #fefefe; border: 1px solid #888; - margin: 15% auto; + margin: 10% auto; max-width: 600px; padding: 20px; width: 60%; diff --git a/accessible/sidebar.component.js b/accessible/sidebar.component.js index 9d70afbbe..70fc806e5 100644 --- a/accessible/sidebar.component.js +++ b/accessible/sidebar.component.js @@ -37,11 +37,18 @@ blocklyApp.SidebarComponent = ng.core.Component({ {{buttonConfig.text}} - + @@ -77,12 +79,14 @@ blocklyApp.ToolboxModalComponent = ng.core.Component({ this.firstBlockIndexes = []; this.activeButtonIndex = 0; this.totalNumBlocks = null; + this.isBlockAvailable = null; var that = this; this.toolboxModalService.registerPreShowHook( - function(toolboxCategories) { + function(toolboxCategories, isBlockAvailable) { that.modalIsVisible = true; that.toolboxCategories = toolboxCategories; + that.isBlockAvailable = isBlockAvailable; var cumulativeIndex = 0; that.toolboxCategories.forEach(function(category) { @@ -105,14 +109,20 @@ blocklyApp.ToolboxModalComponent = ng.core.Component({ var button = document.getElementById( that.getOptionId(that.activeButtonIndex)); + if (button.disabled) { + evt.preventDefault(); + evt.stopPropagation(); + return; + } + for (var i = 0; i < that.toolboxCategories.length; i++) { if (that.firstBlockIndexes[i + 1] > that.activeButtonIndex) { var categoryIndex = i; var blockIndex = that.activeButtonIndex - that.firstBlockIndexes[i]; - - that.selectBlock(categoryIndex, blockIndex); - break; + var block = that.getBlock(categoryIndex, blockIndex); + that.hideModal(block); + return; } } @@ -154,19 +164,8 @@ blocklyApp.ToolboxModalComponent = ng.core.Component({ getOverallIndex: function(categoryIndex, blockIndex) { return this.firstBlockIndexes[categoryIndex] + blockIndex; }, - selectBlock: function(categoryIndex, blockIndex) { - var block = this.toolboxCategories[categoryIndex].blocks[blockIndex]; - var blockDescription = this.getBlockDescription(block); - var xml = Blockly.Xml.blockToDom(block); - var newBlockId = Blockly.Xml.domToBlock(blocklyApp.workspace, xml).id; - - var that = this; - setTimeout(function() { - that.treeService.focusOnBlock(newBlockId); - that.notificationsService.setStatusMessage( - blockDescription + ' added to workspace. ' + - 'Now on added block in workspace.'); - }); + getBlock: function(categoryIndex, blockIndex) { + return this.toolboxCategories[categoryIndex].blocks[blockIndex]; }, getBlockDescription: function(block) { return this.utilsService.getBlockDescription(block); @@ -189,9 +188,9 @@ blocklyApp.ToolboxModalComponent = ng.core.Component({ return 'toolbox-modal-option-' + this.totalNumBlocks; }, // Closes the modal. - hideModal: function() { + hideModal: function(opt_block) { this.modalIsVisible = false; this.keyboardInputService.clearOverride(); - this.toolboxModalService.hideModal(); + this.toolboxModalService.hideModal(opt_block); } }); diff --git a/accessible/toolbox-modal.service.js b/accessible/toolbox-modal.service.js index 525e6635d..ec52899f2 100644 --- a/accessible/toolbox-modal.service.js +++ b/accessible/toolbox-modal.service.js @@ -27,6 +27,7 @@ blocklyApp.ToolboxModalService = ng.core.Class({ constructor: [function() { this.modalIsShown = false; this.onHideCallback = null; + this.isBlockAvailable = null; this.preShowHook = function() { throw Error( 'A pre-show hook must be defined for the toolbox modal before it ' + @@ -69,21 +70,20 @@ blocklyApp.ToolboxModalService = ng.core.Class({ }], registerPreShowHook: function(preShowHook) { this.preShowHook = function() { - preShowHook(this.toolboxCategories); + preShowHook(this.toolboxCategories, this.isBlockAvailable); }; }, isModalShown: function() { return this.modalIsShown; }, - showModal: function(onHideCallback) { + showModal: function(onHideCallback, isBlockAvailable) { this.onHideCallback = onHideCallback; + this.isBlockAvailable = isBlockAvailable; this.preShowHook(); this.modalIsShown = true; }, - hideModal: function() { + hideModal: function(opt_block) { this.modalIsShown = false; - if (this.onHideCallback) { - this.onHideCallback(); - } + this.onHideCallback(opt_block); } });