button.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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("button", function(b) {
  6. function d(a) {
  7. var b = this.getValue();
  8. b
  9. ? ((a.attributes[this.id] = b),
  10. "name" == this.id && (a.attributes["data-cke-saved-name"] = b))
  11. : (delete a.attributes[this.id],
  12. "name" == this.id && delete a.attributes["data-cke-saved-name"]);
  13. }
  14. return {
  15. title: b.lang.forms.button.title,
  16. minWidth: 350,
  17. minHeight: 150,
  18. onShow: function() {
  19. delete this.button;
  20. var a = this.getParentEditor()
  21. .getSelection()
  22. .getSelectedElement();
  23. a &&
  24. a.is("input") &&
  25. a.getAttribute("type") in { button: 1, reset: 1, submit: 1 } &&
  26. ((this.button = a), this.setupContent(a));
  27. },
  28. onOk: function() {
  29. var a = this.getParentEditor(),
  30. b = this.button,
  31. d = !b,
  32. c = b
  33. ? CKEDITOR.htmlParser.fragment.fromHtml(b.getOuterHtml()).children[0]
  34. : new CKEDITOR.htmlParser.element("input");
  35. this.commitContent(c);
  36. var e = new CKEDITOR.htmlParser.basicWriter();
  37. c.writeHtml(e);
  38. c = CKEDITOR.dom.element.createFromHtml(e.getHtml(), a.document);
  39. d
  40. ? a.insertElement(c)
  41. : (c.replace(b), a.getSelection().selectElement(c));
  42. },
  43. contents: [
  44. {
  45. id: "info",
  46. label: b.lang.forms.button.title,
  47. title: b.lang.forms.button.title,
  48. elements: [
  49. {
  50. id: "name",
  51. type: "text",
  52. bidi: !0,
  53. label: b.lang.common.name,
  54. default: "",
  55. setup: function(a) {
  56. this.setValue(
  57. a.data("cke-saved-name") || a.getAttribute("name") || ""
  58. );
  59. },
  60. commit: d
  61. },
  62. {
  63. id: "value",
  64. type: "text",
  65. label: b.lang.forms.button.text,
  66. accessKey: "V",
  67. default: "",
  68. setup: function(a) {
  69. this.setValue(a.getAttribute("value") || "");
  70. },
  71. commit: d
  72. },
  73. {
  74. id: "type",
  75. type: "select",
  76. label: b.lang.forms.button.type,
  77. default: "button",
  78. accessKey: "T",
  79. items: [
  80. [b.lang.forms.button.typeBtn, "button"],
  81. [b.lang.forms.button.typeSbm, "submit"],
  82. [b.lang.forms.button.typeRst, "reset"]
  83. ],
  84. setup: function(a) {
  85. this.setValue(a.getAttribute("type") || "");
  86. },
  87. commit: d
  88. }
  89. ]
  90. }
  91. ]
  92. };
  93. });