home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-includes / js / tinymce / plugins / charmap / plugin.js next >
Encoding:
JavaScript  |  2017-05-30  |  17.8 KB  |  618 lines

  1. (function () {
  2.  
  3. var defs = {}; // id -> {dependencies, definition, instance (possibly undefined)}
  4.  
  5. // Used when there is no 'main' module.
  6. // The name is probably (hopefully) unique so minification removes for releases.
  7. var register_3795 = function (id) {
  8.   var module = dem(id);
  9.   var fragments = id.split('.');
  10.   var target = Function('return this;')();
  11.   for (var i = 0; i < fragments.length - 1; ++i) {
  12.     if (target[fragments[i]] === undefined)
  13.       target[fragments[i]] = {};
  14.     target = target[fragments[i]];
  15.   }
  16.   target[fragments[fragments.length - 1]] = module;
  17. };
  18.  
  19. var instantiate = function (id) {
  20.   var actual = defs[id];
  21.   var dependencies = actual.deps;
  22.   var definition = actual.defn;
  23.   var len = dependencies.length;
  24.   var instances = new Array(len);
  25.   for (var i = 0; i < len; ++i)
  26.     instances[i] = dem(dependencies[i]);
  27.   var defResult = definition.apply(null, instances);
  28.   if (defResult === undefined)
  29.      throw 'module [' + id + '] returned undefined';
  30.   actual.instance = defResult;
  31. };
  32.  
  33. var def = function (id, dependencies, definition) {
  34.   if (typeof id !== 'string')
  35.     throw 'module id must be a string';
  36.   else if (dependencies === undefined)
  37.     throw 'no dependencies for ' + id;
  38.   else if (definition === undefined)
  39.     throw 'no definition function for ' + id;
  40.   defs[id] = {
  41.     deps: dependencies,
  42.     defn: definition,
  43.     instance: undefined
  44.   };
  45. };
  46.  
  47. var dem = function (id) {
  48.   var actual = defs[id];
  49.   if (actual === undefined)
  50.     throw 'module [' + id + '] was undefined';
  51.   else if (actual.instance === undefined)
  52.     instantiate(id);
  53.   return actual.instance;
  54. };
  55.  
  56. var req = function (ids, callback) {
  57.   var len = ids.length;
  58.   var instances = new Array(len);
  59.   for (var i = 0; i < len; ++i)
  60.     instances.push(dem(ids[i]));
  61.   callback.apply(null, callback);
  62. };
  63.  
  64. var ephox = {};
  65.  
  66. ephox.bolt = {
  67.   module: {
  68.     api: {
  69.       define: def,
  70.       require: req,
  71.       demand: dem
  72.     }
  73.   }
  74. };
  75.  
  76. var define = def;
  77. var require = req;
  78. var demand = dem;
  79. // this helps with minificiation when using a lot of global references
  80. var defineGlobal = function (id, ref) {
  81.   define(id, [], function () { return ref; });
  82. };
  83. /*jsc
  84. ["tinymce.plugins.charmap.Plugin","tinymce.core.PluginManager","tinymce.core.util.Tools","global!tinymce.util.Tools.resolve"]
  85. jsc*/
  86. defineGlobal("global!tinymce.util.Tools.resolve", tinymce.util.Tools.resolve);
  87. /**
  88.  * ResolveGlobal.js
  89.  *
  90.  * Released under LGPL License.
  91.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  92.  *
  93.  * License: http://www.tinymce.com/license
  94.  * Contributing: http://www.tinymce.com/contributing
  95.  */
  96.  
  97. define(
  98.   'tinymce.core.PluginManager',
  99.   [
  100.     'global!tinymce.util.Tools.resolve'
  101.   ],
  102.   function (resolve) {
  103.     return resolve('tinymce.PluginManager');
  104.   }
  105. );
  106.  
  107. /**
  108.  * ResolveGlobal.js
  109.  *
  110.  * Released under LGPL License.
  111.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  112.  *
  113.  * License: http://www.tinymce.com/license
  114.  * Contributing: http://www.tinymce.com/contributing
  115.  */
  116.  
  117. define(
  118.   'tinymce.core.util.Tools',
  119.   [
  120.     'global!tinymce.util.Tools.resolve'
  121.   ],
  122.   function (resolve) {
  123.     return resolve('tinymce.util.Tools');
  124.   }
  125. );
  126.  
  127. /**
  128.  * Plugin.js
  129.  *
  130.  * Released under LGPL License.
  131.  * Copyright (c) 1999-2017 Ephox Corp. All rights reserved
  132.  *
  133.  * License: http://www.tinymce.com/license
  134.  * Contributing: http://www.tinymce.com/contributing
  135.  */
  136.  
  137. /**
  138.  * This class contains all core logic for the charmap plugin.
  139.  *
  140.  * @class tinymce.charmap.Plugin
  141.  * @private
  142.  */
  143. define(
  144.   'tinymce.plugins.charmap.Plugin',
  145.   [
  146.     'tinymce.core.PluginManager',
  147.     'tinymce.core.util.Tools'
  148.   ],
  149.   function (PluginManager, Tools) {
  150.     PluginManager.add('charmap', function (editor) {
  151.       var isArray = Tools.isArray;
  152.  
  153.       function getDefaultCharMap() {
  154.         return [
  155.           ['160', 'no-break space'],
  156.           ['173', 'soft hyphen'],
  157.           ['34', 'quotation mark'],
  158.           // finance
  159.           ['162', 'cent sign'],
  160.           ['8364', 'euro sign'],
  161.           ['163', 'pound sign'],
  162.           ['165', 'yen sign'],
  163.           // signs
  164.           ['169', 'copyright sign'],
  165.           ['174', 'registered sign'],
  166.           ['8482', 'trade mark sign'],
  167.           ['8240', 'per mille sign'],
  168.           ['181', 'micro sign'],
  169.           ['183', 'middle dot'],
  170.           ['8226', 'bullet'],
  171.           ['8230', 'three dot leader'],
  172.           ['8242', 'minutes / feet'],
  173.           ['8243', 'seconds / inches'],
  174.           ['167', 'section sign'],
  175.           ['182', 'paragraph sign'],
  176.           ['223', 'sharp s / ess-zed'],
  177.           // quotations
  178.           ['8249', 'single left-pointing angle quotation mark'],
  179.           ['8250', 'single right-pointing angle quotation mark'],
  180.           ['171', 'left pointing guillemet'],
  181.           ['187', 'right pointing guillemet'],
  182.           ['8216', 'left single quotation mark'],
  183.           ['8217', 'right single quotation mark'],
  184.           ['8220', 'left double quotation mark'],
  185.           ['8221', 'right double quotation mark'],
  186.           ['8218', 'single low-9 quotation mark'],
  187.           ['8222', 'double low-9 quotation mark'],
  188.           ['60', 'less-than sign'],
  189.           ['62', 'greater-than sign'],
  190.           ['8804', 'less-than or equal to'],
  191.           ['8805', 'greater-than or equal to'],
  192.           ['8211', 'en dash'],
  193.           ['8212', 'em dash'],
  194.           ['175', 'macron'],
  195.           ['8254', 'overline'],
  196.           ['164', 'currency sign'],
  197.           ['166', 'broken bar'],
  198.           ['168', 'diaeresis'],
  199.           ['161', 'inverted exclamation mark'],
  200.           ['191', 'turned question mark'],
  201.           ['710', 'circumflex accent'],
  202.           ['732', 'small tilde'],
  203.           ['176', 'degree sign'],
  204.           ['8722', 'minus sign'],
  205.           ['177', 'plus-minus sign'],
  206.           ['247', 'division sign'],
  207.           ['8260', 'fraction slash'],
  208.           ['215', 'multiplication sign'],
  209.           ['185', 'superscript one'],
  210.           ['178', 'superscript two'],
  211.           ['179', 'superscript three'],
  212.           ['188', 'fraction one quarter'],
  213.           ['189', 'fraction one half'],
  214.           ['190', 'fraction three quarters'],
  215.           // math / logical
  216.           ['402', 'function / florin'],
  217.           ['8747', 'integral'],
  218.           ['8721', 'n-ary sumation'],
  219.           ['8734', 'infinity'],
  220.           ['8730', 'square root'],
  221.           ['8764', 'similar to'],
  222.           ['8773', 'approximately equal to'],
  223.           ['8776', 'almost equal to'],
  224.           ['8800', 'not equal to'],
  225.           ['8801', 'identical to'],
  226.           ['8712', 'element of'],
  227.           ['8713', 'not an element of'],
  228.           ['8715', 'contains as member'],
  229.           ['8719', 'n-ary product'],
  230.           ['8743', 'logical and'],
  231.           ['8744', 'logical or'],
  232.           ['172', 'not sign'],
  233.           ['8745', 'intersection'],
  234.           ['8746', 'union'],
  235.           ['8706', 'partial differential'],
  236.           ['8704', 'for all'],
  237.           ['8707', 'there exists'],
  238.           ['8709', 'diameter'],
  239.           ['8711', 'backward difference'],
  240.           ['8727', 'asterisk operator'],
  241.           ['8733', 'proportional to'],
  242.           ['8736', 'angle'],
  243.           // undefined
  244.           ['180', 'acute accent'],
  245.           ['184', 'cedilla'],
  246.           ['170', 'feminine ordinal indicator'],
  247.           ['186', 'masculine ordinal indicator'],
  248.           ['8224', 'dagger'],
  249.           ['8225', 'double dagger'],
  250.           // alphabetical special chars
  251.           ['192', 'A - grave'],
  252.           ['193', 'A - acute'],
  253.           ['194', 'A - circumflex'],
  254.           ['195', 'A - tilde'],
  255.           ['196', 'A - diaeresis'],
  256.           ['197', 'A - ring above'],
  257.           ['256', 'A - macron'],
  258.           ['198', 'ligature AE'],
  259.           ['199', 'C - cedilla'],
  260.           ['200', 'E - grave'],
  261.           ['201', 'E - acute'],
  262.           ['202', 'E - circumflex'],
  263.           ['203', 'E - diaeresis'],
  264.           ['274', 'E - macron'],
  265.           ['204', 'I - grave'],
  266.           ['205', 'I - acute'],
  267.           ['206', 'I - circumflex'],
  268.           ['207', 'I - diaeresis'],
  269.           ['298', 'I - macron'],
  270.           ['208', 'ETH'],
  271.           ['209', 'N - tilde'],
  272.           ['210', 'O - grave'],
  273.           ['211', 'O - acute'],
  274.           ['212', 'O - circumflex'],
  275.           ['213', 'O - tilde'],
  276.           ['214', 'O - diaeresis'],
  277.           ['216', 'O - slash'],
  278.           ['332', 'O - macron'],
  279.           ['338', 'ligature OE'],
  280.           ['352', 'S - caron'],
  281.           ['217', 'U - grave'],
  282.           ['218', 'U - acute'],
  283.           ['219', 'U - circumflex'],
  284.           ['220', 'U - diaeresis'],
  285.           ['362', 'U - macron'],
  286.           ['221', 'Y - acute'],
  287.           ['376', 'Y - diaeresis'],
  288.           ['562', 'Y - macron'],
  289.           ['222', 'THORN'],
  290.           ['224', 'a - grave'],
  291.           ['225', 'a - acute'],
  292.           ['226', 'a - circumflex'],
  293.           ['227', 'a - tilde'],
  294.           ['228', 'a - diaeresis'],
  295.           ['229', 'a - ring above'],
  296.           ['257', 'a - macron'],
  297.           ['230', 'ligature ae'],
  298.           ['231', 'c - cedilla'],
  299.           ['232', 'e - grave'],
  300.           ['233', 'e - acute'],
  301.           ['234', 'e - circumflex'],
  302.           ['235', 'e - diaeresis'],
  303.           ['275', 'e - macron'],
  304.           ['236', 'i - grave'],
  305.           ['237', 'i - acute'],
  306.           ['238', 'i - circumflex'],
  307.           ['239', 'i - diaeresis'],
  308.           ['299', 'i - macron'],
  309.           ['240', 'eth'],
  310.           ['241', 'n - tilde'],
  311.           ['242', 'o - grave'],
  312.           ['243', 'o - acute'],
  313.           ['244', 'o - circumflex'],
  314.           ['245', 'o - tilde'],
  315.           ['246', 'o - diaeresis'],
  316.           ['248', 'o slash'],
  317.           ['333', 'o macron'],
  318.           ['339', 'ligature oe'],
  319.           ['353', 's - caron'],
  320.           ['249', 'u - grave'],
  321.           ['250', 'u - acute'],
  322.           ['251', 'u - circumflex'],
  323.           ['252', 'u - diaeresis'],
  324.           ['363', 'u - macron'],
  325.           ['253', 'y - acute'],
  326.           ['254', 'thorn'],
  327.           ['255', 'y - diaeresis'],
  328.           ['563', 'y - macron'],
  329.           ['913', 'Alpha'],
  330.           ['914', 'Beta'],
  331.           ['915', 'Gamma'],
  332.           ['916', 'Delta'],
  333.           ['917', 'Epsilon'],
  334.           ['918', 'Zeta'],
  335.           ['919', 'Eta'],
  336.           ['920', 'Theta'],
  337.           ['921', 'Iota'],
  338.           ['922', 'Kappa'],
  339.           ['923', 'Lambda'],
  340.           ['924', 'Mu'],
  341.           ['925', 'Nu'],
  342.           ['926', 'Xi'],
  343.           ['927', 'Omicron'],
  344.           ['928', 'Pi'],
  345.           ['929', 'Rho'],
  346.           ['931', 'Sigma'],
  347.           ['932', 'Tau'],
  348.           ['933', 'Upsilon'],
  349.           ['934', 'Phi'],
  350.           ['935', 'Chi'],
  351.           ['936', 'Psi'],
  352.           ['937', 'Omega'],
  353.           ['945', 'alpha'],
  354.           ['946', 'beta'],
  355.           ['947', 'gamma'],
  356.           ['948', 'delta'],
  357.           ['949', 'epsilon'],
  358.           ['950', 'zeta'],
  359.           ['951', 'eta'],
  360.           ['952', 'theta'],
  361.           ['953', 'iota'],
  362.           ['954', 'kappa'],
  363.           ['955', 'lambda'],
  364.           ['956', 'mu'],
  365.           ['957', 'nu'],
  366.           ['958', 'xi'],
  367.           ['959', 'omicron'],
  368.           ['960', 'pi'],
  369.           ['961', 'rho'],
  370.           ['962', 'final sigma'],
  371.           ['963', 'sigma'],
  372.           ['964', 'tau'],
  373.           ['965', 'upsilon'],
  374.           ['966', 'phi'],
  375.           ['967', 'chi'],
  376.           ['968', 'psi'],
  377.           ['969', 'omega'],
  378.           // symbols
  379.           ['8501', 'alef symbol'],
  380.           ['982', 'pi symbol'],
  381.           ['8476', 'real part symbol'],
  382.           ['978', 'upsilon - hook symbol'],
  383.           ['8472', 'Weierstrass p'],
  384.           ['8465', 'imaginary part'],
  385.           // arrows
  386.           ['8592', 'leftwards arrow'],
  387.           ['8593', 'upwards arrow'],
  388.           ['8594', 'rightwards arrow'],
  389.           ['8595', 'downwards arrow'],
  390.           ['8596', 'left right arrow'],
  391.           ['8629', 'carriage return'],
  392.           ['8656', 'leftwards double arrow'],
  393.           ['8657', 'upwards double arrow'],
  394.           ['8658', 'rightwards double arrow'],
  395.           ['8659', 'downwards double arrow'],
  396.           ['8660', 'left right double arrow'],
  397.           ['8756', 'therefore'],
  398.           ['8834', 'subset of'],
  399.           ['8835', 'superset of'],
  400.           ['8836', 'not a subset of'],
  401.           ['8838', 'subset of or equal to'],
  402.           ['8839', 'superset of or equal to'],
  403.           ['8853', 'circled plus'],
  404.           ['8855', 'circled times'],
  405.           ['8869', 'perpendicular'],
  406.           ['8901', 'dot operator'],
  407.           ['8968', 'left ceiling'],
  408.           ['8969', 'right ceiling'],
  409.           ['8970', 'left floor'],
  410.           ['8971', 'right floor'],
  411.           ['9001', 'left-pointing angle bracket'],
  412.           ['9002', 'right-pointing angle bracket'],
  413.           ['9674', 'lozenge'],
  414.           ['9824', 'black spade suit'],
  415.           ['9827', 'black club suit'],
  416.           ['9829', 'black heart suit'],
  417.           ['9830', 'black diamond suit'],
  418.           ['8194', 'en space'],
  419.           ['8195', 'em space'],
  420.           ['8201', 'thin space'],
  421.           ['8204', 'zero width non-joiner'],
  422.           ['8205', 'zero width joiner'],
  423.           ['8206', 'left-to-right mark'],
  424.           ['8207', 'right-to-left mark']
  425.         ];
  426.       }
  427.  
  428.       function charmapFilter(charmap) {
  429.         return Tools.grep(charmap, function (item) {
  430.           return isArray(item) && item.length == 2;
  431.         });
  432.       }
  433.  
  434.       function getCharsFromSetting(settingValue) {
  435.         if (isArray(settingValue)) {
  436.           return [].concat(charmapFilter(settingValue));
  437.         }
  438.  
  439.         if (typeof settingValue == "function") {
  440.           return settingValue();
  441.         }
  442.  
  443.         return [];
  444.       }
  445.  
  446.       function extendCharMap(charmap) {
  447.         var settings = editor.settings;
  448.  
  449.         if (settings.charmap) {
  450.           charmap = getCharsFromSetting(settings.charmap);
  451.         }
  452.  
  453.         if (settings.charmap_append) {
  454.           return [].concat(charmap).concat(getCharsFromSetting(settings.charmap_append));
  455.         }
  456.  
  457.         return charmap;
  458.       }
  459.  
  460.       function getCharMap() {
  461.         return extendCharMap(getDefaultCharMap());
  462.       }
  463.  
  464.       function insertChar(chr) {
  465.         editor.fire('insertCustomChar', { chr: chr }).chr;
  466.         editor.execCommand('mceInsertContent', false, chr);
  467.       }
  468.  
  469.       function showDialog() {
  470.         var gridHtml, x, y, win;
  471.  
  472.         function getParentTd(elm) {
  473.           while (elm) {
  474.             if (elm.nodeName == 'TD') {
  475.               return elm;
  476.             }
  477.  
  478.             elm = elm.parentNode;
  479.           }
  480.         }
  481.  
  482.         gridHtml = '<table role="presentation" cellspacing="0" class="mce-charmap"><tbody>';
  483.  
  484.         var charmap = getCharMap();
  485.         var width = Math.min(charmap.length, 25);
  486.         var height = Math.ceil(charmap.length / width);
  487.         for (y = 0; y < height; y++) {
  488.           gridHtml += '<tr>';
  489.  
  490.           for (x = 0; x < width; x++) {
  491.             var index = y * width + x;
  492.             if (index < charmap.length) {
  493.               var chr = charmap[index];
  494.               var chrText = chr ? String.fromCharCode(parseInt(chr[0], 10)) : ' ';
  495.  
  496.               gridHtml += (
  497.                 '<td title="' + chr[1] + '">' +
  498.                 '<div tabindex="-1" title="' + chr[1] + '" role="button" data-chr="' + chrText + '">' +
  499.                 chrText +
  500.                 '</div>' +
  501.                 '</td>'
  502.               );
  503.             } else {
  504.               gridHtml += '<td />';
  505.             }
  506.           }
  507.  
  508.           gridHtml += '</tr>';
  509.         }
  510.  
  511.         gridHtml += '</tbody></table>';
  512.  
  513.         var charMapPanel = {
  514.           type: 'container',
  515.           html: gridHtml,
  516.           onclick: function (e) {
  517.             var target = e.target;
  518.  
  519.             if (/^(TD|DIV)$/.test(target.nodeName)) {
  520.               var charDiv = getParentTd(target).firstChild;
  521.               if (charDiv && charDiv.hasAttribute('data-chr')) {
  522.                 insertChar(charDiv.getAttribute('data-chr'));
  523.  
  524.                 if (!e.ctrlKey) {
  525.                   win.close();
  526.                 }
  527.               }
  528.             }
  529.           },
  530.           onmouseover: function (e) {
  531.             var td = getParentTd(e.target);
  532.  
  533.             if (td && td.firstChild) {
  534.               win.find('#preview').text(td.firstChild.firstChild.data);
  535.               win.find('#previewTitle').text(td.title);
  536.             } else {
  537.               win.find('#preview').text(' ');
  538.               win.find('#previewTitle').text(' ');
  539.             }
  540.           }
  541.         };
  542.  
  543.         win = editor.windowManager.open({
  544.           title: "Special character",
  545.           spacing: 10,
  546.           padding: 10,
  547.           items: [
  548.             charMapPanel,
  549.             {
  550.               type: 'container',
  551.               layout: 'flex',
  552.               direction: 'column',
  553.               align: 'center',
  554.               spacing: 5,
  555.               minWidth: 160,
  556.               minHeight: 160,
  557.               items: [
  558.                 {
  559.                   type: 'label',
  560.                   name: 'preview',
  561.                   text: ' ',
  562.                   style: 'font-size: 40px; text-align: center',
  563.                   border: 1,
  564.                   minWidth: 140,
  565.                   minHeight: 80
  566.                 },
  567.                 {
  568.                   type: 'spacer',
  569.                   minHeight: 20
  570.                 },
  571.                 {
  572.                   type: 'label',
  573.                   name: 'previewTitle',
  574.                   text: ' ',
  575.                   style: 'white-space: pre-wrap;',
  576.                   border: 1,
  577.                   minWidth: 140
  578.                 }
  579.               ]
  580.             }
  581.           ],
  582.           buttons: [
  583.             {
  584.               text: "Close", onclick: function () {
  585.                 win.close();
  586.               }
  587.             }
  588.           ]
  589.         });
  590.       }
  591.  
  592.       editor.addCommand('mceShowCharmap', showDialog);
  593.  
  594.       editor.addButton('charmap', {
  595.         icon: 'charmap',
  596.         tooltip: 'Special character',
  597.         cmd: 'mceShowCharmap'
  598.       });
  599.  
  600.       editor.addMenuItem('charmap', {
  601.         icon: 'charmap',
  602.         text: 'Special character',
  603.         cmd: 'mceShowCharmap',
  604.         context: 'insert'
  605.       });
  606.  
  607.       return {
  608.         getCharMap: getCharMap,
  609.         insertChar: insertChar
  610.       };
  611.     });
  612.  
  613.     return function () { };
  614.   }
  615. );
  616. dem('tinymce.plugins.charmap.Plugin')();
  617. })();
  618.