1 function update_images() { |
1 function prtfl_setMessage( msg ) { |
2 (function($){ |
2 ( function( $ ){ |
3 setMessage( "<p>" + prtfl_var.update_img_message + "</p>" ); |
3 $( ".error" ).hide(); |
4 var curr = 0; |
4 $( ".prtfl_image_update_message" ).html( msg ).show(); |
5 $.ajax({ |
5 } )( jQuery ); |
6 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
6 } |
7 type: "POST", |
|
8 data: "action1=get_all_attachment" + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, |
|
9 success: function( result ) { |
|
10 var list = eval( '(' + result + ')' ); |
|
11 if ( ! list ) { |
|
12 setError( "<p>" + prtfl_var.not_found_img_info + "</p>" ); |
|
13 $( "#ajax_update_images" ).removeAttr( "disabled" ); |
|
14 return; |
|
15 } |
|
16 $( '#prtfl_img_loader' ).show(); |
|
17 |
7 |
18 function updatenImageItem() { |
8 function prtfl_setError( msg ) { |
19 if ( curr >= list.length ) { |
9 ( function( $ ){ |
20 $.ajax({ |
10 $( ".prtfl_image_update_message" ).hide(); |
|
11 $( ".error" ).html( msg ).show();; |
|
12 } )( jQuery ); |
|
13 } |
|
14 |
|
15 ( function( $ ) { |
|
16 $( document ).ready( function() { |
|
17 $( '#prtfl_ajax_update_images' ).click( function() { |
|
18 prtfl_setMessage( "<p>" + prtfl_vars.update_img_message + "</p>" ); |
|
19 var curr = 0; |
|
20 $.ajax( { |
|
21 /* update_img_url */ |
|
22 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
|
23 type: "POST", |
|
24 data: "action1=get_all_attachment&prtfl_ajax_nonce_field=" + prtfl_vars.prtfl_nonce, |
|
25 success: function( result ) { |
|
26 var list = $.parseJSON( result ); |
|
27 if ( ! list ) { |
|
28 prtfl_setError( "<p>" + prtfl_vars.not_found_img_info + "</p>" ); |
|
29 return; |
|
30 } |
|
31 $( '.prtfl_loader' ).css( 'display', 'inline-block' ); |
|
32 |
|
33 var curr = 0, |
|
34 all_count = Object.keys( list ).length; |
|
35 $.each( list, function( index, value ) { |
|
36 $.ajax( { |
21 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
37 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
22 type: "POST", |
38 type: "POST", |
23 data: "action1=update_options" + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, |
39 data: "action1=update_image&id=" + value + '&prtfl_ajax_nonce_field=' + prtfl_vars.prtfl_nonce, |
24 success: function( result ) { |
40 success: function( result ) { |
25 /**/ |
41 curr = curr + 1; |
|
42 if ( curr >= all_count ) { |
|
43 $.ajax( { |
|
44 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
|
45 type: "POST", |
|
46 data: "action1=update_options&prtfl_ajax_nonce_field=" + prtfl_vars.prtfl_nonce, |
|
47 } ); |
|
48 prtfl_setMessage( "<p>" + prtfl_vars.img_success + "</p>" ); |
|
49 $( '.prtfl_loader' ).hide(); |
|
50 } |
26 } |
51 } |
27 }); |
52 } ); |
28 $( "#ajax_update_images" ).removeAttr( "disabled" ); |
53 } ); |
29 setMessage("<p>" + prtfl_var.img_success + "</p>"); |
54 }, |
30 $( '#prtfl_img_loader' ).hide(); |
55 error: function( request, status, error ) { |
31 return; |
56 prtfl_setError( "<p>" + prtfl_vars.img_error + request.status + "</p>" ); |
|
57 } |
|
58 } ); |
|
59 } ); |
|
60 |
|
61 var is_rtl = ( $( 'body' ).hasClass( 'rtl' ) ); |
|
62 |
|
63 $( '#_prtfl_date_compl' ).datepicker( { |
|
64 dateFormat : 'dd.mm.yy', |
|
65 isRTL : is_rtl |
|
66 } ); |
|
67 |
|
68 $( '[name^="prtfl_custom_image_size_"]' ).change( function() { |
|
69 $( '#prtfl_ajax_update_images' ).attr( 'disabled', 'disabled' ); |
|
70 } ); |
|
71 |
|
72 /* Portfolio images */ |
|
73 var images_frame; |
|
74 |
|
75 $( '.prtfl_add_portfolio_images' ).on( 'click', 'a', function( event ) { |
|
76 event.preventDefault(); |
|
77 var $element = $( this ); |
|
78 |
|
79 /* If the media frame already exists, reopen it */ |
|
80 if ( images_frame ) { |
|
81 images_frame.open(); |
|
82 return; |
|
83 } |
|
84 |
|
85 /* Create the media frame */ |
|
86 images_frame = wp.media.frames.product_gallery = wp.media({ |
|
87 title: $element.data( 'choose' ), |
|
88 button: { |
|
89 text: $element.data( 'update' ) |
|
90 }, |
|
91 states: [ |
|
92 new wp.media.controller.Library( { |
|
93 title: $element.data( 'choose' ), |
|
94 filterable: 'all', |
|
95 multiple: true |
|
96 } ) |
|
97 ] |
|
98 } ); |
|
99 |
|
100 /* run a callback when an image is selected */ |
|
101 images_frame.on( 'select', function() { |
|
102 var selection = images_frame.state().get( 'selection' ); |
|
103 var attachment_ids = $( '#prtfl_images' ).val(); |
|
104 |
|
105 selection.map( function( attachment ) { |
|
106 attachment = attachment.toJSON(); |
|
107 |
|
108 if ( attachment.id ) { |
|
109 attachment_ids = attachment_ids ? attachment_ids + ',' + attachment.id : attachment.id; |
|
110 var attachment_image = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; |
|
111 |
|
112 $( '#prtfl_images_container ul' ).append( '<li class="prtfl_single_image" data-attachment_id="' + attachment.id + '"><img src="' + attachment_image + '" /><span class="prtfl_delete_image"><a href="#" title="' + $element.data( 'delete' ) + '">' + $element.data( 'text' ) + '</a></span></li>' ); |
32 } |
113 } |
33 $.ajax({ |
114 } ); |
34 url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', |
115 |
35 type: "POST", |
116 $( '#prtfl_images' ).val( attachment_ids ); |
36 data: "action1=update_image&id=" + list[ curr ].ID + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, |
117 } ); |
37 success: function( result ) { |
118 |
38 curr = curr + 1; |
119 /* Open the modal */ |
39 updatenImageItem(); |
120 images_frame.open(); |
40 } |
121 } ); |
41 }); |
122 |
|
123 /* Add image ordering */ |
|
124 if ( $( '#prtfl_images_container ul' ).length > 0 ) { |
|
125 $( '#prtfl_images_container ul' ).sortable({ |
|
126 items: 'li.prtfl_single_image', |
|
127 cursor: 'move', |
|
128 scrollSensitivity: 40, |
|
129 forcePlaceholderSize: true, |
|
130 forceHelperSize: false, |
|
131 helper: 'clone', |
|
132 opacity: 0.65, |
|
133 placeholder: 'prtfl-sortable-placeholder', |
|
134 start: function( event, ui ) { |
|
135 ui.item.css( 'background-color', '#f6f6f6' ); |
|
136 }, |
|
137 stop: function( event, ui ) { |
|
138 ui.item.removeAttr( 'style' ); |
|
139 }, |
|
140 update: function() { |
|
141 var attachment_ids = ''; |
|
142 $( '#prtfl_images_container' ).find( 'ul li.prtfl_single_image' ).css( 'cursor', 'default' ).each( function() { |
|
143 var attachment_id = $( this ).attr( 'data-attachment_id' ); |
|
144 attachment_ids = attachment_ids + attachment_id + ','; |
|
145 } ); |
|
146 $( '#prtfl_images' ).val( attachment_ids ); |
42 } |
147 } |
|
148 } ); |
|
149 } |
43 |
150 |
44 updatenImageItem(); |
151 /* Remove image */ |
45 }, |
152 $( '#prtfl_images_container' ).on( 'click', '.prtfl_delete_image a', function() { |
46 error: function( request, status, error ) { |
153 $( this ).closest( 'li.prtfl_single_image' ).remove(); |
47 setError( "<p>" + prtfl_var.img_error + request.status + "</p>" ); |
154 var attachment_ids = ''; |
48 } |
|
49 }); |
|
50 })(jQuery); |
|
51 } |
|
52 |
155 |
53 function setMessage( msg ) { |
156 $( '#prtfl_images_container' ).find( 'ul li.prtfl_single_image' ).css( 'cursor', 'default' ).each( function() { |
54 (function($){ |
157 var attachment_id = $( this ).attr( 'data-attachment_id' ); |
55 $( ".error" ).hide(); |
158 attachment_ids = attachment_ids + attachment_id + ','; |
56 $( ".updated" ).html( msg ); |
159 } ); |
57 $( ".updated" ).show(); |
|
58 $( '#prtfl_settings_notice' ).hide(); |
|
59 })(jQuery); |
|
60 } |
|
61 |
160 |
62 function setError( msg ) { |
161 $( '#prtfl_images' ).val( attachment_ids ); |
63 (function($){ |
162 return false; |
64 $( ".updated" ).hide(); |
163 } ); |
65 $( ".error" ).html( msg ); |
164 } ); |
66 $( ".error" ).show(); |
165 } )( jQuery ); |
67 })(jQuery); |
|
68 } |
|
69 |
|
70 (function($) { |
|
71 $(document).ready( function() { |
|
72 $( '#prtfl_form_image_size input' ).bind( "change click select", function() { |
|
73 if ( $( this ).attr( 'type' ) != 'submit' ) { |
|
74 $( '.updated.fade' ).css( 'display', 'none' ); |
|
75 $( '#prtfl_settings_notice' ).css( 'display', 'block' ); |
|
76 }; |
|
77 }); |
|
78 }); |
|
79 })(jQuery); |
|