Commit 92d482b1 authored by carlosperate's avatar carlosperate

Fixes carlosperate/ardublockly#3 and carlosperate/ardublockly#9

parent 6a30d3aa
...@@ -26,6 +26,8 @@ window.addEventListener('load', function load(event) { ...@@ -26,6 +26,8 @@ window.addEventListener('load', function load(event) {
ArduinoMaterial.bindDesignEventListeners_(); ArduinoMaterial.bindDesignEventListeners_();
ArduinoMaterial.bindBlocklyEventListeners_(); ArduinoMaterial.bindBlocklyEventListeners_();
ArduinoMaterial.resizeToggleToolboxBotton();
// Check if not running locally (including developer's local network IP) // Check if not running locally (including developer's local network IP)
if (document.location.hostname != 'localhost' && if (document.location.hostname != 'localhost' &&
document.location.hostname != '192.168.0.7') { document.location.hostname != '192.168.0.7') {
...@@ -423,7 +425,7 @@ ArduinoMaterial.toogleToolbox = function() { ...@@ -423,7 +425,7 @@ ArduinoMaterial.toogleToolbox = function() {
function() { ArduinoMaterial.showToolboxButtonState(false); }); function() { ArduinoMaterial.showToolboxButtonState(false); });
ArduinoMaterial.workspace.toolbox_.flyout_.hide(); ArduinoMaterial.workspace.toolbox_.flyout_.hide();
} else { } else {
ArduinoMaterial.showToolboxButtonState(true); ArduinoMaterial.showToolboxButtonState(true);
ArduinoMaterial.showToolbox(true); ArduinoMaterial.showToolbox(true);
} }
ArduinoMaterial.TOOLBAR_SHOWING_ = !ArduinoMaterial.TOOLBAR_SHOWING_; ArduinoMaterial.TOOLBAR_SHOWING_ = !ArduinoMaterial.TOOLBAR_SHOWING_;
......
...@@ -54,7 +54,7 @@ ArduinoMaterial.injectBlockly = function(blocklyEl, toolboxPath) { ...@@ -54,7 +54,7 @@ ArduinoMaterial.injectBlockly = function(blocklyEl, toolboxPath) {
trashcan: true }); trashcan: true });
ArduinoMaterial.BLOCKLY_INJECTED = true; ArduinoMaterial.BLOCKLY_INJECTED = true;
} }
} };
// If file run locally Chrome will fail here // If file run locally Chrome will fail here
try { try {
...@@ -159,15 +159,16 @@ ArduinoMaterial.loadBlocksfromXmlDom = function(blocksXmlDom) { ...@@ -159,15 +159,16 @@ ArduinoMaterial.loadBlocksfromXmlDom = function(blocksXmlDom) {
*/ */
ArduinoMaterial.showToolbox = function(show, callback) { ArduinoMaterial.showToolbox = function(show, callback) {
var resizeWorkspaceAndCallback = function() { var resizeWorkspaceAndCallback = function() {
/* For some reason the workspace only resizes after second call */ ArduinoMaterial.workspace.render();
//Blockly.fireUiEvent(window, 'resize'); if (callback && ((typeof callback) === (typeof Function))) {
//Blockly.fireUiEvent(window, 'resize'); callback();
//callback.call(); }
} };
if (show == false) { if (show == false) {
$('.blocklyToolboxDiv').slideUp(300, callback); $('.blocklyToolboxDiv').slideUp(300, resizeWorkspaceAndCallback);
} else { } else {
$('.blocklyToolboxDiv').slideDown(300, callback); $('.blocklyToolboxDiv').slideDown(300, resizeWorkspaceAndCallback);
} }
}; };
...@@ -177,7 +178,7 @@ ArduinoMaterial.showToolbox = function(show, callback) { ...@@ -177,7 +178,7 @@ ArduinoMaterial.showToolbox = function(show, callback) {
ArduinoMaterial.discard = function() { ArduinoMaterial.discard = function() {
var blockCount = ArduinoMaterial.workspace.getAllBlocks().length; var blockCount = ArduinoMaterial.workspace.getAllBlocks().length;
if (blockCount == 1) { if (blockCount == 1) {
Blockly.mainWorkspace.clear(); ArduinoMaterial.workspace.clear();
ArduinoMaterial.renderContent(); ArduinoMaterial.renderContent();
} else if (blockCount > 1) { } else if (blockCount > 1) {
ArduinoMaterial.materialAlert( ArduinoMaterial.materialAlert(
...@@ -186,7 +187,7 @@ ArduinoMaterial.discard = function() { ...@@ -186,7 +187,7 @@ ArduinoMaterial.discard = function() {
sure you want to delete them?', sure you want to delete them?',
true, true,
function() { function() {
Blockly.mainWorkspace.clear(); ArduinoMaterial.workspace.clear();
ArduinoMaterial.renderContent(); ArduinoMaterial.renderContent();
}); });
} }
...@@ -215,4 +216,4 @@ ArduinoMaterial.ajaxRequest = function() { ...@@ -215,4 +216,4 @@ ArduinoMaterial.ajaxRequest = function() {
} }
} }
return request; return request;
}; };
\ No newline at end of file
...@@ -80,14 +80,14 @@ ArduinoMaterial.showToolboxButtonState = function(toolboxVisible) { ...@@ -80,14 +80,14 @@ ArduinoMaterial.showToolboxButtonState = function(toolboxVisible) {
// Element conatins several classes, use replace to maintain the rest // Element conatins several classes, use replace to maintain the rest
if (toolboxVisible == true) { if (toolboxVisible == true) {
toolboxButton.className = toolboxButton.className.replace( toolboxButton.className = toolboxButton.className.replace(
'button_toggle_toolbox_on', 'button_toggle_toolbox_off'); 'button_toggle_toolbox_on', 'button_toggle_toolbox_off');
toolboxButtonIcon.className = toolboxButtonIcon.className.replace( toolboxButtonIcon.className = toolboxButtonIcon.className.replace(
'mdi-action-visibility', 'mdi-action-visibility-off'); 'mdi-action-visibility', 'mdi-action-visibility-off');
} else { } else {
toolboxButton.className = toolboxButton.className.replace( toolboxButton.className = toolboxButton.className.replace(
'button_toggle_toolbox_off', 'button_toggle_toolbox_on'); 'button_toggle_toolbox_off', 'button_toggle_toolbox_on');
toolboxButtonIcon.className = toolboxButtonIcon.className.replace( toolboxButtonIcon.className = toolboxButtonIcon.className.replace(
'mdi-action-visibility-off', 'mdi-action-visibility'); 'mdi-action-visibility-off', 'mdi-action-visibility');
} }
}; };
...@@ -109,17 +109,26 @@ ArduinoMaterial.resizeBlocklyWorkspace = function() { ...@@ -109,17 +109,26 @@ ArduinoMaterial.resizeBlocklyWorkspace = function() {
contentBlocks.style.width = wrapperPanelSize.width + 'px'; contentBlocks.style.width = wrapperPanelSize.width + 'px';
contentBlocks.style.width = contentBlocks.style.width =
(2 * wrapperPanelSize.width - contentBlocks.offsetWidth) + 'px'; (2 * wrapperPanelSize.width - contentBlocks.offsetWidth) + 'px';
};
//Blockly.MsvgResize(); /**
//Blockly.mainWorkspace.render(); * Resizes the toolbox button to toggle its visibility to the width of the
//alert( * toolbox.
// 'resized ' + wrapperPanelSize.width + ' ' + contentBlocks.style.width); * The toolbox width does not change with workspace width, so safe to do once,
* but it needs to be done after blockly has been injected.
// Sets the toolbox toggle button width to that of the toolbox * @private
if ( ArduinoMaterial.isToolboxVisible() && */
ArduinoMaterial.workspace.toolbox_.width ) { ArduinoMaterial.resizeToggleToolboxBotton = function() {
// For some reason normal set style and getElementById didn't work // As the toolbox inject is asynchronous we need to wait
$('#button_toggle_toolbox').width(ArduinoMaterial.workspace.toolbox_.width); if (ArduinoMaterial.BLOCKLY_INJECTED == false) {
setTimeout(ArduinoMaterial.resizeToggleToolboxBotton, 50);
} else {
// Sets the toolbox toggle button width to that of the toolbox
if ( ArduinoMaterial.isToolboxVisible() &&
ArduinoMaterial.workspace.toolbox_.width ) {
// For some reason normal set style and getElementById didn't work
$('#button_toggle_toolbox').width(ArduinoMaterial.workspace.toolbox_.width);
}
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment