Make WordPress Core

Changeset 26292


Ignore:
Timestamp:
11/20/2013 10:46:43 PM (11 years ago)
Author:
SergeyBiryukov
Message:

Fix JSHint errors in image-edit.js.

props dougwollison.
fixes #26000.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/image-edit.js

    r25547 r26292  
    1 var imageEdit;
     1/* global imageEditL10n, ajaxurl, confirm */
    22
    33(function($) {
    4 imageEdit = {
     4var imageEdit = window.imageEdit = {
    55    iasapi : {},
    66    hold : {},
     
    2121    },
    2222
    23     init : function(postid, nonce) {
     23    init : function(postid) {
    2424        var t = this, old = $('#image-editor-' + t.postid),
    2525            x = t.intval( $('#imgedit-x-' + postid).val() ),
    2626            y = t.intval( $('#imgedit-y-' + postid).val() );
    2727
    28         if ( t.postid != postid && old.length )
     28        if ( t.postid !== postid && old.length ) {
    2929            t.close(t.postid);
    30 
    31         t.hold['w'] = t.hold['ow'] = x;
    32         t.hold['h'] = t.hold['oh'] = y;
    33         t.hold['xy_ratio'] = x / y;
    34         t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() );
     30        }
     31
     32        t.hold.w = t.hold.ow = x;
     33        t.hold.h = t.hold.oh = y;
     34        t.hold.xy_ratio = x / y;
     35        t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
    3536        t.postid = postid;
    3637        $('#imgedit-response-' + postid).empty();
     
    3940            var k = e.keyCode;
    4041
    41             if ( 36 < k && k < 41 )
    42                 $(this).blur()
    43 
    44             if ( 13 == k ) {
     42            if ( 36 < k && k < 41 ) {
     43                $(this).blur();
     44            }
     45
     46            if ( 13 === k ) {
    4547                e.preventDefault();
    4648                e.stopPropagation();
     
    5355        var wait = $('#imgedit-wait-' + postid);
    5456
    55         if ( toggle )
     57        if ( toggle ) {
    5658            wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast');
    57         else
     59        } else {
    5860            wait.fadeOut('fast');
     61        }
    5962    },
    6063
     
    7376
    7477        if ( x ) {
    75             h1 = (w.val() != '') ? Math.round( w.val() / this.hold['xy_ratio'] ) : '';
     78            h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : '';
    7679            h.val( h1 );
    7780        } else {
    78             w1 = (h.val() != '') ? Math.round( h.val() * this.hold['xy_ratio'] ) : '';
     81            w1 = ( h.val() !== '' ) ? Math.round( h.val() * this.hold.xy_ratio ) : '';
    7982            w.val( w1 );
    8083        }
    8184
    82         if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) )
     85        if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) {
    8386            warn.css('visibility', 'visible');
    84         else
     87        } else {
    8588            warn.css('visibility', 'hidden');
     89        }
    8690    },
    8791
    8892    getSelRatio : function(postid) {
    89         var x = this.hold['w'], y = this.hold['h'],
     93        var x = this.hold.w, y = this.hold.h,
    9094            X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
    9195            Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
    9296
    93         if ( X && Y )
     97        if ( X && Y ) {
    9498            return X + ':' + Y;
    95 
    96         if ( x && y )
     99        }
     100
     101        if ( x && y ) {
    97102            return x + ':' + y;
     103        }
    98104
    99105        return '1:1';
     
    104110        var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
    105111
    106         if ( history != '' ) {
     112        if ( history !== '' ) {
    107113            history = JSON.parse(history);
    108114            pop = this.intval( $('#imgedit-undone-' + postid).val() );
     
    116122            if ( setSize ) {
    117123                if ( !history.length ) {
    118                     this.hold['w'] = this.hold['ow'];
    119                     this.hold['h'] = this.hold['oh'];
     124                    this.hold.w = this.hold.ow;
     125                    this.hold.h = this.hold.oh;
    120126                    return '';
    121127                }
     
    126132
    127133                if ( o ) {
    128                     this.hold['w'] = o.fw;
    129                     this.hold['h'] = o.fh;
     134                    this.hold.w = o.fw;
     135                    this.hold.h = o.fh;
    130136                }
    131137            }
     
    168174                max1 = Math.max( t.hold.w, t.hold.h );
    169175                max2 = Math.max( $(img).width(), $(img).height() );
    170                 t.hold['sizer'] = max1 > max2 ? max2 / max1 : 1;
     176                t.hold.sizer = max1 > max2 ? max2 / max1 : 1;
    171177
    172178                t.initCrop(postid, img, parent);
    173179                t.setCropSelection(postid, 0);
    174180
    175                 if ( (typeof callback != "unknown") && callback != null )
     181                if ( (typeof callback !== 'undefined') && callback !== null ) {
    176182                    callback();
    177 
    178                 if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 )
     183                }
     184
     185                if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === 0 ) {
    179186                    $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
    180                 else
     187                } else {
    181188                    $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
     189                }
    182190
    183191                t.toggleEditor(postid, 0);
     
    193201        var t = this, data, w, h, fw, fh;
    194202
    195         if ( t.notsaved(postid) )
    196             return false;
     203        if ( t.notsaved(postid) ) {
     204            return false;
     205        }
    197206
    198207        data = {
     
    202211        };
    203212
    204         if ( 'scale' == action ) {
     213        if ( 'scale' === action ) {
    205214            w = $('#imgedit-scale-width-' + postid),
    206215            h = $('#imgedit-scale-height-' + postid),
     
    216225            }
    217226
    218             if ( fw == t.hold.ow || fh == t.hold.oh )
     227            if ( fw === t.hold.ow || fh === t.hold.oh ) {
    219228                return false;
     229            }
    220230
    221231            data['do'] = 'scale';
    222             data['fwidth'] = fw;
    223             data['fheight'] = fh;
    224         } else if ( 'restore' == action ) {
     232            data.fwidth = fw;
     233            data.fheight = fh;
     234        } else if ( 'restore' === action ) {
    225235            data['do'] = 'restore';
    226236        } else {
     
    238248        var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0);
    239249
    240         if ( '' == history )
    241             return false;
     250        if ( '' === history ) {
     251            return false;
     252        }
    242253
    243254        this.toggleEditor(postid, 1);
     
    261272            }
    262273
    263             if ( ret.fw && ret.fh )
     274            if ( ret.fw && ret.fh ) {
    264275                $('#media-dims-' + postid).html( ret.fw + ' &times; ' + ret.fh );
    265 
    266             if ( ret.thumbnail )
     276            }
     277
     278            if ( ret.thumbnail ) {
    267279                $('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail);
    268 
    269             if ( ret.msg )
     280            }
     281
     282            if ( ret.msg ) {
    270283                $('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>');
     284            }
    271285
    272286            imageEdit.close(postid);
     
    317331            minHeight: 3,
    318332
    319             onInit: function(img, c) {
     333            onInit: function() {
    320334                parent.children().mousedown(function(e){
    321335                    var ratio = false, sel, defRatio;
     
    333347            },
    334348
    335             onSelectStart: function(img, c) {
     349            onSelectStart: function() {
    336350                imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1);
    337351            },
     
    351365    setCropSelection : function(postid, c) {
    352366        var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128',
    353             sizer = this.hold['sizer'];
     367            sizer = this.hold.sizer;
    354368            min = min.split(':');
    355369            c = c || 0;
     
    378392        warn = warn || false;
    379393
    380         if ( warn && this.notsaved(postid) )
    381             return false;
     394        if ( warn && this.notsaved(postid) ) {
     395            return false;
     396        }
    382397
    383398        this.iasapi = {};
     
    391406    notsaved : function(postid) {
    392407        var h = $('#imgedit-history-' + postid).val(),
    393             history = (h != '') ? JSON.parse(h) : new Array(),
     408            history = ( h !== '' ) ? JSON.parse(h) : [],
    394409            pop = this.intval( $('#imgedit-undone-' + postid).val() );
    395410
    396411        if ( pop < history.length ) {
    397             if ( confirm( $('#imgedit-leaving-' + postid).html() ) )
     412            if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) {
    398413                return false;
     414            }
    399415            return true;
    400416        }
     
    404420    addStep : function(op, postid, nonce) {
    405421        var t = this, elem = $('#imgedit-history-' + postid),
    406         history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array(),
     422        history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [],
    407423        undone = $('#imgedit-undone-' + postid),
    408424        pop = t.intval(undone.val());
     
    424440
    425441    rotate : function(angle, postid, nonce, t) {
    426         if ( $(t).hasClass('disabled') )
    427             return false;
    428 
    429         this.addStep({ 'r': { 'r': angle, 'fw': this.hold['h'], 'fh': this.hold['w'] }}, postid, nonce);
     442        if ( $(t).hasClass('disabled') ) {
     443            return false;
     444        }
     445
     446        this.addStep({ 'r': { 'r': angle, 'fw': this.hold.h, 'fh': this.hold.w }}, postid, nonce);
    430447    },
    431448
    432449    flip : function (axis, postid, nonce, t) {
    433         if ( $(t).hasClass('disabled') )
    434             return false;
    435 
    436         this.addStep({ 'f': { 'f': axis, 'fw': this.hold['w'], 'fh': this.hold['h'] }}, postid, nonce);
     450        if ( $(t).hasClass('disabled') ) {
     451            return false;
     452        }
     453
     454        this.addStep({ 'f': { 'f': axis, 'fw': this.hold.w, 'fh': this.hold.h }}, postid, nonce);
    437455    },
    438456
     
    442460            h = this.intval( $('#imgedit-sel-height-' + postid).val() );
    443461
    444         if ( $(t).hasClass('disabled') || sel == '' )
    445             return false;
     462        if ( $(t).hasClass('disabled') || sel === '' ) {
     463            return false;
     464        }
    446465
    447466        sel = JSON.parse(sel);
    448467        if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
    449             sel['fw'] = w;
    450             sel['fh'] = h;
     468            sel.fw = w;
     469            sel.fh = h;
    451470            this.addStep({ 'c': sel }, postid, nonce);
    452471        }
     
    457476            pop = t.intval( elem.val() ) + 1;
    458477
    459         if ( button.hasClass('disabled') )
     478        if ( button.hasClass('disabled') ) {
    460479            return;
     480        }
    461481
    462482        elem.val(pop);
    463483        t.refreshEditor(postid, nonce, function() {
    464484            var elem = $('#imgedit-history-' + postid),
    465             history = (elem.val() != '') ? JSON.parse(elem.val()) : new Array();
     485            history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [];
    466486
    467487            t.setDisabled($('#image-redo-' + postid), true);
     
    474494            pop = t.intval( elem.val() ) - 1;
    475495
    476         if ( button.hasClass('disabled') )
     496        if ( button.hasClass('disabled') ) {
    477497            return;
     498        }
    478499
    479500        elem.val(pop);
     
    488509            x = this.intval( elX.val() ), y = this.intval( elY.val() ),
    489510            img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
    490             sizer = this.hold['sizer'], x1, y1, x2, y2, ias = this.iasapi;
     511            sizer = this.hold.sizer, x1, y1, x2, y2, ias = this.iasapi;
    491512
    492513        if ( x < 1 ) {
     
    528549        num = Math.round(num);
    529550
    530         if ( this.hold.sizer > 0.6 )
     551        if ( this.hold.sizer > 0.6 ) {
    531552            return num;
     553        }
    532554
    533555        s = num.toString().slice(-1);
    534556
    535         if ( '1' == s )
     557        if ( '1' === s ) {
    536558            return num - 1;
    537         else if ( '9' == s )
     559        } else if ( '9' === s ) {
    538560            return num + 1;
     561        }
    539562
    540563        return num;
     
    557580
    558581            if ( sel = this.iasapi.getSelection(true) ) {
    559                 r = Math.ceil( sel.y1 + ((sel.x2 - sel.x1) / (x / y)) );
     582                r = Math.ceil( sel.y1 + ( ( sel.x2 - sel.x1 ) / ( x / y ) ) );
    560583
    561584                if ( r > h ) {
    562585                    r = h;
    563                     if ( n )
     586                    if ( n ) {
    564587                        $('#imgedit-crop-height-' + postid).val('');
    565                     else
     588                    } else {
    566589                        $('#imgedit-crop-width-' + postid).val('');
     590                    }
    567591                }
    568592
     
    572596        }
    573597    }
    574 }
     598};
    575599})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.