mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 16:44:51 +00:00
97a1edfd72
Change-Id: Ibc658e5f67a373394a4ba149e9b9003f3803023a
75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
/**
|
|
* 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;
|
|
|
|
var _this = this;
|
|
this.toolbar.surfaceView.model.on( 'history', function() {
|
|
_this.updateState();
|
|
});
|
|
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
ve.ui.HistoryButtonTool.prototype.onClick = function() {
|
|
this.toolbar.surfaceView.stopPolling();
|
|
switch ( this.name ) {
|
|
case 'undo':
|
|
var selection = this.toolbar.surfaceView.model.undo( 1 ) || this.toolbar.surfaceView.model.selection;
|
|
this.toolbar.surfaceView.showSelection( selection );
|
|
break;
|
|
case 'redo':
|
|
var selection = this.toolbar.surfaceView.model.redo( 1 ) || this.toolbar.surfaceView.model.selection;
|
|
this.toolbar.surfaceView.showSelection( selection );
|
|
break;
|
|
}
|
|
this.toolbar.surfaceView.clearPollData();
|
|
this.toolbar.surfaceView.startPolling();
|
|
};
|
|
|
|
ve.ui.HistoryButtonTool.prototype.updateState = function( annotations ) {
|
|
var surfaceModel = this.toolbar.surfaceView.model;
|
|
switch( this.name ) {
|
|
case 'undo':
|
|
this.enabled = surfaceModel.bigStack.length - surfaceModel.undoIndex > 0;
|
|
break;
|
|
case 'redo':
|
|
this.enabled = surfaceModel.undoIndex > 0;
|
|
break;
|
|
}
|
|
|
|
this.updateEnabled();
|
|
};
|
|
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.Tool.tools.undo = {
|
|
'constructor': ve.ui.HistoryButtonTool,
|
|
'name': 'undo',
|
|
'title': mw.msg( 'visualeditor-historybutton-undo-tooltip' )
|
|
};
|
|
|
|
ve.ui.Tool.tools.redo = {
|
|
'constructor': ve.ui.HistoryButtonTool,
|
|
'name': 'redo',
|
|
'title': mw.msg( 'visualeditor-historybutton-redo-tooltip' )
|
|
};
|
|
|
|
/* Inhertiance */
|
|
|
|
ve.extendClass( ve.ui.HistoryButtonTool, ve.ui.ButtonTool );
|