/* Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.md or http://ckeditor.com/license*/(function(a){if("undefined"==typeofa)throwError("jQuery should be loaded before CKEditor jQuery adapter.");if("undefined"==typeofCKEDITOR)throwError("CKEditor should be loaded before CKEditor jQuery adapter.");CKEDITOR.config.jqueryOverrideVal="undefined"==typeofCKEDITOR.config.jqueryOverrideVal?!0:CKEDITOR.config.jqueryOverrideVal;a.extend(a.fn,{ckeditorGet:function(){vara=this.eq(0).data("ckeditorInstance");if(!a)throw"CKEditor is not initialized yet, use ckeditor() with a callback.";returna},ckeditor:function(g,d){if(!CKEDITOR.env.isCompatible)throwError("The environment is incompatible.");if(!a.isFunction(g)){varm=d;d=g;g=m}vark=[];d=d||{};this.each(function(){varb=a(this),c=b.data("ckeditorInstance"),f=b.data("_ckeditorInstanceLock"),h=this,l=newa.Deferred;k.push(l.promise());if(c&&!f)g&&g.apply(c,[this]),l.resolve();elseif(f)c.once("instanceReady",function(){setTimeout(function(){c.element?(c.element.$==h&&g&&g.apply(c,[h]),l.resolve()):setTimeout(arguments.callee,100)},0)},null,null,9999);else{if(d.autoUpdateElement||"undefined"==typeofd.autoUpdateElement&&CKEDITOR.config.autoUpdateElement)d.autoUpdateElementJquery=!0;d.autoUpdateElement=!1;b.data("_ckeditorInstanceLock",!0);c=a(this).is("textarea")?CKEDITOR.replace(h,d):CKEDITOR.inline(h,d);b.data("ckeditorInstance",c);c.on("instanceReady",function(d){vare=d.editor;setTimeout(function(){if(e.element){d.removeListener();e.on("dataReady",function(){b.trigger("dataReady.ckeditor",[e])});e.on("setData",function(a){b.trigger("setData.ckeditor",[e,a.data])});e.on("getData",function(a){b.trigger("getData.ckeditor",[e,a.data])},999);e.on("destroy",function(){b.trigger("destroy.ckeditor",[e])});e.on("save",function(){a(h.form).submit();return!1},null,null,20);if(e.config.autoUpdateElementJquery&&b.is("textarea")&&a(h.form).length){varc=function(){b.ckeditor(function(){e.updateElement()})};a(h.form).submit(c);a(h.form).bind("form-pre-serialize",c);b.bind("destroy.ckeditor",function(){a(h.form).unbind("submit",c);a(h.form).unbind("form-pre-serialize",c)})}e.on("destroy",function(){b.removeData("ckeditorInstance")});b.removeData("_ckeditorInstanceLock");b.trigger("instanceReady.ckeditor",[e]);g&&g.apply(e,[h]);l.resolve()}elsesetTimeout(arguments.callee,100)},0)},null,null,9999)}});varf=newa.Deferred;this.promise=f.promise();a.when.apply(this,k).then(function(){f.resolve()});this.editor=this.eq(0).data("ckeditorInstance");returnthis}});CKEDITOR.config.jqueryOverrideVal&&(a.fn.val=CKEDITOR.tools.override(a.fn.val,function(g){returnfunction(d){if(arguments.length){varm=this,k=[],f=this.each(function(){varb=a(this),c=b.data("ckeditorInstance");if(b.is("textarea")&&c){varf=newa.Deferred;c.setData(d,function(){f.resolve()});k.push(f.promise());return!0}returng.call(b,d)});if(k.length){varb=newa.Deferred;a.when.apply(this,k).done(function(){b.resolveWith(m)});returnb.promise()}returnf}varf=a(this).eq(0),c=f.data("ckeditorInstance");returnf.is("textarea")&&c?c.getData():g.call(f)}}))})(window.jQuery);