@jens @richnguyen @ericstein As Eric mentioned, the faculty in the CS department are eager to begin working with the new Snap! API. However, the documentation for the API on GitHub does not appear to provide them with enough information to implement the API.
Is not current docs helpful?
I think so.
There are two big ideas:
- First, Snap! API are methods from IDE morph. So it's easy to reference that object (IDE) from outside:
var ide = world.children;
- Second, these functions allow you to do "Snap! normal actions" with your JS code. You can fire Snap! actions from outside (broadcast and setVariable) and you can get events or info from Snap! to do something outside (addMessageListener and getVar)
Example. If you build a WebServer, you can connect Snap! with your network.
Thanks for the help; I will let you know if I have additional questions about Morphic.
The link you provided states the following:
This experimental Snap! API is a set of methods for an IDE_Morph containing a Snap! project.
How would I embed a Snap! project in an IDE_Morph? Can the Snap! project be an iFrame inside of a canvas that was used to initialize a WorldMorph with the following js:
world = new Morphic.WorldMorph(document.getElementById('world'));
if the id of said canvas is 'world'?
"clarification on how a Snap! iFrame relates to the IDE object that is needed to enable two-way communication"
Evidently they have not been able to locate this information in the API documentation that you created. They commented, "This information is the last bit that we need to finish the implementation."
If you could provide this information or point them to the point at which it is explained in the current API documentation, it would be a huge help. And, of course, an example would also be very welcome!
Thanks so much for the assistance,
Maybe I don't understand your context... but I think there are two main options:
- If you want use iframes, you can do it, but you will still need your own snap distro (Snap! on your server) to avoid cross domain restrictions. Then, from your html code (the page with the iframe) you can do something like:
var snapFrame = document.getElementById("yourFrameId"), snapWorld = snapFrame.contentWindow.world, snapIde = snapWorld.children;
And with this snapIde defined, you can use Snap! API outside your iframe. Something like:
- But also you can "hack" your Snap! distro, loading your JS code, and then, world are directly available on your JS code.
I think the issue is not so much the Snap! API, but the security model of an
iframe. True 2-way communication between a
iframe and the parent document requires some extra work if the domains do not much. Hosting Snap! on your own server will remove some of those restrictions.
We just have one more question: How can we load an existing Snap! project as a preset for the local instance of Snap! (as we did with an iFrame that ran a Snap! project being run on your servers)? Would this involve downloading the .xml file of the project and implementing it locally on our servers? If so, how would we go about doing this?
Thank you again for your time and patience.
Different options here.
If you run your own Snap! copy, you can load by URL Snap! project files (xml) easily.
You only need to call
That worked; thanks for all the help!