Esanders has uploaded a new change for review.
https://gerrit.wikimedia.org/r/322600
Change subject: Re-use target widgets
......................................................................
Re-use target widgets
Change-Id: Icba13d84e10cf18a6c68e26448b2efe93b8c42b8
Depends-On: I5ed0591048a17e84077bde5490e05c0467d0394a
---
M modules/ve-cite/ve.ui.MWReferenceDialog.js
1 file changed, 23 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cite
refs/changes/00/322600/1
diff --git a/modules/ve-cite/ve.ui.MWReferenceDialog.js
b/modules/ve-cite/ve.ui.MWReferenceDialog.js
index 6504471..4bf6c10 100644
--- a/modules/ve-cite/ve.ui.MWReferenceDialog.js
+++ b/modules/ve-cite/ve.ui.MWReferenceDialog.js
@@ -151,14 +151,14 @@
*/
ve.ui.MWReferenceDialog.prototype.canApply = function () {
return this.documentHasContent() &&
- (
this.referenceTarget.getSurface().getModel().hasBeenModified() ||
+ ( this.referenceTarget.hasBeenModified() ||
this.referenceGroupInput.getValue() !== this.originalGroup );
};
/**
- * Handle reference surface change events
+ * Handle reference target widget change events
*/
-ve.ui.MWReferenceDialog.prototype.onSurfaceHistory = function () {
+ve.ui.MWReferenceDialog.prototype.onTargetChange = function () {
var hasContent = this.documentHasContent();
this.actions.setAbilities( {
@@ -229,7 +229,7 @@
* @chainable
*/
ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
- var group, citeCommands;
+ var group;
// Properties
if ( ref instanceof ve.dm.MWReferenceModel ) {
@@ -240,31 +240,7 @@
this.referenceModel = new ve.dm.MWReferenceModel(
this.getFragment().getDocument() );
}
- // Cleanup
- if ( this.referenceTarget ) {
- this.referenceTarget.destroy();
- }
-
- citeCommands = Object.keys(
ve.init.target.getSurface().commandRegistry.registry ).filter( function (
command ) {
- return command.indexOf( 'cite-' ) !== -1;
- } );
-
- // Properties
- this.referenceTarget = ve.init.target.createTargetWidget(
- this.referenceModel.getDocument(),
- {
- tools: ve.copy(
ve.init.target.constructor.static.toolbarGroups ),
- includeCommands:
this.constructor.static.includeCommands,
- excludeCommands:
this.constructor.static.excludeCommands.concat( citeCommands ),
- importRules: this.constructor.static.getImportRules(),
- inDialog: this.constructor.static.name
- }
- );
-
- // Events
- this.referenceTarget.getSurface().getModel().connect( this, {
- history: this.onSurfaceHistory.bind( this )
- } );
+ this.referenceTarget.setDocument( this.referenceModel.getDocument() );
// Initialization
this.originalGroup = this.referenceModel.getGroup();
@@ -272,7 +248,6 @@
this.referenceGroupInput.setDisabled( true );
this.referenceGroupInput.setValue( this.originalGroup );
this.referenceGroupInput.setDisabled( false );
- this.contentFieldset.$element.append( this.referenceTarget.$element );
this.referenceTarget.initialize();
group = this.getFragment().getDocument().getInternalList()
@@ -294,6 +269,10 @@
* @inheritdoc
*/
ve.ui.MWReferenceDialog.prototype.initialize = function () {
+ var citeCommands = Object.keys(
ve.init.target.getSurface().commandRegistry.registry ).filter( function (
command ) {
+ return command.indexOf( 'cite-' ) !== -1;
+ } );
+
// Parent method
ve.ui.MWReferenceDialog.super.prototype.initialize.call( this );
@@ -308,11 +287,23 @@
this.$reuseWarningText = $( '<span>' );
this.$reuseWarning = $( '<span>' ).append(
this.reuseWarningIcon.$element, this.$reuseWarningText );
+ this.referenceTarget = ve.init.target.createTargetWidget(
+ {
+ tools: ve.copy(
ve.init.target.constructor.static.toolbarGroups ),
+ includeCommands:
this.constructor.static.includeCommands,
+ excludeCommands:
this.constructor.static.excludeCommands.concat( citeCommands ),
+ importRules: this.constructor.static.getImportRules(),
+ inDialog: this.constructor.static.name
+ }
+ );
+
this.contentFieldset = new OO.ui.FieldsetLayout();
this.optionsFieldset = new OO.ui.FieldsetLayout( {
label: ve.msg( 'cite-ve-dialog-reference-options-section' ),
icon: 'settings'
} );
+ this.contentFieldset.$element.append( this.referenceTarget.$element );
+
this.referenceGroupInput = new ve.ui.MWReferenceGroupInputWidget( {
$overlay: this.$overlay,
emptyGroupName: ve.msg(
'cite-ve-dialog-reference-options-group-placeholder' )
@@ -326,6 +317,7 @@
// Events
this.search.getResults().connect( this, { choose:
'onSearchResultsChoose' } );
+ this.referenceTarget.connect( this, { change: 'onTargetChange' } );
// Initialization
this.panels.addItems( [ this.editPanel, this.searchPanel ] );
@@ -431,8 +423,7 @@
.first( function () {
this.referenceTarget.getSurface().getModel().disconnect( this );
this.search.getQuery().setValue( '' );
- this.referenceTarget.destroy();
- this.referenceTarget = null;
+ this.referenceTarget.clear();
this.referenceModel = null;
}, this );
};
--
To view, visit https://gerrit.wikimedia.org/r/322600
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icba13d84e10cf18a6c68e26448b2efe93b8c42b8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cite
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits