/*! This file is auto-generated */ wp.mediaWidgets=function(h){"use strict";var g={controlConstructors:{},modelConstructors:{}};return g.PersistentDisplaySettingsLibrary=wp.media.controller.Library.extend({initialize:function(e){_.bindAll(this,"handleDisplaySettingChange"),wp.media.controller.Library.prototype.initialize.call(this,e)},handleDisplaySettingChange:function(e){this.get("selectedDisplaySettings").set(e.attributes)},display:function(e){var t,i=this.get("selectedDisplaySettings");return(t=wp.media.controller.Library.prototype.display.call(this,e)).off("change",this.handleDisplaySettingChange),t.set(i.attributes),"custom"===i.get("link_type")&&(t.linkUrl=i.get("link_url")),t.on("change",this.handleDisplaySettingChange),t}}),g.MediaEmbedView=wp.media.view.Embed.extend({initialize:function(e){var t,i=this;wp.media.view.Embed.prototype.initialize.call(i,e),"image"!==i.controller.options.mimeType&&(t=i.controller.states.get("embed")).off("scan",t.scanImage,t)},refresh:function(){var e;e="image"===this.controller.options.mimeType?wp.media.view.EmbedImage:wp.media.view.EmbedLink.extend({setAddToWidgetButtonDisabled:function(e){this.views.parent.views.parent.views.get(".media-frame-toolbar")[0].$el.find(".media-button-select").prop("disabled",e)},setErrorNotice:function(e){var t;t=this.views.parent.$el.find("> .notice:first-child"),e?(t.length||((t=h('
')).hide(),this.views.parent.$el.prepend(t)),t.empty(),t.append(h("

",{html:e})),t.slideDown("fast")):t.length&&t.slideUp("fast")},updateoEmbed:function(){var e,t=this;if(!(e=t.model.get("url")))return t.setErrorNotice(""),void t.setAddToWidgetButtonDisabled(!0);e.match(/^(http|https):\/\/.+\//)||(t.controller.$el.find("#embed-url-field").addClass("invalid"),t.setAddToWidgetButtonDisabled(!0)),wp.media.view.EmbedLink.prototype.updateoEmbed.call(t)},fetch:function(){var t,e,i,n,d,o,a=this;if(d=a.model.get("url"),a.dfd&&"pending"===a.dfd.state()&&a.dfd.abort(),t=function(e){a.renderoEmbed({data:{body:e}}),a.controller.$el.find("#embed-url-field").removeClass("invalid"),a.setErrorNotice(""),a.setAddToWidgetButtonDisabled(!1)},(n=document.createElement("a")).href=d,e=n.pathname.toLowerCase().match(/\.(\w+)$/))return i=e[1],void(wp.media.view.settings.embedMimes[i]?0!==wp.media.view.settings.embedMimes[i].indexOf(a.controller.options.mimeType)?a.renderFail():t("\x3c!--success--\x3e"):a.renderFail());(o=/https?:\/\/www\.youtube\.com\/embed\/([^/]+)/.exec(d))&&(d="https://www.youtube.com/watch?v="+o[1],a.model.attributes.url=d),a.dfd=wp.apiRequest({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:d,maxwidth:a.model.get("width"),maxheight:a.model.get("height"),discover:!1},type:"GET",dataType:"json",context:a}),a.dfd.done(function(e){a.controller.options.mimeType===e.type?t(e.html):a.renderFail()}),a.dfd.fail(_.bind(a.renderFail,a))},renderFail:function(){var e=this;e.controller.$el.find("#embed-url-field").addClass("invalid"),e.setErrorNotice(e.controller.options.invalidEmbedTypeError||"ERROR"),e.setAddToWidgetButtonDisabled(!0)}}),this.settings(new e({controller:this.controller,model:this.model.props,priority:40}))}}),g.MediaFrameSelect=wp.media.view.MediaFrame.Post.extend({createStates:function(){var t=this.options.mimeType,i=[];_.each(wp.media.view.settings.embedMimes,function(e){0===e.indexOf(t)&&i.push(e)}),0 .widget-inside > .form, > .widget-inside > form")).find("> .id_base").val(),m=d.find("> .widget-id").val(),g.widgetControls[m]||(a=g.controlConstructors[o])&&(r=g.modelConstructors[o]||g.MediaWidgetModel,i=h("

"),(n=t.find(".widget-content:first")).before(i),s={},n.find(".media-widget-instance-property").each(function(){var e=h(this);s[e.data("property")]=e.val()}),s.widget_id=m,c=new r(s),l=new a({el:i,syncContainer:n,model:c}),(p=function(){t.hasClass("open")?l.render():setTimeout(p,50)})(),g.modelCollection.add([c]),g.widgetControls[c.get("widget_id")]=l)},g.setupAccessibleMode=function(){var e,t,i,n,d,o,a,r,s;0!==(e=h(".editwidget > form")).length&&(i=e.find("> .widget-control-actions > .id_base").val(),(d=g.controlConstructors[i])&&(t=e.find("> .widget-control-actions > .widget-id").val(),o=g.modelConstructors[i]||g.MediaWidgetModel,r=h("
"),(s=e.find("> .widget-inside")).before(r),a={},s.find(".media-widget-instance-property").each(function(){var e=h(this);a[e.data("property")]=e.val()}),a.widget_id=t,n=new d({el:r,syncContainer:s,model:new o(a)}),g.modelCollection.add([n.model]),(g.widgetControls[n.model.get("widget_id")]=n).render()))},g.handleWidgetUpdated=function(e,t){var i,n,d,o={};n=(i=t.find("> .widget-inside > .form, > .widget-inside > form")).find("> .widget-id").val(),(d=g.widgetControls[n])&&(i.find("> .widget-content").find(".media-widget-instance-property").each(function(){var e=h(this).data("property");o[e]=h(this).val()}),d.stopListening(d.model,"change",d.syncModelToInputs),d.model.set(o),d.listenTo(d.model,"change",d.syncModelToInputs))},g.init=function(){var e=h(document);e.on("widget-added",g.handleWidgetAdded),e.on("widget-synced widget-updated",g.handleWidgetUpdated),h(function(){"widgets"===window.pagenow&&(h(".widgets-holder-wrap:not(#available-widgets)").find("div.widget").one("click.toggle-widget-expanded",function(){var e=h(this);g.handleWidgetAdded(new jQuery.Event("widget-added"),e)}),h(window).on("load",function(){g.setupAccessibleMode()}))})},g}(jQuery);