]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/image-edit.js
Wordpress 4.6
[autoinstalls/wordpress.git] / wp-admin / js / image-edit.js
index ae7599230168dad7dafb21f32acb3011d495edb9..6af28dc84f393a8b4f04b51f4323f4ffc3f8b6e7 100644 (file)
@@ -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);