templates.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. (function() {
  6. CKEDITOR.dialog.add("templates", function(c) {
  7. function r(a, b) {
  8. var m = CKEDITOR.dom.element.createFromHtml(
  9. '\x3ca href\x3d"javascript:void(0)" tabIndex\x3d"-1" role\x3d"option" \x3e\x3cdiv class\x3d"cke_tpl_item"\x3e\x3c/div\x3e\x3c/a\x3e'
  10. ),
  11. d =
  12. '\x3ctable style\x3d"width:350px;" class\x3d"cke_tpl_preview" role\x3d"presentation"\x3e\x3ctr\x3e';
  13. a.image &&
  14. b &&
  15. (d +=
  16. '\x3ctd class\x3d"cke_tpl_preview_img"\x3e\x3cimg src\x3d"' +
  17. CKEDITOR.getUrl(b + a.image) +
  18. '"' +
  19. (CKEDITOR.env.ie6Compat
  20. ? ' onload\x3d"this.width\x3dthis.width"'
  21. : "") +
  22. ' alt\x3d"" title\x3d""\x3e\x3c/td\x3e');
  23. d +=
  24. '\x3ctd style\x3d"white-space:normal;"\x3e\x3cspan class\x3d"cke_tpl_title"\x3e' +
  25. a.title +
  26. "\x3c/span\x3e\x3cbr/\x3e";
  27. a.description && (d += "\x3cspan\x3e" + a.description + "\x3c/span\x3e");
  28. d += "\x3c/td\x3e\x3c/tr\x3e\x3c/table\x3e";
  29. m.getFirst().setHtml(d);
  30. m.on("click", function() {
  31. t(a.html);
  32. });
  33. return m;
  34. }
  35. function t(a) {
  36. var b = CKEDITOR.dialog.getCurrent();
  37. b.getValueOf("selectTpl", "chkInsertOpt")
  38. ? (c.fire("saveSnapshot"),
  39. c.setData(a, function() {
  40. b.hide();
  41. var a = c.createRange();
  42. a.moveToElementEditStart(c.editable());
  43. a.select();
  44. setTimeout(function() {
  45. c.fire("saveSnapshot");
  46. }, 0);
  47. }))
  48. : (c.insertHtml(a), b.hide());
  49. }
  50. function k(a) {
  51. var b = a.data.getTarget(),
  52. c = g.equals(b);
  53. if (c || g.contains(b)) {
  54. var d = a.data.getKeystroke(),
  55. f = g.getElementsByTag("a"),
  56. e;
  57. if (f) {
  58. if (c) e = f.getItem(0);
  59. else
  60. switch (d) {
  61. case 40:
  62. e = b.getNext();
  63. break;
  64. case 38:
  65. e = b.getPrevious();
  66. break;
  67. case 13:
  68. case 32:
  69. b.fire("click");
  70. }
  71. e && (e.focus(), a.data.preventDefault());
  72. }
  73. }
  74. }
  75. var h = CKEDITOR.plugins.get("templates");
  76. CKEDITOR.document.appendStyleSheet(
  77. CKEDITOR.getUrl(h.path + "dialogs/templates.css")
  78. );
  79. var g,
  80. h = "cke_tpl_list_label_" + CKEDITOR.tools.getNextNumber(),
  81. f = c.lang.templates,
  82. n = c.config;
  83. return {
  84. title: c.lang.templates.title,
  85. minWidth: CKEDITOR.env.ie ? 440 : 400,
  86. minHeight: 340,
  87. contents: [
  88. {
  89. id: "selectTpl",
  90. label: f.title,
  91. elements: [
  92. {
  93. type: "vbox",
  94. padding: 5,
  95. children: [
  96. {
  97. id: "selectTplText",
  98. type: "html",
  99. html: "\x3cspan\x3e" + f.selectPromptMsg + "\x3c/span\x3e"
  100. },
  101. {
  102. id: "templatesList",
  103. type: "html",
  104. focus: !0,
  105. html:
  106. '\x3cdiv class\x3d"cke_tpl_list" tabIndex\x3d"-1" role\x3d"listbox" aria-labelledby\x3d"' +
  107. h +
  108. '"\x3e\x3cdiv class\x3d"cke_tpl_loading"\x3e\x3cspan\x3e\x3c/span\x3e\x3c/div\x3e\x3c/div\x3e\x3cspan class\x3d"cke_voice_label" id\x3d"' +
  109. h +
  110. '"\x3e' +
  111. f.options +
  112. "\x3c/span\x3e"
  113. },
  114. {
  115. id: "chkInsertOpt",
  116. type: "checkbox",
  117. label: f.insertOption,
  118. default: n.templates_replaceContent
  119. }
  120. ]
  121. }
  122. ]
  123. }
  124. ],
  125. buttons: [CKEDITOR.dialog.cancelButton],
  126. onShow: function() {
  127. var a = this.getContentElement("selectTpl", "templatesList");
  128. g = a.getElement();
  129. CKEDITOR.loadTemplates(n.templates_files, function() {
  130. var b = (n.templates || "default").split(",");
  131. if (b.length) {
  132. var c = g;
  133. c.setHtml("");
  134. for (var d = 0, h = b.length; d < h; d++)
  135. for (
  136. var e = CKEDITOR.getTemplates(b[d]),
  137. k = e.imagesPath,
  138. e = e.templates,
  139. q = e.length,
  140. l = 0;
  141. l < q;
  142. l++
  143. ) {
  144. var p = r(e[l], k);
  145. p.setAttribute("aria-posinset", l + 1);
  146. p.setAttribute("aria-setsize", q);
  147. c.append(p);
  148. }
  149. a.focus();
  150. } else g.setHtml('\x3cdiv class\x3d"cke_tpl_empty"\x3e\x3cspan\x3e' + f.emptyListMsg + "\x3c/span\x3e\x3c/div\x3e");
  151. });
  152. this._.element.on("keydown", k);
  153. },
  154. onHide: function() {
  155. this._.element.removeListener("keydown", k);
  156. }
  157. };
  158. });
  159. })();