plugin.js 8.9 KB

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