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-galleries.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-galleries.js
706 lines
1 ( function ( $ ) {
2
3 $( document ).on( 'ready', function () {
4 var gallery_frame = null,
5 attachment_frame = null,
6 gallery_container = $( '.rl-gallery-images' ),
7 gallery_ids = $( '.rl-gallery-ids' ),
8 wikimedia = { '1': '' };
9
10 media_gallery_sortable( gallery_container, gallery_ids, $( 'input[name="rl_gallery[images][menu_item]"]:checked' ).val() );
11
12 // color picker
13 $( '.rl-gallery-tab-content .color-picker' ).wpColorPicker();
14
15 // make sure HTML5 validation is turned off
16 $( 'form#post' ).attr( 'novalidate', 'novalidate' );
17
18 // make sure to dispay images metabox at start
19 $( '#responsive-gallery-images' ).show();
20
21 // move navigation tabs and metaboxes to second postbox container to fix mobile devices problem
22 $( '.rl-display-metabox, .rl-hide-metabox, h2.nav-tab-wrapper' ).prependTo( '#postbox-container-2' );
23
24 // change navigation menu
25 $( document ).on( 'change', '.rl-gallery-tab-menu-item', function () {
26 var tab = $( this ).closest( '.postbox' ).attr( 'id' ).replace( 'responsive-gallery-', '' ),
27 source = $( this ).closest( '.rl-gallery-tab-menu' ),
28 container = $( this ).closest( '.inside' ).find( '.rl-gallery-tab-content' ),
29 spinner = source.find( '.spinner' ),
30 menu_item = $( this ).val();
31
32 // disable nav on ajax
33 container.addClass( 'rl-loading-content' );
34 source.addClass( 'rl-loading-content' );
35
36 // display spinner
37 spinner.fadeIn( 'fast' ).css( 'visibility', 'visible' );
38
39 // post ajax request
40 $.post( ajaxurl, {
41 action: 'rl-get-menu-content',
42 post_id: rlArgsGalleries.post_id,
43 tab: tab,
44 menu_item: menu_item,
45 nonce: rlArgsGalleries.nonce
46 } ).done( function ( response ) {
47 try {
48 if ( response.success ) {
49 // replace HTML
50 container.html( response.data );
51
52 // enable nav after ajax
53 container.removeClass( 'rl-loading-content' );
54 source.removeClass( 'rl-loading-content' );
55
56 // update gallery data
57 gallery_frame = null;
58 gallery_container = $( '.rl-gallery-images' );
59 gallery_ids = $( '.rl-gallery-ids' );
60
61 // refresh sortable only for media library
62 media_gallery_sortable( gallery_container, gallery_ids, menu_item );
63
64 // color picker
65 container.find( '.color-picker' ).wpColorPicker();
66
67 /*
68 var click = $( this ),
69 type = click.hasClass( 'rl-gallery-update-preview' ) ? 'update' : 'page',
70 menu_item = $( '.rl-gallery-tab-menu-images input:checked' ).val(),
71 container = $( '.rl-gallery-tab-inside-images-' + menu_item ),
72 spinner = click.closest( 'td' ).find( '.rl-gallery-preview-inside .spinner' ),
73 query_args = {},
74 inside = $( this ).closest( '.inside' ).find( '.rl-gallery-tab-content' );
75
76 // disable nav on ajax
77 inside.addClass( 'rl-loading-content' );
78 */
79
80 container.find( 'tr[data-field_type]' ).each( function() {
81 var el = $( this ),
82 field_name = el.data( 'field_name' ),
83 change = false;
84
85 switch ( el.data( 'field_type' ) ) {
86 case 'text':
87 el.find( 'input' ).on( 'change', function() {
88 console.log( 'text' );
89 } );
90 break;
91
92 case 'number':
93 el.find( 'input' ).on( 'change', function() {
94 console.log( 'number' );
95 } );
96 break;
97
98 case 'taxonomy':
99 // value = {
100 // 'id': parseInt( el.find( 'select option:selected' ).val() ),
101 // 'children': el.find( 'input[type="checkbox"]' ).prop( 'checked' )
102 // };
103 break;
104
105 case 'select':
106 el.find( 'select' ).on( 'change', function() {
107 console.log( 'select' );
108 } );
109 value = '';
110 break;
111
112 case 'radio':
113 // value = el.find( 'input:checked' ).val();
114 break;
115
116 case 'multiselect':
117 // value = el.find( 'select' ).val();
118 break;
119 }
120 } );
121 } else {
122 // @todo
123 }
124 } catch ( e ) {
125 // @todo
126 }
127
128 // hide spinner
129 spinner.fadeOut( 'fast' );
130 } ).fail( function () {
131 // hide spinner
132 spinner.fadeOut( 'fast' );
133 } );
134 } );
135
136 // change navigation menu
137 $( document ).on( 'click', '.nav-tab', function ( e ) {
138 e.preventDefault();
139
140 var anchor = $( this ).attr( 'href' ).substr( 1 );
141
142 // remove active class
143 $( '.nav-tab' ).removeClass( 'nav-tab-active' );
144
145 // add active class
146 $( this ).addClass( 'nav-tab-active' );
147
148 // hide all normal metaboxes
149 $( '#postbox-container-2 div[id^="responsive-gallery-"]' ).removeClass( 'rl-display-metabox' ).addClass( 'rl-hide-metabox' );
150
151 // display needed metabox
152 if ( anchor === '' ) {
153 $( '#responsive-gallery-images' ).addClass( 'rl-display-metabox' ).removeClass( 'rl-hide-metabox' );
154 } else {
155 $( '#responsive-gallery-' + anchor ).addClass( 'rl-display-metabox' ).removeClass( 'rl-hide-metabox' );
156 }
157
158 $( 'input[name="rl_active_tab"]' ).val( anchor );
159 } );
160
161 $( '.rl-shortcode' ).on( 'click', function () {
162 $( this ).select();
163 } );
164
165 // remove image
166 $( document ).on( 'click', '.rl-gallery-image-remove', function ( e ) {
167 e.preventDefault();
168
169 // prevent featured images being removed
170 if ( $( this ).closest( '.rl-gallery-images-featured' ).length === 1 ) {
171 return false;
172 }
173
174 var li = $( this ).closest( 'li.rl-gallery-image' ),
175 attachment_ids = get_current_attachments( gallery_ids );
176
177 // remove id
178 attachment_ids = _.without( attachment_ids, parseInt( li.data( 'attachment_id' ) ) );
179
180 // remove attachment
181 li.remove();
182
183 // update attachment ids
184 gallery_ids.val( $.unique( attachment_ids ).join( ',' ) );
185
186 return false;
187 } );
188
189 // edit image
190 $( document ).on( 'click', '.rl-gallery-image-edit', function ( e ) {
191 e.preventDefault();
192
193 var li = $( this ).closest( 'li.rl-gallery-image' ),
194 attachment_id = parseInt( li.data( 'attachment_id' ) ),
195 attachment_changed = false;
196
197 // frame already exists?
198 if ( attachment_frame !== null ) {
199 attachment_frame.detach();
200 attachment_frame.dispose();
201 attachment_frame = null;
202 }
203
204 // create new frame
205 attachment_frame = wp.media( {
206 id: 'rl-edit-attachment-modal',
207 frame: 'select',
208 uploader: false,
209 multiple: false,
210 title: rlArgsGalleries.editTitle,
211 library: {
212 post__in: attachment_id
213 },
214 button: {
215 text: rlArgsGalleries.buttonEditFile
216 }
217 } ).on( 'open', function () {
218 var attachment = wp.media.attachment( attachment_id ),
219 selection = attachment_frame.state().get( 'selection' );
220
221 attachment_frame.$el.closest( '.media-modal' ).addClass( 'rl-edit-modal' );
222
223 // get attachment
224 attachment.fetch();
225
226 // reset selection
227 //selection.reset();
228
229 // add attachment
230 selection.add( attachment );
231 } );
232
233 attachment_frame.open();
234
235 return false;
236 } );
237
238 // change image status
239 $( document ).on( 'click', '.rl-gallery-image-status', function ( e ) {
240 e.preventDefault();
241
242 var li = $( this ).closest( 'li.rl-gallery-image' ),
243 input = li.find( '.rl-gallery-exclude' ),
244 status = li.hasClass( 'rl-status-active' ),
245 id = parseInt( li.data( 'attachment_id' ) ),
246 item = '';
247
248 if ( id > 0 )
249 item = id;
250 else
251 item = li.find( '.rl-gallery-inner img' ).attr( 'src' );
252
253 // exclude?
254 if ( status ) {
255 li.addClass( 'rl-status-inactive' ).removeClass( 'rl-status-active' );
256
257 // add item
258 input.val( item );
259 } else {
260 li.addClass( 'rl-status-active' ).removeClass( 'rl-status-inactive' );
261
262 // remove item
263 input.val( '' );
264 }
265
266 return false;
267 } );
268
269 // open the modal on click
270 $( document ).on( 'click', '.rl-gallery-select', function ( e ) {
271 e.preventDefault();
272
273 // open media frame if already exists
274 if ( gallery_frame !== null ) {
275 gallery_frame.open();
276
277 return;
278 }
279
280 // create the media frame
281 gallery_frame = wp.media( {
282 title: rlArgsGalleries.textSelectImages,
283 multiple: 'add',
284 autoSelect: true,
285 library: {
286 type: 'image'
287 },
288 button: {
289 text: rlArgsGalleries.textUseImages
290 }
291 } ).on( 'open', function () {
292 var selection = gallery_frame.state().get( 'selection' ),
293 attachment_ids = get_current_attachments( gallery_ids );
294
295 // deselect all attachments
296 selection.reset();
297
298 $.each( attachment_ids, function () {
299 // prepare attachment
300 attachment = wp.media.attachment( this );
301
302 // select attachment
303 selection.add( attachment ? [ attachment ] : [ ] );
304 } );
305 } ).on( 'select', function () {
306 var selection = gallery_frame.state().get( 'selection' ),
307 attachment_ids = get_current_attachments( gallery_ids ),
308 selected_ids = [ ];
309
310 if ( selection ) {
311 selection.map( function ( attachment ) {
312 if ( attachment.id ) {
313 // add attachment
314 selected_ids.push( attachment.id );
315
316 // is image already in gallery?
317 if ( $.inArray( attachment.id, attachment_ids ) !== -1 ) {
318 return;
319 }
320
321 // add attachment
322 attachment_ids.push( attachment.id );
323 attachment = attachment.toJSON();
324
325 // is preview size available?
326 if ( attachment.sizes && attachment.sizes['thumbnail'] ) {
327 attachment.url = attachment.sizes['thumbnail'].url;
328 }
329
330 // append new image
331 gallery_container.append( rlArgsGalleries.mediaItemTemplate.replace( /__IMAGE_ID__/g, attachment.id ).replace( /__IMAGE__/g, '<img width="150" height="150" src="' + attachment.url + '" class="attachment-thumbnail size-thumbnail" alt="" sizes="(max-width: 150px) 100vw, 150px" />' ).replace( /__IMAGE_STATUS__/g, 'rl-status-active' ) );
332 }
333 } );
334 }
335
336 // assign copy of attachment ids
337 var copy = attachment_ids;
338
339 for ( var i = 0; i < attachment_ids.length; i++ ) {
340 // unselected image?
341 if ( $.inArray( attachment_ids[i], selected_ids ) === -1 ) {
342 gallery_container.find( 'li.rl-gallery-image[data-attachment_id="' + attachment_ids[i] + '"]' ).remove();
343
344 copy = _.without( copy, attachment_ids[i] );
345 }
346 }
347
348 gallery_ids.val( $.unique( copy ).join( ',' ) );
349 } );
350
351 // open media frame
352 gallery_frame.open();
353 } );
354
355 // preview pagination
356 $( document ).on( 'click', '.rl-gallery-update-preview, .rl-gallery-preview-pagination a', function ( e ) {
357 e.preventDefault();
358
359 var click = $( this ),
360 type = click.hasClass( 'rl-gallery-update-preview' ) ? 'update' : 'page',
361 menu_item = $( '.rl-gallery-tab-menu-images input:checked' ).val(),
362 container = $( '.rl-gallery-tab-inside-images-' + menu_item ),
363 spinner = click.closest( 'td' ).find( '.rl-gallery-preview-inside .spinner' ),
364 query_args = {},
365 inside = $( this ).closest( '.inside' ).find( '.rl-gallery-tab-content' );
366
367 // disable nav on ajax
368 inside.addClass( 'rl-loading-content' );
369
370 // pagination?
371 if ( type === 'page' ) {
372 var content = click.attr( 'href' ).match( 'preview_page/\\d+' ),
373 page = 1;
374
375 // get valid page number
376 if ( content !== null )
377 page = content[0].split( '/' )[1];
378
379 query_args['preview_page'] = page;
380 }
381
382 container.find( 'tr[data-field_type]' ).each( function() {
383 var el = $( this ),
384 field_name = el.data( 'field_name' ),
385 value = null;
386
387 switch ( el.data( 'field_type' ) ) {
388 case 'text':
389 value = el.find( 'input' ).val();
390
391 if ( ! value )
392 value = '';
393 break;
394
395 case 'number':
396 value = parseInt( el.find( 'input' ).val() );
397
398 if ( ! value )
399 value = 0;
400 break;
401
402 case 'taxonomy':
403 value = {
404 'id': parseInt( el.find( 'select option:selected' ).val() ),
405 'children': el.find( 'input[type="checkbox"]' ).prop( 'checked' )
406 };
407
408 if ( ! value )
409 value = {
410 'id': 0,
411 'children': false
412 };
413 break;
414
415 case 'select':
416 value = el.find( 'select option:selected' ).val();
417
418 if ( ! value )
419 value = '';
420 break;
421
422 case 'radio':
423 value = el.find( 'input:checked' ).val();
424
425 if ( ! value )
426 value = '';
427 break;
428
429 case 'multiselect':
430 value = el.find( 'select' ).val();
431
432 if ( ! value )
433 value = [];
434 break;
435
436 case 'hidden':
437 var subel = el.find( 'input[type="hidden"]' ),
438 nofa = parseInt( subel.data( 'subarg' ) ),
439 val = el.find( 'input[type="hidden"]' ).val();
440
441 if ( nofa > 0 ) {
442 var atts = subel.attr( 'name' ).slice( 0, -1 ).split( '][' ),
443 new_value = {},
444 last;
445
446 for ( var i = atts.length; i > atts.length - nofa; i-- ) {
447 var number = i - 1;
448
449 // first element?
450 if ( i === atts.length )
451 new_value[atts[number]] = val;
452 else
453 new_value[atts[number]] = last;
454
455 // remember last array
456 last = new_value;
457
458 // do not reset for last element
459 if ( number > atts.length - nofa )
460 new_value = {};
461 }
462
463 // get new array
464 value = new_value;
465
466 // save wikimedia aicontinue for pages
467 if ( ! ( query_args['preview_page'] in wikimedia ) )
468 wikimedia[query_args['preview_page']] = value.wikimedia.continue;
469
470 value.wikimedia.continue = wikimedia[query_args['preview_page']];
471 } else
472 value = val;
473 break;
474 }
475
476 query_args[field_name] = value;
477 } );
478
479 // display spinner
480 spinner.fadeIn( 'fast' ).css( 'visibility', 'visible' );
481
482 // post ajax request
483 $.post( ajaxurl, {
484 action: 'rl-get-preview-content',
485 post_id: rlArgsGalleries.post_id,
486 menu_item: menu_item,
487 query: query_args,
488 preview_type: type,
489 excluded: $( '.rl-gallery-exclude' ).map( function( i, elem ) { return $( elem ).val(); } ).get(),
490 nonce: rlArgsGalleries.nonce
491 } ).done( function ( response ) {
492 try {
493 if ( response.success ) {
494 container.find( 'tr[data-field_type]' ).each( function() {
495 var el = $( this ),
496 field_name = el.data( 'field_name' ),
497 value = null;
498
499 switch ( el.data( 'field_type' ) ) {
500 case 'hidden':
501 $( '#rl_images_remote_library_response_data_wikimedia_continue' ).val( response.data.data.wikimedia.continue );
502
503 var next_page = parseInt( query_args['preview_page'] ) + 1;
504
505 // save wikimedia aicontinue for pages
506 if ( ! ( next_page in wikimedia ) )
507 wikimedia[next_page] = response.data.data.wikimedia.continue;
508 /*
509 var subel = el.find( 'input[type="hidden"]' ),
510 nofa = parseInt( subel.data( 'subarg' ) ),
511 val = el.find( 'input[type="hidden"]' ).val();
512
513 if ( nofa > 0 ) {
514 var atts = subel.attr( 'name' ).slice( 0, -1 ).split( '][' ),
515 new_value = {},
516 last;
517 console.log( atts );
518
519 for ( var i = atts.length - nofa; i <= atts.length; i++ ) {
520 console.log( 1 );
521 // console.log( nofa );
522 var number = i - 1;
523 console.log( 2 );
524 // first element?
525 if ( i === atts.length ) {
526 console.log( 2.1 );
527 // new_value2 .= '[' + atts[number] + ']';
528 new_value = response.data.data[atts[number]];
529 } else {
530 console.log( 2.2 );
531 last = new_value[atts[number]];
532 }
533 console.log( 3 );
534 // remember last array
535 new_value = last;
536 console.log( 4 );
537 // do not reset for last element
538 // if ( number > atts.length - nofa )
539 // new_value = {};
540 }
541
542 console.log( 5 );
543 // get new array
544 value = new_value;
545 console.log( value );
546 console.log( 6 );
547 } else
548 subel.val( response.data.data );
549 break;
550 */
551 }
552 } );
553
554 $( '.rl-gallery-images' ).empty().append( response.data.images );
555
556 if ( type === 'page' )
557 $( '.rl-gallery-preview-pagination' ).replaceWith( response.data.pagination );
558 } else {
559 // @todo
560 }
561 } catch ( e ) {
562 // @todo
563 }
564 } ).always( function () {
565 // hide spinner
566 spinner.fadeOut( 'fast' );
567
568 // enable content
569 inside.removeClass( 'rl-loading-content' );
570 } );
571
572 return false;
573 } );
574
575 // load values for specified rule
576 $( document ).on( 'change', '.rl-rule-type', function () {
577 var _this = $( this ),
578 td = _this.closest( 'tr' ).find( 'td.value' ),
579 select = td.find( 'select' ),
580 spinner = td.find( '.spinner' );
581
582 select.hide();
583 spinner.fadeIn( 'fast' ).css( 'visibility', 'visible' );
584
585 $.post( ajaxurl, {
586 action: 'rl-get-group-rules-values',
587 type: _this.val(),
588 nonce: rlArgsGalleries.nonce
589 } ).done( function ( data ) {
590 spinner.hide();
591
592 try {
593 var response = JSON.parse( data );
594
595 // remove old select options and adds new ones
596 select.fadeIn( 'fast' ).find( 'option, optgroup' ).remove().end().append( response.select );
597 } catch ( e ) {
598 //
599 }
600 } ).fail( function () {
601 //
602 } );
603 } );
604 } );
605
606 // listen for insert/remove media library thumbnail
607 $( document ).on( 'DOMNodeInserted', '#postimagediv .inside', function ( e ) {
608 var value = $( '#postimagediv .inside' ).attr( 'data-featured-type' );
609
610 if ( $( '#rl-gallery-featured-' + value ).length > 0 ) {
611 $( '#rl-gallery-featured-' + value ).prop( 'checked', true );
612
613 $( '#postimagediv .inside' ).trigger( 'change' );
614 }
615 } );
616
617 // handle featured image change
618 $( document ).on( 'change', '#postimagediv .inside', function () {
619 var el = $( this ).find( 'input[name="rl_gallery_featured_image"]:checked' ),
620 value = $( el ).val();
621
622 $( '#postimagediv .inside' ).attr( 'data-featured-type', value );
623 $( '.rl-gallery-featured-image-select' ).children( 'div' ).hide();
624 $( '.rl-gallery-featured-image-select-' + value ).show();
625
626 // media library
627 if ( value === 'id' ) {
628 var thumbnail_id = parseInt( $( '#_thumbnail_id' ).attr( 'data-featured-id' ) );
629 if ( thumbnail_id > 0 ) {
630 $( '#_thumbnail_id' ).val( thumbnail_id ).attr( 'data-featured-id', -1 );
631 }
632 // custom URL
633 } else if ( value === 'url' ) {
634 var thumbnail_id = parseInt( $( '#_thumbnail_id' ).val() );
635 if ( thumbnail_id > 0 ) {
636 $( '#_thumbnail_id' ).attr( 'data-featured-id', thumbnail_id ).val( -1 );
637 }
638 // first gallery image
639 } else {
640 var thumbnail_id = parseInt( $( '#_thumbnail_id' ).val() );
641 if ( thumbnail_id > 0 ) {
642 $( '#_thumbnail_id' ).attr( 'data-featured-id', thumbnail_id ).val( -1 );
643 }
644 }
645 } );
646
647 $( document ).on( 'ready ajaxComplete', function () {
648 // init select2
649 $( '.rl-gallery-tab-inside select.select2' ).select2( {
650 closeOnSelect: true,
651 multiple: true,
652 width: 300,
653 minimumInputLength: 0
654 } );
655 } );
656
657 function createSubValue( value, new_value, arg ) {
658 value = new_value;
659 // value = value[arg];
660
661 return value
662 }
663
664 // get attachment ids
665 function get_current_attachments( gallery_ids ) {
666 var attachments = gallery_ids.val();
667
668 // return integer image ids or empty array
669 return attachments !== '' ? attachments.split( ',' ).map( function ( i ) {
670 return parseInt( i )
671 } ) : [];
672 }
673
674 //
675 function media_gallery_sortable( gallery, ids, type ) {
676 if ( type === 'media' ) {
677 // images order
678 gallery.sortable( {
679 items: 'li.rl-gallery-image',
680 cursor: 'move',
681 scrollSensitivity: 40,
682 forcePlaceholderSize: true,
683 forceHelperSize: false,
684 helper: 'clone',
685 opacity: 0.65,
686 placeholder: 'rl-gallery-sortable-placeholder',
687 start: function ( event, ui ) {
688 ui.item.css( 'border-color', '#f6f6f6' );
689 },
690 stop: function ( event, ui ) {
691 ui.item.removeAttr( 'style' );
692 },
693 update: function ( event, ui ) {
694 var attachment_ids = [ ];
695
696 gallery.find( 'li.rl-gallery-image' ).each( function () {
697 attachment_ids.push( parseInt( $( this ).attr( 'data-attachment_id' ) ) );
698 } );
699
700 ids.val( $.unique( attachment_ids ).join( ',' ) );
701 }
702 } );
703 }
704 }
705
706 } )( jQuery );