div.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. (function() {
  2. function t(a, m, r) {
  3. (m.is && m.getCustomData("block_processed")) ||
  4. (m.is && CKEDITOR.dom.element.setMarker(r, m, "block_processed", !0),
  5. a.push(m));
  6. }
  7. function q(a, m) {
  8. function r() {
  9. this.foreach(function(a) {
  10. /^(?!vbox|hbox)/.test(a.type) &&
  11. (a.setup ||
  12. (a.setup = function(c) {
  13. a.setValue(c.getAttribute(a.id) || "", 1);
  14. }),
  15. a.commit ||
  16. (a.commit = function(c) {
  17. var g = this.getValue();
  18. if ("dir" != a.id || c.getComputedStyle("direction") != g)
  19. g ? c.setAttribute(a.id, g) : c.removeAttribute(a.id);
  20. }));
  21. });
  22. }
  23. var q = (function() {
  24. var f = CKEDITOR.tools.extend({}, CKEDITOR.dtd.$blockLimit);
  25. a.config.div_wrapTable && (delete f.td, delete f.th);
  26. return f;
  27. })(),
  28. u = CKEDITOR.dtd.div,
  29. n = {},
  30. p = [];
  31. return {
  32. title: a.lang.div.title,
  33. minWidth: 400,
  34. minHeight: 165,
  35. contents: [
  36. {
  37. id: "info",
  38. label: a.lang.common.generalTab,
  39. title: a.lang.common.generalTab,
  40. elements: [
  41. {
  42. type: "hbox",
  43. widths: ["50%", "50%"],
  44. children: [
  45. {
  46. id: "elementStyle",
  47. type: "select",
  48. style: "width: 100%;",
  49. label: a.lang.div.styleSelectLabel,
  50. default: "",
  51. items: [[a.lang.common.notSet, ""]],
  52. onChange: function() {
  53. var f = [
  54. "info:elementStyle",
  55. "info:class",
  56. "advanced:dir",
  57. "advanced:style"
  58. ],
  59. c = this.getDialog(),
  60. g =
  61. (c._element && c._element.clone()) ||
  62. new CKEDITOR.dom.element("div", a.document);
  63. this.commit(g, !0);
  64. for (
  65. var f = [].concat(f), b = f.length, k, e = 0;
  66. e < b;
  67. e++
  68. )
  69. (k = c.getContentElement.apply(c, f[e].split(":"))) &&
  70. k.setup &&
  71. k.setup(g, !0);
  72. },
  73. setup: function(f) {
  74. for (var c in n)
  75. n[c].checkElementRemovable(f, !0, a) &&
  76. this.setValue(c, 1);
  77. },
  78. commit: function(f) {
  79. var c;
  80. (c = this.getValue())
  81. ? n[c].applyToObject(f, a)
  82. : f.removeAttribute("style");
  83. }
  84. },
  85. {
  86. id: "class",
  87. type: "text",
  88. requiredContent: "div(cke-xyz)",
  89. label: a.lang.common.cssClass,
  90. default: ""
  91. }
  92. ]
  93. }
  94. ]
  95. },
  96. {
  97. id: "advanced",
  98. label: a.lang.common.advancedTab,
  99. title: a.lang.common.advancedTab,
  100. elements: [
  101. {
  102. type: "vbox",
  103. padding: 1,
  104. children: [
  105. {
  106. type: "hbox",
  107. widths: ["50%", "50%"],
  108. children: [
  109. {
  110. type: "text",
  111. id: "id",
  112. requiredContent: "div[id]",
  113. label: a.lang.common.id,
  114. default: ""
  115. },
  116. {
  117. type: "text",
  118. id: "lang",
  119. requiredContent: "div[lang]",
  120. label: a.lang.common.langCode,
  121. default: ""
  122. }
  123. ]
  124. },
  125. {
  126. type: "hbox",
  127. children: [
  128. {
  129. type: "text",
  130. id: "style",
  131. requiredContent: "div{cke-xyz}",
  132. style: "width: 100%;",
  133. label: a.lang.common.cssStyle,
  134. default: "",
  135. commit: function(a) {
  136. a.setAttribute("style", this.getValue());
  137. }
  138. }
  139. ]
  140. },
  141. {
  142. type: "hbox",
  143. children: [
  144. {
  145. type: "text",
  146. id: "title",
  147. requiredContent: "div[title]",
  148. style: "width: 100%;",
  149. label: a.lang.common.advisoryTitle,
  150. default: ""
  151. }
  152. ]
  153. },
  154. {
  155. type: "select",
  156. id: "dir",
  157. requiredContent: "div[dir]",
  158. style: "width: 100%;",
  159. label: a.lang.common.langDir,
  160. default: "",
  161. items: [
  162. [a.lang.common.notSet, ""],
  163. [a.lang.common.langDirLtr, "ltr"],
  164. [a.lang.common.langDirRtl, "rtl"]
  165. ]
  166. }
  167. ]
  168. }
  169. ]
  170. }
  171. ],
  172. onLoad: function() {
  173. r.call(this);
  174. var f = this,
  175. c = this.getContentElement("info", "elementStyle");
  176. a.getStylesSet(function(g) {
  177. var b, k;
  178. if (g)
  179. for (var e = 0; e < g.length; e++)
  180. (k = g[e]),
  181. k.element &&
  182. "div" == k.element &&
  183. ((b = k.name),
  184. (n[b] = k = new CKEDITOR.style(k)),
  185. a.filter.check(k) && (c.items.push([b, b]), c.add(b, b)));
  186. c[1 < c.items.length ? "enable" : "disable"]();
  187. setTimeout(function() {
  188. f._element && c.setup(f._element);
  189. }, 0);
  190. });
  191. },
  192. onShow: function() {
  193. "editdiv" == m &&
  194. this.setupContent(
  195. (this._element = CKEDITOR.plugins.div.getSurroundDiv(a))
  196. );
  197. },
  198. onOk: function() {
  199. if ("editdiv" == m) p = [this._element];
  200. else {
  201. var f = [],
  202. c = {},
  203. g = [],
  204. b,
  205. k = a.getSelection(),
  206. e = k.getRanges(),
  207. n = k.createBookmarks(),
  208. h,
  209. l;
  210. for (h = 0; h < e.length; h++)
  211. for (l = e[h].createIterator(); (b = l.getNextParagraph()); )
  212. if (b.getName() in q && !b.isReadOnly()) {
  213. var d = b.getChildren();
  214. for (b = 0; b < d.count(); b++) t(g, d.getItem(b), c);
  215. } else {
  216. for (; !u[b.getName()] && !b.equals(e[h].root); )
  217. b = b.getParent();
  218. t(g, b, c);
  219. }
  220. CKEDITOR.dom.element.clearAllMarkers(c);
  221. e = [];
  222. h = null;
  223. for (l = 0; l < g.length; l++)
  224. (b = g[l]),
  225. (d = a.elementPath(b).blockLimit),
  226. d.isReadOnly() && (d = d.getParent()),
  227. a.config.div_wrapTable &&
  228. d.is(["td", "th"]) &&
  229. (d = a.elementPath(d.getParent()).blockLimit),
  230. d.equals(h) || ((h = d), e.push([])),
  231. b.getParent() && e[e.length - 1].push(b);
  232. for (h = 0; h < e.length; h++)
  233. if (e[h].length) {
  234. d = e[h][0];
  235. g = d.getParent();
  236. for (b = 1; b < e[h].length; b++)
  237. g = g.getCommonAncestor(e[h][b]);
  238. g || (g = a.editable());
  239. l = new CKEDITOR.dom.element("div", a.document);
  240. for (b = 0; b < e[h].length; b++) {
  241. for (d = e[h][b]; d.getParent() && !d.getParent().equals(g); )
  242. d = d.getParent();
  243. e[h][b] = d;
  244. }
  245. for (b = 0; b < e[h].length; b++)
  246. (d = e[h][b]),
  247. (d.getCustomData && d.getCustomData("block_processed")) ||
  248. (d.is &&
  249. CKEDITOR.dom.element.setMarker(
  250. c,
  251. d,
  252. "block_processed",
  253. !0
  254. ),
  255. b || l.insertBefore(d),
  256. l.append(d));
  257. CKEDITOR.dom.element.clearAllMarkers(c);
  258. f.push(l);
  259. }
  260. k.selectBookmarks(n);
  261. p = f;
  262. }
  263. f = p.length;
  264. for (c = 0; c < f; c++)
  265. this.commitContent(p[c]),
  266. !p[c].getAttribute("style") && p[c].removeAttribute("style");
  267. this.hide();
  268. },
  269. onHide: function() {
  270. "editdiv" == m && this._element.removeCustomData("elementStyle");
  271. delete this._element;
  272. }
  273. };
  274. }
  275. CKEDITOR.dialog.add("creatediv", function(a) {
  276. return q(a, "creatediv");
  277. });
  278. CKEDITOR.dialog.add("editdiv", function(a) {
  279. return q(a, "editdiv");
  280. });
  281. })();