[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-atto_charmap-button', function (Y, NAME) { 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /* 19 * @package atto_charmap 20 * @copyright 2014 Frédéric Massart 21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 22 */ 23 24 /** 25 * Atto text editor character map plugin 26 * 27 * @module moodle-atto_charmap-button 28 */ 29 30 var COMPONENTNAME = 'atto_charmap', 31 CSS = { 32 BUTTON: 'atto_charmap_character', 33 CHARMAP: 'atto_charmap_selector' 34 }, 35 /* 36 * Map of special characters, kindly borrowed from TinyMCE. 37 * 38 * Each entries contains in order: 39 * - {String} HTML code 40 * - {String} HTML numerical code 41 * - {Boolean} Whether or not to include it in the list 42 * - {String} The language string key 43 * 44 * @property CHARMAP 45 * @type {Array} 46 */ 47 CHARMAP = [ 48 [' ', ' ', true, 'nobreakspace'], 49 ['&', '&', true, 'ampersand'], 50 ['"', '"', true, 'quotationmark'], 51 ['‽', '‽', true, 'interrobang'], 52 // Finance. 53 ['¢', '¢', true, 'centsign'], 54 ['€', '€', true, 'eurosign'], 55 ['£', '£', true, 'poundsign'], 56 ['¥', '¥', true, 'yensign'], 57 // Signs. 58 ['©', '©', true, 'copyrightsign'], 59 ['®', '®', true, 'registeredsign'], 60 ['™', '™', true, 'trademarksign'], 61 ['‰', '‰', true, 'permillesign'], 62 ['µ', 'µ', true, 'microsign'], 63 ['·', '·', true, 'middledot'], 64 ['•', '•', true, 'bullet'], 65 ['…', '…', true, 'threedotleader'], 66 ['′', '′', true, 'minutesfeet'], 67 ['″', '″', true, 'secondsinches'], 68 ['§', '§', true, 'sectionsign'], 69 ['¶', '¶', true, 'paragraphsign'], 70 ['ß', 'ß', true, 'sharpsesszed'], 71 // Quotations. 72 ['‹', '‹', true, 'singleleftpointinganglequotationmark'], 73 ['›', '›', true, 'singlerightpointinganglequotationmark'], 74 ['«', '«', true, 'leftpointingguillemet'], 75 ['»', '»', true, 'rightpointingguillemet'], 76 ['‘', '‘', true, 'leftsinglequotationmark'], 77 ['’', '’', true, 'rightsinglequotationmark'], 78 ['“', '“', true, 'leftdoublequotationmark'], 79 ['”', '”', true, 'rightdoublequotationmark'], 80 ['‚', '‚', true, 'singlelow9quotationmark'], 81 ['„', '„', true, 'doublelow9quotationmark'], 82 ['<', '<', true, 'lessthansign'], 83 ['>', '>', true, 'greaterthansign'], 84 ['≤', '≤', true, 'lessthanorequalto'], 85 ['≥', '≥', true, 'greaterthanorequalto'], 86 ['–', '–', true, 'endash'], 87 ['—', '—', true, 'emdash'], 88 ['¯', '¯', true, 'macron'], 89 ['‾', '‾', true, 'overline'], 90 ['¤', '¤', true, 'currencysign'], 91 ['¦', '¦', true, 'brokenbar'], 92 ['¨', '¨', true, 'diaeresis'], 93 ['¡', '¡', true, 'invertedexclamationmark'], 94 ['¿', '¿', true, 'turnedquestionmark'], 95 ['ˆ', 'ˆ', true, 'circumflexaccent'], 96 ['˜', '˜', true, 'smalltilde'], 97 ['°', '°', true, 'degreesign'], 98 ['−', '−', true, 'minussign'], 99 ['±', '±', true, 'plusminussign'], 100 ['÷', '÷', true, 'divisionsign'], 101 ['⁄', '⁄', true, 'fractionslash'], 102 ['×', '×', true, 'multiplicationsign'], 103 ['¹', '¹', true, 'superscriptone'], 104 ['²', '²', true, 'superscripttwo'], 105 ['³', '³', true, 'superscriptthree'], 106 ['¼', '¼', true, 'fractiononequarter'], 107 ['½', '½', true, 'fractiononehalf'], 108 ['¾', '¾', true, 'fractionthreequarters'], 109 // Math / logical. 110 ['ƒ', 'ƒ', true, 'functionflorin'], 111 ['∫', '∫', true, 'integral'], 112 ['∑', '∑', true, 'narysumation'], 113 ['∞', '∞', true, 'infinity'], 114 ['√', '√', true, 'squareroot'], 115 ['∼', '∼', false, 'similarto'], 116 ['≅', '≅', false, 'approximatelyequalto'], 117 ['≈', '≈', true, 'almostequalto'], 118 ['≠', '≠', true, 'notequalto'], 119 ['≡', '≡', true, 'identicalto'], 120 ['∈', '∈', false, 'elementof'], 121 ['∉', '∉', false, 'notanelementof'], 122 ['∋', '∋', false, 'containsasmember'], 123 ['∏', '∏', true, 'naryproduct'], 124 ['∧', '∧', false, 'logicaland'], 125 ['∨', '∨', false, 'logicalor'], 126 ['¬', '¬', true, 'notsign'], 127 ['∩', '∩', true, 'intersection'], 128 ['∪', '∪', false, 'union'], 129 ['∂', '∂', true, 'partialdifferential'], 130 ['∀', '∀', false, 'forall'], 131 ['∃', '∃', false, 'thereexists'], 132 ['∅', '∅', false, 'diameter'], 133 ['∇', '∇', false, 'backwarddifference'], 134 ['∗', '∗', false, 'asteriskoperator'], 135 ['∝', '∝', false, 'proportionalto'], 136 ['∠', '∠', false, 'angle'], 137 // Undefined. 138 ['´', '´', true, 'acuteaccent'], 139 ['¸', '¸', true, 'cedilla'], 140 ['ª', 'ª', true, 'feminineordinalindicator'], 141 ['º', 'º', true, 'masculineordinalindicator'], 142 ['†', '†', true, 'dagger'], 143 ['‡', '‡', true, 'doubledagger'], 144 // Alphabetical special chars. 145 ['À', 'À', true, 'agrave_caps'], 146 ['Á', 'Á', true, 'aacute_caps'], 147 ['Â', 'Â', true, 'acircumflex_caps'], 148 ['Ã', 'Ã', true, 'atilde_caps'], 149 ['Ä', 'Ä', true, 'adiaeresis_caps'], 150 ['Å', 'Å', true, 'aringabove_caps'], 151 ['Ā', 'Ā', true, 'amacron_caps'], 152 ['Æ', 'Æ', true, 'ligatureae_caps'], 153 ['Ç', 'Ç', true, 'ccedilla_caps'], 154 ['È', 'È', true, 'egrave_caps'], 155 ['É', 'É', true, 'eacute_caps'], 156 ['Ê', 'Ê', true, 'ecircumflex_caps'], 157 ['Ë', 'Ë', true, 'ediaeresis_caps'], 158 ['Ē', 'Ē', true, 'emacron_caps'], 159 ['Ì', 'Ì', true, 'igrave_caps'], 160 ['Í', 'Í', true, 'iacute_caps'], 161 ['Î', 'Î', true, 'icircumflex_caps'], 162 ['Ï', 'Ï', true, 'idiaeresis_caps'], 163 ['Ī', 'Ī', true, 'imacron_caps'], 164 ['Ð', 'Ð', true, 'eth_caps'], 165 ['Ñ', 'Ñ', true, 'ntilde_caps'], 166 ['Ò', 'Ò', true, 'ograve_caps'], 167 ['Ó', 'Ó', true, 'oacute_caps'], 168 ['Ô', 'Ô', true, 'ocircumflex_caps'], 169 ['Õ', 'Õ', true, 'otilde_caps'], 170 ['Ö', 'Ö', true, 'odiaeresis_caps'], 171 ['Ø', 'Ø', true, 'oslash_caps'], 172 ['Ō', 'Ō', true, 'omacron_caps'], 173 ['Œ', 'Œ', true, 'ligatureoe_caps'], 174 ['Š', 'Š', true, 'scaron_caps'], 175 ['Ù', 'Ù', true, 'ugrave_caps'], 176 ['Ú', 'Ú', true, 'uacute_caps'], 177 ['Û', 'Û', true, 'ucircumflex_caps'], 178 ['Ü', 'Ü', true, 'udiaeresis_caps'], 179 ['Ū', 'Ū', true, 'umacron_caps'], 180 ['Ý', 'Ý', true, 'yacute_caps'], 181 ['Ÿ', 'Ÿ', true, 'ydiaeresis_caps'], 182 ['Þ', 'Þ', true, 'thorn_caps'], 183 ['à', 'à', true, 'agrave'], 184 ['á', 'á', true, 'aacute'], 185 ['â', 'â', true, 'acircumflex'], 186 ['ã', 'ã', true, 'atilde'], 187 ['ä', 'ä', true, 'adiaeresis'], 188 ['å', 'å', true, 'aringabove'], 189 ['ā', 'ā', true, 'amacron'], 190 ['æ', 'æ', true, 'ligatureae'], 191 ['ç', 'ç', true, 'ccedilla'], 192 ['è', 'è', true, 'egrave'], 193 ['é', 'é', true, 'eacute'], 194 ['ê', 'ê', true, 'ecircumflex'], 195 ['ë', 'ë', true, 'ediaeresis'], 196 ['ē', 'ē', true, 'emacron'], 197 ['ì', 'ì', true, 'igrave'], 198 ['í', 'í', true, 'iacute'], 199 ['î', 'î', true, 'icircumflex'], 200 ['ï', 'ï', true, 'idiaeresis'], 201 ['ī', 'ī', true, 'imacron'], 202 ['ð', 'ð', true, 'eth'], 203 ['ñ', 'ñ', true, 'ntilde'], 204 ['ò', 'ò', true, 'ograve'], 205 ['ó', 'ó', true, 'oacute'], 206 ['ô', 'ô', true, 'ocircumflex'], 207 ['õ', 'õ', true, 'otilde'], 208 ['ö', 'ö', true, 'odiaeresis'], 209 ['ø', 'ø', true, 'oslash'], 210 ['ō', 'ō', true, 'omacron'], 211 ['œ', 'œ', true, 'ligatureoe'], 212 ['š', 'š', true, 'scaron'], 213 ['ù', 'ù', true, 'ugrave'], 214 ['ú', 'ú', true, 'uacute'], 215 ['û', 'û', true, 'ucircumflex'], 216 ['ü', 'ü', true, 'udiaeresis'], 217 ['ū', 'ū', true, 'umacron'], 218 ['ý', 'ý', true, 'yacute'], 219 ['þ', 'þ', true, 'thorn'], 220 ['ÿ', 'ÿ', true, 'ydiaeresis'], 221 ['Α', 'Α', true, 'alpha_caps'], 222 ['Β', 'Β', true, 'beta_caps'], 223 ['Γ', 'Γ', true, 'gamma_caps'], 224 ['Δ', 'Δ', true, 'delta_caps'], 225 ['Ε', 'Ε', true, 'epsilon_caps'], 226 ['Ζ', 'Ζ', true, 'zeta_caps'], 227 ['Η', 'Η', true, 'eta_caps'], 228 ['Θ', 'Θ', true, 'theta_caps'], 229 ['Ι', 'Ι', true, 'iota_caps'], 230 ['Κ', 'Κ', true, 'kappa_caps'], 231 ['Λ', 'Λ', true, 'lambda_caps'], 232 ['Μ', 'Μ', true, 'mu_caps'], 233 ['Ν', 'Ν', true, 'nu_caps'], 234 ['Ξ', 'Ξ', true, 'xi_caps'], 235 ['Ο', 'Ο', true, 'omicron_caps'], 236 ['Π', 'Π', true, 'pi_caps'], 237 ['Ρ', 'Ρ', true, 'rho_caps'], 238 ['Σ', 'Σ', true, 'sigma_caps'], 239 ['Τ', 'Τ', true, 'tau_caps'], 240 ['Υ', 'Υ', true, 'upsilon_caps'], 241 ['Φ', 'Φ', true, 'phi_caps'], 242 ['Χ', 'Χ', true, 'chi_caps'], 243 ['Ψ', 'Ψ', true, 'psi_caps'], 244 ['Ω', 'Ω', true, 'omega_caps'], 245 ['α', 'α', true, 'alpha'], 246 ['β', 'β', true, 'beta'], 247 ['γ', 'γ', true, 'gamma'], 248 ['δ', 'δ', true, 'delta'], 249 ['ε', 'ε', true, 'epsilon'], 250 ['ζ', 'ζ', true, 'zeta'], 251 ['η', 'η', true, 'eta'], 252 ['θ', 'θ', true, 'theta'], 253 ['ι', 'ι', true, 'iota'], 254 ['κ', 'κ', true, 'kappa'], 255 ['λ', 'λ', true, 'lambda'], 256 ['μ', 'μ', true, 'mu'], 257 ['ν', 'ν', true, 'nu'], 258 ['ξ', 'ξ', true, 'xi'], 259 ['ο', 'ο', true, 'omicron'], 260 ['π', 'π', true, 'pi'], 261 ['ρ', 'ρ', true, 'rho'], 262 ['ς', 'ς', true, 'finalsigma'], 263 ['σ', 'σ', true, 'sigma'], 264 ['τ', 'τ', true, 'tau'], 265 ['υ', 'υ', true, 'upsilon'], 266 ['φ', 'φ', true, 'phi'], 267 ['χ', 'χ', true, 'chi'], 268 ['ψ', 'ψ', true, 'psi'], 269 ['ω', 'ω', true, 'omega'], 270 // Symbols. 271 ['ℵ', 'ℵ', false, 'alefsymbol'], 272 ['ϖ', 'ϖ', false, 'pisymbol'], 273 ['ℜ', 'ℜ', false, 'realpartsymbol'], 274 ['ϑ', 'ϑ', false, 'thetasymbol'], 275 ['ϒ', 'ϒ', false, 'upsilonhooksymbol'], 276 ['℘', '℘', false, 'weierstrassp'], 277 ['ℑ', 'ℑ', false, 'imaginarypart'], 278 // Arrows. 279 ['←', '←', true, 'leftwardsarrow'], 280 ['↑', '↑', true, 'upwardsarrow'], 281 ['→', '→', true, 'rightwardsarrow'], 282 ['↓', '↓', true, 'downwardsarrow'], 283 ['↔', '↔', true, 'leftrightarrow'], 284 ['↵', '↵', false, 'carriagereturn'], 285 ['⇐', '⇐', false, 'leftwardsdoublearrow'], 286 ['⇑', '⇑', false, 'upwardsdoublearrow'], 287 ['⇒', '⇒', false, 'rightwardsdoublearrow'], 288 ['⇓', '⇓', false, 'downwardsdoublearrow'], 289 ['⇔', '⇔', false, 'leftrightdoublearrow'], 290 ['∴', '∴', false, 'therefore'], 291 ['⊂', '⊂', false, 'subsetof'], 292 ['⊃', '⊃', false, 'supersetof'], 293 ['⊄', '⊄', false, 'notasubsetof'], 294 ['⊆', '⊆', false, 'subsetoforequalto'], 295 ['⊇', '⊇', false, 'supersetoforequalto'], 296 ['⊕', '⊕', false, 'circledplus'], 297 ['⊗', '⊗', false, 'circledtimes'], 298 ['⊥', '⊥', false, 'perpendicular'], 299 ['⋅', '⋅', false, 'dotoperator'], 300 ['⌈', '⌈', false, 'leftceiling'], 301 ['⌉', '⌉', false, 'rightceiling'], 302 ['⌊', '⌊', false, 'leftfloor'], 303 ['⌋', '⌋', false, 'rightfloor'], 304 ['⟨', '〈', false, 'leftpointinganglebracket'], 305 ['⟩', '〉', false, 'rightpointinganglebracket'], 306 ['◊', '◊', true, 'lozenge'], 307 ['♠', '♠', true, 'blackspadesuit'], 308 ['♣', '♣', true, 'blackclubsuit'], 309 ['♥', '♥', true, 'blackheartsuit'], 310 ['♦', '♦', true, 'blackdiamondsuit'], 311 [' ', ' ', false, 'enspace'], 312 [' ', ' ', false, 'emspace'], 313 [' ', ' ', false, 'thinspace'], 314 ['‌', '‌', false, 'zerowidthnonjoiner'], 315 ['‍', '‍', false, 'zerowidthjoiner'], 316 ['‎', '‎', false, 'lefttorightmark'], 317 ['‏', '‏', false, 'righttoleftmark'], 318 ['­', '­', false, 'softhyphen'] 319 ]; 320 321 /** 322 * Atto text editor charmap plugin. 323 * 324 * @namespace M.atto_charmap 325 * @class button 326 * @extends M.editor_atto.EditorPlugin 327 */ 328 329 Y.namespace('M.atto_charmap').Button = Y.Base.create('button', Y.M.editor_atto.EditorPlugin, [], { 330 /** 331 * A reference to the current selection at the time that the dialogue 332 * was opened. 333 * 334 * @property _currentSelection 335 * @type Range 336 * @private 337 */ 338 _currentSelection: null, 339 340 initializer: function() { 341 this.addButton({ 342 icon: 'e/special_character', 343 callback: this._displayDialogue 344 }); 345 }, 346 347 /** 348 * Display the Character Map selector. 349 * 350 * @method _displayDialogue 351 * @private 352 */ 353 _displayDialogue: function() { 354 // Store the current selection. 355 this._currentSelection = this.get('host').getSelection(); 356 if (this._currentSelection === false) { 357 return; 358 } 359 360 var dialogue = this.getDialogue({ 361 headerContent: M.util.get_string('insertcharacter', COMPONENTNAME), 362 focusAfterHide: true 363 }, true); 364 365 // Set the dialogue content, and then show the dialogue. 366 dialogue.set('bodyContent', this._getDialogueContent()) 367 .show(); 368 }, 369 370 /** 371 * Return the dialogue content for the tool. 372 * 373 * @method _getDialogueContent 374 * @private 375 * @return {Node} The content to place in the dialogue. 376 */ 377 _getDialogueContent: function() { 378 var template = Y.Handlebars.compile( 379 '<div class="{{CSS.CHARMAP}}">' + 380 '{{#each CHARMAP}}' + 381 '{{#if this.[2]}}' + 382 '<button class="{{../../CSS.BUTTON}}" ' + 383 'aria-label="{{get_string this.[3] ../../component}}" ' + 384 'title="{{get_string this.[3] ../../component}}" ' + 385 'data-character="{{this.[0]}}" ' + 386 '>{{{this.[0]}}}</button>' + 387 '{{/if}}' + 388 '{{/each}}' + 389 '</div>' 390 ); 391 392 var content = Y.Node.create(template({ 393 component: COMPONENTNAME, 394 CSS: CSS, 395 CHARMAP: CHARMAP 396 })); 397 398 content.delegate('click', this._insertChar, '.' + CSS.BUTTON, this); 399 return content; 400 }, 401 402 /** 403 * Insert the picked character into the editor. 404 * 405 * @method _insertChar 406 * @param {EventFacade} e 407 * @private 408 */ 409 _insertChar: function(e) { 410 var character = e.target.getData('character'); 411 412 // Hide the dialogue. 413 this.getDialogue({ 414 focusAfterHide: null 415 }).hide(); 416 417 var host = this.get('host'); 418 419 // Focus on the last point. 420 host.setSelection(this._currentSelection); 421 422 // And add the character. 423 host.insertContentAtFocusPoint(character); 424 425 // And mark the text area as updated. 426 this.markUpdated(); 427 } 428 }); 429 430 431 }, '@VERSION@', {"requires": ["moodle-editor_atto-plugin"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |