Last active
August 29, 2015 14:02
-
-
Save bordoni/34384a519b7c310d74be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.ajax({ | |
| 'url': ajaxurl, | |
| 'data': { | |
| 'action': data.crop_action, | |
| 'crop': data.crop, | |
| 'attachment': data.$.return.val() | |
| }, | |
| 'dataType': 'json', | |
| 'type': 'POST', | |
| 'success': function (response, textStatus, jqXHR){ | |
| if (typeof response !== 'object') | |
| response = { 'status': false, 'message': data.error }; | |
| console.log(response); | |
| if (!response.status) | |
| return data.$.uploader.trigger('flag.cropper', ['is_empty']).trigger('unflag.cropper', ['is_loading', response.message]); | |
| data.$.img = $('<img>').attr('src', response.image.url + "?r=" + parseInt(new Date().getTime()/1000, 10)); | |
| data.$.img.on({ | |
| 'load': function() { | |
| $(this).siblings('img').remove(); | |
| data.$.uploader.trigger('unflag.cropper', ['is_loading']).trigger('flag.cropper', ['is_loaded']) | |
| } | |
| }).appendTo(data.$.images); | |
| }, | |
| 'error': function (jqXHR, textStatus, errorThrow){ | |
| return data.$.uploader.trigger('unflag.cropper', ['is_loading', data.error]).trigger('flag.cropper', ['is_empty']); | |
| }, | |
| 'complete': function (jqXHR, textStatus){ | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action('wp_ajax_javascript_action_value', "ajax_func_action"); | |
| add_action('wp_ajax_nopriv_javascript_action_value', 'ajax_func_action'); | |
| function ajax_func_action() { | |
| if ( ! defined( 'DOING_AJAX' ) ) { | |
| return; | |
| } | |
| $response = (object) array( | |
| 'status' => false, | |
| 'message' => __("Houve um erro na requisição"), | |
| ); | |
| $request = (object) array( | |
| 'width' => absint($_POST['width']), | |
| 'height' => absint($_POST['height']) | |
| ); | |
| check_ajax_referer( "javascript_nonce_value" ); | |
| $response->image = (object) array( | |
| 'url' => esc_url($image[0]), | |
| 'width' => absint($image[1]), | |
| 'height' => absint($image[2]), | |
| ); | |
| $response->ratio = $response->image->width/$response->image->height; | |
| exit(json_encode($response)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment