-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These are minimal changes to make the tools work together; cf issue #3. More cleanup is necessary.
- Loading branch information
Showing
4 changed files
with
64 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as Blockly from 'blockly'; | ||
import {setCategory, hideCategory, disable_sup_grid} from './blocks.js'; | ||
import {ques_generator} from './generator.js'; | ||
|
||
function injectWorkspace() { | ||
|
||
var toolbox = document.getElementById('toolbox'); | ||
|
||
// Injecting workspace | ||
var blocklyDiv = document.getElementById('blocklyDiv'); | ||
var workspace = Blockly.inject(blocklyDiv, { | ||
toolbox: toolbox, | ||
zoom: { | ||
controls: true, | ||
wheel: true, | ||
startScale: 1, | ||
maxScale: 1.5, | ||
minScale: 0.8, | ||
scaleSpeed: 1.2 | ||
} | ||
}); | ||
|
||
// Resizing workspace | ||
blocklyDiv.style.position = 'absolute'; | ||
var area = document.getElementById('blocklyContainer'); | ||
var onresize = function(e) { | ||
var el = area; | ||
var x = 0; | ||
var y = 0; | ||
do { | ||
x += el.offsetLeft; | ||
y += el.offsetTop; | ||
el = el.offsetParent; | ||
} while(el); | ||
blocklyDiv.style.left = x + 'px'; | ||
blocklyDiv.style.top = y + 'px'; | ||
blocklyDiv.style.width = area.offsetWidth + 'px'; | ||
blocklyDiv.style.height = area.offsetHeight + 'px'; | ||
Blockly.svgResize(workspace); | ||
}; | ||
window.addEventListener('resize', onresize, false); | ||
onresize(); | ||
|
||
// Category hiding | ||
var refresh = function(){ | ||
setCategory(workspace); | ||
ques_generator(workspace); | ||
disable_sup_grid(workspace); | ||
} | ||
workspace.addChangeListener(refresh); | ||
hideCategory(); | ||
Blockly.myFlyout&&Blockly.myFlyout.flyoutCategory&&(workspace.registerToolboxCategoryCallback(Blockly.MYFLYOUT_CATEGORY_NAME,Blockly.myFlyout.flyoutCategory)); | ||
Blockly.gridFlyout&&Blockly.gridFlyout.flyoutCategory&&(workspace.registerToolboxCategoryCallback(Blockly.GRIDFLYOUT_CATEGORY_NAME,Blockly.gridFlyout.flyoutCategory)); | ||
} | ||
|
||
window.onload = injectWorkspace; |