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