/*
 Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
 For licensing, see LICENSE.md or http://ckeditor.com/license
*/
(function(){function i(c,e){function d(){c.widgets.finalizeCreation(h)}var b=c.editable().findOne('a[data-cke-autoembed="'+e+'"]');if(b&&b.data("cke-saved-href")){var b=b.data("cke-saved-href"),a=CKEDITOR.plugins.autoEmbed.getWidgetDefinition(c,b);if(a){var f="function"==typeof a.defaults?a.defaults():a.defaults,f=CKEDITOR.dom.element.createFromHtml(a.template.output(f)),g=c.widgets.wrapElement(f,a.name),h=new CKEDITOR.dom.documentFragment(g.getDocument());h.append(g);(a=c.widgets.initOn(f,a))?a.loadContent(b,
{callback:function(){var a=c.editable().findOne('a[data-cke-autoembed="'+e+'"]'),b=c.createRange();a&&(b.setStartAt(a,CKEDITOR.POSITION_BEFORE_START),b.setEndAt(a,CKEDITOR.POSITION_AFTER_END),c.editable().insertElementIntoRange(g,b));d()},error:d}):d()}else window.console&&window.console.log("[CKEDITOR.plugins.autoEmbed] Incorrect config.autoEmbed_widget value. No widget definition found.")}}CKEDITOR.plugins.add("autoembed",{requires:"autolink,undo",init:function(c){var e=1;c.on("paste",function(d){if(d.data.dataTransfer.getTransferType(c)!=
CKEDITOR.DATA_TRANSFER_INTERNAL){var b=d.data.dataValue,a;b.match(/^<a [^<]+<\/a>$/i)&&(a=CKEDITOR.htmlParser.fragment.fromHtml(b),1==a.children.length&&(a=a.children[0],a.type==CKEDITOR.NODE_ELEMENT&&a.getHtml()==a.attributes.href&&(d.data.dataValue='<a data-cke-autoembed="'+ ++e+'"'+b.substr(2))))}},null,null,20);c.on("afterPaste",function(){i(c,e)})}});CKEDITOR.plugins.autoEmbed={getWidgetDefinition:function(c,e){var d=c.config.autoEmbed_widget||"embed,embedSemantic",b,a=c.widgets.registered;if("string"==
typeof d)for(d=d.split(",");b=d.shift();){if(a[b])return a[b]}else if("function"==typeof d)return a[d(e)];return null}}})();