diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-content/plugins/portfolio/js/script.js --- a/wp/wp-content/plugins/portfolio/js/script.js Tue Jun 09 11:14:17 2015 +0000 +++ b/wp/wp-content/plugins/portfolio/js/script.js Mon Oct 14 17:39:30 2019 +0200 @@ -1,79 +1,165 @@ -function update_images() { - (function($){ - setMessage( "
" + prtfl_var.update_img_message + "
" ); - var curr = 0; - $.ajax({ - url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', - type: "POST", - data: "action1=get_all_attachment" + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, - success: function( result ) { - var list = eval( '(' + result + ')' ); - if ( ! list ) { - setError( "" + prtfl_var.not_found_img_info + "
" ); - $( "#ajax_update_images" ).removeAttr( "disabled" ); - return; - } - $( '#prtfl_img_loader' ).show(); +function prtfl_setMessage( msg ) { + ( function( $ ){ + $( ".error" ).hide(); + $( ".prtfl_image_update_message" ).html( msg ).show(); + } )( jQuery ); +} + +function prtfl_setError( msg ) { + ( function( $ ){ + $( ".prtfl_image_update_message" ).hide(); + $( ".error" ).html( msg ).show();; + } )( jQuery ); +} - function updatenImageItem() { - if ( curr >= list.length ) { - $.ajax({ - url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', - type: "POST", - data: "action1=update_options" + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, - success: function( result ) { - /**/ - } - }); - $( "#ajax_update_images" ).removeAttr( "disabled" ); - setMessage("" + prtfl_var.img_success + "
"); - $( '#prtfl_img_loader' ).hide(); +( function( $ ) { + $( document ).ready( function() { + $( '#prtfl_ajax_update_images' ).click( function() { + prtfl_setMessage( "" + prtfl_vars.update_img_message + "
" ); + var curr = 0; + $.ajax( { + /* update_img_url */ + url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', + type: "POST", + data: "action1=get_all_attachment&prtfl_ajax_nonce_field=" + prtfl_vars.prtfl_nonce, + success: function( result ) { + var list = $.parseJSON( result ); + if ( ! list ) { + prtfl_setError( "" + prtfl_vars.not_found_img_info + "
" ); return; } - $.ajax({ - url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', - type: "POST", - data: "action1=update_image&id=" + list[ curr ].ID + '&prtfl_ajax_nonce_field=' + prtfl_var.prtfl_nonce, - success: function( result ) { - curr = curr + 1; - updatenImageItem(); - } - }); + $( '.prtfl_loader' ).css( 'display', 'inline-block' ); + + var curr = 0, + all_count = Object.keys( list ).length; + $.each( list, function( index, value ) { + $.ajax( { + url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', + type: "POST", + data: "action1=update_image&id=" + value + '&prtfl_ajax_nonce_field=' + prtfl_vars.prtfl_nonce, + success: function( result ) { + curr = curr + 1; + if ( curr >= all_count ) { + $.ajax( { + url: '../wp-admin/admin-ajax.php?action=prtfl_update_image', + type: "POST", + data: "action1=update_options&prtfl_ajax_nonce_field=" + prtfl_vars.prtfl_nonce, + } ); + prtfl_setMessage( "" + prtfl_vars.img_success + "
" ); + $( '.prtfl_loader' ).hide(); + } + } + } ); + } ); + }, + error: function( request, status, error ) { + prtfl_setError( "" + prtfl_vars.img_error + request.status + "
" ); } + } ); + } ); - updatenImageItem(); - }, - error: function( request, status, error ) { - setError( "" + prtfl_var.img_error + request.status + "
" ); + var is_rtl = ( $( 'body' ).hasClass( 'rtl' ) ); + + $( '#_prtfl_date_compl' ).datepicker( { + dateFormat : 'dd.mm.yy', + isRTL : is_rtl + } ); + + $( '[name^="prtfl_custom_image_size_"]' ).change( function() { + $( '#prtfl_ajax_update_images' ).attr( 'disabled', 'disabled' ); + } ); + + /* Portfolio images */ + var images_frame; + + $( '.prtfl_add_portfolio_images' ).on( 'click', 'a', function( event ) { + event.preventDefault(); + var $element = $( this ); + + /* If the media frame already exists, reopen it */ + if ( images_frame ) { + images_frame.open(); + return; } - }); - })(jQuery); -} -function setMessage( msg ) { - (function($){ - $( ".error" ).hide(); - $( ".updated" ).html( msg ); - $( ".updated" ).show(); - $( '#prtfl_settings_notice' ).hide(); - })(jQuery); -} + /* Create the media frame */ + images_frame = wp.media.frames.product_gallery = wp.media({ + title: $element.data( 'choose' ), + button: { + text: $element.data( 'update' ) + }, + states: [ + new wp.media.controller.Library( { + title: $element.data( 'choose' ), + filterable: 'all', + multiple: true + } ) + ] + } ); + + /* run a callback when an image is selected */ + images_frame.on( 'select', function() { + var selection = images_frame.state().get( 'selection' ); + var attachment_ids = $( '#prtfl_images' ).val(); + + selection.map( function( attachment ) { + attachment = attachment.toJSON(); + + if ( attachment.id ) { + attachment_ids = attachment_ids ? attachment_ids + ',' + attachment.id : attachment.id; + var attachment_image = attachment.sizes && attachment.sizes.thumbnail ? attachment.sizes.thumbnail.url : attachment.url; + + $( '#prtfl_images_container ul' ).append( '