From 11c00783f240a6377c5edb04735641256c296f2a Mon Sep 17 00:00:00 2001 From: Sean Lip Date: Fri, 10 Jun 2016 17:36:39 -0700 Subject: [PATCH] Consolidate the usages of the 'blockly-disabled' label. --- accessible/clipboard.service.js | 15 ++-- accessible/fieldview.component.js | 21 +++-- accessible/toolbox_treeview.component.js | 14 ++-- accessible/toolboxview.component.js | 2 +- accessible/utils.service.js | 19 ++--- accessible/workspace_treeview.component.js | 89 +++++++++++----------- accessible/workspaceview.component.js | 16 ++-- 7 files changed, 78 insertions(+), 98 deletions(-) diff --git a/accessible/clipboard.service.js b/accessible/clipboard.service.js index 25508fc6c..29f0baaed 100644 --- a/accessible/clipboard.service.js +++ b/accessible/clipboard.service.js @@ -111,14 +111,11 @@ blocklyApp.ClipboardService = ng.core this.isCompatibleWithConnection_( blockConnection, this.markedConnection_); }, - getClipboardCompatibilityHTMLText: function(connection) { - if (this.isCompatibleWithConnection_(connection, - this.clipboardBlockSuperiorConnection_) || - this.isCompatibleWithConnection_(connection, - this.clipboardBlockNextConnection_)){ - return ''; - } else { - return 'blockly-disabled'; - } + isClipboardCompatibleWithConnection: function(connection) { + var superiorConnection = this.clipboardBlockSuperiorConnection_; + var nextConnection = this.clipboardBlockNextConnection_; + return + this.isCompatibleWithConnection_(connection, superiorConnection) || + this.isCompatibleWithConnection_(connection, nextConnection); } }); diff --git a/accessible/fieldview.component.js b/accessible/fieldview.component.js index 114a256b6..a53995556 100644 --- a/accessible/fieldview.component.js +++ b/accessible/fieldview.component.js @@ -30,12 +30,12 @@ blocklyApp.FieldView = ng.core template: `
  • + [attr.aria-level]="level" aria-selected=false>
  • -
  • + [attr.aria-level]="level" aria-selected=false>
  • -
  • - // Checkboxes not currently supported. +
  • + // Checkboxes are not currently supported.
  • -
  • @@ -135,13 +135,9 @@ blocklyApp.ToolboxTreeView = ng.core this.idMap['parentList'] = this.utilsService.generateUniqueId(); } }, - getMarkedBlockCompatibilityHTMLText: function(isCompatible) { - return this.utilsService.getMarkedBlockCompatibilityHTMLText( - isCompatible); - }, - generateAriaLabelledByAttr: function() { - return this.utilsService.generateAriaLabelledByAttr.apply( - this, arguments); + generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) { + return this.utilsService.generateAriaLabelledByAttr( + mainLabel, secondLabel, isDisabled); }, setActiveDesc: function(parentList) { // If this is the first child of the toolbox and the diff --git a/accessible/toolboxview.component.js b/accessible/toolboxview.component.js index bb33692e3..523eeb331 100644 --- a/accessible/toolboxview.component.js +++ b/accessible/toolboxview.component.js @@ -67,7 +67,7 @@ blocklyApp.ToolboxView = ng.core `, directives: [blocklyApp.ToolboxTreeView], - providers: [blocklyApp.TreeService, blocklyApp.UtilsService], + providers: [blocklyApp.TreeService], }) .Class({ constructor: [ diff --git a/accessible/utils.service.js b/accessible/utils.service.js index 569dc7aa1..7a1e0d273 100644 --- a/accessible/utils.service.js +++ b/accessible/utils.service.js @@ -42,8 +42,12 @@ blocklyApp.UtilsService = ng.core } return idMap; }, - generateAriaLabelledByAttr: function() { - return Array.from(arguments).join(' ').trim(); + generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) { + var attrValue = mainLabel + ' ' + secondLabel; + if (isDisabled) { + attrValue += ' blockly-disabled'; + } + return attrValue; }, getInputTypeLabel: function(connection) { // Returns an upper case string in the case of official input type names. @@ -63,16 +67,5 @@ blocklyApp.UtilsService = ng.core } else { return Blockly.Msg.VALUE; } - }, - getMarkedBlockCompatibilityHTMLText: function(isCompatible) { - if (isCompatible) { - // undefined will result in the - // 'copy to marked block' option being ENABLED. - return ''; - } else { - // Anything will result in the - // 'copy to marked block' option being DISABLED. - return 'blockly-disabled'; - } } }); diff --git a/accessible/workspace_treeview.component.js b/accessible/workspace_treeview.component.js index 3740e4dec..fc052be10 100644 --- a/accessible/workspace_treeview.component.js +++ b/accessible/workspace_treeview.component.js @@ -50,34 +50,40 @@ blocklyApp.WorkspaceTreeView = ng.core
  • + [disabled]="!hasNextConnection(block) || !isCompatibleWithClipboard(block.nextConnection)"> + {{'PASTE_BELOW'|translate}} +
  • + [disabled]="!hasPreviousConnection(block) || !isCompatibleWithClipboard(block.previousConnection)"> + {{'PASTE_ABOVE'|translate}} +
  • + [disabled]="!hasNextConnection(block)"> + {{'MARK_SPOT_BELOW'|translate}} +
  • + [disabled]="!hasPreviousConnection(block)">{{'MARK_SPOT_ABOVE'|translate}}
  • + [disabled]="!clipboardService.isBlockCompatibleWithMarkedConnection(block)">{{'MOVE_TO_MARKED_SPOT'|translate}}
  • {{'MARK_THIS_SPOT'|translate}}
  • + [disabled]="!isCompatibleWithClipboard(inputBlock.connection)"> + {{'PASTE'|translate}} +
  • @@ -133,27 +141,6 @@ blocklyApp.WorkspaceTreeView = ng.core this.treeService = _treeService; this.utilsService = _utilsService; }], - deleteBlock: function(block) { - // If this is the top block, we should shift focus to the previous tree - var topBlocks = blocklyApp.workspace.topBlocks_; - for (var i = 0; i < topBlocks.length; i++) { - if (topBlocks[i].id == block.id) { - this.treeService.goToPreviousTree(this.parentId); - break; - } - } - - // If this is not the top block, we should change the active descendant - // of the tree. - block.dispose(true); - }, - getMarkedBlockCompatibilityHTMLText: function(isCompatible) { - return this.utilsService.getMarkedBlockCompatibilityHTMLText(isCompatible); - }, - generateAriaLabelledByAttr: function() { - return this.utilsService.generateAriaLabelledByAttr.apply( - this, arguments); - }, ngOnInit: function() { var elementsNeedingIds = ['blockSummary', 'listItem', 'label', 'cutListItem', 'cutButton', 'copyListItem', 'copyButton', @@ -172,6 +159,26 @@ blocklyApp.WorkspaceTreeView = ng.core this.idMap = this.utilsService.generateIds(elementsNeedingIds); this.idMap['parentList'] = this.generateParentListId(); }, + isCompatibleWithClipboard: function(connection) { + return this.clipboardService.isClipboardCompatibleWithConnection( + connection); + }, + deleteBlock: function(block) { + // If this is the top block, shift focus to the previous tree. + var topBlocks = blocklyApp.workspace.topBlocks_; + for (var i = 0; i < topBlocks.length; i++) { + if (topBlocks[i].id == block.id) { + this.treeService.goToPreviousTree(this.parentId); + break; + } + } + // If this is not the top block, change the active descendant of the tree. + block.dispose(true); + }, + generateAriaLabelledByAttr: function(mainLabel, secondLabel, isDisabled) { + return this.utilsService.generateAriaLabelledByAttr( + mainLabel, secondLabel, isDisabled); + }, generateParentListId: function() { if (this.isTopBlock) { return this.parentId + '-node0' @@ -179,19 +186,11 @@ blocklyApp.WorkspaceTreeView = ng.core return this.utilsService.generateUniqueId(); } }, - getNoPreviousConnectionHTMLText: function(block) { - if (!block.previousConnection) { - return 'blockly-disabled'; - } else { - return ''; - } + hasPreviousConnection: function(block) { + return Boolean(block.previousConnection); }, - getNoNextConnectionHTMLText: function(block) { - if (!block.nextConnection) { - return 'blockly-disabled'; - } else { - return ''; - } + hasNextConnection: function(block) { + return Boolean(block.nextConnection); }, checkParentList: function(parentList) { blocklyApp.debug && console.log('setting parent list'); diff --git a/accessible/workspaceview.component.js b/accessible/workspaceview.component.js index 281b87b55..2c0d2c6f0 100644 --- a/accessible/workspaceview.component.js +++ b/accessible/workspaceview.component.js @@ -30,17 +30,19 @@ blocklyApp.WorkspaceView = ng.core +
    - -
    +