Built motion from commit 67e5df37.|2.0.62
[motion2.git] / public / assets / plugins / ckeditor / adapters / jquery.js
1 /*
2  Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3  For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5 (function(a) {
6     if ("undefined" == typeof a) throw Error("jQuery should be loaded before CKEditor jQuery adapter.");
7     if ("undefined" == typeof CKEDITOR) throw Error("CKEditor should be loaded before CKEditor jQuery adapter.");
8     CKEDITOR.config.jqueryOverrideVal = "undefined" == typeof CKEDITOR.config.jqueryOverrideVal ? !0 : CKEDITOR.config.jqueryOverrideVal;
9     a.extend(a.fn, {
10         ckeditorGet: function() {
11             var a = this.eq(0).data("ckeditorInstance");
12             if (!a) throw "CKEditor is not initialized yet, use ckeditor() with a callback.";
13             return a
14         },
15         ckeditor: function(g, d) {
16             if (!CKEDITOR.env.isCompatible) throw Error("The environment is incompatible.");
17             if (!a.isFunction(g)) {
18                 var m = d;
19                 d = g;
20                 g = m
21             }
22             var k = [];
23             d = d || {};
24             this.each(function() {
25                 var b = a(this),
26                     c = b.data("ckeditorInstance"),
27                     f = b.data("_ckeditorInstanceLock"),
28                     h = this,
29                     l = new a.Deferred;
30                 k.push(l.promise());
31                 if (c && !f) g && g.apply(c, [this]), l.resolve();
32                 else if (f) c.once("instanceReady", function() {
33                         setTimeout(function() {
34                             c.element ? (c.element.$ == h && g && g.apply(c, [h]), l.resolve()) : setTimeout(arguments.callee, 100)
35                         }, 0)
36                     },
37                     null, null, 9999);
38                 else {
39                     if (d.autoUpdateElement || "undefined" == typeof d.autoUpdateElement && CKEDITOR.config.autoUpdateElement) d.autoUpdateElementJquery = !0;
40                     d.autoUpdateElement = !1;
41                     b.data("_ckeditorInstanceLock", !0);
42                     c = a(this).is("textarea") ? CKEDITOR.replace(h, d) : CKEDITOR.inline(h, d);
43                     b.data("ckeditorInstance", c);
44                     c.on("instanceReady", function(d) {
45                         var e = d.editor;
46                         setTimeout(function() {
47                             if (e.element) {
48                                 d.removeListener();
49                                 e.on("dataReady", function() {
50                                     b.trigger("dataReady.ckeditor", [e])
51                                 });
52                                 e.on("setData", function(a) {
53                                     b.trigger("setData.ckeditor", [e, a.data])
54                                 });
55                                 e.on("getData", function(a) {
56                                     b.trigger("getData.ckeditor", [e, a.data])
57                                 }, 999);
58                                 e.on("destroy", function() {
59                                     b.trigger("destroy.ckeditor", [e])
60                                 });
61                                 e.on("save", function() {
62                                     a(h.form).submit();
63                                     return !1
64                                 }, null, null, 20);
65                                 if (e.config.autoUpdateElementJquery && b.is("textarea") && a(h.form).length) {
66                                     var c = function() {
67                                         b.ckeditor(function() {
68                                             e.updateElement()
69                                         })
70                                     };
71                                     a(h.form).submit(c);
72                                     a(h.form).bind("form-pre-serialize", c);
73                                     b.bind("destroy.ckeditor", function() {
74                                         a(h.form).unbind("submit", c);
75                                         a(h.form).unbind("form-pre-serialize",
76                                             c)
77                                     })
78                                 }
79                                 e.on("destroy", function() {
80                                     b.removeData("ckeditorInstance")
81                                 });
82                                 b.removeData("_ckeditorInstanceLock");
83                                 b.trigger("instanceReady.ckeditor", [e]);
84                                 g && g.apply(e, [h]);
85                                 l.resolve()
86                             } else setTimeout(arguments.callee, 100)
87                         }, 0)
88                     }, null, null, 9999)
89                 }
90             });
91             var f = new a.Deferred;
92             this.promise = f.promise();
93             a.when.apply(this, k).then(function() {
94                 f.resolve()
95             });
96             this.editor = this.eq(0).data("ckeditorInstance");
97             return this
98         }
99     });
100     CKEDITOR.config.jqueryOverrideVal && (a.fn.val = CKEDITOR.tools.override(a.fn.val, function(g) {
101         return function(d) {
102             if (arguments.length) {
103                 var m =
104                     this,
105                     k = [],
106                     f = this.each(function() {
107                         var b = a(this),
108                             c = b.data("ckeditorInstance");
109                         if (b.is("textarea") && c) {
110                             var f = new a.Deferred;
111                             c.setData(d, function() {
112                                 f.resolve()
113                             });
114                             k.push(f.promise());
115                             return !0
116                         }
117                         return g.call(b, d)
118                     });
119                 if (k.length) {
120                     var b = new a.Deferred;
121                     a.when.apply(this, k).done(function() {
122                         b.resolveWith(m)
123                     });
124                     return b.promise()
125                 }
126                 return f
127             }
128             var f = a(this).eq(0),
129                 c = f.data("ckeditorInstance");
130             return f.is("textarea") && c ? c.getData() : g.call(f)
131         }
132     }))
133 })(window.jQuery);