Bookmarking system complete
Wrote the bookmarking system for the eXist site, which is basically as described in my previous post. Here's a more technical breakdown of the features:
Adding a Bookmark
When a user adds a bookmark, an AJAX request with the video ID, the timestamp, and any optional comments is sent to plugins/bookmarks/ajax/add.xql. This XQuery script returns a JSON object with the ID (i.e. bookmark/@n) of the new bookmark, the timestamp, and the comments if applicable. The add.xql script actually returns XML that is passed through the eXist JSON serializer:
declare option exist:serialize "method=json media-type=text/javascript";
If the bookmark can't be added, which happens if the video ID is invalid, then a 500 error is returned.
Upon successful addition, the JSON response object is parsed by the calling Javascript, which adds a list element to the ordered list of bookmarks.
Deleting a Bookmark
Deleting a bookmark (clicking on the 'X' image next to the bookmark in the ordered list) simply removes the bookmark from the DOM. Bookmark data files are never actually deleted from the server.
Saving Bookmarks
Saving a bookmark list requires no AJAX interaction with the server. Rather, all of the bookmark IDs are gathered from the ordered list of bookmarks (each of which has an ID of bookmark-## where ## corresponds to bookmark/@n in the XML data) and then simply appended to the URL of the video page. This URL is given to the user, who can add it to their bookmark collection for later use. The ids are added as comma-separated values of a "bm" GET parameter. For example: player.xql?id=fraq1&bm=54,55,56
Loading Saved Bookmarks
When a user visits a video with a bm query string (see 'Saving Bookmarks' above), an AJAX call is sent to plugins/bookmarks/ajax/load.xql for each bookmark ID in the query string. Upon successful load of the bookmark - success means that the ID corresponds to bookmark/@n and the current video corresponds to bookmark/@videoId - a JSON-serialized XML node is returned (see 'Adding a Bookmark' above), which is then used to populate the unordered list of bookmarks.