_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;
},
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 );
btn.removeClass( 'button-activated' );
spin.removeClass( 'is-active' );
});
+ // Initialise the Image Editor now that everything is ready.
+ imageEdit.init( postid );
});
return dfd;
});
},
- 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;
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;
}
this.iasapi.update();
}
}
+ },
+
+ validateNumeric: function( el ) {
+ if ( ! this.intval( $( el ).val() ) ) {
+ $( el ).val( '' );
+ return false;
+ }
}
};
})(jQuery);