[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/editor/atto/plugins/charmap/yui/build/moodle-atto_charmap-button/ -> moodle-atto_charmap-button-debug.js (source)

   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          ['&nbsp;', '&#160;', true, 'nobreakspace'],
  49          ['&amp;', '&#38;', true, 'ampersand'],
  50          ['&quot;', '&#34;', true, 'quotationmark'],
  51          ['&#8253;', '&#8253;', true, 'interrobang'],
  52          // Finance.
  53          ['&cent;', '&#162;', true, 'centsign'],
  54          ['&euro;', '&#8364;', true, 'eurosign'],
  55          ['&pound;', '&#163;', true, 'poundsign'],
  56          ['&yen;', '&#165;', true, 'yensign'],
  57          // Signs.
  58          ['&copy;', '&#169;', true, 'copyrightsign'],
  59          ['&reg;', '&#174;', true, 'registeredsign'],
  60          ['&trade;', '&#8482;', true, 'trademarksign'],
  61          ['&permil;', '&#8240;', true, 'permillesign'],
  62          ['&micro;', '&#181;', true, 'microsign'],
  63          ['&middot;', '&#183;', true, 'middledot'],
  64          ['&bull;', '&#8226;', true, 'bullet'],
  65          ['&hellip;', '&#8230;', true, 'threedotleader'],
  66          ['&prime;', '&#8242;', true, 'minutesfeet'],
  67          ['&Prime;', '&#8243;', true, 'secondsinches'],
  68          ['&sect;', '&#167;', true, 'sectionsign'],
  69          ['&para;', '&#182;', true, 'paragraphsign'],
  70          ['&szlig;', '&#223;', true, 'sharpsesszed'],
  71          // Quotations.
  72          ['&lsaquo;', '&#8249;', true, 'singleleftpointinganglequotationmark'],
  73          ['&rsaquo;', '&#8250;', true, 'singlerightpointinganglequotationmark'],
  74          ['&laquo;', '&#171;', true, 'leftpointingguillemet'],
  75          ['&raquo;', '&#187;', true, 'rightpointingguillemet'],
  76          ['&lsquo;', '&#8216;', true, 'leftsinglequotationmark'],
  77          ['&rsquo;', '&#8217;', true, 'rightsinglequotationmark'],
  78          ['&ldquo;', '&#8220;', true, 'leftdoublequotationmark'],
  79          ['&rdquo;', '&#8221;', true, 'rightdoublequotationmark'],
  80          ['&sbquo;', '&#8218;', true, 'singlelow9quotationmark'],
  81          ['&bdquo;', '&#8222;', true, 'doublelow9quotationmark'],
  82          ['&lt;', '&#60;', true, 'lessthansign'],
  83          ['&gt;', '&#62;', true, 'greaterthansign'],
  84          ['&le;', '&#8804;', true, 'lessthanorequalto'],
  85          ['&ge;', '&#8805;', true, 'greaterthanorequalto'],
  86          ['&ndash;', '&#8211;', true, 'endash'],
  87          ['&mdash;', '&#8212;', true, 'emdash'],
  88          ['&macr;', '&#175;', true, 'macron'],
  89          ['&oline;', '&#8254;', true, 'overline'],
  90          ['&curren;', '&#164;', true, 'currencysign'],
  91          ['&brvbar;', '&#166;', true, 'brokenbar'],
  92          ['&uml;', '&#168;', true, 'diaeresis'],
  93          ['&iexcl;', '&#161;', true, 'invertedexclamationmark'],
  94          ['&iquest;', '&#191;', true, 'turnedquestionmark'],
  95          ['&circ;', '&#710;', true, 'circumflexaccent'],
  96          ['&tilde;', '&#732;', true, 'smalltilde'],
  97          ['&deg;', '&#176;', true, 'degreesign'],
  98          ['&minus;', '&#8722;', true, 'minussign'],
  99          ['&plusmn;', '&#177;', true, 'plusminussign'],
 100          ['&divide;', '&#247;', true, 'divisionsign'],
 101          ['&frasl;', '&#8260;', true, 'fractionslash'],
 102          ['&times;', '&#215;', true, 'multiplicationsign'],
 103          ['&sup1;', '&#185;', true, 'superscriptone'],
 104          ['&sup2;', '&#178;', true, 'superscripttwo'],
 105          ['&sup3;', '&#179;', true, 'superscriptthree'],
 106          ['&frac14;', '&#188;', true, 'fractiononequarter'],
 107          ['&frac12;', '&#189;', true, 'fractiononehalf'],
 108          ['&frac34;', '&#190;', true, 'fractionthreequarters'],
 109          // Math / logical.
 110          ['&fnof;', '&#402;', true, 'functionflorin'],
 111          ['&int;', '&#8747;', true, 'integral'],
 112          ['&sum;', '&#8721;', true, 'narysumation'],
 113          ['&infin;', '&#8734;', true, 'infinity'],
 114          ['&radic;', '&#8730;', true, 'squareroot'],
 115          ['&sim;', '&#8764;', false, 'similarto'],
 116          ['&cong;', '&#8773;', false, 'approximatelyequalto'],
 117          ['&asymp;', '&#8776;', true, 'almostequalto'],
 118          ['&ne;', '&#8800;', true, 'notequalto'],
 119          ['&equiv;', '&#8801;', true, 'identicalto'],
 120          ['&isin;', '&#8712;', false, 'elementof'],
 121          ['&notin;', '&#8713;', false, 'notanelementof'],
 122          ['&ni;', '&#8715;', false, 'containsasmember'],
 123          ['&prod;', '&#8719;', true, 'naryproduct'],
 124          ['&and;', '&#8743;', false, 'logicaland'],
 125          ['&or;', '&#8744;', false, 'logicalor'],
 126          ['&not;', '&#172;', true, 'notsign'],
 127          ['&cap;', '&#8745;', true, 'intersection'],
 128          ['&cup;', '&#8746;', false, 'union'],
 129          ['&part;', '&#8706;', true, 'partialdifferential'],
 130          ['&forall;', '&#8704;', false, 'forall'],
 131          ['&exist;', '&#8707;', false, 'thereexists'],
 132          ['&empty;', '&#8709;', false, 'diameter'],
 133          ['&nabla;', '&#8711;', false, 'backwarddifference'],
 134          ['&lowast;', '&#8727;', false, 'asteriskoperator'],
 135          ['&prop;', '&#8733;', false, 'proportionalto'],
 136          ['&ang;', '&#8736;', false, 'angle'],
 137          // Undefined.
 138          ['&acute;', '&#180;', true, 'acuteaccent'],
 139          ['&cedil;', '&#184;', true, 'cedilla'],
 140          ['&ordf;', '&#170;', true, 'feminineordinalindicator'],
 141          ['&ordm;', '&#186;', true, 'masculineordinalindicator'],
 142          ['&dagger;', '&#8224;', true, 'dagger'],
 143          ['&Dagger;', '&#8225;', true, 'doubledagger'],
 144          // Alphabetical special chars.
 145          ['&Agrave;', '&#192;', true, 'agrave_caps'],
 146          ['&Aacute;', '&#193;', true, 'aacute_caps'],
 147          ['&Acirc;', '&#194;', true, 'acircumflex_caps'],
 148          ['&Atilde;', '&#195;', true, 'atilde_caps'],
 149          ['&Auml;', '&#196;', true, 'adiaeresis_caps'],
 150          ['&Aring;', '&#197;', true, 'aringabove_caps'],
 151          ['&#256;', '&#256;', true, 'amacron_caps'],
 152          ['&AElig;', '&#198;', true, 'ligatureae_caps'],
 153          ['&Ccedil;', '&#199;', true, 'ccedilla_caps'],
 154          ['&Egrave;', '&#200;', true, 'egrave_caps'],
 155          ['&Eacute;', '&#201;', true, 'eacute_caps'],
 156          ['&Ecirc;', '&#202;', true, 'ecircumflex_caps'],
 157          ['&Euml;', '&#203;', true, 'ediaeresis_caps'],
 158          ['&#274;', '&#274;', true, 'emacron_caps'],
 159          ['&Igrave;', '&#204;', true, 'igrave_caps'],
 160          ['&Iacute;', '&#205;', true, 'iacute_caps'],
 161          ['&Icirc;', '&#206;', true, 'icircumflex_caps'],
 162          ['&Iuml;', '&#207;', true, 'idiaeresis_caps'],
 163          ['&#298;', '&#298;', true, 'imacron_caps'],
 164          ['&ETH;', '&#208;', true, 'eth_caps'],
 165          ['&Ntilde;', '&#209;', true, 'ntilde_caps'],
 166          ['&Ograve;', '&#210;', true, 'ograve_caps'],
 167          ['&Oacute;', '&#211;', true, 'oacute_caps'],
 168          ['&Ocirc;', '&#212;', true, 'ocircumflex_caps'],
 169          ['&Otilde;', '&#213;', true, 'otilde_caps'],
 170          ['&Ouml;', '&#214;', true, 'odiaeresis_caps'],
 171          ['&Oslash;', '&#216;', true, 'oslash_caps'],
 172          ['&#332;', '&#332;', true, 'omacron_caps'],
 173          ['&OElig;', '&#338;', true, 'ligatureoe_caps'],
 174          ['&Scaron;', '&#352;', true, 'scaron_caps'],
 175          ['&Ugrave;', '&#217;', true, 'ugrave_caps'],
 176          ['&Uacute;', '&#218;', true, 'uacute_caps'],
 177          ['&Ucirc;', '&#219;', true, 'ucircumflex_caps'],
 178          ['&Uuml;', '&#220;', true, 'udiaeresis_caps'],
 179          ['&#362;', '&#362;', true, 'umacron_caps'],
 180          ['&Yacute;', '&#221;', true, 'yacute_caps'],
 181          ['&Yuml;', '&#376;', true, 'ydiaeresis_caps'],
 182          ['&THORN;', '&#222;', true, 'thorn_caps'],
 183          ['&agrave;', '&#224;', true, 'agrave'],
 184          ['&aacute;', '&#225;', true, 'aacute'],
 185          ['&acirc;', '&#226;', true, 'acircumflex'],
 186          ['&atilde;', '&#227;', true, 'atilde'],
 187          ['&auml;', '&#228;', true, 'adiaeresis'],
 188          ['&aring;', '&#229;', true, 'aringabove'],
 189          ['&#257;', '&#257;', true, 'amacron'],
 190          ['&aelig;', '&#230;', true, 'ligatureae'],
 191          ['&ccedil;', '&#231;', true, 'ccedilla'],
 192          ['&egrave;', '&#232;', true, 'egrave'],
 193          ['&eacute;', '&#233;', true, 'eacute'],
 194          ['&ecirc;', '&#234;', true, 'ecircumflex'],
 195          ['&euml;', '&#235;', true, 'ediaeresis'],
 196          ['&#275;', '&#275;', true, 'emacron'],
 197          ['&igrave;', '&#236;', true, 'igrave'],
 198          ['&iacute;', '&#237;', true, 'iacute'],
 199          ['&icirc;', '&#238;', true, 'icircumflex'],
 200          ['&iuml;', '&#239;', true, 'idiaeresis'],
 201          ['&#299;', '&#299;', true, 'imacron'],
 202          ['&eth;', '&#240;', true, 'eth'],
 203          ['&ntilde;', '&#241;', true, 'ntilde'],
 204          ['&ograve;', '&#242;', true, 'ograve'],
 205          ['&oacute;', '&#243;', true, 'oacute'],
 206          ['&ocirc;', '&#244;', true, 'ocircumflex'],
 207          ['&otilde;', '&#245;', true, 'otilde'],
 208          ['&ouml;', '&#246;', true, 'odiaeresis'],
 209          ['&oslash;', '&#248;', true, 'oslash'],
 210          ['&#333;', '&#333;', true, 'omacron'],
 211          ['&oelig;', '&#339;', true, 'ligatureoe'],
 212          ['&scaron;', '&#353;', true, 'scaron'],
 213          ['&ugrave;', '&#249;', true, 'ugrave'],
 214          ['&uacute;', '&#250;', true, 'uacute'],
 215          ['&ucirc;', '&#251;', true, 'ucircumflex'],
 216          ['&uuml;', '&#252;', true, 'udiaeresis'],
 217          ['&#363;', '&#363;', true, 'umacron'],
 218          ['&yacute;', '&#253;', true, 'yacute'],
 219          ['&thorn;', '&#254;', true, 'thorn'],
 220          ['&yuml;', '&#255;', true, 'ydiaeresis'],
 221          ['&Alpha;', '&#913;', true, 'alpha_caps'],
 222          ['&Beta;', '&#914;', true, 'beta_caps'],
 223          ['&Gamma;', '&#915;', true, 'gamma_caps'],
 224          ['&Delta;', '&#916;', true, 'delta_caps'],
 225          ['&Epsilon;', '&#917;', true, 'epsilon_caps'],
 226          ['&Zeta;', '&#918;', true, 'zeta_caps'],
 227          ['&Eta;', '&#919;', true, 'eta_caps'],
 228          ['&Theta;', '&#920;', true, 'theta_caps'],
 229          ['&Iota;', '&#921;', true, 'iota_caps'],
 230          ['&Kappa;', '&#922;', true, 'kappa_caps'],
 231          ['&Lambda;', '&#923;', true, 'lambda_caps'],
 232          ['&Mu;', '&#924;', true, 'mu_caps'],
 233          ['&Nu;', '&#925;', true, 'nu_caps'],
 234          ['&Xi;', '&#926;', true, 'xi_caps'],
 235          ['&Omicron;', '&#927;', true, 'omicron_caps'],
 236          ['&Pi;', '&#928;', true, 'pi_caps'],
 237          ['&Rho;', '&#929;', true, 'rho_caps'],
 238          ['&Sigma;', '&#931;', true, 'sigma_caps'],
 239          ['&Tau;', '&#932;', true, 'tau_caps'],
 240          ['&Upsilon;', '&#933;', true, 'upsilon_caps'],
 241          ['&Phi;', '&#934;', true, 'phi_caps'],
 242          ['&Chi;', '&#935;', true, 'chi_caps'],
 243          ['&Psi;', '&#936;', true, 'psi_caps'],
 244          ['&Omega;', '&#937;', true, 'omega_caps'],
 245          ['&alpha;', '&#945;', true, 'alpha'],
 246          ['&beta;', '&#946;', true, 'beta'],
 247          ['&gamma;', '&#947;', true, 'gamma'],
 248          ['&delta;', '&#948;', true, 'delta'],
 249          ['&epsilon;', '&#949;', true, 'epsilon'],
 250          ['&zeta;', '&#950;', true, 'zeta'],
 251          ['&eta;', '&#951;', true, 'eta'],
 252          ['&theta;', '&#952;', true, 'theta'],
 253          ['&iota;', '&#953;', true, 'iota'],
 254          ['&kappa;', '&#954;', true, 'kappa'],
 255          ['&lambda;', '&#955;', true, 'lambda'],
 256          ['&mu;', '&#956;', true, 'mu'],
 257          ['&nu;', '&#957;', true, 'nu'],
 258          ['&xi;', '&#958;', true, 'xi'],
 259          ['&omicron;', '&#959;', true, 'omicron'],
 260          ['&pi;', '&#960;', true, 'pi'],
 261          ['&rho;', '&#961;', true, 'rho'],
 262          ['&sigmaf;', '&#962;', true, 'finalsigma'],
 263          ['&sigma;', '&#963;', true, 'sigma'],
 264          ['&tau;', '&#964;', true, 'tau'],
 265          ['&upsilon;', '&#965;', true, 'upsilon'],
 266          ['&phi;', '&#966;', true, 'phi'],
 267          ['&chi;', '&#967;', true, 'chi'],
 268          ['&psi;', '&#968;', true, 'psi'],
 269          ['&omega;', '&#969;', true, 'omega'],
 270          // Symbols.
 271          ['&alefsym;', '&#8501;', false, 'alefsymbol'],
 272          ['&piv;', '&#982;', false, 'pisymbol'],
 273          ['&real;', '&#8476;', false, 'realpartsymbol'],
 274          ['&thetasym;', '&#977;', false, 'thetasymbol'],
 275          ['&upsih;', '&#978;', false, 'upsilonhooksymbol'],
 276          ['&weierp;', '&#8472;', false, 'weierstrassp'],
 277          ['&image;', '&#8465;', false, 'imaginarypart'],
 278          // Arrows.
 279          ['&larr;', '&#8592;', true, 'leftwardsarrow'],
 280          ['&uarr;', '&#8593;', true, 'upwardsarrow'],
 281          ['&rarr;', '&#8594;', true, 'rightwardsarrow'],
 282          ['&darr;', '&#8595;', true, 'downwardsarrow'],
 283          ['&harr;', '&#8596;', true, 'leftrightarrow'],
 284          ['&crarr;', '&#8629;', false, 'carriagereturn'],
 285          ['&lArr;', '&#8656;', false, 'leftwardsdoublearrow'],
 286          ['&uArr;', '&#8657;', false, 'upwardsdoublearrow'],
 287          ['&rArr;', '&#8658;', false, 'rightwardsdoublearrow'],
 288          ['&dArr;', '&#8659;', false, 'downwardsdoublearrow'],
 289          ['&hArr;', '&#8660;', false, 'leftrightdoublearrow'],
 290          ['&there4;', '&#8756;', false, 'therefore'],
 291          ['&sub;', '&#8834;', false, 'subsetof'],
 292          ['&sup;', '&#8835;', false, 'supersetof'],
 293          ['&nsub;', '&#8836;', false, 'notasubsetof'],
 294          ['&sube;', '&#8838;', false, 'subsetoforequalto'],
 295          ['&supe;', '&#8839;', false, 'supersetoforequalto'],
 296          ['&oplus;', '&#8853;', false, 'circledplus'],
 297          ['&otimes;', '&#8855;', false, 'circledtimes'],
 298          ['&perp;', '&#8869;', false, 'perpendicular'],
 299          ['&sdot;', '&#8901;', false, 'dotoperator'],
 300          ['&lceil;', '&#8968;', false, 'leftceiling'],
 301          ['&rceil;', '&#8969;', false, 'rightceiling'],
 302          ['&lfloor;', '&#8970;', false, 'leftfloor'],
 303          ['&rfloor;', '&#8971;', false, 'rightfloor'],
 304          ['&lang;', '&#9001;', false, 'leftpointinganglebracket'],
 305          ['&rang;', '&#9002;', false, 'rightpointinganglebracket'],
 306          ['&loz;', '&#9674;', true, 'lozenge'],
 307          ['&spades;', '&#9824;', true, 'blackspadesuit'],
 308          ['&clubs;', '&#9827;', true, 'blackclubsuit'],
 309          ['&hearts;', '&#9829;', true, 'blackheartsuit'],
 310          ['&diams;', '&#9830;', true, 'blackdiamondsuit'],
 311          ['&ensp;', '&#8194;', false, 'enspace'],
 312          ['&emsp;', '&#8195;', false, 'emspace'],
 313          ['&thinsp;', '&#8201;', false, 'thinspace'],
 314          ['&zwnj;', '&#8204;', false, 'zerowidthnonjoiner'],
 315          ['&zwj;', '&#8205;', false, 'zerowidthjoiner'],
 316          ['&lrm;', '&#8206;', false, 'lefttorightmark'],
 317          ['&rlm;', '&#8207;', false, 'righttoleftmark'],
 318          ['&shy;', '&#173;', 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"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1