Constructor
new ve.ce.GeneratedContentNode()abstract
#
ContentEditable generated content node.
Methods
abortGenerating()
#
Abort the currently pending generation, if any, and remove the generating CSS class.
This invokes .abort() on the pending promise if the promise has that method. It also ensures that if the promise does get resolved or rejected later, this is ignored.
afterRender()
#
Trigger rerender events after rendering the contents of the node.
Nodes may override this method if the rerender event needs to be deferred (e.g. until images have loaded)
Fires:
doneGenerating(generatedContents, [config], [staged])
#
Called when the node successfully finishes generating new content.
Parameters:
failGenerating()
#
Called when the GeneratedContentNode has failed to generate new content.
filterRenderedDomElements(domElements) → {Array.<Node>}
#
forceUpdate([config], [staged])
#
Force the contents to be updated. Like update(), but bypasses the store.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config |
Object |
optional |
Optional additional data to pass to generateContents() |
|
staged |
boolean |
optional |
false | Update happened in staging mode |
generateContents([config]) → {jQuery.Promise}abstract
#
Start a deferred process to generate the contents of the node.
If successful, the returned promise must be resolved with the generated DOM elements passed in as the first parameter, i.e. promise.resolve( domElements ); . Any other parameters to .resolve() are ignored.
If the returned promise object is abortable (has an .abort() method), .abort() will be called if a newer update is started before the current update has finished. When a promise is aborted, it should cease its work and shouldn't be resolved or rejected. If an outdated update's promise is resolved or rejected anyway (which may happen if an aborted promise misbehaves, or if the promise wasn't abortable), this is ignored and doneGenerating()/failGenerating() is not called.
Additional data may be passed in the config object to instruct this function to render something different than what's in the model. This data is implementation-specific and is passed through by forceUpdate().
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
config |
Object |
optional |
Optional additional data |
Returns:
Promise object, may be abortable
- Type
- jQuery.Promise
getRenderedDomElements(domElements) → {Array.<HTMLElement>}
#
Make an array of DOM elements suitable for rendering.
Subclasses can override this to provide their own cleanup steps. This function takes an array of DOM elements cloned within the source document and returns an array of DOM elements cloned into the target document. If it's important that the DOM elements still be associated with the original document, you should modify domElements before calling the parent implementation, otherwise you should call the parent implementation first and modify its return value.
Parameters:
Returns:
Clones of the DOM elements in the right document, with modifications
- Type
- Array.<HTMLElement>
isGenerating() → {boolean}
#
Check whether this GeneratedContentNode is currently generating new content.
Returns:
Whether we're generating
- Type
- boolean
onGeneratedContentNodeUpdate(staged)
#
Handler for the update event
Parameters:
Name | Type | Description |
---|---|---|
staged |
boolean | Update happened in staging mode |
preventTabbingInside()private
#
Prevent tabbing to focusable elements inside the editable surface, because it conflicts with allowing tabbing out of the surface. (The surface takes the focus back when it moves to an element inside it.)
In the future, this might be implemented using the inert
property, currently not supported by
any browser: https://html.spec.whatwg.org/multipage/interaction.html#inert-subtrees
https://caniuse.com/mdn-api_htmlelement_inert
Prevent tabbing to focusable elements inside the editable surface, because it conflicts with allowing tabbing out of the surface.
render(generatedContents, [staged])
#
startGenerating()
#
Called when the node starts generating new content.
This function is only called when the node wasn't already generating content. If a second update comes in, this function will only be called if the first update has already finished (i.e. doneGenerating or failGenerating has already been called).
update([config], [staged])
#
Update the contents of this node based on the model and config data. If this combination of model and config data has been rendered before, the cached rendering in the store will be used.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
config |
Object |
optional |
Optional additional data to pass to generateContents() |
|
staged |
boolean |
optional |
false | Update happened in staging mode |
validateGeneratedContents($element) → {boolean}
#
Check whether the response HTML contains an error.
The default implementation always returns true.
Parameters:
Name | Type | Description |
---|---|---|
$element |
jQuery | The generated element |
Returns:
There is no error
- Type
- boolean
awaitGeneratedContent(view) → {jQuery.Promise}static
#
Wait for all content-generation within a given node to finish
If no GeneratedContentNodes are within the node, a resolved promise will be returned.
Parameters:
Name | Type | Description |
---|---|---|
view |
ve.ce.View | Any view node |
Returns:
Promise, resolved when content is generated
- Type
- jQuery.Promise
Wait for all content-generation within a given node to finish
If no GeneratedContentNodes are within the node, a resolved promise will be returned.