2017-07-28 04:36:46 +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({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")},fetch:function(){var b,c,d,e,f,g,h,i=this;return i.dfd&&"pending"===i.dfd.state()&&i.dfd.abort(),i.model.get("url")?(b=function(b){i.renderoEmbed({data:{body:b}}),a("#embed-url-field").removeClass("invalid"),i.setErrorNotice(""),i.setAddToWidgetButtonDisabled(!1)},e=document.createElement("a"),e.href=i.model.get("url"),(c=e.pathname.toLowerCase().match(/\.(\w+)$/))?(d=c[1],void(wp.media.view.settings.embedMimes[d]?0!==wp.media.view.settings.embedMimes[d].indexOf(i.controller.options.mimeType)?i.renderFail():b("<!--success-->"):i.renderFail())):"video"!==this.controller.options.mimeType||/vimeo|youtu\.?be/.test(e.host)?(f=i.model.get("url"),g=/https?:\/\/www\.youtube\.com\/embed\/([^\/]+)/,h=g.exec(f),h&&(f="https://www.youtube.com/watch?v="+h[1],i.model.attributes.url=f),i.dfd=a.ajax({url:wp.media.view.settings.oEmbedProxyUrl,data:{url:f,maxwidth:i.model.get("width"),maxheight:i.model.get("height"),_wpnonce:wp.media.view.settings.nonce.wpRestApi,discover:!1},type:"GET",dataType:"json",context:i}),i.dfd.done(function(a){return i.controller.options.mimeType!==a.type?void i.renderFail():void b(a.html)}),void i.dfd.fail(_.bind(i.renderFail,i))):void i.renderFail()):void i.setErrorNotice("")},renderFail:function(){var b=this;a("#embed-url-field").addClass("invalid"),b.setErrorNotice(b.controller.options.invalidEmbedTypeError||"ERROR"),b.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})])},mainInsertToolbar:function(a){var b=this;a.set("insert",{style:"primary",priority:80,text:b.options.text,requires:{selection:!0},click:function(){var a=b.state(),c=a.get("selection");b.close(),a.trigger("insert",c).reset()}})},mainEmbedToolbar:function(a){a.view=new wp.media.view.Toolbar.Embed({controller:this,text:this.options.text,event:"insert"})},embedContent:funct
|