mediawiki-extensions-Visual.../modules/syntaxhighlight/ve.ui.MWSyntaxHighlightDialog.js
Trevor Parscal d2dfb9ac4f Split oojs-ui from ve.ui
* Move and rename generic parts of ve.ui to OO.ui
* We now have a UI test suite because ve.Element (outside ve.ui)
  is now part of oojs-ui, so it needs a test suite.
* Added to the MW test run (just like we do for unicodejs).
* Updated csslint config (also added ve-mw and syntaxhighlight
  which were missing).

oojs-ui still depends on the TriggerRegistry in VE, this is addressed
in a follow-up commit.

Change-Id: Iec147155c1ddf20b73a4d15d87b8742207032312
2013-10-28 22:40:08 -07:00

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.frame.$$, 'scrollable': false, 'padded': false
} );
this.applyButton = new OO.ui.PushButtonWidget( {
'$$': this.frame.$$, 'label': ve.msg( 'visualeditor-dialog-action-apply' ), 'flags': ['primary']
} );
this.applyButton.connect( this, { 'click': [ 'close', 'apply' ] } );
this.$body.append( this.editPanel.$ );
this.$foot.append( this.applyButton.$ );
};
/**
* 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.$.append( this.editSurface.$ );
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 );