PluginProbe
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress / 4.7.5
Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress v4.7.5
4.8.1 4.8.0 4.7.9 trunk 2.01 2.02 2.03 2.04 2.05 2.06 2.07 2.08 2.09 2.10 2.11 2.12 2011.1.01 2011.1.02 3.01 3.02 3.03 3.04 3.05 3.06 3.1 All 131 releases
gallery-plugin / js / script.js

script.js in Gallery by BestWebSoft – Customizable Image and Photo Galleries for WordPress 4.7.5, at js/script.js

326 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 function gllr_setMessage( msg ) {
2 ( function( $ ) {
3 $( ".error" ).hide();
4 $( ".gllr_image_update_message" ).html( msg ).show();
5 } )( jQuery );
6 }
7
8 function gllr_setError( msg ) {
9 ( function( $ ) {
10 $( ".gllr_image_update_message" ).hide();
11 $( ".error" ).html( msg ).show();
12 } )( jQuery );
13 }
14
15 ( function( $ ) {
16 $( document ).ready( function() {
17 /* include color-picker */
18 if ( $.fn.wpColorPicker ) {
19 $( '.gllr_color_field' ).wpColorPicker();
20 }
21
22 $( 'input[name="gllr_enable_image_opening"]' ).on( 'change', function() {
23 if( $( 'input[name="gllr_enable_image_opening"]' ).prop( 'checked' ) ) {
24 $( 'input[name="gllr_enable_lightbox"]' ).prop( 'checked', false );
25 $( 'input[name="gllr_enable_lightbox"]' ).attr( 'disabled', true );
26 $( 'input[name="gllr_enable_lightbox"]' ).trigger( 'change' );
27 } else {
28 $('input[name="gllr_enable_lightbox"]').removeAttr("disabled");
29 }
30 } );
31
32 $( '#gllr_ajax_update_images' ).click( function() {
33 gllr_setMessage( "<p>" + gllr_vars.update_img_message + "</p>" );
34 var curr = 0;
35 $.ajax( {
36 /* update_img_url */
37 url: '../wp-admin/admin-ajax.php?action=gllr_update_image',
38 type: "POST",
39 data: "action1=get_all_attachment&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce,
40 success: function( result ) {
41 var list = $.parseJSON( result );
42 if ( ! list ) {
43 gllr_setError( "<p>" + gllr_vars.not_found_img_info + "</p>" );
44 return;
45 }
46 $( '.gllr_loader' ).css( 'display', 'inline-block' );
47
48 var curr = 0,
49 all_count = Object.keys( list ).length;
50 $.each( list, function( index, value ) {
51 $.ajax( {
52 url: '../wp-admin/admin-ajax.php?action=gllr_update_image',
53 type: "POST",
54 data: "action1=update_image&id=" + value + '&gllr_ajax_nonce_field=' + gllr_vars.gllr_nonce,
55 success: function( result ) {
56 curr = curr + 1;
57 if ( curr >= all_count ) {
58 $.ajax( {
59 url: '../wp-admin/admin-ajax.php?action=gllr_update_image',
60 type: "POST",
61 data: "action1=update_options&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce,
62 } );
63 gllr_setMessage( "<p>" + gllr_vars.img_success + "</p>" );
64 $( '.gllr_loader' ).hide();
65 }
66 }
67 } );
68 } );
69 },
70 error: function( request, status, error ) {
71 gllr_setError( "<p>" + gllr_vars.img_error + request.status + "</p>" );
72 }
73 } );
74 } );
75
76 if ( $( window ).width() < 800 ) {
77 $( '.gllr_info_show' ).on( 'click', function( event ) {
78 event.preventDefault();
79 if ( $( this ).next( '.gllr_info' ).is( ':hidden' ) ) {
80 $( this ).next( '.gllr_info' ).show();
81 } else {
82 $( this ).next( '.gllr_info' ).hide();
83 }
84 } );
85 }
86
87 if ( ! $( '#post-body-content .attachments li' ).length )
88 $( '.gllr-media-bulk-select-button' ).hide();
89
90 $( '#gllr-media-insert' ).click( function open_media_window() {
91 if ( this.window === undefined ) {
92 this.window = wp.media( {
93 title: gllr_vars.wp_media_title,
94 library: { type: 'image' },
95 multiple: true,
96 button: { text: gllr_vars.wp_media_button }
97 } );
98
99 var self = this; /* Needed to retrieve our variable in the anonymous function below */
100 this.window.on( 'select', function() {
101 if ( 'grid' == $( 'input[name="gllr_mode"]' ).val() ) {
102 var all = self.window.state().get( 'selection' ).toJSON();
103 all.forEach( function( item, i, arr ) {
104 $.ajax({
105 url: '../wp-admin/admin-ajax.php',
106 type: "POST",
107 data: "action=gllr_add_from_media&add_id="+item.id+"&post_id="+$( '#post_ID' ).val()+"&mode=grid&gllr_ajax_add_nonce=" + gllr_vars.gllr_add_nonce,
108 success: function( result ) {
109 $( '#post-body-content .attachments' ).prepend( result );
110 $( '#post-body-content .attachments li:first-child' ).addClass( 'success' );
111 $( '.gllr-media-bulk-select-button' ).show();
112
113 if ( ! $( '.attachments' ).data( 'ui-sortable' ) ) {
114 gllr_add_sortable();
115 }
116 }
117 } );
118 $( '<input type="hidden" name="gllr_new_image[]" id="gllr_new_image" value="' + item.id + '" />' ).appendTo( '#hidden' );
119 } );
120 } else {
121 var all = self.window.state().get( 'selection' ).toJSON();
122 all.forEach( function( item, i, arr ) {
123 $.ajax({
124 url: '../wp-admin/admin-ajax.php',
125 type: "POST",
126 data: "action=gllr_add_from_media&add_id="+item.id+"&post_id="+$( '#post_ID' ).val()+"&mode=list&gllr_ajax_add_nonce=" + gllr_vars.gllr_add_nonce,
127 success: function( result ) {
128 $( '#the-list' ).prepend( result );
129 $( '#the-list tr:first-child' ).addClass( 'success' );
130 $( '#the-list tr.no-items' ).remove();
131 if ( ! $( '#the-list' ).data( 'ui-sortable' ) ) {
132 gllr_add_sortable();
133 }
134 }
135 } );
136 $( '<input type="hidden" name="gllr_new_image[]" id="gllr_new_image" value="' + item.id + '" />' ).appendTo( '#hidden' );
137 } );
138 }
139 } );
140 }
141
142 this.window.open();
143 return false;
144 } );
145
146 function gllr_add_sortable() {
147 if ( $.fn.sortable ) {
148 if ( $( "#the-list tr" ).length > 1 ) {
149 $( '#the-list' ).sortable( {
150 stop: function( event, ui ) {
151 var g = $( '#the-list' ).sortable( 'toArray', { handle: ":not(input)" } );
152 var f = g.length;
153 $.each( g,
154 function( k,l ) {
155 $( '#' + l + ' input[name^="_gallery_order"]' ).val( k + 1 );
156 }
157 );
158 }
159 } );
160 $( "#the-list input" ).on( 'click', function() { $( this ).focus(); } );
161 } else if ( $( ".attachments li" ).length > 1 ) {
162 $( '.attachments' ).sortable( {
163 stop: function( event, ui ) {
164 var g = $( '.attachments' ).sortable( 'toArray' );
165 var f = g.length;
166 $.each( g,
167 function( k,l ) {
168 $( '#' + l + ' input[name^="_gallery_order"]' ).val( k + 1 );
169 }
170 );
171 }
172 } );
173 }
174 }
175 }
176 gllr_add_sortable();
177
178 $( '.gllr-media-bulk-select-button' ).on( 'click', function() {
179 $( '.attachments' ).sortable( 'disable' ).addClass( 'bulk-selected' );
180 $( '.gllr-wp-filter' ).addClass( 'selected' );
181 $( '.gllr-media-attachment' ).on( 'click', function(){
182 if ( $( this ).hasClass( 'details' ) )
183 $( this ).removeClass( 'details' ).removeClass( 'selected' );
184 else
185 $( this ).addClass( 'details' ).addClass( 'selected' );
186 if ( $( '.gllr-media-attachment.selected' ).length > 0 )
187 $( '.gllr-media-bulk-delete-selected-button' ).removeAttr( 'disabled' );
188 else
189 $( '.gllr-media-bulk-delete-selected-button' ).attr( 'disabled', 'disabled' );
190 } );
191 $( '.gllr-media-check' ).on( 'click', function(){
192 if ( $( this ).parent().hasClass( 'details' ) )
193 $( this ).parent().removeClass( 'details' ).removeClass( 'selected' );
194 else
195 $( this ).parent().addClass( 'details' ).addClass( 'selected' );
196 if ( $( '.gllr-media-attachment.selected' ).length > 0 )
197 $( '.gllr-media-bulk-delete-selected-button' ).removeAttr( 'disabled' );
198 else
199 $( '.gllr-media-bulk-delete-selected-button' ).attr( 'disabled', 'disabled' );
200 return false;
201 } );
202 return false;
203 } );
204
205 $( '.gllr-media-bulk-cansel-select-button' ).on( 'click', function() {
206 $( '.attachments' ).sortable().removeClass( 'bulk-selected' );
207 $( '.attachments' ).sortable( 'option', 'disabled', false );
208 $( '.attachments li' ).removeClass( 'details selected' );
209 $( '.gllr-wp-filter' ).removeClass( 'selected' );
210 $( '.gllr-media-attachment' ).off( 'click' );
211 $( '.gllr-media-check' ).off( 'click' );
212 return false;
213 } );
214
215 $( document ).on( 'click', '.gllr-media-actions-delete', function() {
216 if ( window.confirm( gllr_vars.warnSingleDelete ) ) {
217 var gllr_attachment_id = $( this ).parent().find( '.gllr_attachment_id' ).val();
218 var gllr_post_id = $( this ).parent().find( '.gllr_post_id' ).val();
219
220 $.ajax( {
221 url: '../wp-admin/admin-ajax.php',
222 type: "POST",
223 data: "action=gllr_delete_image&delete_id_array=" + gllr_attachment_id + "&post_id=" + gllr_post_id + "&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce,
224 success: function( result ) {
225 if ( 'updated' == result ) {
226 $( '#post-' + gllr_attachment_id ).remove();
227 tb_remove();
228 if ( ! $( '#post-body-content .attachments li' ).length ) {
229 $( '.gllr-media-bulk-select-button' ).hide();
230 }
231 }
232 }
233 } );
234 }
235 } );
236
237 $( '.gllr-media-bulk-delete-selected-button' ).on( 'click', function() {
238 if ( 'disabled' != $( this ).attr( 'disabled' ) ) {
239 if ( window.confirm( gllr_vars.warnBulkDelete ) ) {
240 var delete_id_array = '';
241 $( '.attachments li.selected' ).each( function() {
242 delete_id_array += $( this ).attr( 'id' ).replace( 'post-', '' ) + ',';
243 } );
244 $( '.gllr-media-spinner' ).css( 'display', 'inline-block' );
245 $( '.attachments' ).attr( 'disabled', 'disabled' );
246 $.ajax( {
247 url: '../wp-admin/admin-ajax.php',
248 type: "POST",
249 data: "action=gllr_delete_image&delete_id_array=" + delete_id_array + "&post_id=" + $( '#post_ID' ).val() + "&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce,
250 success: function( result ) {
251 if ( 'updated' == result ) {
252 $( '.gllr-media-attachment.selected' ).remove();
253 $( '.gllr-media-bulk-delete-selected-button' ).attr( 'disabled', 'disabled' );
254 if ( ! $( '#post-body-content .attachments li' ).length ) {
255 $( '.gllr-media-bulk-cansel-select-button' ).trigger( 'click' );
256 $( '.gllr-media-bulk-select-button' ).hide();
257 }
258 }
259 $( '.gllr-media-spinner' ).css( 'display', 'none' );
260 $( '.attachments' ).removeAttr( 'disabled' );
261 }
262 } );
263 }
264 }
265 return false;
266 } );
267
268 $( '.post-type-gallery .view-switch a' ).on( 'click', function( event ) {
269 if ( window.confirm( gllr_vars.confirm_update_gallery ) ) {
270 event.preventDefault();
271 var mode = $( 'input[name="gllr_mode"]' ).val();
272 /* change view mode */
273 $.ajax( {
274 url: "../wp-admin/admin-ajax.php",
275 type: "POST",
276 data: "action=gllr_change_view_mode&mode=" + mode + "&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce,
277 success: function( result ) {
278 $( '#publishing-action .button-primary' ).click();
279 }
280 } );
281 }
282 } );
283
284 $( '#gllr-export-slider' ).on( 'click', function() {
285 $.ajax( {
286 url: ajaxurl,
287 type: "POST",
288 data: { action: 'gllr_export_slider', post_id: gllr_vars.post, post_title: gllr_vars.title, gllr_ajax_nonce_field: gllr_vars.gllr_nonce },
289 beforeSend: function() {
290 $( '.gllr_loader' ).css( 'display', 'inline-block' );
291 },
292 success: function () {
293 $( '.gllr_loader' ).hide();
294 $( '<div class="updated fade"><p><strong>' + gllr_vars.export_message + '</strong></p></div>' ).insertAfter( "#titlewrap" );
295 }
296 } );
297 } );
298
299 $( 'input[name="gllr_csv_file"]' ).on( 'change', function(){
300 $( '#bws_save_settings_notice' ).css( 'display', 'none' );
301 });
302 } );
303 } )( jQuery );
304
305 /* Create notice on a gallery page */
306 function gllr_notice_wiev( data_id ) {
307 ( function( $ ) {
308 /* function to send Ajax request to gallery notice */
309 gllr_notice_media_attach = function( post_id, thumb_id, typenow ) {
310 $.ajax( {
311 url: "../wp-admin/admin-ajax.php",
312 type: "POST",
313 data: "action=gllr_media_check&thumbnail_id=" + thumb_id + "&gllr_ajax_nonce_field=" + gllr_vars.gllr_nonce + "&post_type=" + typenow,
314 success: function( html ) {
315 if ( undefined != html.data ) {
316 $( ".media-frame-content" ).find( "#gllr_media_notice" ).html( html.data );
317 $( '.button.media-button-select' ).attr( 'disabled', 'disabled' );
318 } else {
319 $( '.button.media-button-select' ).removeAttr( 'disabled' );
320 }
321 }
322 } );
323 }
324 gllr_notice_media_attach( wp.media.view.settings.post.id, data_id, typenow );
325 } )( jQuery );
326 }