X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/256a3b381f63716209b3527d0a14442ae570c283..refs/tags/wordpress-4.7-scripts:/wp-admin/js/image-edit.js diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index 9eaf51bf..6af28dc8 100644 --- a/wp-admin/js/image-edit.js +++ b/wp-admin/js/image-edit.js @@ -5,18 +5,27 @@ var imageEdit = window.imageEdit = { iasapi : {}, hold : {}, postid : '', + _view : false, intval : function(f) { + /* + * Bitwise OR operator: one of the obscure ways to truncate floating point figures, + * worth reminding JavaScript doesn't have a distinct "integer" type. + */ return f | 0; }, - setDisabled : function(el, s) { + setDisabled : function( el, s ) { + /* + * `el` can be a single form element or a fieldset. Before #28864, the disabled state on + * some text fields was handled targeting $('input', el). Now we need to handle the + * disabled state on buttons too so we can just target `el` regardless if it's a single + * element or a fieldset because when a fieldset is disabled, its descendants are disabled too. + */ if ( s ) { - el.removeClass('disabled'); - $('input', el).removeAttr('disabled'); + el.removeClass( 'disabled' ).prop( 'disabled', false ); } else { - el.addClass('disabled'); - $('input', el).prop('disabled', true); + el.addClass( 'disabled' ).prop( 'disabled', true ); } }, @@ -55,14 +64,18 @@ var imageEdit = window.imageEdit = { var wait = $('#imgedit-wait-' + postid); if ( toggle ) { - wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast'); + wait.fadeIn( 'fast' ); } else { wait.fadeOut('fast'); } }, toggleHelp : function(el) { - $(el).siblings('.imgedit-help').slideToggle('fast'); + var $el = $( el ); + $el + .attr( 'aria-expanded', 'false' === $el.attr( 'aria-expanded' ) ? 'true' : 'false' ) + .parents( '.imgedit-group-top' ).toggleClass( 'imgedit-help-toggled' ).find( '.imgedit-help' ).slideToggle( 'fast' ); + return false; }, @@ -70,10 +83,14 @@ var imageEdit = window.imageEdit = { return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full'; }, - scaleChanged : function(postid, x) { + scaleChanged : function( postid, x, el ) { var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid), warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = ''; + if ( false === this.validateNumeric( el ) ) { + return; + } + if ( x ) { h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : ''; h.val( h1 ); @@ -164,9 +181,26 @@ var imageEdit = window.imageEdit = { 'rand': t.intval(Math.random() * 1000000) }; - img = $('') - .on('load', function() { - var max1, max2, parent = $('#imgedit-crop-' + postid), t = imageEdit; + img = $( '' ) + .on( 'load', { history: data.history }, function( event ) { + var max1, max2, + parent = $( '#imgedit-crop-' + postid ), + t = imageEdit, + historyObj; + + if ( '' !== event.data.history ) { + historyObj = JSON.parse( event.data.history ); + // If last executed action in history is a crop action. + if ( historyObj[historyObj.length - 1].hasOwnProperty( 'c' ) ) { + /* + * A crop action has completed and the crop button gets disabled + * ensure the undo button is enabled. + */ + t.setDisabled( $( '#image-undo-' + postid) , true ); + // Move focus to the undo button to avoid a focus loss. + $( '#image-undo-' + postid ).focus(); + } + } parent.empty().append(img); @@ -241,11 +275,18 @@ var imageEdit = window.imageEdit = { $.post(ajaxurl, data, function(r) { $('#image-editor-' + postid).empty().append(r); t.toggleEditor(postid, 0); + // refresh the attachment model so that changes propagate + if ( t._view ) { + t._view.refresh(); + } }); }, save : function(postid, nonce) { - var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0); + var data, + target = this.getTarget(postid), + history = this.filterHistory(postid, 0), + self = this; if ( '' === history ) { return false; @@ -266,7 +307,7 @@ var imageEdit = window.imageEdit = { var ret = JSON.parse(r); if ( ret.error ) { - $('#imgedit-response-' + postid).html('
' + ret.error + '
' + ret.error + '
' + ret.msg + '