Class jabberwerx.ui.JWView
Extends
jabberwerx.JWModel.
Abstract base class for views.
Subclasses MUST override the following:
- #createDOM to generate the content
Subclasses SHOULD override the following:
- #update to update the view.
This class provides the following events:
Constructor Attributes | Constructor Name and Description |
---|---|
Creates a new jabberwerx.ui.JWView instance. |
Field Attributes | Field Name and Description |
---|---|
The jQuery-wrapped content element for this jabberwerx.ui.JWView. |
|
<static> <constant> |
jabberwerx.ui.JWView.persist_html
Base class automatically saves and loads the innerHTML of the
view's current #jq
|
<static> <constant> |
jabberwerx.ui.JWView.persist_none
No automatic persistence by base class
|
Method Attributes | Method Name and Description |
---|---|
createDOM(doc)
Called by #render to generate the content for this View. |
|
destroy()
Destroys this view. |
|
Called by #remove to destroy the DOM content of this view. |
|
dimensions(dim)
Retrieves or changes the dimensions of this view. |
|
height(h, noupdate)
Retrieves or changes the height of this view. |
|
hide()
Hides the view if visible in the document. |
|
parent()
Retreives the parent jabberwerx.ui.JWView for this instance. |
|
persistOptions(opts)
Set or retrieve built in persistence flags. |
|
remove()
Removes this jabberwerx.ui.JWView's contents. |
|
render(doc)
Renders this jabberwerx.ui.JWView. |
|
restoreDOM(doc)
Called by #restoreRender to generate the content for this View from previously persisted state data. |
|
restoreRender(doc)
Renders this jabberwerx.ui.JWView the first time after rehydration. |
|
Called by #restoreRender when the view's jq member has been assigned. |
|
Determines if this view should be saved in object graphs. |
|
show()
Shows the view if hidden in the document. |
|
update()
Updates this view. |
|
Called when this instance has been rehydrated. |
|
width(w, noupdate)
Retrieves or changes the width of this view. |
|
Check #persistOptions and save the current JQ's xml as needed. |
- Methods borrowed from class jabberwerx.JWModel:
- applyEvent, event
- Methods borrowed from class jabberwerx.JWBase:
- getClassName, graphUnserialized, init, invocation, shouldBeSerializedInline, toString
The jQuery-wrapped content element for this jabberwerx.ui.JWView.
NOTE: Do not modify this value directly; instead it is created via #render and deleted via #remove.
- See:
- #persistOptions
- See:
- #persistOptions
Called by #render to generate the content for this View. Subclasses MUST override this method, returning the DOM element that is to be this view's content.
NOTE: This method should not be called directly; instead it is called by #render when necessary.
- Parameters:
- {Document} doc
- The Document to use for creating content
- Returns:
- {Element|jQuery} The content element (either as a DOM element or the jQuery-wrapped DOM element)
- See:
- #render
Destroys this view. This implementation calls #remove before calling the superclass' implementation.
Called by #remove to destroy the DOM content of this view. The current implementation does nothing.
Subclasses MAY override this method to perform any necessary cleanup. The value of #jq has not yet been deleted.
NOTE: This method should not be called directly; instead it is called by #remove when necessary.
Retrieves or changes the dimensions of this view. This method is a convenience for calling #width and #height within a single method call, although #update is only called once.
If this method is called without any arguments, the current dimensions are returned. Otherwise, the dimensions are changed and this jabberwerx.ui.JWView is returned.
The return value (or value of {dim}) is an object with the following properties:
{ width: {Number|String}, //the pixel width (if Number), or CSS //value (if String) height: {Number|String}, //the pixel height (if Number), or CSS //value (if String) }
- Parameters:
- {Object} dim Optional
- The new dimensions, or undefined to retrieve the current dimensions
- Returns:
- {Object|jabberwerx.ui.JWView} The current dimensions (if {dim} is undefined); or this jabberwerx.ui.JWView if the dimensions were changed
Retrieves or changes the height of this view.
If {h} is not defined, this method returns the current height of this view, in pixels. Otherwise the height is changed to the value of {h} in pixels (if a Number) or the CSS value (if a String), #update is called (unless {noupdate} is true), and this jabberwerx.ui.JWView is returned.
If this view is not currently rendered, this method returns 0 for retrieval, and ignores {h} for changes.
- Parameters:
- {Number|String} h Optional
- The new height (or undefined to retrieve the current height)
- {Boolean} noupdate Optional
- true if the view should NOT be updated
- Returns:
- {Number|jabberwerx.ui.JWView} The current height (if retrieving); or this jabberwerx.ui.JWView (if changing)
- See:
- #dimensions
Hides the view if visible in the document. View state is kept in #jq so this method does nothing if called before #render .
- Returns:
- {jabberwerx.ui.JWView} self refernce
Retreives the parent jabberwerx.ui.JWView for this instance. This method locates the parent by recursing through the parent DOM elments until a jabberwerx.ui.JWView instance is found.
- Returns:
- {jabberwerx.ui.JWView} The parent view, or null if not found
Set or retrieve built in persistence flags. The jabberwerx.ui.JWView base class can serialize its JQ reference by storing the JQ's innerHTML. The default is #persist_none. If #persist_html is set the base class will store and reload the JQ's html. /p>
- Parameters:
- {Integer} opts
- Serialization options implemented implemented in the base class. #persist_html.
- Returns:
- {jabberwerx.ui.JWView} self reference
Removes this jabberwerx.ui.JWView's contents. This method performs the following:
- Calls #destroyDOM.
- Removes #jq from its parent
- Deletes #jq.
- Triggers the "viewRemoved" event with the previous value of #jq as the data.
If #jq is not valid when this method is called, no actions are taken.
- Returns:
- {jabberwerx.ui.JWView} This jabberwerx.ui.JWView instance
Renders this jabberwerx.ui.JWView. This method performs the following:
- Calls #createDOM to generate the content to render
- Stores the content as a jQuery-wrapped object in #jq.
- Triggers the "viewRendered" event with the jQuery-wrapped object as data.
- Calls #update.
- Returns #jq.
If this view has already been rendered, then #update is called and #jq is returned.
- Parameters:
- {Document} doc Optional
- The document to use for rendering; defaults to the global document object is not defined.
- Throws:
- {TypeError}
- if {doc} is not a valid Document.
- {ReferenceError}
- if the generated DOM is not valid
- Returns:
- {jQuery} The jQuery-wrapped content to be inserted
Called by #restoreRender to generate the content for this View from previously persisted state data. Subclasses may override this method, returning the DOM element that is to be this view's content. Default behavior is to return the result of a #createDOM call if #persist_html was not in #persistOptions. If HTML was persisted this base class returns the DOM element built from it. .
NOTE: This method should not be called directly; instead it is called by #restoreRender when necessary.
- Parameters:
- {Document} doc
- The Document to use for creating content
- Returns:
- {Element|jQuery} The content element (either as a DOM element or the jQuery-wrapped DOM element)
- See:
- #restoreRender
Renders this jabberwerx.ui.JWView the first time after rehydration.
This method is called the first time the view is rendered after rehydration. Unlike #render this method invokes restoreDOM, restoreUpdate and does not trigger any events.
- Parameters:
- {Document} doc Optional
- The document to use for rendering; defaults to the global document object is not defined.
- Throws:
- {TypeError}
- if {doc} is not a valid Document.
- {ReferenceError}
- if the generated DOM is not valid
- Returns:
- {jQuery} The jQuery-wrapped content to be inserted
Called by #restoreRender when the view's jq member has been assigned. Gives subclasses a way of initializing the DOM, above and beyond #update. Update is used to refresh the view from its current state (redraw) *or* from associated models, a behavior undeeded and unwanted when rehydrating.
NOTE: This method should not be called directly; instead it is called by #restoreRender when necessary.
- Returns:
- {jabberwerx.ui.JWView} self reference
- See:
- #restoreRender
Determines if this view should be saved in object graphs. Default behavior is to include the view
- Returns:
- {Boolean} Always true
Shows the view if hidden in the document. View state is kept in #jq so this method does nothing if called before #render .
- Returns:
- {jabberwerx.ui.JWView} self refernce
Updates this view. This method is called by #dimensions, #height, and #width automatically, but may also be called directly to force an update of the view.
Subclasses SHOULD override this method to perform any necessary changes, but SHOULD call the super-classes implementation.
- Returns:
- {Boolean} true if the view is updatable (e.g. if #jq is valid).
Called when this instance has been rehydrated. Subclass changes #render to a #restoreRender reference. This allows special handling of the first render after a rehydration.
- Returns:
- {Boolean} Always true
Retrieves or changes the width of this view.
If {w} is not defined, this method returns the current width of this view, in pixels. Otherwise the width is changed to the value of {w} in pixels (if a Number) or the CSS value (if a String), #update is called (unless {noupdate} is true), and this jabberwerx.ui.JWView is returned.
If this view is not currently rendered, this method returns 0 for retrieval, and ignores {w} for changes.
- Parameters:
- {Number|String} w Optional
- The new width (or undefined to retrieve the current width)
- {Boolean} noupdate Optional
- true if the view should NOT be updated
- Returns:
- {Number|jabberwerx.ui.JWView} The current width (if retrieving); or this jabberwerx.ui.JWView (if changing)
- See:
- #dimensions
Check #persistOptions and save the current JQ's xml as needed. Sets JQ to null to prevent any further serialization of that object.
- Returns:
- {Boolean} Always true