Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

466 lignes
11 KiB

  1. /**
  2. * plugin.js
  3. *
  4. * Released under LGPL License.
  5. * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*global tinymce:true */
  11. tinymce.PluginManager.add('charmap', function(editor) {
  12. var isArray = tinymce.util.Tools.isArray;
  13. function getDefaultCharMap() {
  14. return [
  15. ['160', 'no-break space'],
  16. ['173', 'soft hyphen'],
  17. ['34', 'quotation mark'],
  18. // finance
  19. ['162', 'cent sign'],
  20. ['8364', 'euro sign'],
  21. ['163', 'pound sign'],
  22. ['165', 'yen sign'],
  23. // signs
  24. ['169', 'copyright sign'],
  25. ['174', 'registered sign'],
  26. ['8482', 'trade mark sign'],
  27. ['8240', 'per mille sign'],
  28. ['181', 'micro sign'],
  29. ['183', 'middle dot'],
  30. ['8226', 'bullet'],
  31. ['8230', 'three dot leader'],
  32. ['8242', 'minutes / feet'],
  33. ['8243', 'seconds / inches'],
  34. ['167', 'section sign'],
  35. ['182', 'paragraph sign'],
  36. ['223', 'sharp s / ess-zed'],
  37. // quotations
  38. ['8249', 'single left-pointing angle quotation mark'],
  39. ['8250', 'single right-pointing angle quotation mark'],
  40. ['171', 'left pointing guillemet'],
  41. ['187', 'right pointing guillemet'],
  42. ['8216', 'left single quotation mark'],
  43. ['8217', 'right single quotation mark'],
  44. ['8220', 'left double quotation mark'],
  45. ['8221', 'right double quotation mark'],
  46. ['8218', 'single low-9 quotation mark'],
  47. ['8222', 'double low-9 quotation mark'],
  48. ['60', 'less-than sign'],
  49. ['62', 'greater-than sign'],
  50. ['8804', 'less-than or equal to'],
  51. ['8805', 'greater-than or equal to'],
  52. ['8211', 'en dash'],
  53. ['8212', 'em dash'],
  54. ['175', 'macron'],
  55. ['8254', 'overline'],
  56. ['164', 'currency sign'],
  57. ['166', 'broken bar'],
  58. ['168', 'diaeresis'],
  59. ['161', 'inverted exclamation mark'],
  60. ['191', 'turned question mark'],
  61. ['710', 'circumflex accent'],
  62. ['732', 'small tilde'],
  63. ['176', 'degree sign'],
  64. ['8722', 'minus sign'],
  65. ['177', 'plus-minus sign'],
  66. ['247', 'division sign'],
  67. ['8260', 'fraction slash'],
  68. ['215', 'multiplication sign'],
  69. ['185', 'superscript one'],
  70. ['178', 'superscript two'],
  71. ['179', 'superscript three'],
  72. ['188', 'fraction one quarter'],
  73. ['189', 'fraction one half'],
  74. ['190', 'fraction three quarters'],
  75. // math / logical
  76. ['402', 'function / florin'],
  77. ['8747', 'integral'],
  78. ['8721', 'n-ary sumation'],
  79. ['8734', 'infinity'],
  80. ['8730', 'square root'],
  81. ['8764', 'similar to'],
  82. ['8773', 'approximately equal to'],
  83. ['8776', 'almost equal to'],
  84. ['8800', 'not equal to'],
  85. ['8801', 'identical to'],
  86. ['8712', 'element of'],
  87. ['8713', 'not an element of'],
  88. ['8715', 'contains as member'],
  89. ['8719', 'n-ary product'],
  90. ['8743', 'logical and'],
  91. ['8744', 'logical or'],
  92. ['172', 'not sign'],
  93. ['8745', 'intersection'],
  94. ['8746', 'union'],
  95. ['8706', 'partial differential'],
  96. ['8704', 'for all'],
  97. ['8707', 'there exists'],
  98. ['8709', 'diameter'],
  99. ['8711', 'backward difference'],
  100. ['8727', 'asterisk operator'],
  101. ['8733', 'proportional to'],
  102. ['8736', 'angle'],
  103. // undefined
  104. ['180', 'acute accent'],
  105. ['184', 'cedilla'],
  106. ['170', 'feminine ordinal indicator'],
  107. ['186', 'masculine ordinal indicator'],
  108. ['8224', 'dagger'],
  109. ['8225', 'double dagger'],
  110. // alphabetical special chars
  111. ['192', 'A - grave'],
  112. ['193', 'A - acute'],
  113. ['194', 'A - circumflex'],
  114. ['195', 'A - tilde'],
  115. ['196', 'A - diaeresis'],
  116. ['197', 'A - ring above'],
  117. ['256', 'A - macron'],
  118. ['198', 'ligature AE'],
  119. ['199', 'C - cedilla'],
  120. ['200', 'E - grave'],
  121. ['201', 'E - acute'],
  122. ['202', 'E - circumflex'],
  123. ['203', 'E - diaeresis'],
  124. ['274', 'E - macron'],
  125. ['204', 'I - grave'],
  126. ['205', 'I - acute'],
  127. ['206', 'I - circumflex'],
  128. ['207', 'I - diaeresis'],
  129. ['298', 'I - macron'],
  130. ['208', 'ETH'],
  131. ['209', 'N - tilde'],
  132. ['210', 'O - grave'],
  133. ['211', 'O - acute'],
  134. ['212', 'O - circumflex'],
  135. ['213', 'O - tilde'],
  136. ['214', 'O - diaeresis'],
  137. ['216', 'O - slash'],
  138. ['332', 'O - macron'],
  139. ['338', 'ligature OE'],
  140. ['352', 'S - caron'],
  141. ['217', 'U - grave'],
  142. ['218', 'U - acute'],
  143. ['219', 'U - circumflex'],
  144. ['220', 'U - diaeresis'],
  145. ['362', 'U - macron'],
  146. ['221', 'Y - acute'],
  147. ['376', 'Y - diaeresis'],
  148. ['562', 'Y - macron'],
  149. ['222', 'THORN'],
  150. ['224', 'a - grave'],
  151. ['225', 'a - acute'],
  152. ['226', 'a - circumflex'],
  153. ['227', 'a - tilde'],
  154. ['228', 'a - diaeresis'],
  155. ['229', 'a - ring above'],
  156. ['257', 'a - macron'],
  157. ['230', 'ligature ae'],
  158. ['231', 'c - cedilla'],
  159. ['232', 'e - grave'],
  160. ['233', 'e - acute'],
  161. ['234', 'e - circumflex'],
  162. ['235', 'e - diaeresis'],
  163. ['275', 'e - macron'],
  164. ['236', 'i - grave'],
  165. ['237', 'i - acute'],
  166. ['238', 'i - circumflex'],
  167. ['239', 'i - diaeresis'],
  168. ['299', 'i - macron'],
  169. ['240', 'eth'],
  170. ['241', 'n - tilde'],
  171. ['242', 'o - grave'],
  172. ['243', 'o - acute'],
  173. ['244', 'o - circumflex'],
  174. ['245', 'o - tilde'],
  175. ['246', 'o - diaeresis'],
  176. ['248', 'o slash'],
  177. ['333', 'o macron'],
  178. ['339', 'ligature oe'],
  179. ['353', 's - caron'],
  180. ['249', 'u - grave'],
  181. ['250', 'u - acute'],
  182. ['251', 'u - circumflex'],
  183. ['252', 'u - diaeresis'],
  184. ['363', 'u - macron'],
  185. ['253', 'y - acute'],
  186. ['254', 'thorn'],
  187. ['255', 'y - diaeresis'],
  188. ['563', 'y - macron'],
  189. ['913', 'Alpha'],
  190. ['914', 'Beta'],
  191. ['915', 'Gamma'],
  192. ['916', 'Delta'],
  193. ['917', 'Epsilon'],
  194. ['918', 'Zeta'],
  195. ['919', 'Eta'],
  196. ['920', 'Theta'],
  197. ['921', 'Iota'],
  198. ['922', 'Kappa'],
  199. ['923', 'Lambda'],
  200. ['924', 'Mu'],
  201. ['925', 'Nu'],
  202. ['926', 'Xi'],
  203. ['927', 'Omicron'],
  204. ['928', 'Pi'],
  205. ['929', 'Rho'],
  206. ['931', 'Sigma'],
  207. ['932', 'Tau'],
  208. ['933', 'Upsilon'],
  209. ['934', 'Phi'],
  210. ['935', 'Chi'],
  211. ['936', 'Psi'],
  212. ['937', 'Omega'],
  213. ['945', 'alpha'],
  214. ['946', 'beta'],
  215. ['947', 'gamma'],
  216. ['948', 'delta'],
  217. ['949', 'epsilon'],
  218. ['950', 'zeta'],
  219. ['951', 'eta'],
  220. ['952', 'theta'],
  221. ['953', 'iota'],
  222. ['954', 'kappa'],
  223. ['955', 'lambda'],
  224. ['956', 'mu'],
  225. ['957', 'nu'],
  226. ['958', 'xi'],
  227. ['959', 'omicron'],
  228. ['960', 'pi'],
  229. ['961', 'rho'],
  230. ['962', 'final sigma'],
  231. ['963', 'sigma'],
  232. ['964', 'tau'],
  233. ['965', 'upsilon'],
  234. ['966', 'phi'],
  235. ['967', 'chi'],
  236. ['968', 'psi'],
  237. ['969', 'omega'],
  238. // symbols
  239. ['8501', 'alef symbol'],
  240. ['982', 'pi symbol'],
  241. ['8476', 'real part symbol'],
  242. ['978', 'upsilon - hook symbol'],
  243. ['8472', 'Weierstrass p'],
  244. ['8465', 'imaginary part'],
  245. // arrows
  246. ['8592', 'leftwards arrow'],
  247. ['8593', 'upwards arrow'],
  248. ['8594', 'rightwards arrow'],
  249. ['8595', 'downwards arrow'],
  250. ['8596', 'left right arrow'],
  251. ['8629', 'carriage return'],
  252. ['8656', 'leftwards double arrow'],
  253. ['8657', 'upwards double arrow'],
  254. ['8658', 'rightwards double arrow'],
  255. ['8659', 'downwards double arrow'],
  256. ['8660', 'left right double arrow'],
  257. ['8756', 'therefore'],
  258. ['8834', 'subset of'],
  259. ['8835', 'superset of'],
  260. ['8836', 'not a subset of'],
  261. ['8838', 'subset of or equal to'],
  262. ['8839', 'superset of or equal to'],
  263. ['8853', 'circled plus'],
  264. ['8855', 'circled times'],
  265. ['8869', 'perpendicular'],
  266. ['8901', 'dot operator'],
  267. ['8968', 'left ceiling'],
  268. ['8969', 'right ceiling'],
  269. ['8970', 'left floor'],
  270. ['8971', 'right floor'],
  271. ['9001', 'left-pointing angle bracket'],
  272. ['9002', 'right-pointing angle bracket'],
  273. ['9674', 'lozenge'],
  274. ['9824', 'black spade suit'],
  275. ['9827', 'black club suit'],
  276. ['9829', 'black heart suit'],
  277. ['9830', 'black diamond suit'],
  278. ['8194', 'en space'],
  279. ['8195', 'em space'],
  280. ['8201', 'thin space'],
  281. ['8204', 'zero width non-joiner'],
  282. ['8205', 'zero width joiner'],
  283. ['8206', 'left-to-right mark'],
  284. ['8207', 'right-to-left mark']
  285. ];
  286. }
  287. function charmapFilter(charmap) {
  288. return tinymce.util.Tools.grep(charmap, function(item) {
  289. return isArray(item) && item.length == 2;
  290. });
  291. }
  292. function getCharsFromSetting(settingValue) {
  293. if (isArray(settingValue)) {
  294. return [].concat(charmapFilter(settingValue));
  295. }
  296. if (typeof settingValue == "function") {
  297. return settingValue();
  298. }
  299. return [];
  300. }
  301. function extendCharMap(charmap) {
  302. var settings = editor.settings;
  303. if (settings.charmap) {
  304. charmap = getCharsFromSetting(settings.charmap);
  305. }
  306. if (settings.charmap_append) {
  307. return [].concat(charmap).concat(getCharsFromSetting(settings.charmap_append));
  308. }
  309. return charmap;
  310. }
  311. function getCharMap() {
  312. return extendCharMap(getDefaultCharMap());
  313. }
  314. function insertChar(chr) {
  315. editor.fire('insertCustomChar', {chr: chr}).chr;
  316. editor.execCommand('mceInsertContent', false, chr);
  317. }
  318. function showDialog() {
  319. var gridHtml, x, y, win;
  320. function getParentTd(elm) {
  321. while (elm) {
  322. if (elm.nodeName == 'TD') {
  323. return elm;
  324. }
  325. elm = elm.parentNode;
  326. }
  327. }
  328. gridHtml = '<table role="presentation" cellspacing="0" class="mce-charmap"><tbody>';
  329. var charmap = getCharMap();
  330. var width = Math.min(charmap.length, 25);
  331. var height = Math.ceil(charmap.length / width);
  332. for (y = 0; y < height; y++) {
  333. gridHtml += '<tr>';
  334. for (x = 0; x < width; x++) {
  335. var index = y * width + x;
  336. if (index < charmap.length) {
  337. var chr = charmap[index];
  338. var chrText = chr ? String.fromCharCode(parseInt(chr[0], 10)) : '&nbsp;';
  339. gridHtml += (
  340. '<td title="' + chr[1] + '"><div tabindex="-1" title="' + chr[1] + '" role="button" data-chr="' + chrText + '">' +
  341. chrText +
  342. '</div></td>'
  343. );
  344. } else {
  345. gridHtml += '<td />';
  346. }
  347. }
  348. gridHtml += '</tr>';
  349. }
  350. gridHtml += '</tbody></table>';
  351. var charMapPanel = {
  352. type: 'container',
  353. html: gridHtml,
  354. onclick: function(e) {
  355. var target = e.target;
  356. if (/^(TD|DIV)$/.test(target.nodeName)) {
  357. if (getParentTd(target).firstChild) {
  358. insertChar(target.getAttribute('data-chr'));
  359. if (!e.ctrlKey) {
  360. win.close();
  361. }
  362. }
  363. }
  364. },
  365. onmouseover: function(e) {
  366. var td = getParentTd(e.target);
  367. if (td && td.firstChild) {
  368. win.find('#preview').text(td.firstChild.firstChild.data);
  369. win.find('#previewTitle').text(td.title);
  370. } else {
  371. win.find('#preview').text(' ');
  372. win.find('#previewTitle').text(' ');
  373. }
  374. }
  375. };
  376. win = editor.windowManager.open({
  377. title: "Special character",
  378. spacing: 10,
  379. padding: 10,
  380. items: [
  381. charMapPanel,
  382. {
  383. type: 'container',
  384. layout: 'flex',
  385. direction: 'column',
  386. align: 'center',
  387. spacing: 5,
  388. minWidth: 160,
  389. minHeight: 160,
  390. items: [
  391. {
  392. type: 'label',
  393. name: 'preview',
  394. text: ' ',
  395. style: 'font-size: 40px; text-align: center',
  396. border: 1,
  397. minWidth: 140,
  398. minHeight: 80
  399. },
  400. {
  401. type: 'label',
  402. name: 'previewTitle',
  403. text: ' ',
  404. style: 'text-align: center',
  405. border: 1,
  406. minWidth: 140,
  407. minHeight: 80
  408. }
  409. ]
  410. }
  411. ],
  412. buttons: [
  413. {text: "Close", onclick: function() {
  414. win.close();
  415. }}
  416. ]
  417. });
  418. }
  419. editor.addCommand('mceShowCharmap', showDialog);
  420. editor.addButton('charmap', {
  421. icon: 'charmap',
  422. tooltip: 'Special character',
  423. cmd: 'mceShowCharmap'
  424. });
  425. editor.addMenuItem('charmap', {
  426. icon: 'charmap',
  427. text: 'Special character',
  428. cmd: 'mceShowCharmap',
  429. context: 'insert'
  430. });
  431. return {
  432. getCharMap: getCharMap,
  433. insertChar: insertChar
  434. };
  435. });