Mooeypoo has uploaded a new change for review. https://gerrit.wikimedia.org/r/90940
Change subject: [WIP] Insert special character tool ...................................................................... [WIP] Insert special character tool A tool to add special characters and diacritics to text. Change-Id: I26d1f437feef1c8b61ed3be5f74ef524b33baf49 --- M VisualEditor.i18n.php M VisualEditor.php A modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js M modules/ve/ui/styles/ve.ui.Widget.css M modules/ve/ui/tools/ve.ui.ExperimentalTool.js A modules/ve/ui/widgets/ve.ui.SpecialCharacterWidget.js 6 files changed, 212 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/VisualEditor refs/changes/40/90940/1 diff --git a/VisualEditor.i18n.php b/VisualEditor.i18n.php index f384c36..07de457 100644 --- a/VisualEditor.i18n.php +++ b/VisualEditor.i18n.php @@ -148,6 +148,8 @@ 'visualeditor-linkinspector-title' => 'Hyperlink', 'visualeditor-listbutton-bullet-tooltip' => 'Bullet list', 'visualeditor-listbutton-number-tooltip' => 'Numbered list', + 'visualeditor-specialcharacter-button-tooltip' => 'Special characters', + 'visualeditor-specialcharacterinspector-title' => 'Special characters', 'visualeditor-loadwarning' => 'Error loading data from server: $1. Would you like to retry?', 'visualeditor-loadwarning-token' => 'Error loading edit token from server: $1. Would you like to retry?', 'visualeditor-mainnamespacepagelink' => 'Project:Main namespace', @@ -511,6 +513,8 @@ {{Identical|Hyperlink}}', 'visualeditor-listbutton-bullet-tooltip' => 'Tooltip text for the bullet list button', 'visualeditor-listbutton-number-tooltip' => 'Tooltip text for the numbered list button', + 'visualeditor-specialcharacter-button-tooltip' => 'Tooltip text for the insert character button', + 'visualeditor-specialcharacterinspector-title' => 'Used as title for special character inspector', 'visualeditor-loadwarning' => 'Text (JavaScript confirm()) shown when the editor fails to load properly. Parameters: diff --git a/VisualEditor.php b/VisualEditor.php index 82a55d9..44aa611 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -730,6 +730,8 @@ 've/ui/widgets/ve.ui.LanguageInputWidget.js', 've/ui/tools/ve.ui.ExperimentalTool.js', 've-mw/ui/tools/ve.ui.MWExperimentalTool.js', + 've/ui/widgets/ve.ui.SpecialCharacterWidget.js', + 've/ui/inspectors/ve.ui.SpecialCharacterInspector.js', ), 'dependencies' => array( 'ext.visualEditor.core', @@ -750,6 +752,8 @@ 'visualeditor-mwalienextensioninspector-title', 'visualeditor-mwhieroinspector-title', 'visualeditor-mwmathinspector-title', + 'visualeditor-specialcharacter-button-tooltip', + 'visualeditor-specialcharacterinspector-title', ), ), diff --git a/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js b/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js new file mode 100644 index 0000000..1493d8f --- /dev/null +++ b/modules/ve/ui/inspectors/ve.ui.SpecialCharacterInspector.js @@ -0,0 +1,145 @@ +/*! + * VisualEditor UserInterface LanguageInspector class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * Special character inspector. + * + * @class + * @extends ve.ui.SurfaceInspector + * + * @constructor + * @param {ve.ui.SurfaceWindowSet} windowSet Window set this inspector is part of + * @param {Object} [config] Configuration options + */ +ve.ui.SpecialCharacterInspector = function VeUiSpecialCharacterInspector( windowSet, config ) { + // Parent constructor + ve.ui.SurfaceInspector.call( this, windowSet, config ); + + this.characters = null; +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.SpecialCharacterInspector, ve.ui.SurfaceInspector ); + +/* Static properties */ + +ve.ui.SpecialCharacterInspector.static.name = 'specialcharacter'; + +ve.ui.SpecialCharacterInspector.static.icon = 'specialcharacter'; + +ve.ui.SpecialCharacterInspector.static.titleMessage = 'visualeditor-specialcharacterinspector-title'; + +/* Methods */ + +/** + * Handle frame ready events. + * + * @method + */ +ve.ui.SpecialCharacterInspector.prototype.initialize = function () { + // Parent method + ve.ui.SurfaceInspector.prototype.initialize.call( this ); + + // Get the special character list + // This is temporarily hard-coded + this.characters = { + 'symbols': { + '¡': '¡', + '¿': '¿', + '†': '†', + '‡': '‡', + }, + 'cyrillic': { + 'Б': 'Б', + 'б': 'б', + 'Г': 'Г', + 'Ґ': 'Ґ', + 'Ѓ': 'Ѓ', + 'Д': 'Д' + }, + 'Nikkud': { + 'בּ': 'ּ', + 'וֹ': 'ֹ', + 'בַ': 'ַ', + 'בָ': 'ָ', + 'בֶ': 'ֶ', + 'בֵ': 'ֵ', + 'בִ': 'ִ', + 'בֳ': 'ֳ', + 'בֲ': 'ֲ', + 'בֱ': 'ֱ', + 'בְ': 'ְ', + 'בֻ': 'ֻ', + 'שׁ': 'שׁ', + 'שׂ': 'שׂ', + 'rlm': '&rlm' + } + }; + + // Get widget + this.characterListWidget = new ve.ui.SpecialCharacterWidget( { + '$$': this.frame.$$, + '$overlay': this.surface.$localOverlay + } ); + + this.characterListWidget.$.append( this.buildList() ); + + // Initialization + this.$form.append( this.characterListWidget.$ ); +}; + +ve.ui.SpecialCharacterInspector.prototype.buildList = function () { + var category, item, charButton, + $categoryOutput, + itemCounter = 0, + $widgetOutput = $( '<div>' ).addClass( 've-specialchar-list' ); + + for ( category in this.characters ) { + $categoryOutput = $( '<div>' ) + .addClass( 've-specialchar-list-category' ); + + itemCounter = 0; + for ( item in this.characters[category] ) { + charButton = new ve.ui.PushButtonWidget({ + 'label': item, + }); + + charButton.on( 'click', ve.bind( this.onSpecialCharAdd, this, this.characters[category][item] ) ); + + charButton.$.addClass( 've-specialchar-singlechar-button' ); + if ( itemCounter > 7 ) { + $categoryOutput.append( $( '<br />' ) ); + itemCounter = 0; + } + + $categoryOutput.append( charButton.$ ); + + itemCounter++; + } + $widgetOutput + .append( $( '<h2>').text( category ) ) + .append( $categoryOutput ); + } + + return $widgetOutput; +}; +/* Methods */ +ve.ui.SpecialCharacterInspector.prototype.onSpecialCharAdd = function ( charToInsert ) { + var fragment = this.surface.getModel().getFragment( null, true ); + // insert the character: + fragment.insertContent( charToInsert, false ); + fragment.select(); + // Close the inspector: + +}; + +/* Registration */ + +ve.ui.inspectorFactory.register( ve.ui.SpecialCharacterInspector ); + + diff --git a/modules/ve/ui/styles/ve.ui.Widget.css b/modules/ve/ui/styles/ve.ui.Widget.css index 67493e9..9172f21 100644 --- a/modules/ve/ui/styles/ve.ui.Widget.css +++ b/modules/ve/ui/styles/ve.ui.Widget.css @@ -650,3 +650,13 @@ border-bottom-left-radius: 0; border-bottom-width: 0; } + +/* ve.ui.SpecialCharacterWidget.js */ +.ve-specialchar-list h2 { + font-size: 1em; + text-transform: capitalize; +} +.ve-specialchar-list-category { + display: block; + width: 250px; +} diff --git a/modules/ve/ui/tools/ve.ui.ExperimentalTool.js b/modules/ve/ui/tools/ve.ui.ExperimentalTool.js index 0be47b3..43b5fd3 100644 --- a/modules/ve/ui/tools/ve.ui.ExperimentalTool.js +++ b/modules/ve/ui/tools/ve.ui.ExperimentalTool.js @@ -25,3 +25,23 @@ ve.ui.LanguageInspectorTool.static.inspector = 'language'; ve.ui.LanguageInspectorTool.static.modelClasses = [ ve.dm.LanguageAnnotation ]; ve.ui.toolFactory.register( ve.ui.LanguageInspectorTool ); + +/** + * Insert characters tool. + * + * @class + * @extends ve.ui.InspectorTool + * @constructor + * @param {ve.ui.SurfaceToolbar} toolbar + * @param {Object} [config] Configuration options + */ +ve.ui.InsertCharacterTool = function VeUiInsertCharacterTool( toolbar, config ) { + ve.ui.InspectorTool.call( this, toolbar, config ); +}; +OO.inheritClass( ve.ui.InsertCharacterTool, ve.ui.InspectorTool ); +ve.ui.InsertCharacterTool.static.name = 'specialcharacter'; +ve.ui.InsertCharacterTool.static.group = 'insert'; +ve.ui.InsertCharacterTool.static.icon = 'check'; +ve.ui.InsertCharacterTool.static.titleMessage = 'visualeditor-specialcharacter-button-tooltip'; +ve.ui.InsertCharacterTool.static.inspector = 'specialcharacter'; +ve.ui.toolFactory.register( ve.ui.InsertCharacterTool ); diff --git a/modules/ve/ui/widgets/ve.ui.SpecialCharacterWidget.js b/modules/ve/ui/widgets/ve.ui.SpecialCharacterWidget.js new file mode 100644 index 0000000..a050d17 --- /dev/null +++ b/modules/ve/ui/widgets/ve.ui.SpecialCharacterWidget.js @@ -0,0 +1,29 @@ +/*! + * VisualEditor UserInterface SpecialCharacterWidget class. + * + * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ + +/** + * Creates an SpecialCharacterWidget object. + * + * @class + * @extends ve.ui.Widget + * + * @constructor + * @param {Object} [config] Configuration options + */ +ve.ui.SpecialCharacterWidget = function VeUiSpecialCharacterWidget( config ) { + // Parent constructor + ve.ui.Widget.call( this, config ); + + this.$.addClass( 've-specialcharacter-widget' ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ui.SpecialCharacterWidget, ve.ui.Widget ); + +/* Static properties */ + -- To view, visit https://gerrit.wikimedia.org/r/90940 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I26d1f437feef1c8b61ed3be5f74ef524b33baf49 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