Still wondering if there is a way to alter this code or maybe use it in a Skin so it can write all the json data to just
one file rather than the 2 separate files it currently is set up to do? The reason I ask this, is, many compilers (an example would be
handlebars.js ) are not able to load 2 separate json files to use in a template, only one is possible. Not being able to ustilize the tree.json data in a template is a handicap. Since json files are small, one file would be more efficient as well.
Any help on this would be appreciated!
Mike
This idea was raised by our current German intern too. With such overwhelming request for this idea, I just had to do something about it
. The
latest jAlbum 13 beta now has a new API to generate a JSON metadata tree to a JavaScript variable. You can then use jQuery to parse it. Here's what you need to do in your skin:
This will generate a full JSON formatted data tree to the variable "dataTree". Now, this variable is only known during album-build time. You therefore need to pass it to a client-side javascript variable. To do so, in your index.htt, add the following:
<script>dataTree = ${dataTree};</script>
Now, just continue referring to javascript code snippets, like this:
<script src="res/js/main.js" type="text/javascript"></script>
. These snippets can now simply refer to the dataTree variable via jQuery for instance.
I hope this new "JSONMaker" API will make it far easier to produce skins.
If you like to have other custom variables added to the generated tree, just call setIncludes() on the JSONMaker and pass a string array of variable names. If you wish to switch off the recursive behavior of the generated tree, i.e. so it only lists objects in the current folder, call setMakeTree(false); prior to calling getTreeAsString().
You can also call getTree() which delivers an object tree that can be manipulated on the Java side (in init.bsh). When you're happy with the manipulation, call toJSONString() on the object returned by getTree().