smiley.js 4.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. CKEDITOR.dialog.add("smiley", function (f) {
  6. for (var e = f.config, a = f.lang.smiley, h = e.smiley_images, g = e.smiley_columns || 12, k, m = function (l) {
  7. var c = l.data.getTarget(), b = c.getName();
  8. if ("a" == b) c = c.getChild(0); else if ("img" != b) return;
  9. var b = c.getAttribute("cke_src"), a = c.getAttribute("title"), c = f.document.createElement("img", {
  10. attributes: {
  11. src: b,
  12. "data-cke-saved-src": b,
  13. title: a,
  14. alt: a,
  15. class: 'smiley',
  16. /*width: c.$.width,
  17. height: c.$.height,*/
  18. width: 28,
  19. height: 28
  20. }
  21. });
  22. f.insertElement(c);
  23. k.hide();
  24. l.data.preventDefault()
  25. }, q = CKEDITOR.tools.addFunction(function (a, c) {
  26. a =
  27. new CKEDITOR.dom.event(a);
  28. c = new CKEDITOR.dom.element(c);
  29. var b;
  30. b = a.getKeystroke();
  31. var d = "rtl" == f.lang.dir;
  32. switch (b) {
  33. case 38:
  34. if (b = c.getParent().getParent().getPrevious()) b = b.getChild([c.getParent().getIndex(), 0]), b.focus();
  35. a.preventDefault();
  36. break;
  37. case 40:
  38. (b = c.getParent().getParent().getNext()) && (b = b.getChild([c.getParent().getIndex(), 0])) && b.focus();
  39. a.preventDefault();
  40. break;
  41. case 32:
  42. m({data: a});
  43. a.preventDefault();
  44. break;
  45. case d ? 37 : 39:
  46. if (b = c.getParent().getNext()) b = b.getChild(0), b.focus(), a.preventDefault(!0);
  47. else if (b = c.getParent().getParent().getNext()) (b = b.getChild([0, 0])) && b.focus(), a.preventDefault(!0);
  48. break;
  49. case d ? 39 : 37:
  50. if (b = c.getParent().getPrevious()) b = b.getChild(0), b.focus(), a.preventDefault(!0); else if (b = c.getParent().getParent().getPrevious()) b = b.getLast().getChild(0), b.focus(), a.preventDefault(!0)
  51. }
  52. }), d = CKEDITOR.tools.getNextId() + "_smiley_emtions_label smiley_emtions_group", d = ['\x3cdiv\x3e\x3cspan id\x3d"' + d + '" class\x3d"cke_voice_label"\x3e' + a.options + "\x3c/span\x3e", '\x3ctable role\x3d"listbox" aria-labelledby\x3d"' +
  53. d + '" style\x3d"width:100%;height:100%;border-collapse:separate;" cellspacing\x3d"2" cellpadding\x3d"2"', CKEDITOR.env.ie && CKEDITOR.env.quirks ? ' style\x3d"position:absolute;"' : "", "\x3e\x3ctbody\x3e"], n = h.length, a = 0; a < n; a++) {
  54. 0 === a % g && d.push('\x3ctr role\x3d"presentation"\x3e');
  55. var p = "cke_smile_label_" + a + "_" + CKEDITOR.tools.getNextNumber();
  56. d.push('\x3ctd class\x3d"cke_dark_background cke_centered" style\x3d"vertical-align: middle;" role\x3d"presentation"\x3e\x3ca href\x3d"javascript:void(0)" role\x3d"option"',
  57. ' aria-posinset\x3d"' + (a + 1) + '"', ' aria-setsize\x3d"' + n + '"', ' aria-labelledby\x3d"' + p + '"', ' class\x3d"cke_smile cke_hand" tabindex\x3d"-1" onkeydown\x3d"CKEDITOR.tools.callFunction( ', q, ', event, this );"\x3e', '\x3cimg class\x3d"cke_hand" style\x3d"width:35px !important;height:35px !important" title\x3d"', e.smiley_descriptions[a], '" cke_src\x3d"', CKEDITOR.tools.htmlEncode(e.smiley_path + h[a]), '" alt\x3d"', e.smiley_descriptions[a], '"', ' src\x3d"', CKEDITOR.tools.htmlEncode(e.smiley_path + h[a]), '"', CKEDITOR.env.ie ? " onload\x3d\"this.setAttribute('width', 2); this.removeAttribute('width');\" " :
  58. "", '\x3e\x3cspan id\x3d"' + p + '" class\x3d"cke_voice_label"\x3e' + e.smiley_descriptions[a] + "\x3c/span\x3e\x3c/a\x3e", "\x3c/td\x3e");
  59. a % g == g - 1 && d.push("\x3c/tr\x3e")
  60. }
  61. if (a < g - 1) {
  62. for (; a < g - 1; a++) d.push("\x3ctd\x3e\x3c/td\x3e");
  63. d.push("\x3c/tr\x3e")
  64. }
  65. d.push("\x3c/tbody\x3e\x3c/table\x3e\x3c/div\x3e");
  66. e = {
  67. type: "html", id: "smileySelector", html: d.join(""), onLoad: function (a) {
  68. k = a.sender
  69. }, focus: function () {
  70. var a = this;
  71. setTimeout(function () {
  72. a.getElement().getElementsByTag("a").getItem(0).focus()
  73. }, 0)
  74. }, onClick: m, style: "width: 100%; border-collapse: separate;"
  75. };
  76. return {
  77. title: f.lang.smiley.title,
  78. minWidth: 550,
  79. minHeight: 120,
  80. contents: [{id: "tab1", label: "", title: "", expand: !0, padding: 0, elements: [e]}],
  81. buttons: [CKEDITOR.dialog.cancelButton]
  82. }
  83. });