mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 08:34:54 +00:00
71020f7175
[jshint] ce/ve.ce.Surface.js: line 670, col 9, Too many var statements. ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon. ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='. ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='. ce/ve.ce.Surface.js: line 733, col 13, Too many var statements. ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='. ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements. ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements. ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements. ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements. dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'. dm/ve.dm.Converter.js: line 383, col 29, Empty block. dm/ve.dm.Converter.js: line 423, col 33, Empty block. Commands: * jshint . * ack '(if|else|function|switch|for|while)\(' * Sublime Text 2: Find(*): (if|else|function|switch|for|while)\( Replace: $1 ( * ack ' ' -Q # double spaces, except in certain comments Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
/**
|
|
* VisualEditor user interface HistoryButtonTool class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Creates an ve.ui.HistoryButtonTool object.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.ui.ButtonTool}
|
|
* @param {ve.ui.Toolbar} toolbar
|
|
* @param {String} name
|
|
*/
|
|
ve.ui.HistoryButtonTool = function ( toolbar, name, title, data ) {
|
|
// Inheritance
|
|
ve.ui.ButtonTool.call( this, toolbar, name, title );
|
|
|
|
// Properties
|
|
this.data = data;
|
|
this.enabled = false;
|
|
|
|
this.toolbar.getSurfaceView().model.on( 'history', ve.bind( this.updateState, this ) );
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.HistoryButtonTool.prototype.onClick = function () {
|
|
switch ( this.name ) {
|
|
case 'undo':
|
|
case 'redo':
|
|
if ( this.isButtonEnabled( this.name ) ) {
|
|
var surfaceView = this.toolbar.getSurfaceView();
|
|
surfaceView.stopPolling();
|
|
surfaceView.showSelection(
|
|
surfaceView.getModel()[this.name]( 1 ) || surfaceView.model.selection
|
|
);
|
|
surfaceView.clearPollData();
|
|
surfaceView.startPolling();
|
|
}
|
|
break;
|
|
}
|
|
};
|
|
|
|
ve.ui.HistoryButtonTool.prototype.updateState = function ( annotations ) {
|
|
this.enabled = this.isButtonEnabled( this.name );
|
|
this.updateEnabled();
|
|
};
|
|
|
|
ve.ui.HistoryButtonTool.prototype.isButtonEnabled = function ( name ) {
|
|
var surfaceModel = this.toolbar.getSurfaceView().getModel();
|
|
switch ( name ) {
|
|
case 'undo':
|
|
return surfaceModel.bigStack.length - surfaceModel.undoIndex > 0;
|
|
case 'redo':
|
|
return surfaceModel.undoIndex > 0;
|
|
default:
|
|
return false;
|
|
}
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.Tool.tools.undo = {
|
|
'constructor': ve.ui.HistoryButtonTool,
|
|
'name': 'undo',
|
|
'title': ve.msg( 'visualeditor-historybutton-undo-tooltip' )
|
|
};
|
|
|
|
ve.ui.Tool.tools.redo = {
|
|
'constructor': ve.ui.HistoryButtonTool,
|
|
'name': 'redo',
|
|
'title': ve.msg( 'visualeditor-historybutton-redo-tooltip' )
|
|
};
|
|
|
|
/* Inhertiance */
|
|
|
|
ve.extendClass( ve.ui.HistoryButtonTool, ve.ui.ButtonTool );
|