Octavo exports an object called octavo
into the main JavaScript namespace. The following sections document some of the stuff that you can do with it.
Set a new command, e.g.
octavo.command "Category", "command name", "Documentation for the command", (element) -> element.doSomething()
element
is a jQuery object, though depending on the Category
value, you might get different things passed to the command such as an Octavo position object or nothing at all.
This is a mapping of key combinations to functions that do things.
You could use this to map a key combination to a command:
octavo.shortcuts["Ctrl+U"] = (position) -> octavo.commands["Category"]["command name"] position.block
At the moment, you can't easily reassign shortcuts to other existing shortcuts. Say you wanted to swap the action of ⌃D and ⌃G for example. You'd have to cache the values and then swap them.
Ctrl_D = octavo.shortcuts["Ctrl+D"] Ctrl_G = octavo.shortcuts["Ctrl+G"] octavo.shortcuts["Ctrl+D"] = Ctrl_G octavo.shortcuts["Ctrl+G"] = Ctrl_D
Do stuff, but remember where the caret was!
octavo.silently -> octavo.commands["Category"]["command name"] position.block
This gets user input and then does something with it using a callback.
octavo.input (value) -> console.log "#{value} is what the user entered"
Changes an element.
octavo.change position.block, "diamonds" # Your ticket is now DIAMONDS
These take a node or jQuery object and do pretty much what they say on the tin.
These do what octavo.silently
does, but in two stages. What kind of crazy buffalo would do such a thing? Well, sometimes you need to defer restoration of the caret—for example when you're making a call to octavo.input
. Also, saveCaret and restoreCaret remember the most recent change only, so you don't end up with Rangy accidentally replacing your caret boundary marker and then not being able to restore it.
A boolean saying whether Octavo is in edit mode or not.
Booleans representing internal options. Don't set these both to true
, that would be wacky.
This is a hash of the commands.
This maps commands to their documentation. Maybe it should be called octavo.documentation
. Too logical? What do you think?
Turn Octavo's editor mode on, off, or toggle it.
This is metadata about what Octavo considers to be block elements and phrasal elements.
Use them as follows:
if element.tagName.toLowerCase() of octavo.blocks console.log "#{element.tagName} is an Octavo block"