mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-10-03 22:27:04 +00:00
Media: Improve form validation errors handling when editing images.
* Use the same check for a numeric value used on the crop fields on all the other fields: don't display "NaN", just empty the field. * Remove the inline script that runs the initialization of the image editor and call it after the editor UI is fully ready. Props afercia. Fixes #36316. git-svn-id: https://develop.svn.wordpress.org/trunk@37966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -8,6 +8,10 @@ var imageEdit = window.imageEdit = {
|
||||
_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;
|
||||
},
|
||||
|
||||
@@ -79,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 );
|
||||
@@ -361,6 +369,8 @@ var imageEdit = window.imageEdit = {
|
||||
btn.removeClass( 'button-activated' );
|
||||
spin.removeClass( 'is-active' );
|
||||
});
|
||||
// Initialise the Image Editor now that everything is ready.
|
||||
imageEdit.init( postid );
|
||||
});
|
||||
|
||||
return dfd;
|
||||
@@ -586,12 +596,16 @@ var imageEdit = window.imageEdit = {
|
||||
});
|
||||
},
|
||||
|
||||
setNumSelection : function(postid) {
|
||||
setNumSelection : function( postid, el ) {
|
||||
var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid),
|
||||
x = this.intval( elX.val() ), y = this.intval( elY.val() ),
|
||||
img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
|
||||
sizer = this.hold.sizer, x1, y1, x2, y2, ias = this.iasapi;
|
||||
|
||||
if ( false === this.validateNumeric( el ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( x < 1 ) {
|
||||
elX.val('');
|
||||
return false;
|
||||
@@ -650,8 +664,7 @@ var imageEdit = window.imageEdit = {
|
||||
y = this.intval( $('#imgedit-crop-height-' + postid).val() ),
|
||||
h = $('#image-preview-' + postid).height();
|
||||
|
||||
if ( !this.intval( $(el).val() ) ) {
|
||||
$(el).val('');
|
||||
if ( false === this.validateNumeric( el ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -676,6 +689,13 @@ var imageEdit = window.imageEdit = {
|
||||
this.iasapi.update();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
validateNumeric: function( el ) {
|
||||
if ( ! this.intval( $( el ).val() ) ) {
|
||||
$( el ).val( '' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
||||
|
||||
Reference in New Issue
Block a user