| Current File : /home/digitaw/www/wp-content/plugins/responsive-lightbox/js/admin-media.js |
var e;(e=jQuery)(()=>{if(e.isEmptyObject(wp.media.view))return;const t="undefined"!=typeof rlBlockEditor;t&&(RLWPMediaViewMediaFramePostTrigger=wp.media.view.MediaFrame.Post.prototype.trigger,Object.assign(wp.media.view.MediaFrame.Post.prototype,{trigger(...t){RLWPMediaViewMediaFramePostTrigger.apply(this,t);const[i]=t;"open"===i&&(e(this.modal.clickedOpenerEl).hasClass("rl-remote-library-media-button")?this.setState("rl-remote-library"):e(this.modal.clickedOpenerEl).hasClass("rl-gallery-media-button")&&this.setState("rl-gallery"))}}));const i=wp.media.view.AttachmentFilters.extend({id:"media-attachment-rl-remote-library-filters",className:"attachment-filters attachment-rl-remote-library-filter",createFilters(){const e={all:{text:rlRemoteLibraryMedia.allProviders,priority:1,props:{media_provider:"all"}}};for(let t=0;t<rlRemoteLibraryMedia.providersActive.length;t++){const i=rlRemoteLibraryMedia.providersActive[t];e[i]={text:rlRemoteLibraryMedia.providers[i].name,priority:t+2,props:{media_provider:i}}}this.filters=e}}),r=wp.media.view.AttachmentsBrowser;let a,s;wp.media.view.AttachmentsBrowser=wp.media.view.AttachmentsBrowser.extend({createToolbar(){r.prototype.createToolbar.call(this),"rl-remote-library"===this.model.get("id")&&(this.toolbar.set("RLremoteLibraryFilterLabel",new wp.media.view.Label({value:rlRemoteLibraryMedia.filterByremoteLibrary,attributes:{for:"media-attachment-rl-remote-library-filters"},priority:-75}).render()),this.toolbar.set("RLremoteLibraryAttachmentFilters",new i({controller:this.controller,model:this.collection.props,priority:-75}).render()))}});const l=wp.media.view.MediaFrame.Post,o={width:0,height:0,url:""};l.currentAttachment=o,l.remoteLibraryImage=!1,l.requestHash="",wp.media.view.MediaFrame.Post=l.extend({initialize(...e){l.prototype.initialize.apply(this,e),this.states.add([new wp.media.controller.Library({id:"rl-remote-library",title:"Remote Library",priority:99,toolbar:t?"select":"main-insert",multiple:!1,editable:!0,allowLocalEdits:!0,library:new wp.media.model.Attachments,displaySettings:!0,displayUserSettings:!0,filterable:!0,searchable:!0,content:"browse",router:!1,date:!1,sortable:!1,type:"image",dragInfo:!1,menu:!t&&"default"})]);const i=wp.media.editor.send.attachment;wp.media.editor.send.attachment=(e,t)=>(void 0!==t.remote_library_image&&!0===t.remote_library_image&&(l.remoteLibraryImage=!0,"thumbnail"===e.size?(l.currentAttachment.width=t.thumbnail_width,l.currentAttachment.height=t.thumbnail_height,l.currentAttachment.url=t.thumbnail_url):(l.currentAttachment.width=t.width,l.currentAttachment.height=t.height,l.currentAttachment.url=t.url)),i(e,t));const r=wp.media.post;wp.media.post=(e,t)=>{if("send-attachment-to-editor"===e&&!0===l.remoteLibraryImage){const e=t.attachment.id;t.attachment.id=parseInt(rlRemoteLibraryMedia.thumbnailID),t.attachment.att_id=e,t.attachment.remote_library_image=!0,t.attachment.width=l.currentAttachment.width,t.attachment.height=l.currentAttachment.height,l.currentAttachment=o,l.remoteLibraryImage=!1,void 0===t.attachment.url&&(t.attachment.rl_url=l.currentAttachment.url)}return r(e,t)},this.on("activate",this.activateContent,this)},activateContent(){const i=this.content.get();if(null!==i&&"model"in i&&"rl-remote-library"===i.model.id){this.state().get("selection").reset();const r=this.toolbar.get(),l=this,o=i.toolbar.get("spinner");o.$el.css("marginLeft","6px"),o.show(),i.$el.find(".uploader-inline").addClass("hidden"),this.selectionStatusToolbar(r),r.set("rl-upload-insert",{style:"primary",priority:20,text:t?rlRemoteLibraryMedia.uploadAndSelect:rlRemoteLibraryMedia.uploadAndInsert,requires:{selection:!0},click(){const i=l.state(),r=i.get("selection"),a=r.single(),s=l.content.get().attachments.$el.find(`li[data-id="${a.attributes.id}"] .thumbnail`),o=s.find(".centered");o.css({opacity:.1,transition:"opacity 500ms"}),o.after('<div class="media-progress-bar"><div style="width: 20%"></div></div>');const n=s.find(".media-progress-bar div"),d=n.css("transition");n.css("transition","width 10s").animate({width:"100%"},0),e.post(ajaxurl,{action:"rl_upload_image",image:a.attributes,post_id:rlRemoteLibraryMedia.postID,rlnonce:rlRemoteLibraryMedia.getUploadNonce}).done(e=>{n.css("transition","width 0.5s").animate({width:"100%"},0,()=>{o.css({opacity:1,transition:""}),n.css("transition",d),r.models[0].attributes.id=parseInt(e.id),r.models[0].attributes.url=e.full[0],r.models[0].attributes.sizes.full.url=e.full[0],n.remove(),l.close(),i.trigger(t?"select":"insert",r).reset()})}).always(e=>{})}}),s=i,s.blockScrolling=!1,s.responseData=[];const n=i.model.collection.get("rl-remote-library");this.handleScroll=_.chain(this.handleScroll).bind(i).throttle(wp.media.isTouchDevice?300:200).value(),i.attachments.$el.on("scroll",this.handleScroll),a=n,m("all","",1,[]).then(e=>{e.images.length&&(n.attributes.library.push(e.images),d.media_page++,s.blockScrolling=!1,s.responseData=e.data,!1===e.last&&this.handleScroll()),i.toolbar.get("spinner").hide()},e=>{s.blockScrolling=!1,s.responseData=[]})}},handleScroll(){if(s.blockScrolling)return;let t=this.views.parent,i=this.attachments.el,r=i.scrollTop;if(i===document&&(i=document.body,r=e(document).scrollTop()),!e(i).is(":visible"))return;const l=t.content.get();i.scrollHeight-(r+i.clientHeight)<i.clientHeight/3&&l.toolbar.get("spinner").show(),i.scrollHeight<r+3*i.clientHeight&&(s.blockScrolling=!0,l.toolbar.get("spinner").show(),m(d.media_provider,d.media_search,d.media_page,s.responseData).then(e=>{e.images.length&&(a.attributes.library.push(e.images),d.media_page++,s.blockScrolling=!1,s.responseData=e.data,!1===e.last&&t.handleScroll(e.data)),l.toolbar.get("spinner").hide()},e=>{s.blockScrolling=!1,s.responseData=[]}))}});const n=wp.media.view.Settings.AttachmentDisplay;wp.media.view.Settings.AttachmentDisplay=wp.media.view.Settings.AttachmentDisplay.extend({render(){return void 0!==this.options.attachment.attributes.remote_library_image&&this.options.attachment.attributes.remote_library_image&&delete this.options.attachment.attributes.sizes.medium,n.prototype.render.call(this),this}});const d=wp.media.model.Attachments;d.media_page=1,d.media_provider="all",d.media_search="",wp.media.model.Attachments=d.extend({initialize(...e){d.prototype.initialize.apply(this,e),this.props.on("change",this.handleFilters)},handleFilters(){a.attributes.library.reset(),a.get("selection").reset(),s.$el.find(".uploader-inline").addClass("hidden"),d.media_page=1,s.responseData=[],void 0===this.attributes.media_provider?d.media_provider=this.attributes.media_provider="all":d.media_provider=this.attributes.media_provider,void 0===this.attributes.search?d.media_search=this.attributes.search="":d.media_search=this.attributes.search,s.blockScrolling=!0,s.toolbar.get("spinner").show(),m(this.attributes.media_provider,this.attributes.search,d.media_page,s.responseData).then(e=>{e.images.length&&(a.attributes.library.push(e.images),d.media_page++,s.blockScrolling=!1,s.responseData=e.data,!1===e.last&&s.views.parent.handleScroll()),s.toolbar.get("spinner").hide()},e=>{s.blockScrolling=!1,s.responseData=[]})}});const m=(t,i,r,a)=>new Promise((s,o)=>{l.requestHash=`provider:${t}|phrase:${i}`,e.post(ajaxurl,{action:"rl_remote_library_query",media_provider:t,media_search:i,media_page:r,response_data:a,nonce:rlRemoteLibraryMedia.queryNonce}).done(e=>{l.requestHash===`provider:${t}|phrase:${i}`?s(e):o([])}).fail(()=>{o([])})})});