mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-29 00:30:44 +00:00
db9f941fa6
Objectives: * Rename this.$ to this.$element * Rename this.$$ to this.$ * Get rid of the need to use this.frame.$$ * Rename OO.ui.Element.get$$ to OO.ui.Element.getJQuery Changes: (using Sublime Text regex patterns) * Replace "get$$" with "getJQuery" * Replace "\.(\$)([^\$a-zA-Z])" with ".$element$2" * Replace "\.(\$\$)" with ".$" * Replace "'$$'" with "'$'" * Set this.$ to null in constructor of OO.ui.Window * Set this.$ to this.frame.$ in initialize method of OO.ui.Window * Replace "\.(frame.\$)([^\$a-zA-Z])" with ".\$$2" Bonus: * Use this.$() in a bunch of places where $() was erroneously used Change-Id: If3d870124ab8d10f8223532cda95c2b2b075db94
105 lines
2.8 KiB
JavaScript
105 lines
2.8 KiB
JavaScript
/*!
|
|
* VisualEditor user interface MWSyntaxHighlightDialog class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* Document dialog.
|
|
*
|
|
* @class
|
|
* @extends ve.ui.MWDialog
|
|
*
|
|
* @constructor
|
|
* @param {OO.ui.WindowSet} windowSet Window set this dialog is part of
|
|
* @param {Object} [config] Config options
|
|
*/
|
|
ve.ui.MWSyntaxHighlightDialog = function VeUiMWSyntaxHighlightDialog( windowSet, config ) {
|
|
// Parent constructor
|
|
ve.ui.MWDialog.call( this, windowSet, config );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ui.MWSyntaxHighlightDialog, ve.ui.MWDialog );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.titleMessage = 'visualeditor-dialog-syntaxhighlight-title';
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.icon = 'syntaxHighlight';
|
|
|
|
ve.ui.MWSyntaxHighlightDialog.static.name = 'mwSyntaxHighlight';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.initialize = function () {
|
|
// Call parent method
|
|
ve.ui.MWDialog.prototype.initialize.call( this );
|
|
this.editPanel = new OO.ui.PanelLayout( {
|
|
'$': this.$, 'scrollable': false, 'padded': false
|
|
} );
|
|
this.applyButton = new OO.ui.PushButtonWidget( {
|
|
'$': this.$, 'label': ve.msg( 'visualeditor-dialog-action-apply' ), 'flags': ['primary']
|
|
} );
|
|
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
|
|
this.$body.append( this.editPanel.$element );
|
|
this.$foot.append( this.applyButton.$element );
|
|
};
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.onOpen = function () {
|
|
// Parent method
|
|
ve.ui.MWDialog.prototype.onOpen.call( this );
|
|
// Properties
|
|
this.sourceNode = this.surface.getView().getFocusedNode();
|
|
this.sourceText = this.sourceNode.getModel().getAttribute( 'body' );
|
|
this.sourceLang = this.sourceNode.getModel().getAttribute( 'lang' );
|
|
this.editSurface = new ve.ui.MWSyntaxHighlightSimpleSurface( this.sourceText, this.sourceLang );
|
|
// Initialization
|
|
this.editPanel.$element.append( this.editSurface.$element );
|
|
this.editSurface.initialize();
|
|
};
|
|
|
|
/**
|
|
* Handle frame ready events.
|
|
*
|
|
* @method
|
|
* @param {string} action Action that caused the window to be closed
|
|
*/
|
|
ve.ui.MWSyntaxHighlightDialog.prototype.onClose = function ( action ) {
|
|
var tx,
|
|
doc = this.surface.getModel().getDocument();
|
|
// Parent method
|
|
ve.ui.MWDialog.prototype.onClose.call( this );
|
|
// Save changes via Transaction
|
|
if ( action === 'apply' ) {
|
|
tx = ve.dm.Transaction.newFromAttributeChanges(
|
|
doc,
|
|
this.sourceNode.getModel().getOffset(),
|
|
{
|
|
'body':this.editSurface.getModel(),
|
|
'lang':this.editSurface.getLang()
|
|
}
|
|
);
|
|
this.surface.getModel().change( tx );
|
|
}
|
|
|
|
// Cleanup
|
|
this.editSurface.destroy();
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.dialogFactory.register( ve.ui.MWSyntaxHighlightDialog );
|