Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/tools/ve.ui.MWSaveTool.js

raw symbols SCIP
1 /**
2 * MediaWiki save tool
3 *
4 * @class
5 * @abstract
6 * @extends ve.ui.Tool
7 * @constructor
8 * @param {OO.ui.ToolGroup} toolGroup
9 * @param {Object} [config] Configuration options
10 */
11 ve.ui.MWSaveTool = function VeUiMWSaveTool() {
12 // Parent constructor
13 ve.ui.MWSaveTool.super.apply( this, arguments );
14
15 // NOTE (phuedx, 2014-08-20): This class is used by the firsteditve guided
16 // tour to attach a guider to the "Save page" button.
17 this.$link.addClass( 've-ui-toolbar-saveButton' );
18
19 if ( this.toolbar instanceof ve.ui.TargetToolbar ) {
20 if ( ve.msg( 'accesskey-save' ) !== '-' && ve.msg( 'accesskey-save' ) !== '' ) {
21 // FlaggedRevs tries to use this - it's useless on VE pages because all that stuff gets hidden, but it will still conflict so get rid of it
22 this.toolbar.target.$saveAccessKeyElements = $( '[accesskey="' + ve.msg( 'accesskey-save' ) + '"]' ).removeAttr( 'accesskey' );
23 this.$link.attr( 'accesskey', ve.msg( 'accesskey-save' ) );
24 }
25
26 this.setTitle( this.toolbar.target.getSaveButtonLabel( true ) );
27 this.narrowConfig = {
28 title: this.toolbar.target.getSaveButtonLabel( true, true )
29 };
30 }
31 };
32
33 /* Inheritance */
34
35 OO.inheritClass( ve.ui.MWSaveTool, ve.ui.Tool );
36
37 /* Static properties */
38
39 ve.ui.MWSaveTool.static.name = 'showSave';
40
41 ve.ui.MWSaveTool.static.flags = [ 'primary', 'progressive' ];
42 ve.ui.MWSaveTool.static.displayBothIconAndLabel = true;
43 ve.ui.MWSaveTool.static.group = 'save';
44 ve.ui.MWSaveTool.static.fallbackIcon = 'next';
45 ve.ui.MWSaveTool.static.commandName = 'showSave';
46 ve.ui.MWSaveTool.static.autoAddToCatchall = false;
47 if ( OO.ui.isMobile() ) {
48 // TODO: Have the mobile target build an icon-only version automatically.
49 ve.ui.MWSaveTool.static.icon = 'next';
50 ve.ui.MWSaveTool.static.displayBothIconAndLabel = false;
51 }
52
53 /* Methods */
54
55 /**
56 * @inheritdoc
57 */
58 ve.ui.MWSaveTool.prototype.onUpdateState = function () {
59 const wasSaveable = !this.isDisabled(),
60 isSaveable = this.toolbar instanceof ve.ui.TargetToolbar &&
61 this.toolbar.target.isSaveable();
62
63 // This could be a ve.ui.WindowTool that becomes active
64 // when the save dialog is open, but onUpdateState is
65 // called without arguments in ArticleTarget for speed.
66
67 if ( wasSaveable !== isSaveable ) {
68 this.setDisabled( !isSaveable );
69 mw.hook( 've.toolbarSaveButton.stateChanged' ).fire( !isSaveable );
70 }
71 };
72
73 /* Registration */
74
75 ve.ui.toolFactory.register( ve.ui.MWSaveTool );