PluginProbe ʕ •ᴥ•ʔ
Responsive Lightbox & Gallery / 2.3.1
Responsive Lightbox & Gallery v2.3.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-widgets.js
responsive-lightbox / js Last commit date
admin-folders.js 5 years ago admin-galleries.js 5 years ago admin-gallery.js 5 years ago admin-media.js 5 years ago admin-plugins.js 5 years ago admin-widgets.js 5 years ago admin.js 5 years ago front-basicmasonry.js 5 years ago front-basicslider.js 5 years ago front.js 5 years ago gutenberg.min.js 5 years ago
admin-widgets.js
251 lines
1 ( function( window, $ ) {
2
3 /* Gallery widget */
4 var rl_galleries = [ ],
5 rl_gallery_frames = [ ],
6 rl_gallery_ids = [ ],
7 rl_gallery_images = [ ];
8
9 /* Single image widget */
10 var rl_image_frame,
11 rl_image_container,
12 rl_image_input;
13
14 // ready event
15 $( function() {
16 init_rl_gallery_widget();
17 init_rl_image_widget();
18 } );
19
20 // custom events trigger
21 $( document ).on( 'widget-updated widget-added', function() {
22 init_rl_gallery_widget();
23 init_rl_image_widget();
24 } );
25
26 function init_rl_gallery_widget() {
27 rl_galleries = $( '.rl-gallery-widget' );
28
29 if ( rl_galleries.length > 0 ) {
30 $.each( rl_galleries, function( index, gallery ) {
31 var gallery_id_attr = $( gallery ).attr( 'id' ),
32 gallery_id_arr = gallery_id_attr.match( /\-\d*\-/ );
33
34 if ( gallery_id_arr != null ) {
35 var gallery_id = gallery_id_arr.shift().replace( /-/g, '' );
36
37 rl_gallery_frames[gallery_id] = [ ];
38 rl_gallery_ids[gallery_id] = $( gallery ).find( '.rl-gallery-ids' );
39 rl_gallery_images[gallery_id] = $( gallery ).find( '.rl-gallery-images' );
40
41 // image ordering
42 rl_gallery_images[gallery_id].sortable( {
43 items: 'li.rl-gallery-image',
44 cursor: 'move',
45 scrollSensitivity: 40,
46 forcePlaceholderSize: true,
47 forceHelperSize: false,
48 helper: 'clone',
49 opacity: 0.65,
50 placeholder: 'rl-gallery-sortable-placeholder',
51 start: function( event, ui ) {
52 ui.item.css( 'border-color', '#f6f6f6' );
53 },
54 stop: function( event, ui ) {
55 ui.item.removeAttr( 'style' );
56 },
57 update: function( event, ui ) {
58 var attachment_ids = [ ];
59
60 $( rl_gallery_images[gallery_id] ).find( 'li.rl-gallery-image' ).each( function() {
61 var attachment_id = jQuery( this ).attr( 'data-attachment_id' );
62 attachment_ids.push( attachment_id );
63 } );
64
65 rl_gallery_ids[gallery_id].val( attachment_ids.join( ',' ) );
66 }
67 } );
68
69 // removing images
70 $( rl_gallery_images[gallery_id] ).on( 'click', '.rl-gallery-image-remove', function() {
71 var li = $( this ).closest( 'li.rl-gallery-image' ),
72 attachment_ids = rl_gallery_ids[gallery_id].val().split( ',' ).map( function( el ) {
73 return parseInt( el )
74 } );
75
76 // remove id
77 attachment_ids = _.without( attachment_ids, parseInt( li.data( 'attachment_id' ) ) );
78
79 // remove attachment
80 li.remove();
81
82 // update attachment ids
83 rl_gallery_ids[gallery_id].val( attachment_ids.join( ',' ) );
84
85 return false;
86 } );
87 }
88 } );
89 }
90
91 // open the modal on click
92 $( '.rl-gallery-widget-select' ).on( 'click', function( event ) {
93 event.preventDefault();
94
95 var gallery = $( this ).closest( '.rl-gallery-widget' ),
96 gallery_id = 0,
97 gallery_id_attr = $( gallery ).attr( 'id' ),
98 gallery_id_arr = gallery_id_attr.match( /\-\d*\-/ );
99
100 if ( gallery_id_arr != null ) {
101 gallery_id = gallery_id_arr.shift().replace( /-/g, '' );
102
103 var attachment_ids = rl_gallery_ids[gallery_id].val();
104
105 // if the media frame already exists, reopen it.
106 if ( rl_gallery_frames[gallery_id].length != 0 ) {
107 rl_gallery_frames[gallery_id].open();
108
109 return;
110 }
111
112 // create the media frame.
113 rl_gallery_frames[gallery_id] = wp.media( {
114 // Set the title of the modal.
115 title: rlArgsWidgets.textSelectImages,
116 multiple: true,
117 button: {
118 text: rlArgsWidgets.textUseImages
119 },
120 library: { type: 'image' },
121 multiple: true
122 } );
123
124 rl_gallery_frames[gallery_id].on( 'open', function() {
125 var selection = rl_gallery_frames[gallery_id].state().get( 'selection' ),
126 attachment_ids = rl_gallery_ids[gallery_id].val().split( ',' );
127
128 $.each( attachment_ids, function() {
129 let _this = this;
130
131 if ( ! isNaN( parseFloat( _this ) ) && isFinite( _this ) ) {
132 attachment = wp.media.attachment( this );
133 attachment.fetch();
134 selection.add( attachment ? [ attachment ] : [ ] );
135 }
136 } );
137 } );
138
139 // when an image is selected, run a callback.
140 rl_gallery_frames[gallery_id].on( 'select', function() {
141 var selection = rl_gallery_frames[gallery_id].state().get( 'selection' ),
142 selected_ids = [ ],
143 attachment_ids = rl_gallery_ids[gallery_id].val().split( ',' ).map( function( el ) {
144 return parseInt( el )
145 } );
146
147 if ( selection ) {
148 selection.map( function( attachment ) {
149 if ( attachment.id ) {
150 selected_ids.push( attachment.id );
151
152 // is image already in gallery?
153 if ( $.inArray( attachment.id, attachment_ids ) !== -1 ) {
154 return;
155 }
156
157 attachment_ids.push( attachment.id );
158 attachment = attachment.toJSON();
159
160 // is preview size available?
161 if ( attachment.sizes && attachment.sizes['thumbnail'] ) {
162 attachment.url = attachment.sizes['thumbnail'].url;
163 }
164
165 rl_gallery_images[gallery_id].append( '\
166 <li class="rl-gallery-image" data-attachment_id="' + attachment.id + '">\
167 <div class="rl-gallery-inner"><img src="' + attachment.url + '" /></div>\
168 <div class="rl-gallery-actions"><a href="#" class="rl-gallery-image-remove dashicons dashicons-no" title="' + rlArgsWidgets.textRemoveImage + '"></a></div>\
169 </li>'
170 );
171 }
172 } );
173 }
174
175 // assign copy of attachments ids
176 var copy = attachment_ids;
177
178 for ( var i = 0; i < attachment_ids.length; i++ ) {
179 // unselected image?
180 if ( $.inArray( attachment_ids[i], selected_ids ) === -1 ) {
181 $( rl_gallery_images[gallery_id] ).find( 'li.rl-gallery-image[data-attachment_id="' + attachment_ids[i] + '"]' ).remove();
182
183 copy = _.without( copy, attachment_ids[i] )
184 }
185 }
186
187 rl_gallery_ids[gallery_id].val( $.uniqueSort( copy ).join( ',' ) );
188 } );
189
190 // finally, open the modal.
191 rl_gallery_frames[gallery_id].open();
192 }
193 } );
194 }
195
196 function init_rl_image_widget() {
197 $( '.rl-image-widget-select' ).on( 'click', function( event ) {
198 var _this = $( this );
199
200 rl_image_container = _this.parent().find( '.rl-image-widget-content' );
201 rl_image_input = _this.parent().find( '.rl-image-widget-image-id' );
202
203 event.preventDefault();
204
205 // create a new media frame
206 rl_image_frame = wp.media( {
207 title: rlArgsWidgets.textSelectImage,
208 button: {
209 text: rlArgsWidgets.textUseImage
210 },
211 library: { type: 'image' },
212 multiple: false
213 } );
214
215 // when an image is selected in the media frame...
216 rl_image_frame.on( 'select', function() {
217 // get media attachment details from the frame state
218 var attachment = rl_image_frame.state().get( 'selection' ).first().toJSON();
219
220 // send the attachment URL to our custom image input field.
221 rl_image_container.html( '<img src="' + attachment.url + '" alt="" />' );
222
223 // send the attachment id to our hidden input
224 rl_image_input.val( attachment.id );
225 } );
226
227 // when an image is already selected in the media frame...
228 rl_image_frame.on( 'open', function() {
229 var selection = rl_image_frame.state().get( 'selection' );
230
231 // get current image
232 var attachment = wp.media.attachment( rl_image_input.val() );
233 attachment.fetch();
234
235 // preselect in media frame
236 selection.add( attachment ? [ attachment ] : [ ] );
237 } );
238
239 rl_image_frame.open();
240 } );
241
242 $( '.rl-image-link-to' ).on( 'change', function() {
243 if ( $( this ).val() == 'custom' ) {
244 $( this ).parent().next().slideDown( 'fast' );
245 } else {
246 $( this ).parent().next().slideUp( 'fast' );
247 }
248 } );
249 }
250
251 } )( this, jQuery );