* Creates a callback to collapse or expand top blocks. * * @param shouldCollapse Whether a block should collapse. * @param topBlocks Top blocks in the workspace.
(shouldCollapse: boolean, topBlocks: BlockSvg[])
| 116 | * @param topBlocks Top blocks in the workspace. |
| 117 | */ |
| 118 | function toggleOption_(shouldCollapse: boolean, topBlocks: BlockSvg[]) { |
| 119 | const DELAY = 10; |
| 120 | let ms = 0; |
| 121 | let timeoutCounter = 0; |
| 122 | function timeoutFn(block: BlockSvg) { |
| 123 | timeoutCounter--; |
| 124 | block.setCollapsed(shouldCollapse); |
| 125 | if (timeoutCounter === 0) { |
| 126 | Events.setGroup(false); |
| 127 | } |
| 128 | } |
| 129 | Events.setGroup(true); |
| 130 | for (let i = 0; i < topBlocks.length; i++) { |
| 131 | let block: BlockSvg | null = topBlocks[i]; |
| 132 | while (block) { |
| 133 | timeoutCounter++; |
| 134 | setTimeout(timeoutFn.bind(null, block), ms); |
| 135 | block = block.getNextBlock(); |
| 136 | ms += DELAY; |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Option to collapse all blocks. |
no test coverage detected