Make WordPress Core

Ticket #11477: ticket-11477-parts1-3-ver1.patch

File ticket-11477-parts1-3-ver1.patch, 2.2 KB (added by miqrogroove, 15 years ago)

First 3 patches combined for clarity.

  • image-edit.dev.js

     
    299299        },
    300300
    301301        initCrop : function(postid, image, parent) {
    302                 var t = this, selW = $('#imgedit-sel-width-' + postid),
    303                         selH = $('#imgedit-sel-height-' + postid);
     302                var t = this;
    304303
    305304                t.iasapi = $(image).imgAreaSelect({
    306305                        parent: parent,
     
    335334                        },
    336335
    337336                        onSelectChange: function(img, c) {
    338                                 var sizer = imageEdit.hold.sizer;
    339                                 selW.val( imageEdit.round(c.width / sizer) );
    340                                 selH.val( imageEdit.round(c.height / sizer) );
     337                                imageEdit.setSelectionInputValues(c.width, c.height);
    341338                        }
    342339                });
    343340        },
     341       
     342        setSelectionInputValues : function(newwidth, newheight) {
     343                var selW = $('#imgedit-sel-width-' + this.postid),
     344                        selH = $('#imgedit-sel-height-' + this.postid),
     345                        sizer = this.hold.sizer;
    344346
     347                selW.val( this.round(newwidth / sizer) );
     348                selH.val( this.round(newheight / sizer) );
     349        },
     350
    345351        setCropSelection : function(postid, c) {
    346352                var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
    347353                        sizer = this.hold['sizer'];
     
    535541        },
    536542
    537543        setRatioSelection : function(postid, n, el) {
    538                 var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ),
     544                var sel, r, x = parseFloat( $('#imgedit-crop-width-' + postid).val() ),
    539545                        y = this.intval( $('#imgedit-crop-height-' + postid).val() ),
    540546                        h = $('#image-preview-' + postid).height();
    541547
     
    550556                        });
    551557
    552558                        if ( sel = this.iasapi.getSelection(true) ) {
    553                                 r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) );
     559                                newy2 = sel.y1 + Math.round((sel.x2 - sel.x1) / (x / y));
    554560
    555                                 if ( r > h ) {
    556                                         r = h;
    557                                         if ( n )
    558                                                 $('#imgedit-crop-height-' + postid).val('');
    559                                         else
    560                                                 $('#imgedit-crop-width-' + postid).val('');
     561                                if ( newy2 > h ) {
     562                                        newy2 = h;
     563                                        newx2 = sel.x1 + Math.round((newy2 - sel.y1) * (x / y));
     564                                } else {
     565                                        newx2 = sel.x2;
    561566                                }
    562567
    563                                 this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r );
     568                                this.iasapi.setSelection( sel.x1, sel.y1, newx2, newy2 );
    564569                                this.iasapi.update();
     570                                this.setSelectionInputValues(newx2 - sel.x1, newy2 - sel.y1);
    565571                        }
    566572                }
    567573        }