PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.2.1
Responsive Lightbox & Gallery v2.2.1
2.7.8 trunk 1.0.0 1.0.1 1.0.1.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.0.1 1.4.1 1.4.11 1.4.12 1.4.13 1.4.14 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.3.1 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7
responsive-lightbox / js / admin-media.js
responsive-lightbox / js Last commit date
admin-folders.js 6 years ago admin-galleries.js 6 years ago admin-gallery.js 6 years ago admin-media.js 6 years ago admin-widgets.js 6 years ago admin.js 6 years ago front-basicmasonry.js 8 years ago front-basicslider.js 8 years ago front.js 6 years ago gutenberg.min.js 6 years ago
admin-media.js
487 lines
1 ( function ( $ ) {
2
3 var gutenberg_active = typeof rlBlockEditor !== 'undefined';
4
5 if ( gutenberg_active ) {
6 RLWPMediaViewMediaFramePostTrigger = wp.media.view.MediaFrame.Post.prototype.trigger;
7
8 // extend MediaFrame.Post
9 wp.media.view.MediaFrame.Post.prototype.trigger = function( action ) {
10 RLWPMediaViewMediaFramePostTrigger.apply( this, Array.prototype.slice.call( arguments ) );
11
12 if ( action === 'open' ) {
13 if ( $( this.modal.clickedOpenerEl ).hasClass( 'rl-remote-library-media-button' ) )
14 this.setState( 'rl-remote-library' );
15 else if ( $( this.modal.clickedOpenerEl ).hasClass( 'rl-gallery-media-button' ) )
16 this.setState( 'rl-gallery' );
17 }
18 }
19 }
20
21 // add new media folder filter
22 var RLWPMediaViewAttachmentFilters = wp.media.view.AttachmentFilters.extend( {
23 id: 'media-attachment-rl-remote-library-filters',
24 className: 'attachment-filters attachment-rl-remote-library-filter',
25 createFilters: function() {
26 var filters = {
27 all: {
28 text: rlRemoteLibraryMedia.allProviders,
29 priority: 1,
30 props: {
31 media_provider: 'all'
32 }
33 }
34 };
35
36 // add active providers
37 for ( var i = 0; i < rlRemoteLibraryMedia.providersActive.length; i++ ) {
38 var provider = rlRemoteLibraryMedia.providersActive[i];
39
40 filters[provider] = {
41 text: rlRemoteLibraryMedia.providers[provider].name,
42 priority: i + 2,
43 props: {
44 media_provider: provider
45 }
46 }
47 }
48
49 this.filters = filters;
50 }
51 } );
52
53 var RLWPMediaViewAttachmentsBrowser = wp.media.view.AttachmentsBrowser;
54
55 wp.media.view.AttachmentsBrowser = wp.media.view.AttachmentsBrowser.extend( {
56 createToolbar: function() {
57 // load the original toolbar
58 RLWPMediaViewAttachmentsBrowser.prototype.createToolbar.call( this );
59
60 if ( this.model.get( 'id' ) === 'rl-remote-library' ) {
61 this.toolbar.set( 'RLremoteLibraryFilterLabel', new wp.media.view.Label( {
62 value: rlRemoteLibraryMedia.filterByremoteLibrary,
63 attributes: {
64 'for': 'media-attachment-rl-remote-library-filters'
65 },
66 priority: -75
67 } ).render() );
68
69 this.toolbar.set( 'RLremoteLibraryAttachmentFilters', new RLWPMediaViewAttachmentFilters( {
70 controller: this.controller,
71 model: this.collection.props,
72 priority: -75
73 } ).render() );
74 }
75 }
76 } );
77
78 var RLRemoteLibraryCollection,
79 RLRemoteLibraryContentView,
80 RLWPMediaViewMediaFramePost = wp.media.view.MediaFrame.Post,
81 attachment_defaults = {
82 width: 0,
83 height: 0
84 };
85
86 // add new attributes
87 RLWPMediaViewMediaFramePost.currentAttachment = attachment_defaults;
88 RLWPMediaViewMediaFramePost.remoteLibraryImage = false;
89 RLWPMediaViewMediaFramePost.requestHash = '';
90
91 // extend media frame
92 wp.media.view.MediaFrame.Post = RLWPMediaViewMediaFramePost.extend( {
93 initialize: function() {
94 // calling the initalize method from the current frame before adding new functionality
95 RLWPMediaViewMediaFramePost.prototype.initialize.apply( this, arguments );
96
97 // adding new state for remote library image
98 this.states.add( [
99 new wp.media.controller.Library( {
100 id: 'rl-remote-library',
101 title: 'Remote Library',
102 priority: 99,
103 toolbar: gutenberg_active ? 'select' : 'main-insert',
104 multiple: false,
105 editable: true,
106 allowLocalEdits: true,
107 library: new wp.media.model.Attachments(),
108 displaySettings: true,
109 displayUserSettings: true,
110 filterable: true,
111 searchable: true,
112 content: 'browse',
113 router: false,
114 date: false,
115 sortable: false,
116 type: 'image',
117 dragInfo: false,
118 menu: gutenberg_active ? false : 'default'
119 } )
120 ] );
121
122 var RLWPMediaEditorSendAttachment = wp.media.editor.send.attachment;
123
124 // replace send attachment
125 wp.media.editor.send.attachment = function( props, attachment ) {
126 // remote library simulated attachment?
127 if ( typeof attachment.remote_library_image !== 'undefined' && attachment.remote_library_image === true ) {
128 RLWPMediaViewMediaFramePost.remoteLibraryImage = true;
129
130 if ( props.size === 'thumbnail' ) {
131 RLWPMediaViewMediaFramePost.currentAttachment.width = attachment.thumbnail_width;
132 RLWPMediaViewMediaFramePost.currentAttachment.height = attachment.thumbnail_height;
133 } else {
134 RLWPMediaViewMediaFramePost.currentAttachment.width = attachment.width;
135 RLWPMediaViewMediaFramePost.currentAttachment.height = attachment.height;
136 }
137 }
138
139 // return original function
140 return RLWPMediaEditorSendAttachment( props, attachment );
141 }
142
143 var RLWPMediaPost = wp.media.post;
144
145 // replace ajax request
146 wp.media.post = function( action, data ) {
147 // send attachment to editor action?
148 if ( action === 'send-attachment-to-editor' && RLWPMediaViewMediaFramePost.remoteLibraryImage === true ) {
149 var attachmentID = data.attachment.id;
150
151 // replace pseudo ID with generated thumbnial ID
152 data.attachment.id = parseInt( rlRemoteLibraryMedia.thumbnailID );
153
154 // set pseudo ID too
155 data.attachment.att_id = attachmentID;
156
157 // select this image as remote library one
158 data.attachment.remote_library_image = true;
159
160 // set new dimensions
161 data.attachment.width = RLWPMediaViewMediaFramePost.currentAttachment.width;
162 data.attachment.height = RLWPMediaViewMediaFramePost.currentAttachment.height;
163
164 // back to defaults
165 RLWPMediaViewMediaFramePost.currentAttachment = attachment_defaults;
166
167 // restore defaulkt behavior
168 RLWPMediaViewMediaFramePost.remoteLibraryImage = false;
169 }
170
171 // return original function
172 return RLWPMediaPost( action, data );
173 }
174
175 // events
176 this.on( 'activate', this.contentRender, this );
177 },
178 contentRender: function() {
179 // get view content
180 var view = this.content.get();
181
182 // valid remote library view?
183 if ( view !== null && 'model' in view && view.model.id === 'rl-remote-library' ) {
184 var contentState = this.state(),
185 contentSelection = contentState.get( 'selection' );
186
187 // clear selection
188 contentSelection.reset();
189
190 var toolbar = this.toolbar.get(),
191 controller = this,
192 spinner = view.toolbar.get( 'spinner' );
193
194 // display spinner
195 spinner.$el.css( 'marginLeft', '6px' );
196 spinner.show();
197
198 // hide uploader view
199 view.$el.find( '.uploader-inline' ).addClass( 'hidden' );
200
201 this.selectionStatusToolbar( toolbar );
202
203 // add upload button
204 toolbar.set( 'rl-upload-insert', {
205 style: 'primary',
206 priority: 80,
207 text: rlRemoteLibraryMedia.uploadAndInsert,
208 requires: { selection: true },
209 click: function() {
210 var state = controller.state(),
211 selection = state.get( 'selection' ),
212 image = selection.single(),
213 content = controller.content.get(),
214 attachment = content.attachments.$el.find( 'li[data-id="' + image.attributes.id + '"] .thumbnail' ),
215 attachment_image = attachment.find( '.centered' );
216
217 attachment_image.css( { opacity: 0.1, transition: 'opacity 500ms' } );
218 attachment_image.after( '<div class="media-progress-bar"><div style="width: 20%"></div></div>' );
219
220 var progress = attachment.find( '.media-progress-bar div' ),
221 transition = progress.css( 'transition' );
222
223 progress.css( 'transition', 'width 10s' ).animate( { width: "100%" }, 0 );
224
225 $.post( ajaxurl, {
226 action: 'rl_upload_image',
227 image: image.attributes,
228 post_id: rlRemoteLibraryMedia.postID,
229 rlnonce: rlRemoteLibraryMedia.getUploadNonce
230 } ).done( function( response ) {
231 progress.css( 'transition', 'width 0.5s' ).animate( { width: "100%" }, 0, function() {
232 attachment_image.css( { opacity: 1, transition: '' } );
233
234 $( this ).css( 'transition', transition );
235
236 // update attachment data
237 selection.models[0].attributes.id = parseInt( response.id );
238 selection.models[0].attributes.url = response.full[0];
239 selection.models[0].attributes.sizes.full.url = response.full[0];
240
241 // remove progress bar
242 progress.remove();
243
244 // close modal
245 controller.close();
246
247 // trigger insert event
248 state.trigger( ( gutenberg_active ? 'select' : 'insert' ), selection ).reset();
249 } );
250 } ).always( function( data ) {
251 //
252 } );
253 }
254 } );
255
256 RLRemoteLibraryContentView = view;
257 RLRemoteLibraryContentView.blockScrolling = false;
258 RLRemoteLibraryContentView.responseData = [];
259
260 var model = view.model.collection.get( 'rl-remote-library' );
261
262 // set scroll event
263 this.handleScroll = _.chain( this.handleScroll ).bind( view ).throttle( wp.media.isTouchDevice ? 300 : 200 ).value();
264
265 // bind scroll event
266 view.attachments.$el.on( 'scroll', this.handleScroll );
267
268 // assign model
269 RLRemoteLibraryCollection = model;
270
271 // run ajax calls for all providers
272 var promise = remoteQuery( 'all', '', 1, [] );
273
274 promise.then(
275 result => {
276 // any results?
277 if ( result.images.length ) {
278 // add images to library
279 model.attributes.library.push( result.images );
280
281 // increase page number
282 RLWPMediaModelAttachments.media_page++;
283
284 RLRemoteLibraryContentView.blockScrolling = false;
285 RLRemoteLibraryContentView.responseData = result.data;
286
287 // last page?
288 if ( result.last === false )
289 this.handleScroll();
290 }
291
292 // hide spinner
293 view.toolbar.get( 'spinner' ).hide();
294 },
295 error => {
296 RLRemoteLibraryContentView.blockScrolling = false;
297 RLRemoteLibraryContentView.responseData = [];
298 }
299 );
300 }
301 },
302 handleScroll: function() {
303 // is another scrolling pending?
304 if ( RLRemoteLibraryContentView.blockScrolling )
305 return;
306
307 var view = this.views.parent,
308 el = this.attachments.el,
309 scrollTop = el.scrollTop;
310
311 // the scroll event occurs on the document, but the element that should be checked is the document body
312 if ( el === document ) {
313 el = document.body;
314 scrollTop = $( document ).scrollTop();
315 }
316
317 if ( ! $( el ).is( ':visible' ) )
318 return;
319
320 // get content view
321 var content = view.content.get();
322
323 // show the spinner only if we are close to the bottom.
324 if ( el.scrollHeight - ( scrollTop + el.clientHeight ) < el.clientHeight / 3 )
325 content.toolbar.get( 'spinner' ).show();
326
327 if ( el.scrollHeight < scrollTop + ( el.clientHeight * 3 ) ) {
328 RLRemoteLibraryContentView.blockScrolling = true;
329
330 // display spinner
331 content.toolbar.get( 'spinner' ).show();
332
333 var promise = remoteQuery( RLWPMediaModelAttachments.media_provider, RLWPMediaModelAttachments.media_search, RLWPMediaModelAttachments.media_page, RLRemoteLibraryContentView.responseData );
334
335 promise.then(
336 result => {
337 // any results?
338 if ( result.images.length ) {
339 // add images to library
340 RLRemoteLibraryCollection.attributes.library.push( result.images );
341
342 // increase page number
343 RLWPMediaModelAttachments.media_page++;
344
345 RLRemoteLibraryContentView.blockScrolling = false;
346 RLRemoteLibraryContentView.responseData = result.data;
347
348 // last page?
349 if ( result.last === false )
350 view.handleScroll( result.data );
351 }
352
353 // hide spinner
354 content.toolbar.get( 'spinner' ).hide();
355 },
356 error => {
357 RLRemoteLibraryContentView.blockScrolling = false;
358 RLRemoteLibraryContentView.responseData = [];
359 }
360 );
361 }
362 }
363 } );
364
365 var RLWPMediaViewSettingsAttachmentDisplay = wp.media.view.Settings.AttachmentDisplay;
366
367 wp.media.view.Settings.AttachmentDisplay = wp.media.view.Settings.AttachmentDisplay.extend( {
368 render: function() {
369 // remove medium size
370 if ( typeof this.options.attachment.attributes.remote_library_image !== 'undefined' && this.options.attachment.attributes.remote_library_image )
371 delete this.options.attachment.attributes.sizes.medium;
372
373 // load the original render function
374 RLWPMediaViewSettingsAttachmentDisplay.prototype.render.call( this );
375
376 return this;
377 }
378 } );
379
380 var RLWPMediaModelAttachments = wp.media.model.Attachments;
381
382 // add new attributes
383 RLWPMediaModelAttachments.media_page = 1;
384 RLWPMediaModelAttachments.media_provider = 'all';
385 RLWPMediaModelAttachments.media_search = '';
386
387 // extend media frame
388 wp.media.model.Attachments = RLWPMediaModelAttachments.extend( {
389 initialize: function() {
390 // calling the initalize method from the current frame before adding new functionality
391 RLWPMediaModelAttachments.prototype.initialize.apply( this, arguments );
392
393 // events
394 this.props.on( 'change', this.handleFilters );
395 },
396 handleFilters: function() {
397 // clear current collection
398 RLRemoteLibraryCollection.attributes.library.reset();
399
400 // clear current selection
401 RLRemoteLibraryCollection.get( 'selection' ).reset();
402
403 // hide uploader view
404 RLRemoteLibraryContentView.$el.find( '.uploader-inline' ).addClass( 'hidden' );
405
406 // reset page to first
407 RLWPMediaModelAttachments.media_page = 1;
408
409 // clear response data
410 RLRemoteLibraryContentView.responseData = [];
411
412 // make sure media provider is set
413 if ( typeof this.attributes.media_provider === 'undefined' )
414 RLWPMediaModelAttachments.media_provider = this.attributes.media_provider = 'all';
415 else
416 RLWPMediaModelAttachments.media_provider = this.attributes.media_provider;
417
418 // make sure search phrase is set
419 if ( typeof this.attributes.search === 'undefined' )
420 RLWPMediaModelAttachments.media_search = this.attributes.search = '';
421 else
422 RLWPMediaModelAttachments.media_search = this.attributes.search;
423
424 // disable scroll event
425 RLRemoteLibraryContentView.blockScrolling = true;
426
427 // display spinner
428 RLRemoteLibraryContentView.toolbar.get( 'spinner' ).show();
429
430 var promise = remoteQuery( this.attributes.media_provider, this.attributes.search, RLWPMediaModelAttachments.media_page, RLRemoteLibraryContentView.responseData );
431
432 promise.then(
433 result => {
434 // any results?
435 if ( result.images.length ) {
436 // add images to library
437 RLRemoteLibraryCollection.attributes.library.push( result.images );
438
439 // increase page number
440 RLWPMediaModelAttachments.media_page++;
441
442 // allow scrolling
443 RLRemoteLibraryContentView.blockScrolling = false;
444 RLRemoteLibraryContentView.responseData = result.data;
445
446 // last page?
447 if ( result.last === false )
448 RLRemoteLibraryContentView.views.parent.handleScroll();
449 }
450
451 // hide spinner
452 RLRemoteLibraryContentView.toolbar.get( 'spinner' ).hide();
453 },
454 error => {
455 RLRemoteLibraryContentView.blockScrolling = false;
456 RLRemoteLibraryContentView.responseData = [];
457 }
458 );
459 }
460 } );
461
462 function remoteQuery( provider, phrase, page, response_data ) {
463 var promise = new Promise( ( resolve, reject ) => {
464 // set current request phrase
465 RLWPMediaViewMediaFramePost.requestHash = 'provider:' + provider + '|phrase:' + phrase;
466
467 $.post( ajaxurl, {
468 action: 'rl_remote_library_query',
469 media_provider: provider,
470 media_search: phrase,
471 media_page: page,
472 response_data: response_data
473 } ).done( function( response ) {
474 // valid request hash?
475 if ( RLWPMediaViewMediaFramePost.requestHash === 'provider:' + provider + '|phrase:' + phrase )
476 resolve( response );
477 else
478 reject( [] );
479 } ).fail( function() {
480 reject( [] );
481 } );
482 } );
483
484 return promise;
485 }
486
487 } )( jQuery );