Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/78545
Change subject: LanguageInputWidget Generalization ...................................................................... LanguageInputWidget Generalization This commit prepares the LanguageInputWidget to handle both annotation and node, so it can be used as the GUI for both the LanguageInspector and the LanguageBlockInspector that's coming up. The LanguageInspector was adjusted mildly to accomodate the change in the widget. Change-Id: I17954707c00ffc4c32fbb44a6807a61760ad573c --- M modules/ve/ui/inspectors/ve.ui.LanguageInspector.js M modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js 2 files changed, 96 insertions(+), 44 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/45/78545/1 diff --git a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js index 9f9fc1a..67a90a9 100644 --- a/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js +++ b/modules/ve/ui/inspectors/ve.ui.LanguageInspector.js @@ -19,6 +19,7 @@ // Parent constructor ve.ui.AnnotationInspector.call( this, surface, config ); + // Placeholder for the dm properties: this.initLang = ''; this.initDir = ''; }; @@ -54,8 +55,12 @@ // Properties this.targetInput = new ve.ui.LanguageInputWidget( { - '$$': this.frame.$$, '$overlay': this.surface.$localOverlay + '$$': this.frame.$$, + '$overlay': this.surface.$localOverlay } ); + + // Define the LanguageInputWidget as an annotation: + this.targetInput.dataType = "annotation"; // Initialization this.$form.append( this.targetInput.$ ); @@ -75,10 +80,10 @@ }, this ), 200 ); }; /** - * Handle the inspector being setup. - * Make sure the initial language and direction are set by the parent of the DOM - * element of the selected fragment before the rest of the onSetup method is - * processed by the parent ve.ui.AnnotationInspector + * Handle the inspector being set up. + * Make sure the initial language and direction are set by the parent + * of the DOM element of the selected fragment before the rest of the + * onSetup method is processed by the parent ve.ui.AnnotationInspector */ ve.ui.LanguageInspector.prototype.onSetup = function () { var fragDOM, diff --git a/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js b/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js index c76e0bc..30bc1ce 100644 --- a/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js +++ b/modules/ve/ui/widgets/ve.ui.LanguageInputWidget.js @@ -20,13 +20,16 @@ // Parent constructor ve.ui.Widget.call( this, config ); - // Properties + // Visual Properties this.$langCodeDisp = this.getDisplayElement( config ); // language code this.$langNameDisp = this.getDisplayElement( config ); // human-readable language name this.$dirDisp = this.getDisplayElement( config ); - // Placeholders for annotation value + // Placeholders for datamodels: this.annotation = null; + this.node = null; + + // Placeholders for attribute values this.lang = ''; this.dir = ''; @@ -65,7 +68,17 @@ ulsParams = { onSelect: function( language ) { - langInpObj.setValue( language ); + var newAnnotation = new ve.dm.LanguageAnnotation( { + 'type': 'language', + 'attributes': { + 'lang': language, + 'dir': $.uls.data.getDir( this.lang ) + } + } ); + // Set the new value, annotation or node: + if ( langInpObj.dataType === 'annotation' ) { + langInpObj.setAnnotation( newAnnotation ); + } }, compact: true, // Temporary Quicklist for the Prototype: @@ -89,7 +102,13 @@ ve.inheritClass( ve.ui.LanguageInputWidget, ve.ui.Widget ); +/* Static properties */ + +// This will define whether we are in "annotation" or "node" mode: +ve.ui.LanguageInputWidget.static.dataType = ''; + /* Methods */ + /** * Get display element. This replaces the 'getInputElement' * of the InputWidget @@ -103,76 +122,104 @@ }; /** - * Set the value of the language display + * Return the current language attributes * - * Overrides setValue to keep annotations in sync. - * - * @method - * @param {string} value New value */ -ve.ui.LanguageInputWidget.prototype.setValue = function ( value ) { - // Keep annotation in sync with value - if ( value === '' ) { - this.annotation = null; - } else { - // Set up the annotation: - this.setAnnotation( new ve.dm.LanguageAnnotation( { - 'type': 'language', - 'attributes': { - 'lang': value, - 'dir': $.uls.data.getDir( value ) - } - } ) ); +ve.ui.LanguageInputWidget.prototype.getAttributes = function () { + return { + 'lang': this.lang, + 'dir': this.dir } }; /** - * Get the value of the current annotation + * Set the current language attributes + * + */ +ve.ui.LanguageInputWidget.prototype.setAttributes = function ( lang, dir ) { + this.lang = lang; + this.dir = dir; +}; + +/** + * Get the language value of the current annotation + * This is required by the AnnotationInspector onClose method */ ve.ui.LanguageInputWidget.prototype.getValue = function () { // Specifically to be displayed return this.lang; }; + /** - * Sets the annotation value. - * - * The input value will automatically be updated. + * Validates and sets the annotation value + * Then updates the attributes and the widget table display * * @method * @param {ve.dm.LanguageAnnotation} annotation Language annotation * @chainable */ ve.ui.LanguageInputWidget.prototype.setAnnotation = function ( annotation ) { - var langNameDisp = ''; - this.annotation = annotation; + var langCode = '', + langDir = ''; - // Give precedence to dir value if it already exists: + // Validate the given annotation: + + // Give precedence to dir value if it already exists + // in the annotation: if ( annotation.element.attributes.dir ) { - this.dir = annotation.element.attributes.dir; + langDir = annotation.element.attributes.dir; } - // Set language according to currently set language + // Set language according to the one in the given annotation // or leave blank if element has no language set if ( annotation.element.attributes.lang ) { - this.lang = annotation.element.attributes.lang; - // Take the full name of the language from its code: - langNameDisp = $.uls.data.getAutonym( this.lang ); - } else { - this.lang = ''; + langCode = annotation.element.attributes.lang; } // If language exists, but dir is undefined/null, // fix the dir in terms of language: - if ( this.lang && !this.dir ) { - this.dir = $.uls.data.getDir( this.lang ); + if ( langCode && !langDir ) { + langDir = $.uls.data.getDir( this.lang ); + } + + // Set the attributes: + this.setAttributes( langCode, langDir ); + + // Set the annotation: + this.annotation = new ve.dm.LanguageAnnotation( { + 'type': 'language', + 'attributes': { + 'lang': this.lang, + 'dir': this.dir + } + } ); + + // Set language in the widget: + this.updateLanguageTable(); + + return this; +}; + +/** + * Updates the language value in the display table + * + * This shouldn't be used directly. It is called from the + * setAnnotation method after receiving annotation details + * to make sure the annotation and the table are synchronized. + * + * @method + */ +ve.ui.LanguageInputWidget.prototype.updateLanguageTable = function () { + var langNameDisp = ''; + + if ( this.lang ) { + langNameDisp = $.uls.data.getAutonym( this.lang ); } // Display the information in the table: this.$langCodeDisp.html( this.lang ); this.$langNameDisp.html( langNameDisp ); this.$dirDisp.html( this.dir ); - - return this; }; /** -- To view, visit https://gerrit.wikimedia.org/r/78545 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I17954707c00ffc4c32fbb44a6807a61760ad573c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Mooeypoo <mor...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits