toolbox in xml file instead of island

335 views
Skip to first unread message

Trevor Shaw

unread,
Apr 10, 2016, 1:46:29 PM4/10/16
to Blockly
sorry for what is probably a noob question...

I would like to improve the readability of my html file by moving the xml island storing the toolbox into a separate xml file.

Could someone suggest a line of code to grab the toolbox from an xlm file so it can be used w. a blockly inject statement?

Trevor

Carlos Pereira

unread,
Apr 10, 2016, 2:14:49 PM4/10/16
to Blockly
You will have to use a XMLHttpRequest to read the XML file, which would will make the toolbox file read, and therefore the Blockly injection, an asynchronous event.

It's not difficult to do, but might require a few more lines, and move things around if any of your page javascript assumes Blockly is injected already by the time it is executed.

I used to do that in my blockly application, but eventually decided to revert it to simplify things a little bit and be able to open the html page with the Blockly application without having a server running on the background. If you are interested you can have a look at this commit which shows the old code (reading the toolbox as an XML file) being removed, essentialy being the reverse of what you'd like to do in your implementation: https://github.com/carlosperate/ardublockly/commit/57624ab3db5e08a7dfff6f7d62fbc454b4bc3b2d

Jayod

unread,
Apr 16, 2016, 12:50:33 PM4/16/16
to Blockly
Another approach you can use is to have a javascript file that contains a variable that holds your toolbox definition (using the string representation).  Have your html file load your "toolbox.js" file (or whatever you call it) and then use the variable holding the toolbox string in your Blockly injection.
Reply all
Reply to author
Forward
0 new messages