sample.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. // Tool scripts for the sample pages.
  6. // This file can be ignored and is not required to make use of CKEditor.
  7. (function() {
  8. CKEDITOR.on("instanceReady", function(ev) {
  9. // Check for sample compliance.
  10. var editor = ev.editor,
  11. meta = CKEDITOR.document.$.getElementsByName(
  12. "ckeditor-sample-required-plugins"
  13. ),
  14. requires = meta.length
  15. ? CKEDITOR.dom.element
  16. .get(meta[0])
  17. .getAttribute("content")
  18. .split(",")
  19. : [],
  20. missing = [],
  21. i;
  22. if (requires.length) {
  23. for (i = 0; i < requires.length; i++) {
  24. if (!editor.plugins[requires[i]])
  25. missing.push("<code>" + requires[i] + "</code>");
  26. }
  27. if (missing.length) {
  28. var warn = CKEDITOR.dom.element.createFromHtml(
  29. '<div class="warning">' +
  30. "<span>To fully experience this demo, the " +
  31. missing.join(", ") +
  32. " plugin" +
  33. (missing.length > 1 ? "s are" : " is") +
  34. " required.</span>" +
  35. "</div>"
  36. );
  37. warn.insertBefore(editor.container);
  38. }
  39. }
  40. // Set icons.
  41. var doc = new CKEDITOR.dom.document(document),
  42. icons = doc.find(".button_icon");
  43. for (i = 0; i < icons.count(); i++) {
  44. var icon = icons.getItem(i),
  45. name = icon.getAttribute("data-icon"),
  46. style = CKEDITOR.skin.getIconStyle(name, CKEDITOR.lang.dir == "rtl");
  47. icon.addClass("cke_button_icon");
  48. icon.addClass("cke_button__" + name + "_icon");
  49. icon.setAttribute("style", style);
  50. icon.setStyle("float", "none");
  51. }
  52. });
  53. })();