2018-10-10 06:11:25 +02:00
|
|
|
wp.mediaWidgets=function(a){"use strict";var b={};return b.controlConstructors={},b.modelConstructors={},b.PersistentDisplaySettingsLibrary=wp.media.controller.Library.extend({initialize:function(a){_.bindAll(this,"handleDisplaySettingChange"),wp.media.controller.Library.prototype.initialize.call(this,a)},handleDisplaySettingChange:function(a){this.get("selectedDisplaySettings").set(a.attributes)},display:function(a){var b,c=this.get("selectedDisplaySettings");return b=wp.media.controller.Library.prototype.display.call(this,a),b.off("change",this.handleDisplaySettingChange),b.set(c.attributes),"custom"===c.get("link_type")&&(b.linkUrl=c.get("link_url")),b.on("change",this.handleDisplaySettingChange),b}}),b.MediaEmbedView=wp.media.view.Embed.extend({initialize:function(a){var b,c=this;wp.media.view.Embed.prototype.initialize.call(c,a),"image"!==c.controller.options.mimeType&&(b=c.controller.states.get("embed"),b.off("scan",b.scanImage,b))},refresh:function(){var b;b="image"===this.controller.options.mimeType?wp.media.view.EmbedImage:wp.media.view.EmbedLink.extend({setAddToWidgetButtonDisabled:function(a){this.views.parent.views.parent.views.get(".media-frame-toolbar")[0].$el.find(".media-button-select").prop("disabled",a)},setErrorNotice:function(b){var c,d=this;c=d.views.parent.$el.find("> .notice:first-child"),b?(c.length||(c=a('<div class="media-widget-embed-notice notice notice-error notice-alt"></div>'),c.hide(),d.views.parent.$el.prepend(c)),c.empty(),c.append(a("<p>",{html:b})),c.slideDown("fast")):c.length&&c.slideUp("fast")},updateoEmbed:function(){var a,b=this;return(a=b.model.get("url"))?(a.match(/^(http|https):\/\/.+\//)||(b.controller.$el.find("#embed-url-field").addClass("invalid"),b.setAddToWidgetButtonDisabled(!0)),void wp.media.view.EmbedLink.prototype.updateoEmbed.call(b)):(b.setErrorNotice(""),void b.setAddToWidgetButtonDisabled(!0))},fetch:function(){var a,b,c,d,e,f,g,h=this;return e=h.model.get("url"),h.dfd&&"pending"===h.dfd.state()&&h.dfd.abort(),a=function(a){h.renderoEmbed({data:{body:a}}),h.controller.$el.find("#embed-url-field").removeClass("invalid"),h.setErrorNotice(""),h.setAddToWidgetButtonDisabled(!1)},d=document.createElement("a"),d.href=e,(b=d.pathname.toLowerCase().match(/\.(\w+)$/))?(c=b[1],void(wp.media.view.settings.embedMimes[c]?0!==wp.media.view.settings.embedMimes[c].indexOf(h.controller.options.mimeType)?h.renderFail():a("<!--success-->"):h.renderFail())):(f=/https?:\/\/www\.youtube\.com\/embed\/([^\/]+)/,g=f.exec(e),g&&(e="https://www.youtube.com/watch?v="+g[1],h.model.attributes.url=e),h.dfd=wp.apiRequest({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:e,maxwidth:h.model.get("width"),maxheight:h.model.get("height"),discover:!1},type:"GET",dataType:"json",context:h}),h.dfd.done(function(b){return h.controller.options.mimeType!==b.type?void h.renderFail():void a(b.html)}),void h.dfd.fail(_.bind(h.renderFail,h)))},renderFail:function(){var a=this;a.controller.$el.find("#embed-url-field").addClass("invalid"),a.setErrorNotice(a.controller.options.invalidEmbedTypeError||"ERROR"),a.setAddToWidgetButtonDisabled(!0)}}),this.settings(new b({controller:this.controller,model:this.model.props,priority:40}))}}),b.MediaFrameSelect=wp.media.view.MediaFrame.Post.extend({createStates:function(){var a=this.options.mimeType,c=[];_.each(wp.media.view.settings.embedMimes,function(b){0===b.indexOf(a)&&c.push(b)}),c.length>0&&(a=c),this.states.add([new b.PersistentDisplaySettingsLibrary({id:"insert",title:this.options.title,selection:this.options.selection,priority:20,toolbar:"main-insert",filterable:"dates",library:wp.media.query({type:a}),multiple:!1,editable:!0,selectedDisplaySettings:this.options.selectedDisplaySettings,displaySettings:!!_.isUndefined(this.options.showDisplaySettings)||this.options.showDisplaySettings,displayUserSettings:!1}),new wp.media.controller.EditImage({model:this.options.editImage}),new wp.media.controller.Embed({metadata:this.options.metadata,type:"image"===this.options.mimeType?"image":"link",invalidEmbedTypeError:this.options.invalidEmbedTypeError})])},mainInsertTo
|