- "Protected": instance variable or function that begins with an underscore (ie
@_loadComplex: () ->
). Should only be used by subclasses - "Attribute":
Backbone.Model
that 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/remove
events and trickle up - keep lists (
Backbone.Collection
) ofgetChildren()
- do not set HTML
- implement
_loadComplex()
serialize()
parse()
(sendparse: true
in options)onReloaded()
onSaved()
Stores all loadable/saveable models
accepts
instance variable contains array of mediatypessave()
optional method (defined inEpubContainer
but unused inWorkspace
)
- refers to set of models (
allContent
Singleton) - fires
reloaded
on models - remembers hash of last commit
- listens to all models
- sets dirty flag (unless
options.parse
is 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:unsaved
boolean: this model has unsaved local changesui:selected
boolean: this model is selected (currently showing in the content editor, or currently in the sidebar)ui:original
JSON: 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):
loaded
reloaded
saved
- Methods:
- defines
load()
: returns a promise - defines
reload()
: returns a promise - defines
isDirty()
: NOTE: use this method instead of checkingui:dirty
because a Book can be dirty if the OPF OR the NavPage have unsaved changes - abstract
onReloaded()
: returnstrue
if 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 ornull
using a depth-first-searchbfs( (model) -> )
returns the first match defined by iterator ornull
using a breadth-first-searchaddChild(child, at)
removeChild(child, options)
newNode(options)
defined only on the root; returns a newBackbone.Model
using the options passed in
- Properties:
_tocNodes
Collection 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
Book
is passed in to the constructor - listens to
toc:add/remove/move
and updates the HTML - Note: abstract
serialize()
andparse()
are still undefined
getPage()
returns aPage
ornull
if it does not point to a Page (like a chapter or unit)- Optionally can store a
title
attribute (overridden title) - Note: abstract
addChild
is still undefined
serialize()
: return an OPF XML fileparse()
: Parse an OPF XML file. Add all<manifest/>
items toALL_CONTENT
saved()
: 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/remove
andresource:add/remove
to update the<manifest/>
items
serialize()
: return@get('body')
and@('head')
(and maybetitle
)parse()
: set@set('body')
,head
, andtitle
reloaded()
: usejsdifflib
to 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
title
property if there is one- NOTE: ToC views should use
@.toJSON().title
instead 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