bookmarks.js - The client-side portion of Gate One's Bookmarks plugin.
Adds the given dateTag to the filter list. bookmarks is unused.
Adds the given tag to the filter list. bookmarks is unused.
Adds the given typeTag to the filter list. bookmarks is unused.
Adds the given tag to the bookmark object associated with URL.
Returns an array of all the tags in localStorage[GateOne.prefs.prefix+'bookmarks'] ordered alphabetically.
All the user's bookmarks are stored in this array which is stored/loaded from localStorage[GateOne.prefs.prefix+'bookmarks']. Each bookmark consists of the following data structure:
{
created: 1356974567922,
images: {favicon: "data:image/x-icon;base64,<gobbledygook>"},
name: "localhost",
notes: "Login to the Gate One server itself",
tags: ["Linux", "Ubuntu", "Production", "Gate One"],
updateSequenceNum: 11,
updated: 1356974567922,
url: "ssh://localhost",
visits: 0
}
Most of that should be self-explanatory except the updateSequenceNum (aka USN). The USN value is used to determine when this bookmark was last changed in comparison to the highest USN stored on the server. By comparing the highest client-side USN against the highest server-side USN we can determine what (if anything) has changed since the last synchronization. It is much more efficient than enumerating all bookmarks on both the client and server in order to figure out what's different.
Creates a new bookmark element and places it in bmContainer. Also returns the bookmark element.
Arguments: |
|
---|
Creates or updates a bookmark (in GateOne.Bookmarks.bookmarks and localStorage) using the given bookmark obj.
Creates the bookmarks panel. If the bookmarks panel already exists it will be destroyed and re-created, resetting the pagination.
If embedded is true then we'll just load the header (without search).
Returns a span representing the current sort direction and "sort by" type.
Asks the user for confirmation then deletes the chosen bookmark...
obj can either be a URL (string) or the "go_bm_delete" anchor tag.
Note
Not the same thing as GateOne.Bookmarks.removeBookmark().
Handles the response from the server after we've sent the 'bookmarks_deleted' WebSocket action. Resets localStorage[GateOne.prefs.prefix+'deletedBookmarks'] and displays a message to the user indicating how many bookmarks were just deleted.
Opens the bookmark editor for the given obj (the bookmark element on the page).
Note
Only meant to be called from a 'bm_edit' anchor tag (as the obj).
Allows the user to save their bookmarks as a Netscape-style HTML file. Immediately starts the download.
If bookmarks is given, that array will be what is exported. Otherwise the complete GateOne.Bookmarks.bookmarks array will be exported.
Filters bookmarks to those matching str (used by the search function).
Loops over localStorage[GateOne.prefs.prefix+'iconQueue'] fetching icons until it is empty.
If the queue is currently being processed this function won't do anything when called.
Returns a random, helpful tip for using bookmarks (as a string).
Returns an array of all the autotags in GateOne.Bookmarks.bookmarks or bookmarks if given.
Note
Ordered alphabetically with the URL types coming before date tags.
Returns the bookmark object associated with the given URL.
Given a Date object, returns a string such as "<7 days". Suitable for use as an autotag.
Calculates and returns the number of bookmarks that will fit in the given element (elem). elem may be an element ID or a DOM node object.
Returns an array of all the tags in GateOne.Bookmarks.bookmarks or bookmarks if given.
Note
Ordered alphabetically
Returns the highest updateSequenceNum that exists in all bookmarks.
Increments by 1 the 'visits' value of the bookmark object associated with the given URL.
Creates the bookmarks panel, initializes some important variables, registers the Control-Alt-b keyboard shortcut, and registers the following WebSocket actions:
GateOne.Net.addAction('bookmarks_updated', GateOne.Bookmarks.syncBookmarks);
GateOne.Net.addAction('bookmarks_save_result', GateOne.Bookmarks.syncComplete);
GateOne.Net.addAction('bookmarks_delete_result', GateOne.Bookmarks.deletedBookmarksSyncComplete);
GateOne.Net.addAction('bookmarks_renamed_tags', GateOne.Bookmarks.tagRenameComplete);
Filters/sorts/displays bookmarks and updates the bookmarks panel to reflect the current state of things (draws the tag cloud and ensures the pagination is correct).
If delay (milliseconds) is given, loading of bookmarks will be delayed by that amount before they're drawn (for animation purposes).
Sets up the pagination for the given array of bookmarks and returns the pagination node.
If page is given the pagination will highlight the given page number and adjust the prev/next links accordingly.
Loads the tag cloud. If active is given it must be one of 'tags' or 'autotags'. It will mark the appropriate header as inactive and load the respective tags.
If the current terminal is in a disconnected state, connects to the given URL in the current terminal.
If the current terminal is already connected, opens a new terminal before opening the given URL.
If the given URL does not start with 'ssh://' it will be opened in a new browser tab/window.
Creates a dialog where the user can select some options and export their bookmarks.
Displays the form where a user can create or edit a bookmark.
If URL is given, pre-fill the form with the associated bookmark for editing.
Displays the form where a user can create or edit a bookmark.
If URL is given, pre-fill the form with the associated bookmark for editing.
Creates a dialog where the user can rename the given tagName.
Creates a dialog where the user can utilize a keyword search URL. title will be used to create the dialog title like this: "Keyword Search: title".
Called when 'panel_toggle:in' event is triggered, calls GateOne.Bookmarks.createPanel() if panel is the Bookmarks panel.
Removes the bookmark matching url from GateOne.Bookmarks.bookmarks and saves the change to localStorage.
If callback is given it will be called after the bookmark has been deleted.
Note
Not the same thing as GateOne.Bookmarks.deleteBookmark().
Removes the given dateTag from the filter list. bookmarks is unused.
Removes the given tag from the filter list. bookmarks is unused.
Removes the given typeTag from the filter list. bookmarks is unused.
Renames the tag matching oldName to be newName for all bookmarks that have it.
An associative array of functions that are used to sort bookmarks. When the user clicks on one of the sorting options it assigns one of these functions to GateOne.Bookmarks.sortfunc() which is then applied like so:
bookmarks.sort(GateOne.Bookmarks.sortfunc);
Sorts bookmarks alphabetically.
Sorts bookmarks by date modified followed by alphabetical.
Sorts bookmarks according to the number of visits followed by alphabetical.
Stores the given bookmarkObj in localStorage.
if callback is given it will be executed after the bookmark is stored with the bookmarkObj as the only argument.
Takes an array of bookmarks and stores them in GateOne.Bookmarks.bookmarks.
If recreatePanel is true, the panel will be re-drawn after bookmarks are stored.
If skipTags is true, bookmark tags will be ignored when saving the bookmark object.
Stores the given dataURI as the 'favicon' image for the given bookmark.
Called when the 'bookmarks_updated' WebSocket action is received from the server. Removes bookmarks marked as deleted on the server, uploads new bookmarks that are not on the server (yet), and processes any tags that have been renamed.
Called when the sync (download) is completed. Stores the current highest updateSequenceNum in localStorage, and notifies the user of any errors that occurred during synchronization.
Called when we right-click on a tag elem. Gives the user the option to rename the tag or cancel the context menu.
Called when the 'bookmarks_renamed_tags' WebSocket action is received from the server. Deletes localStorage[GateOne.prefs.prefix+'renamedTags'] (which stores tags that have been renamed and are awaiting sync) and displays a message to the user indicating that tags were renamed successfully.
Reverses the order of the bookmarks list
Makes an AJAX call to <Gate One URL>/bookmarks/fetchicon to retrieve a favicon for the given bookmark and calls storeFavicon() if an icon was able to be retrieved.
Loops over the given urls attempting to fetch and store their respective favicons.
Note
This function is only used when debugging. It is called by no other functions.
Creates/updates a progress bar given a name, a total, and num representing the current state of an action.
Optionally, a description (desc) may be provided that will be placed above the progress bar.
Updates the updateSequenceNum of the bookmark matching obj in GateOne.Bookmarks.bookmarks (and in localStorage via storeBookmark()).
This gets attached to the "user_login" event. Calls the server-side 'bookmarks_get' WebSocket action with the current USN (Update Sequence Number) to ensure the user's bookmarks are in sync with what's on the server.
bookmarks.py - A plugin for Gate One that adds fancy bookmarking capabilities.
This Python plugin file implements the following hooks:
hooks = {
'Web': [
(r"/bookmarks/fetchicon", FaviconHandler),
(r"/bookmarks/export", ExportHandler),
(r"/bookmarks/import", ImportHandler),
],
'WebSocket': {
'bookmarks_sync': save_bookmarks,
'bookmarks_get': get_bookmarks,
'bookmarks_deleted': delete_bookmarks,
'bookmarks_rename_tags': rename_tags,
}
}
Unescape HTML code refs; c.f. http://wiki.python.org/moin/EscapingHtml
Reads the Netscape-style bookmarks.html in string, html and returns a list of Bookmark objects.
Recursively looks inside json_dict trying to find tags associated with the given url. Returns the tags found as a list.
Given a json_dict, updates urls_list with each URL as it is found within.
Note
Only works with Netscape-style bookmarks.json files.
Given json_str, returns a list of bookmark objects representing the data contained therein.
Used to read and write bookmarks to a file on disk. Can also synchronize a given list of bookmarks with what's on disk. Uses a given bookmark's updateSequenceNum to track what wins the "who is newer?" comparison.
Sets up our bookmarks database object and reads everything in.
Opens the bookmarks stored in self.user_dir. If not present, an empty file will be created.
Given bookmarks, synchronize with self.bookmarks doing conflict resolution and whatnot.
Retrives the biggest favicon-like icon at the given URL. It will try to fetch apple-touch-icons (which can be nice and big) before it falls back to grabbing the favicon.
Note
Works with GET and POST requests but POST is preferred since it keeps the URL from winding up in the server logs.
Parses html looking for a favicon URL. Returns a tuple of:
(<url>, <mimetime>)
If no favicon can be found, returns:
(None, None)
Takes a bookmarks.html in a POST and returns a list of bookmarks in JSON format
Takes a JSON-encoded list of bookmarks and returns a Netscape-style HTML file.
Returns a JSON-encoded list of bookmarks updated since the last updateSequenceNum.
If updateSequenceNum resolves to False, all bookmarks will be sent to the client.
Handles deleting bookmars given a deleted_bookmarks list.
Handles renaming tags.