- "Protected": instance variable or function that begins with an underscore (ie
@_loadComplex: () ->). Should only be used by subclasses - "Attribute":
Backbone.Modelthat can be changed via@get('name')orset('name', value, options) - "Property": instance variable on the model (ie
@propertyName) - "Method": instance function on the model (ie
@isDirty()) - "Event": event fired on the Model (ie
@on 'ui:saved', () ->) - "Singletons": Only one instance of this exists in the runtime
ALL_CAPS: Enum or Singleton_startsWithUnder: "Protected" variable or method (only to be used by subclasses)camelCase: local variable/function or instance variable/functionClassName: class or variable containing a constructor
- manipulate relationships
- fire
child:add/removeevents and trickle up - keep lists (
Backbone.Collection) ofgetChildren() - do not set HTML
- implement
_loadComplex() serialize()parse()(sendparse: truein options)onReloaded()onSaved()
Stores all loadable/saveable models
acceptsinstance variable contains array of mediatypessave()optional method (defined inEpubContainerbut unused inWorkspace)
- refers to set of models (
allContentSingleton) - fires
reloadedon models - remembers hash of last commit
- listens to all models
- sets dirty flag (unless
options.parseis set)
Models may contain state that is not saved (only used for UI).
These are defined as Backbone.Model attributes that begin with ui:.
ui:unsavedboolean: this model has unsaved local changesui:selectedboolean: this model is selected (currently showing in the content editor, or currently in the sidebar)ui:originalJSON: the most recently loaded JSON object
Note: when an event is caused by a remote update, the {remote:true} option will be sent along with the event
- The usual
change:*events toc:add/remove/move- HTML
resource:add/remove: Notify when resources (images) are added/removed
- Attributes:
id: always an absolute href from the root of the EPUBui:unsaved: boolean denotes there are local changes to this model
- Events (optional):
loadedreloadedsaved
- Methods:
- defines
load(): returns a promise - defines
reload(): returns a promise - defines
isDirty(): NOTE: use this method instead of checkingui:dirtybecause a Book can be dirty if the OPF OR the NavPage have unsaved changes - abstract
onReloaded(): returnstrueif there are NO local changes - abstract
_loadComplex()(used byload()if the model needs more than a singlefetch()to "load" itself - abstract
onSaved()(called bySAVER)
- defines
Mixin that provides a tree structure:
getChildren()getParent()getRoot()dfs( (model) -> )returns the first match defined by iterator ornullusing a depth-first-searchbfs( (model) -> )returns the first match defined by iterator ornullusing a breadth-first-searchaddChild(child, at)removeChild(child, options)newNode(options)defined only on the root; returns a newBackbone.Modelusing the options passed in
- Properties:
_tocNodesCollection of all leaf nodes (for easy lookup)
- abstract
getToc()returns theTocPage(or self in the case ofatc)
change:body(possibly also with{remote:true}option)resource:add/remove(Note: Maybe this should be done byxhtml-file?)
- extends
Page getChildren()and fireschild:add/remove/move(possibly also with{remote:true}option)- the
Bookis passed in to the constructor - listens to
toc:add/remove/moveand updates the HTML - Note: abstract
serialize()andparse()are still undefined
getPage()returns aPageornullif it does not point to a Page (like a chapter or unit)- Optionally can store a
titleattribute (overridden title) - Note: abstract
addChildis still undefined
serialize(): return an OPF XML fileparse(): Parse an OPF XML file. Add all<manifest/>items toALL_CONTENTsaved(): clear all "local changes"reloaded(): replay local changes- always add
<manifest>items (never remove, just to be safe) - DO NOT redo local property changes like
title,isbn, etc (instead let the user know they were changed remotely; to reduce thrashing)
- always add
Notes:
- (Optional) fires
item:add/remove(also called because of remote changes with{remote:true}option) - listens to
toc:add/removeandresource:add/removeto update the<manifest/>items
serialize(): return@get('body')and@('head')(and maybetitle)parse(): set@set('body'),head, andtitlereloaded(): usejsdifflibto find changes (and detect conflicts; use the remote one when conflict occurs)
- defines
addChild(model, at)which either links to the child or creates a Copy (if it is a different book) - contains an overridden
titleproperty if there is one- NOTE: ToC views should use
@.toJSON().titleinstead of@get('title')when rendering the ToC to ge the correct title (in the book context)
- NOTE: ToC views should use
- extends
xhtml-file getChildren()- fires
child:add/remove/move