Constructor
new Controller(target, config)
#
EditCheck controller
Manages triggering and updating edit checks.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
target |
ve.init.mw.Target | The VisualEditor target |
||||||
config |
Object |
Properties:
|
- Mixes in:
- Source:
Methods
clearState()
#
Reset controller state (on init or teardown)
- Source:
closeDialog([action]) → {jQuery.Promise}
#
Closes the edit check dialog
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
string |
optional |
Name of action which triggered the close ('mobile-keyboard', 'context', 'preSaveProcess') |
Returns:
- Type
- jQuery.Promise
- Source:
closeSidebars([action]) → {jQuery.Promise}
#
Closes the sidebar edit check dialogs (mid-edit).
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
string |
optional |
Name of action which triggered the close (currently only 'preSaveProcess') |
Returns:
- Type
- jQuery.Promise
- Source:
drawSelections()
#
Redraw selection highlights
- Source:
editChecksArePossible() → {boolean}
#
Check if any edit checks could be run for the current user/context
Returns:
- Type
- boolean
- Source:
ensureActionIsShown(action)
#
Make sure an action is visible to the user
This will scroll the action into view and make sure its widget is expanded so the contents can be seen.
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | Action to focus |
- Source:
Make sure an action is visible to the user
This will scroll the action into view and make sure its widget is expanded so the contents can be seen.
focusAction(action, [scrollTo], [alignToTop])
#
Trigger a focus state for a given action
Will emit a focusAction event if the focused action changed or if scrolling was requested.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
mw.editcheck.EditCheckAction | Action to focus |
|
scrollTo |
boolean |
optional |
Scroll action's selection into view |
alignToTop |
boolean |
optional |
Align selection to top of page when scrolling |
Fires:
- Source:
Trigger a focus state for a given action
Will emit a focusAction event if the focused action changed or if scrolling was requested.
focusActionForSelection()
#
Update actions based on the current selection
Fires:
- Source:
getActions([listener]) → {Array.<mw.editcheck.EditCheckAction>}
#
Get actions by listener
If no listener is specified, then get all actions relevant to the current moment, i.e.:
- During beforeSave, get onBeforeSave listeners
- Otherwise, get all mid-edit listeners
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
listener |
string |
optional |
The listener; if omitted, get all relevant actions |
Returns:
Actions
- Source:
Get actions by listener
If no listener is specified, then get all actions relevant to the current moment, i.e.:
- During beforeSave, get onBeforeSave listeners
- Otherwise, get all mid-edit listeners
onActionAct(action, promise, actionTaken)
#
Handle instrumentation and tracking when an action is used
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | that was used |
promise |
Promise | jQuery.Promise | that will resolve when the action finishes |
actionTaken |
string | name of the action taken |
- Source:
onActionSeen(action)
#
Handle instrumentation and tracking when an action is marked as seen
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | that was seen |
- Source:
onActionsUpdated(listener, actions, newActions, discardedActions)
#
Handler when 'actionsUpdated' fires.
Updates gutter and highlights when the action list has changed. Displays the edit check dialog if it is not already on screen.
Parameters:
| Name | Type | Description |
|---|---|---|
listener |
string | e.g. onBeforeSave, onDocumentChange, onBranchNodeChange |
actions |
Array.<mw.editcheck.EditCheckAction> | |
newActions |
Array.<mw.editcheck.EditCheckAction> | |
discardedActions |
Array.<mw.editcheck.EditCheckAction> |
Listens to Events:
- Source:
onBranchNodeChange()
#
Handle changes to the selection moving between branch nodes
- Source:
onContextChange()
#
Handle contextChange events from the surface model
- Source:
onDocumentChange()
#
Handle changes to the document model (undoStackChange)
- Source:
onPosition(passive)
#
Handle position events from the surface view
Parameters:
| Name | Type | Description |
|---|---|---|
passive |
boolean | Event is passive (don't scroll) |
- Source:
onSelect(selection)
#
Handle select events from the surface model
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
ve.dm.Selection | New selection |
- Source:
onSidebarDialogsOpeningOrClosing(win, openingOrClosing)
#
Handle sidebar dialog open/close events
Transition skin/VE components around to make room for sidebar
Parameters:
| Name | Type | Description |
|---|---|---|
win |
OO.ui.Window | The window instance |
openingOrClosing |
jQuery.Promise | Promise that resolves when closing finishes |
- Source:
Handle sidebar dialog open/close events
Transition skin/VE components around to make room for sidebar
onSurfaceFocus()
#
Handle focus events from the surface view
- Source:
refresh(useCache) → {Promise.<Array.<mw.editcheck.EditCheckAction>>}
#
Update edit check list
Parameters:
| Name | Type | Description |
|---|---|---|
useCache |
boolean | Whether to piggyback onto an existing refresh if one is ongoing |
Returns:
An updated set of actions. This promise will resolve after any actionsUpdated events are fired.
- Type
- Promise.<Array.<mw.editcheck.EditCheckAction>>
Fires:
- Source:
removeAction(listener, action, rejected)
#
Remove an edit check action
Parameters:
| Name | Type | Description |
|---|---|---|
listener |
string | Listener which triggered the action |
action |
mw.editcheck.EditCheckAction | Action to remove |
rejected |
boolean | The action was rejected |
Fires:
- Source:
restoreToolbar(target)
#
Restores the original toolbar tools after review mode is complete.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
ve.init.mw.ArticleTarget |
- Source:
scrollActionIntoView(action, [alignToTop])
#
Scrolls an action's selection into view
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
mw.editcheck.EditCheckAction | ||
alignToTop |
boolean |
optional |
Align the selection to the top of the viewport |
- Source:
setIgnoreNextSelectionChange([ignore])
#
Whether to ignore the next select event that is received
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
ignore |
boolean |
optional |
true |
- Source:
setup()
#
Set up controller
- Source:
setupPreSaveProcess()
#
Adds the pre-save edit check dialog before the normal page commit dialog. Handles closing the mid-edit dialog, as well as restoring it if the user exits the pre-save check dialog.
We execute all pre-save checks, which may be asynchronous, and wait for them to complete before opening the pre-save dialog.
TODO: Set a time-out so that we don't hang forever if an async check takes too long.
- Source:
setupToolbar(target)
#
Replace toolbar tools for review mode during pre-save checks.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
ve.init.mw.ArticleTarget |
- Source:
suppressSuggestionDisplay(suppress)
#
Controls whether suggestions are displayed to the user.
When suppressed, suggestions will still continue to be generated and cached, just not displayed. For use by external tools.
Parameters:
| Name | Type | Description |
|---|---|---|
suppress |
boolean | if true, does not display any suggestions |
- Source:
updateCurrentBranchNodeFromSelection(selection) → {boolean}
#
Set the current branch node from a selection
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
ve.dm.Selection | New selection |
Returns:
whether the branch node changed
- Type
- boolean
- Source:
updateForListener(listener, fromRefresh) → {Promise.<Array.<mw.editcheck.EditCheckAction>>}
#
Fires all edit checks associated with a given listener.
Actions are created anew for every run, but we want continuity for certain state changes. We therefore match them up to existing actions by checking for equality, ie, the same constructor and same ID or fragments.
We return a promise so that UI actions such as opening the pre-save dialog do not occur until checks have completed.
Parameters:
| Name | Type | Description |
|---|---|---|
listener |
string | e.g. onBeforeSave, onDocumentChange, onBranchNodeChange |
fromRefresh |
boolean | Update comes from a manual refresh, not a real event |
Returns:
An updated set of actions.
- Type
- Promise.<Array.<mw.editcheck.EditCheckAction>>
Fires:
- Source:
updatePositions()
#
Update position of edit check highlights
Fires:
- Source:
updateShownStats(actions, moment)
#
Track some actions as having been shown
Parameters:
| Name | Type | Description |
|---|---|---|
actions |
Array.<mw.editcheck.EditCheckAction> | |
moment |
string | 'midedit' or 'presave' |
- Source: