' ).addClass( 've-ui-editCheck-toolbar-title' ).text( ve.msg( 'editcheck-dialog-title' ) )
);
if ( OO.ui.isMobile() ) {
reviewToolbar.$element.addClass( 've-init-mw-mobileArticleTarget-toolbar' );
}
target.toolbar.$element.before( reviewToolbar.$element );
target.toolbar = reviewToolbar;
reviewToolbar.initialize();
this.originalToolbar = toolbar;
this.reviewToolbar = reviewToolbar;
};
Controller.prototype.restoreToolbar = function ( target ) {
if ( !this.reviewToolbar ) {
return;
}
this.reviewToolbar.$element.remove();
this.originalToolbar.toggle( true );
target.toolbar = this.originalToolbar;
// Creating a new PositionedTargetToolbar stole the
// toolbar windowmanagers, so we need to make the
// original toolbar reclaims them:
target.setupToolbar( target.getSurface() );
// If the window was resized while the originalToolbar was hidden then
// the cached measurements will be wrong. Recalculate.
this.originalToolbar.onWindowResize();
this.reviewToolbar = null;
this.originalToolbar = null;
};
Controller.prototype.drawSelections = function () {
const surfaceView = this.surface.getView();
if ( this.focused ) {
// The currently-focused check gets a selection:
// TODO: clicking the selection should activate the sidebar-action
surfaceView.getSelectionManager().drawSelections(
'editCheckWarning',
this.focused.getHighlightSelections().map(
( selection ) => ve.ce.Selection.static.newFromModel( selection, surfaceView )
)
);
} else {
surfaceView.getSelectionManager().drawSelections( 'editCheckWarning', [] );
}
if ( this.listener === 'onBeforeSave' ) {
// Review mode grays out everything that's not highlighted:
const highlightNodes = [];
this.getActions().forEach( ( action ) => {
action.getHighlightSelections().forEach( ( selection ) => {
highlightNodes.push.apply( highlightNodes, surfaceView.getDocument().selectNodes( selection.getCoveringRange(), 'branches' ).map( ( spec ) => spec.node ) );
} );
} );
surfaceView.setReviewMode( true, highlightNodes );
}
};
Controller.prototype.drawGutter = function () {
if ( OO.ui.isMobile() ) {
return;
}
this.$highlights.empty();
const actions = this.getActions();
if ( actions.length === 0 ) {
return;
}
const surfaceView = this.surface.getView();
actions.forEach( ( action ) => {
action.top = Infinity;
action.getHighlightSelections().forEach( ( selection ) => {
const selectionView = ve.ce.Selection.static.newFromModel( selection, surfaceView );
const rect = selectionView.getSelectionBoundingRect();
if ( !rect ) {
return;
}
// The following classes are used here:
// * ve-ui-editCheck-gutter-highlight-error
// * ve-ui-editCheck-gutter-highlight-warning
// * ve-ui-editCheck-gutter-highlight-notice
// * ve-ui-editCheck-gutter-highlight-success
// * ve-ui-editCheck-gutter-highlight-active
// * ve-ui-editCheck-gutter-highlight-inactive
this.$highlights.append( $( '' )
.addClass( 've-ui-editCheck-gutter-highlight' )
.addClass( 've-ui-editCheck-gutter-highlight-' + action.getType() )
.addClass( 've-ui-editCheck-gutter-highlight-' + ( action === this.focused ? 'active' : 'inactive' ) )
.css( {
top: rect.top - 2,
height: rect.height + 4
} )
.on( 'click', () => this.focusAction( action ) )
);
action.top = Math.min( action.top, rect.top );
} );
} );
surfaceView.appendHighlights( this.$highlights, false );
};
Controller.prototype.scrollActionIntoView = function ( action ) {
// scrollSelectionIntoView scrolls to the focus of a selection, but we
// want the very beginning to be in view, so collapse it:
const selection = action.getHighlightSelections()[ 0 ].collapseToStart();
const padding = {
top: OO.ui.isMobile() ? 80 : action.widget.$element[ 0 ].getBoundingClientRect().top,
bottom: 20
};
if ( ve.ui.FixedEditCheckDialog.static.position === 'below' ) {
// TODO: ui.surface getPadding should really be fixed for this
const currentWindow = this.surface.getToolbarDialogs( ve.ui.FixedEditCheckDialog.static.position ).getCurrentWindow();
if ( currentWindow ) {
padding.bottom += currentWindow.getContentHeight();
}
}
this.surface.scrollSelectionIntoView( selection, {
animate: true,
padding: padding,
alignToTop: true
} );
};
Controller.prototype.closeDialog = function ( action ) {
this.focusAction( undefined );
const windowAction = ve.ui.actionFactory.create( 'window', this.surface, 'check' );
return windowAction.close( 'fixedEditCheckDialog', action ? { action: action } : undefined ).closed.then( () => {}, () => {} );
};
Controller.prototype.closeSidebars = function ( action ) {
const currentWindow = this.surface.getSidebarDialogs().getCurrentWindow();
if ( currentWindow ) {
// .always is not chainable
return currentWindow.close( action ? { action: action } : undefined ).closed.then( () => {}, () => {} );
}
return ve.createDeferred().resolve().promise();
};
module.exports = {
Controller: Controller
};