YUI.add('moodle-atto_charmap-button', function (Y, NAME) { // This file is part of Moodle - http://moodle.org/ // // Moodle is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Moodle is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . /* * @package atto_charmap * @copyright 2014 Frédéric Massart * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ /** * Atto text editor character map plugin * * @module moodle-atto_charmap-button */ var COMPONENTNAME = 'atto_charmap', CSS = { BUTTON: 'atto_charmap_character', CHARMAP: 'atto_charmap_selector' }, /* * Map of special characters, kindly borrowed from TinyMCE. * * Each entries contains in order: * - {String} HTML code * - {String} HTML numerical code * - {Boolean} Whether or not to include it in the list * - {String} The language string key * * @property CHARMAP * @type {Array} */ CHARMAP = [ [' ', ' ', true, 'nobreakspace'], ['&', '&', true, 'ampersand'], ['"', '"', true, 'quotationmark'], ['‽', '‽', true, 'interrobang'], // Finance. ['¢', '¢', true, 'centsign'], ['€', '€', true, 'eurosign'], ['£', '£', true, 'poundsign'], ['¥', '¥', true, 'yensign'], // Signs. ['©', '©', true, 'copyrightsign'], ['®', '®', true, 'registeredsign'], ['™', '™', true, 'trademarksign'], ['‰', '‰', true, 'permillesign'], ['µ', 'µ', true, 'microsign'], ['·', '·', true, 'middledot'], ['•', '•', true, 'bullet'], ['…', '…', true, 'threedotleader'], ['′', '′', true, 'minutesfeet'], ['″', '″', true, 'secondsinches'], ['§', '§', true, 'sectionsign'], ['¶', '¶', true, 'paragraphsign'], ['ß', 'ß', true, 'sharpsesszed'], // Quotations. ['‹', '‹', true, 'singleleftpointinganglequotationmark'], ['›', '›', true, 'singlerightpointinganglequotationmark'], ['«', '«', true, 'leftpointingguillemet'], ['»', '»', true, 'rightpointingguillemet'], ['‘', '‘', true, 'leftsinglequotationmark'], ['’', '’', true, 'rightsinglequotationmark'], ['“', '“', true, 'leftdoublequotationmark'], ['”', '”', true, 'rightdoublequotationmark'], ['‚', '‚', true, 'singlelow9quotationmark'], ['„', '„', true, 'doublelow9quotationmark'], ['<', '<', true, 'lessthansign'], ['>', '>', true, 'greaterthansign'], ['≤', '≤', true, 'lessthanorequalto'], ['≥', '≥', true, 'greaterthanorequalto'], ['–', '–', true, 'endash'], ['—', '—', true, 'emdash'], ['¯', '¯', true, 'macron'], ['‾', '‾', true, 'overline'], ['¤', '¤', true, 'currencysign'], ['¦', '¦', true, 'brokenbar'], ['¨', '¨', true, 'diaeresis'], ['¡', '¡', true, 'invertedexclamationmark'], ['¿', '¿', true, 'turnedquestionmark'], ['ˆ', 'ˆ', true, 'circumflexaccent'], ['˜', '˜', true, 'smalltilde'], ['°', '°', true, 'degreesign'], ['−', '−', true, 'minussign'], ['±', '±', true, 'plusminussign'], ['÷', '÷', true, 'divisionsign'], ['⁄', '⁄', true, 'fractionslash'], ['×', '×', true, 'multiplicationsign'], ['¹', '¹', true, 'superscriptone'], ['²', '²', true, 'superscripttwo'], ['³', '³', true, 'superscriptthree'], ['¼', '¼', true, 'fractiononequarter'], ['½', '½', true, 'fractiononehalf'], ['¾', '¾', true, 'fractionthreequarters'], // Math / logical. ['ƒ', 'ƒ', true, 'functionflorin'], ['∫', '∫', true, 'integral'], ['∑', '∑', true, 'narysumation'], ['∞', '∞', true, 'infinity'], ['√', '√', true, 'squareroot'], ['∼', '∼', false, 'similarto'], ['≅', '≅', false, 'approximatelyequalto'], ['≈', '≈', true, 'almostequalto'], ['≠', '≠', true, 'notequalto'], ['≡', '≡', true, 'identicalto'], ['∈', '∈', false, 'elementof'], ['∉', '∉', false, 'notanelementof'], ['∋', '∋', false, 'containsasmember'], ['∏', '∏', true, 'naryproduct'], ['∧', '∧', false, 'logicaland'], ['∨', '∨', false, 'logicalor'], ['¬', '¬', true, 'notsign'], ['∩', '∩', true, 'intersection'], ['∪', '∪', false, 'union'], ['∂', '∂', true, 'partialdifferential'], ['∀', '∀', false, 'forall'], ['∃', '∃', false, 'thereexists'], ['∅', '∅', false, 'diameter'], ['∇', '∇', false, 'backwarddifference'], ['∗', '∗', false, 'asteriskoperator'], ['∝', '∝', false, 'proportionalto'], ['∠', '∠', false, 'angle'], // Undefined. ['´', '´', true, 'acuteaccent'], ['¸', '¸', true, 'cedilla'], ['ª', 'ª', true, 'feminineordinalindicator'], ['º', 'º', true, 'masculineordinalindicator'], ['†', '†', true, 'dagger'], ['‡', '‡', true, 'doubledagger'], // Alphabetical special chars. ['À', 'À', true, 'agrave_caps'], ['Á', 'Á', true, 'aacute_caps'], ['Â', 'Â', true, 'acircumflex_caps'], ['Ã', 'Ã', true, 'atilde_caps'], ['Ä', 'Ä', true, 'adiaeresis_caps'], ['Å', 'Å', true, 'aringabove_caps'], ['Ā', 'Ā', true, 'amacron_caps'], ['Æ', 'Æ', true, 'ligatureae_caps'], ['Ç', 'Ç', true, 'ccedilla_caps'], ['È', 'È', true, 'egrave_caps'], ['É', 'É', true, 'eacute_caps'], ['Ê', 'Ê', true, 'ecircumflex_caps'], ['Ë', 'Ë', true, 'ediaeresis_caps'], ['Ē', 'Ē', true, 'emacron_caps'], ['Ì', 'Ì', true, 'igrave_caps'], ['Í', 'Í', true, 'iacute_caps'], ['Î', 'Î', true, 'icircumflex_caps'], ['Ï', 'Ï', true, 'idiaeresis_caps'], ['Ī', 'Ī', true, 'imacron_caps'], ['Ð', 'Ð', true, 'eth_caps'], ['Ñ', 'Ñ', true, 'ntilde_caps'], ['Ò', 'Ò', true, 'ograve_caps'], ['Ó', 'Ó', true, 'oacute_caps'], ['Ô', 'Ô', true, 'ocircumflex_caps'], ['Õ', 'Õ', true, 'otilde_caps'], ['Ö', 'Ö', true, 'odiaeresis_caps'], ['Ø', 'Ø', true, 'oslash_caps'], ['Ō', 'Ō', true, 'omacron_caps'], ['Œ', 'Œ', true, 'ligatureoe_caps'], ['Š', 'Š', true, 'scaron_caps'], ['Ù', 'Ù', true, 'ugrave_caps'], ['Ú', 'Ú', true, 'uacute_caps'], ['Û', 'Û', true, 'ucircumflex_caps'], ['Ü', 'Ü', true, 'udiaeresis_caps'], ['Ū', 'Ū', true, 'umacron_caps'], ['Ý', 'Ý', true, 'yacute_caps'], ['Ÿ', 'Ÿ', true, 'ydiaeresis_caps'], ['Þ', 'Þ', true, 'thorn_caps'], ['à', 'à', true, 'agrave'], ['á', 'á', true, 'aacute'], ['â', 'â', true, 'acircumflex'], ['ã', 'ã', true, 'atilde'], ['ä', 'ä', true, 'adiaeresis'], ['å', 'å', true, 'aringabove'], ['ā', 'ā', true, 'amacron'], ['æ', 'æ', true, 'ligatureae'], ['ç', 'ç', true, 'ccedilla'], ['è', 'è', true, 'egrave'], ['é', 'é', true, 'eacute'], ['ê', 'ê', true, 'ecircumflex'], ['ë', 'ë', true, 'ediaeresis'], ['ē', 'ē', true, 'emacron'], ['ì', 'ì', true, 'igrave'], ['í', 'í', true, 'iacute'], ['î', 'î', true, 'icircumflex'], ['ï', 'ï', true, 'idiaeresis'], ['ī', 'ī', true, 'imacron'], ['ð', 'ð', true, 'eth'], ['ñ', 'ñ', true, 'ntilde'], ['ò', 'ò', true, 'ograve'], ['ó', 'ó', true, 'oacute'], ['ô', 'ô', true, 'ocircumflex'], ['õ', 'õ', true, 'otilde'], ['ö', 'ö', true, 'odiaeresis'], ['ø', 'ø', true, 'oslash'], ['ō', 'ō', true, 'omacron'], ['œ', 'œ', true, 'ligatureoe'], ['š', 'š', true, 'scaron'], ['ù', 'ù', true, 'ugrave'], ['ú', 'ú', true, 'uacute'], ['û', 'û', true, 'ucircumflex'], ['ü', 'ü', true, 'udiaeresis'], ['ū', 'ū', true, 'umacron'], ['ý', 'ý', true, 'yacute'], ['þ', 'þ', true, 'thorn'], ['ÿ', 'ÿ', true, 'ydiaeresis'], ['Α', 'Α', true, 'alpha_caps'], ['Β', 'Β', true, 'beta_caps'], ['Γ', 'Γ', true, 'gamma_caps'], ['Δ', 'Δ', true, 'delta_caps'], ['Ε', 'Ε', true, 'epsilon_caps'], ['Ζ', 'Ζ', true, 'zeta_caps'], ['Η', 'Η', true, 'eta_caps'], ['Θ', 'Θ', true, 'theta_caps'], ['Ι', 'Ι', true, 'iota_caps'], ['Κ', 'Κ', true, 'kappa_caps'], ['Λ', 'Λ', true, 'lambda_caps'], ['Μ', 'Μ', true, 'mu_caps'], ['Ν', 'Ν', true, 'nu_caps'], ['Ξ', 'Ξ', true, 'xi_caps'], ['Ο', 'Ο', true, 'omicron_caps'], ['Π', 'Π', true, 'pi_caps'], ['Ρ', 'Ρ', true, 'rho_caps'], ['Σ', 'Σ', true, 'sigma_caps'], ['Τ', 'Τ', true, 'tau_caps'], ['Υ', 'Υ', true, 'upsilon_caps'], ['Φ', 'Φ', true, 'phi_caps'], ['Χ', 'Χ', true, 'chi_caps'], ['Ψ', 'Ψ', true, 'psi_caps'], ['Ω', 'Ω', true, 'omega_caps'], ['α', 'α', true, 'alpha'], ['β', 'β', true, 'beta'], ['γ', 'γ', true, 'gamma'], ['δ', 'δ', true, 'delta'], ['ε', 'ε', true, 'epsilon'], ['ζ', 'ζ', true, 'zeta'], ['η', 'η', true, 'eta'], ['θ', 'θ', true, 'theta'], ['ι', 'ι', true, 'iota'], ['κ', 'κ', true, 'kappa'], ['λ', 'λ', true, 'lambda'], ['μ', 'μ', true, 'mu'], ['ν', 'ν', true, 'nu'], ['ξ', 'ξ', true, 'xi'], ['ο', 'ο', true, 'omicron'], ['π', 'π', true, 'pi'], ['ρ', 'ρ', true, 'rho'], ['ς', 'ς', true, 'finalsigma'], ['σ', 'σ', true, 'sigma'], ['τ', 'τ', true, 'tau'], ['υ', 'υ', true, 'upsilon'], ['φ', 'φ', true, 'phi'], ['χ', 'χ', true, 'chi'], ['ψ', 'ψ', true, 'psi'], ['ω', 'ω', true, 'omega'], // Symbols. ['ℵ', 'ℵ', false, 'alefsymbol'], ['ϖ', 'ϖ', false, 'pisymbol'], ['ℜ', 'ℜ', false, 'realpartsymbol'], ['ϑ', 'ϑ', false, 'thetasymbol'], ['ϒ', 'ϒ', false, 'upsilonhooksymbol'], ['℘', '℘', false, 'weierstrassp'], ['ℑ', 'ℑ', false, 'imaginarypart'], // Arrows. ['←', '←', true, 'leftwardsarrow'], ['↑', '↑', true, 'upwardsarrow'], ['→', '→', true, 'rightwardsarrow'], ['↓', '↓', true, 'downwardsarrow'], ['↔', '↔', true, 'leftrightarrow'], ['↵', '↵', false, 'carriagereturn'], ['⇐', '⇐', false, 'leftwardsdoublearrow'], ['⇑', '⇑', false, 'upwardsdoublearrow'], ['⇒', '⇒', false, 'rightwardsdoublearrow'], ['⇓', '⇓', false, 'downwardsdoublearrow'], ['⇔', '⇔', false, 'leftrightdoublearrow'], ['∴', '∴', false, 'therefore'], ['⊂', '⊂', false, 'subsetof'], ['⊃', '⊃', false, 'supersetof'], ['⊄', '⊄', false, 'notasubsetof'], ['⊆', '⊆', false, 'subsetoforequalto'], ['⊇', '⊇', false, 'supersetoforequalto'], ['⊕', '⊕', false, 'circledplus'], ['⊗', '⊗', false, 'circledtimes'], ['⊥', '⊥', false, 'perpendicular'], ['⋅', '⋅', false, 'dotoperator'], ['⌈', '⌈', false, 'leftceiling'], ['⌉', '⌉', false, 'rightceiling'], ['⌊', '⌊', false, 'leftfloor'], ['⌋', '⌋', false, 'rightfloor'], ['⟨', '〈', false, 'leftpointinganglebracket'], ['⟩', '〉', false, 'rightpointinganglebracket'], ['◊', '◊', true, 'lozenge'], ['♠', '♠', true, 'blackspadesuit'], ['♣', '♣', true, 'blackclubsuit'], ['♥', '♥', true, 'blackheartsuit'], ['♦', '♦', true, 'blackdiamondsuit'], [' ', ' ', false, 'enspace'], [' ', ' ', false, 'emspace'], [' ', ' ', false, 'thinspace'], ['‌', '‌', false, 'zerowidthnonjoiner'], ['‍', '‍', false, 'zerowidthjoiner'], ['‎', '‎', false, 'lefttorightmark'], ['‏', '‏', false, 'righttoleftmark'], ['­', '­', false, 'softhyphen'] ]; /** * Atto text editor charmap plugin. * * @namespace M.atto_charmap * @class button * @extends M.editor_atto.EditorPlugin */ Y.namespace('M.atto_charmap').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { /** * A reference to the current selection at the time that the dialogue * was opened. * * @property _currentSelection * @type Range * @private */ _currentSelection: null, initializer: function() { this.addButton({ icon: 'e/special_character', callback: this._displayDialogue }); }, /** * Display the Character Map selector. * * @method _displayDialogue * @private */ _displayDialogue: function() { // Store the current selection. this._currentSelection = this.get('host').getSelection(); if (this._currentSelection === false) { return; } var dialogue = this.getDialogue({ headerContent: M.util.get_string('insertcharacter', COMPONENTNAME), focusAfterHide: true }, true); // Set the dialogue content, and then show the dialogue. dialogue.set('bodyContent', this._getDialogueContent()) .show(); }, /** * Return the dialogue content for the tool. * * @method _getDialogueContent * @private * @return {Node} The content to place in the dialogue. */ _getDialogueContent: function() { var template = Y.Handlebars.compile( '
' + '{{#each CHARMAP}}' + '{{#if this.[2]}}' + '' + '{{/if}}' + '{{/each}}' + '
' ); var content = Y.Node.create(template({ component: COMPONENTNAME, CSS: CSS, CHARMAP: CHARMAP })); content.delegate('click', this._insertChar, '.' + CSS.BUTTON, this); return content; }, /** * Insert the picked character into the editor. * * @method _insertChar * @param {EventFacade} e * @private */ _insertChar: function(e) { var character = e.target.getData('character'); // Hide the dialogue. this.getDialogue({ focusAfterHide: null }).hide(); var host = this.get('host'); // Focus on the last point. host.setSelection(this._currentSelection); // And add the character. host.insertContentAtFocusPoint(character); // And mark the text area as updated. this.markUpdated(); } }); }, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});