Jforrester has uploaded a new change for review.
https://gerrit.wikimedia.org/r/129622
Change subject: Create MWLiveExtensionInspector base class
......................................................................
Create MWLiveExtensionInspector base class
Most of the code stolen from MWMathInspector and genericised.
Also fix issues with fragment not wrapping the new node correctly.
Bug: 58286
Bug: 58045
Change-Id: I708c4cb012becf8c493d5b65a051c0b13f7a11ac
(cherry picked from commit e09e6c9f28ddb7135358867f01fa1f2ec64e7476)
---
M VisualEditor.php
A modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
2 files changed, 113 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor
refs/changes/22/129622/1
diff --git a/VisualEditor.php b/VisualEditor.php
index 6abc6eb..5b2f87b 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -633,6 +633,7 @@
'modules/ve-mw/ui/tools/ve.ui.MWPopupTool.js',
'modules/ve-mw/ui/inspectors/ve.ui.MWExtensionInspector.js',
+
'modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js',
),
'styles' => array(
// ui
diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
new file mode 100644
index 0000000..2cbb71d
--- /dev/null
+++ b/modules/ve-mw/ui/inspectors/ve.ui.MWLiveExtensionInspector.js
@@ -0,0 +1,112 @@
+/*!
+ * VisualEditor UserInterface MWLiveExtensionInspector class.
+ *
+ * @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/**
+ * MediaWiki live extension inspector.
+ *
+ * @class
+ * @abstract
+ * @extends ve.ui.MWExtensionInspector
+ *
+ * @constructor
+ * @param {Object} [config] Configuration options
+ */
+ve.ui.MWLiveExtensionInspector = function VeUiMWLiveExtensionInspector( config
) {
+ // Parent constructor
+ ve.ui.MWExtensionInspector.call( this, config );
+
+ // Late bind onChangeHanlder to a debounced updatePreview
+ this.onChangeHandler = ve.debounce( ve.bind( this.updatePreview, this
), 250 );
+};
+
+/* Inheritance */
+
+OO.inheritClass( ve.ui.MWLiveExtensionInspector, ve.ui.MWExtensionInspector );
+
+/* Static properties */
+
+/**
+ * Name of extension in the mw data, if different from inspector name
+ *
+ * @static
+ * @property {string}
+ * @inheritable
+ */
+ve.ui.MWLiveExtensionInspector.static.mwName = null;
+
+/* Methods */
+
+/**
+ * Create an MW data object for a new node
+ * @returns {Object} MW data
+ */
+ve.ui.MWLiveExtensionInspector.prototype.getNewMwData = function () {
+ return {
+ 'name': this.constructor.static.mwName ||
this.constructor.static.name,
+ 'attrs': {},
+ 'body': {
+ 'extsrc': ''
+ }
+ };
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLiveExtensionInspector.prototype.setup = function ( data ) {
+ // Parent method
+ ve.ui.MWExtensionInspector.prototype.setup.call( this, data );
+
+ // Initialization
+ this.getFragment().getSurface().pushStaging();
+
+ if ( !this.node ) {
+ // Create a new node
+ // collapseRangeToEnd returns a new fragment
+ this.fragment =
this.getFragment().collapseRangeToEnd().insertContent( [
+ {
+ 'type':
this.constructor.static.nodeModel.static.name,
+ 'attributes': { 'mw': this.getNewMwData() }
+ },
+ { 'type': '/' +
this.constructor.static.nodeModel.static.name }
+ ] );
+ // Check if the node was inserted at a structural offset and
wrapped in a paragraph
+ if ( this.getFragment().getRange().getLength() === 4 ) {
+ this.fragment = this.getFragment().adjustRange( 1, -1 );
+ }
+ this.getFragment().select();
+ this.node = this.getFragment().getSelectedNode();
+ }
+ this.input.setValue( this.node.getAttribute( 'mw' ).body.extsrc );
+
+ this.input.on( 'change', this.onChangeHandler );
+};
+
+/**
+ * @inheritdoc
+ */
+ve.ui.MWLiveExtensionInspector.prototype.teardown = function ( data ) {
+ this.input.off( 'change', this.onChangeHandler );
+
+ this.getFragment().getSurface().applyStaging();
+
+ // Parent method
+ ve.ui.MWExtensionInspector.prototype.teardown.call( this, data );
+};
+
+/**
+ * Update the node rendering to reflect the current content in the inspector.
+ */
+ve.ui.MWLiveExtensionInspector.prototype.updatePreview = function () {
+ var mwData = ve.copy( this.node.getAttribute( 'mw' ) );
+
+ mwData.body.extsrc = this.input.getValue();
+
+ if ( this.visible ) {
+ this.getFragment().changeAttributes( { 'mw': mwData } );
+ }
+};
--
To view, visit https://gerrit.wikimedia.org/r/129622
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I708c4cb012becf8c493d5b65a051c0b13f7a11ac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: REL1_23
Gerrit-Owner: Jforrester <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits