5
|
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 |
|
|
11 |
/*global tinymce:true */ |
|
12 |
|
|
13 |
tinymce.PluginManager.add('charmap', function(editor) { |
|
14 |
var charmap = [ |
|
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 |
['198', 'ligature AE'], |
|
118 |
['199', 'C - cedilla'], |
|
119 |
['200', 'E - grave'], |
|
120 |
['201', 'E - acute'], |
|
121 |
['202', 'E - circumflex'], |
|
122 |
['203', 'E - diaeresis'], |
|
123 |
['204', 'I - grave'], |
|
124 |
['205', 'I - acute'], |
|
125 |
['206', 'I - circumflex'], |
|
126 |
['207', 'I - diaeresis'], |
|
127 |
['208', 'ETH'], |
|
128 |
['209', 'N - tilde'], |
|
129 |
['210', 'O - grave'], |
|
130 |
['211', 'O - acute'], |
|
131 |
['212', 'O - circumflex'], |
|
132 |
['213', 'O - tilde'], |
|
133 |
['214', 'O - diaeresis'], |
|
134 |
['216', 'O - slash'], |
|
135 |
['338', 'ligature OE'], |
|
136 |
['352', 'S - caron'], |
|
137 |
['217', 'U - grave'], |
|
138 |
['218', 'U - acute'], |
|
139 |
['219', 'U - circumflex'], |
|
140 |
['220', 'U - diaeresis'], |
|
141 |
['221', 'Y - acute'], |
|
142 |
['376', 'Y - diaeresis'], |
|
143 |
['222', 'THORN'], |
|
144 |
['224', 'a - grave'], |
|
145 |
['225', 'a - acute'], |
|
146 |
['226', 'a - circumflex'], |
|
147 |
['227', 'a - tilde'], |
|
148 |
['228', 'a - diaeresis'], |
|
149 |
['229', 'a - ring above'], |
|
150 |
['230', 'ligature ae'], |
|
151 |
['231', 'c - cedilla'], |
|
152 |
['232', 'e - grave'], |
|
153 |
['233', 'e - acute'], |
|
154 |
['234', 'e - circumflex'], |
|
155 |
['235', 'e - diaeresis'], |
|
156 |
['236', 'i - grave'], |
|
157 |
['237', 'i - acute'], |
|
158 |
['238', 'i - circumflex'], |
|
159 |
['239', 'i - diaeresis'], |
|
160 |
['240', 'eth'], |
|
161 |
['241', 'n - tilde'], |
|
162 |
['242', 'o - grave'], |
|
163 |
['243', 'o - acute'], |
|
164 |
['244', 'o - circumflex'], |
|
165 |
['245', 'o - tilde'], |
|
166 |
['246', 'o - diaeresis'], |
|
167 |
['248', 'o slash'], |
|
168 |
['339', 'ligature oe'], |
|
169 |
['353', 's - caron'], |
|
170 |
['249', 'u - grave'], |
|
171 |
['250', 'u - acute'], |
|
172 |
['251', 'u - circumflex'], |
|
173 |
['252', 'u - diaeresis'], |
|
174 |
['253', 'y - acute'], |
|
175 |
['254', 'thorn'], |
|
176 |
['255', 'y - diaeresis'], |
|
177 |
['913', 'Alpha'], |
|
178 |
['914', 'Beta'], |
|
179 |
['915', 'Gamma'], |
|
180 |
['916', 'Delta'], |
|
181 |
['917', 'Epsilon'], |
|
182 |
['918', 'Zeta'], |
|
183 |
['919', 'Eta'], |
|
184 |
['920', 'Theta'], |
|
185 |
['921', 'Iota'], |
|
186 |
['922', 'Kappa'], |
|
187 |
['923', 'Lambda'], |
|
188 |
['924', 'Mu'], |
|
189 |
['925', 'Nu'], |
|
190 |
['926', 'Xi'], |
|
191 |
['927', 'Omicron'], |
|
192 |
['928', 'Pi'], |
|
193 |
['929', 'Rho'], |
|
194 |
['931', 'Sigma'], |
|
195 |
['932', 'Tau'], |
|
196 |
['933', 'Upsilon'], |
|
197 |
['934', 'Phi'], |
|
198 |
['935', 'Chi'], |
|
199 |
['936', 'Psi'], |
|
200 |
['937', 'Omega'], |
|
201 |
['945', 'alpha'], |
|
202 |
['946', 'beta'], |
|
203 |
['947', 'gamma'], |
|
204 |
['948', 'delta'], |
|
205 |
['949', 'epsilon'], |
|
206 |
['950', 'zeta'], |
|
207 |
['951', 'eta'], |
|
208 |
['952', 'theta'], |
|
209 |
['953', 'iota'], |
|
210 |
['954', 'kappa'], |
|
211 |
['955', 'lambda'], |
|
212 |
['956', 'mu'], |
|
213 |
['957', 'nu'], |
|
214 |
['958', 'xi'], |
|
215 |
['959', 'omicron'], |
|
216 |
['960', 'pi'], |
|
217 |
['961', 'rho'], |
|
218 |
['962', 'final sigma'], |
|
219 |
['963', 'sigma'], |
|
220 |
['964', 'tau'], |
|
221 |
['965', 'upsilon'], |
|
222 |
['966', 'phi'], |
|
223 |
['967', 'chi'], |
|
224 |
['968', 'psi'], |
|
225 |
['969', 'omega'], |
|
226 |
// symbols |
|
227 |
['8501', 'alef symbol'], |
|
228 |
['982', 'pi symbol'], |
|
229 |
['8476', 'real part symbol'], |
|
230 |
['978', 'upsilon - hook symbol'], |
|
231 |
['8472', 'Weierstrass p'], |
|
232 |
['8465', 'imaginary part'], |
|
233 |
// arrows |
|
234 |
['8592', 'leftwards arrow'], |
|
235 |
['8593', 'upwards arrow'], |
|
236 |
['8594', 'rightwards arrow'], |
|
237 |
['8595', 'downwards arrow'], |
|
238 |
['8596', 'left right arrow'], |
|
239 |
['8629', 'carriage return'], |
|
240 |
['8656', 'leftwards double arrow'], |
|
241 |
['8657', 'upwards double arrow'], |
|
242 |
['8658', 'rightwards double arrow'], |
|
243 |
['8659', 'downwards double arrow'], |
|
244 |
['8660', 'left right double arrow'], |
|
245 |
['8756', 'therefore'], |
|
246 |
['8834', 'subset of'], |
|
247 |
['8835', 'superset of'], |
|
248 |
['8836', 'not a subset of'], |
|
249 |
['8838', 'subset of or equal to'], |
|
250 |
['8839', 'superset of or equal to'], |
|
251 |
['8853', 'circled plus'], |
|
252 |
['8855', 'circled times'], |
|
253 |
['8869', 'perpendicular'], |
|
254 |
['8901', 'dot operator'], |
|
255 |
['8968', 'left ceiling'], |
|
256 |
['8969', 'right ceiling'], |
|
257 |
['8970', 'left floor'], |
|
258 |
['8971', 'right floor'], |
|
259 |
['9001', 'left-pointing angle bracket'], |
|
260 |
['9002', 'right-pointing angle bracket'], |
|
261 |
['9674', 'lozenge'], |
|
262 |
['9824', 'black spade suit'], |
|
263 |
['9827', 'black club suit'], |
|
264 |
['9829', 'black heart suit'], |
|
265 |
['9830', 'black diamond suit'], |
|
266 |
['8194', 'en space'], |
|
267 |
['8195', 'em space'], |
|
268 |
['8201', 'thin space'], |
|
269 |
['8204', 'zero width non-joiner'], |
|
270 |
['8205', 'zero width joiner'], |
|
271 |
['8206', 'left-to-right mark'], |
|
272 |
['8207', 'right-to-left mark'] |
|
273 |
]; |
|
274 |
|
|
275 |
function showDialog() { |
|
276 |
var gridHtml, x, y, win; |
|
277 |
|
|
278 |
function getParentTd(elm) { |
|
279 |
while (elm) { |
|
280 |
if (elm.nodeName == 'TD') { |
|
281 |
return elm; |
|
282 |
} |
|
283 |
|
|
284 |
elm = elm.parentNode; |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
gridHtml = '<table role="presentation" cellspacing="0" class="mce-charmap"><tbody>'; |
|
289 |
|
|
290 |
var width = 25; |
|
291 |
var height = Math.ceil(charmap.length / width); |
|
292 |
for (y = 0; y < height; y++) { |
|
293 |
gridHtml += '<tr>'; |
|
294 |
|
|
295 |
for (x = 0; x < width; x++) { |
|
296 |
var index = y * width + x; |
|
297 |
if (index < charmap.length) { |
|
298 |
var chr = charmap[index]; |
|
299 |
|
|
300 |
gridHtml += '<td title="' + chr[1] + '"><div tabindex="-1" title="' + chr[1] + '" role="button">' + |
|
301 |
(chr ? String.fromCharCode(parseInt(chr[0], 10)) : ' ') + '</div></td>'; |
|
302 |
} else { |
|
303 |
gridHtml += '<td />'; |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
gridHtml += '</tr>'; |
|
308 |
} |
|
309 |
|
|
310 |
gridHtml += '</tbody></table>'; |
|
311 |
|
|
312 |
var charMapPanel = { |
|
313 |
type: 'container', |
|
314 |
html: gridHtml, |
|
315 |
onclick: function(e) { |
|
316 |
var target = e.target; |
|
317 |
if (/^(TD|DIV)$/.test(target.nodeName)) { |
|
318 |
if (getParentTd(target).firstChild) { |
|
319 |
editor.execCommand('mceInsertContent', false, tinymce.trim(target.innerText || target.textContent)); |
|
320 |
|
|
321 |
if (!e.ctrlKey) { |
|
322 |
win.close(); |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
326 |
}, |
|
327 |
onmouseover: function(e) { |
|
328 |
var td = getParentTd(e.target); |
|
329 |
|
|
330 |
if (td && td.firstChild) { |
|
331 |
win.find('#preview').text(td.firstChild.firstChild.data); |
|
332 |
win.find('#previewTitle').text(td.title); |
|
333 |
} else { |
|
334 |
win.find('#preview').text(' '); |
|
335 |
win.find('#previewTitle').text(' '); |
|
336 |
} |
|
337 |
} |
|
338 |
}; |
|
339 |
|
|
340 |
win = editor.windowManager.open({ |
|
341 |
title: "Special character", |
|
342 |
spacing: 10, |
|
343 |
padding: 10, |
|
344 |
items: [ |
|
345 |
charMapPanel, |
|
346 |
{ |
|
347 |
type: 'container', |
|
348 |
layout: 'flex', |
|
349 |
direction: 'column', |
|
350 |
align: 'center', |
|
351 |
spacing: 5, |
|
352 |
minWidth: 160, |
|
353 |
minHeight: 160, |
|
354 |
items: [ |
|
355 |
{ |
|
356 |
type: 'label', |
|
357 |
name: 'preview', |
|
358 |
text: ' ', |
|
359 |
style: 'font-size: 40px; text-align: center', |
|
360 |
border: 1, |
|
361 |
minWidth: 140, |
|
362 |
minHeight: 80 |
|
363 |
}, |
|
364 |
{ |
|
365 |
type: 'label', |
|
366 |
name: 'previewTitle', |
|
367 |
text: ' ', |
|
368 |
style: 'text-align: center', |
|
369 |
border: 1, |
|
370 |
minWidth: 140, |
|
371 |
minHeight: 80 |
|
372 |
} |
|
373 |
] |
|
374 |
} |
|
375 |
], |
|
376 |
buttons: [ |
|
377 |
{text: "Close", onclick: function() { |
|
378 |
win.close(); |
|
379 |
}} |
|
380 |
] |
|
381 |
}); |
|
382 |
} |
|
383 |
|
|
384 |
editor.addButton('charmap', { |
|
385 |
icon: 'charmap', |
|
386 |
tooltip: 'Special character', |
|
387 |
onclick: showDialog |
|
388 |
}); |
|
389 |
|
|
390 |
editor.addMenuItem('charmap', { |
|
391 |
icon: 'charmap', |
|
392 |
text: 'Special character', |
|
393 |
onclick: showDialog, |
|
394 |
context: 'insert' |
|
395 |
}); |
|
396 |
}); |