",{html:e})),t.slideDown("fast")):t.length&&t.slideUp("fast")},updateoEmbed:function(){var e=this,t=e.model.get("url");if(!t)return e.setErrorNotice(""),void e.setAddToWidgetButtonDisabled(!0);t.match(/^(http|https):\/\/.+\//)||(e.controller.$el.find("#embed-url-field").addClass("invalid"),e.setAddToWidgetButtonDisabled(!0)),wp.media.view.EmbedLink.prototype.updateoEmbed.call(e)},fetch:function(){var t,e,i,n=this,d=n.model.get("url");if(n.dfd&&"pending"===n.dfd.state()&&n.dfd.abort(),t=function(e){n.renderoEmbed({data:{body:e}}),n.controller.$el.find("#embed-url-field").removeClass("invalid"),n.setErrorNotice(""),n.setAddToWidgetButtonDisabled(!1)},(e=document.createElement("a")).href=d,e=e.pathname.toLowerCase().match(/\.(\w+)$/))return i=e[1],void(!wp.media.view.settings.embedMimes[i]||0!==wp.media.view.settings.embedMimes[i].indexOf(n.controller.options.mimeType)?n.renderFail():t("\x3c!--success--\x3e"));(i=/https?:\/\/www\.youtube\.com\/embed\/([^/]+)/.exec(d))&&(d="https://www.youtube.com/watch?v="+i[1],n.model.attributes.url=d),n.dfd=wp.apiRequest({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:d,maxwidth:n.model.get("width"),maxheight:n.model.get("height"),discover:!1},type:"GET",dataType:"json",context:n}),n.dfd.done(function(e){n.controller.options.mimeType===e.type?t(e.html):n.renderFail()}),n.dfd.fail(_.bind(n.renderFail,n))},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}))}}),m.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"),r=s.find("> .id_base").val(),l=s.find("> .widget-id").val();m.widgetControls[l]||(i=m.controlConstructors[r])&&(o=m.modelConstructors[r]||m.MediaWidgetModel,s=c(""),(r=t.find(".widget-content:first")).before(s),n={},r.find(".media-widget-instance-property").each(function(){var e=c(this);n[e.data("property")]=e.val()}),n.widget_id=l,o=new o(n),d=new i({el:s,syncContainer:r,model:o}),(a=function(){t.hasClass("open")?d.render():setTimeout(a,50)})(),m.modelCollection.add([o]),m.widgetControls[o.get("widget_id")]=d)},m.setupAccessibleMode=function(){var e,t,i,n,d,o=c(".editwidget > form");0!==o.length&&(d=o.find(".id_base").val(),(t=m.controlConstructors[d])&&(e=o.find("> .widget-control-actions > .widget-id").val(),i=m.modelConstructors[d]||m.MediaWidgetModel,d=c(""),(o=o.find("> .widget-inside")).before(d),n={},o.find(".media-widget-instance-property").each(function(){var e=c(this);n[e.data("property")]=e.val()}),n.widget_id=e,i=new t({el:d,syncContainer:o,model:new i(n)}),m.modelCollection.add([i.model]),(m.widgetControls[i.model.get("widget_id")]=i).render()))},m.handleWidgetUpdated=function(e,t){var i={},n=t.find("> .widget-inside > .form, > .widget-inside > form"),t=n.find("> .widget-id").val(),t=m.widgetControls[t];t&&(n.find("> .widget-content").find(".media-widget-instance-property").each(function(){var e=c(this).data("property");i[e]=c(this).val()}),t.stopListening(t.model,"change",t.syncModelToInputs),t.model.set(i),t.listenTo(t.model,"change",t.syncModelToInputs))},m.init=function(){var e=c(document);e.on("widget-added",m.handleWidgetAdded),e.on("widget-synced widget-updated",m.handleWidgetUpdated),c(function(){"widgets"===window.pagenow&&(c(".widgets-holder-wrap:not(#available-widgets)").find("div.widget").one("click.toggle-widget-expanded",function(){var e=c(this);m.handleWidgetAdded(new jQuery.Event("widget-added"),e)}),"complete"===document.readyState?m.setupAccessibleMode():c(window).on("load",function(){m.setupAccessibleMode()}))})},m}(jQuery);