Changeset 26292
- Timestamp:
- 11/20/2013 10:46:43 PM (11 years ago)
- 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 */ 2 2 3 3 (function($) { 4 imageEdit = {4 var imageEdit = window.imageEdit = { 5 5 iasapi : {}, 6 6 hold : {}, … … 21 21 }, 22 22 23 init : function(postid , nonce) {23 init : function(postid) { 24 24 var t = this, old = $('#image-editor-' + t.postid), 25 25 x = t.intval( $('#imgedit-x-' + postid).val() ), 26 26 y = t.intval( $('#imgedit-y-' + postid).val() ); 27 27 28 if ( t.postid != postid && old.length )28 if ( t.postid !== postid && old.length ) { 29 29 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() ); 35 36 t.postid = postid; 36 37 $('#imgedit-response-' + postid).empty(); … … 39 40 var k = e.keyCode; 40 41 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 ) { 45 47 e.preventDefault(); 46 48 e.stopPropagation(); … … 53 55 var wait = $('#imgedit-wait-' + postid); 54 56 55 if ( toggle ) 57 if ( toggle ) { 56 58 wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast'); 57 else59 } else { 58 60 wait.fadeOut('fast'); 61 } 59 62 }, 60 63 … … 73 76 74 77 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 ) : ''; 76 79 h.val( h1 ); 77 80 } 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 ) : ''; 79 82 w.val( w1 ); 80 83 } 81 84 82 if ( ( h1 && h1 > this.hold ['oh'] ) || ( w1 && w1 > this.hold['ow'] ) )85 if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) { 83 86 warn.css('visibility', 'visible'); 84 else87 } else { 85 88 warn.css('visibility', 'hidden'); 89 } 86 90 }, 87 91 88 92 getSelRatio : function(postid) { 89 var x = this.hold ['w'], y = this.hold['h'],93 var x = this.hold.w, y = this.hold.h, 90 94 X = this.intval( $('#imgedit-crop-width-' + postid).val() ), 91 95 Y = this.intval( $('#imgedit-crop-height-' + postid).val() ); 92 96 93 if ( X && Y ) 97 if ( X && Y ) { 94 98 return X + ':' + Y; 95 96 if ( x && y ) 99 } 100 101 if ( x && y ) { 97 102 return x + ':' + y; 103 } 98 104 99 105 return '1:1'; … … 104 110 var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = []; 105 111 106 if ( history != '' ) {112 if ( history !== '' ) { 107 113 history = JSON.parse(history); 108 114 pop = this.intval( $('#imgedit-undone-' + postid).val() ); … … 116 122 if ( setSize ) { 117 123 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; 120 126 return ''; 121 127 } … … 126 132 127 133 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; 130 136 } 131 137 } … … 168 174 max1 = Math.max( t.hold.w, t.hold.h ); 169 175 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; 171 177 172 178 t.initCrop(postid, img, parent); 173 179 t.setCropSelection(postid, 0); 174 180 175 if ( (typeof callback != "unknown") && callback != null )181 if ( (typeof callback !== 'undefined') && callback !== null ) { 176 182 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 ) { 179 186 $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled'); 180 else187 } else { 181 188 $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true); 189 } 182 190 183 191 t.toggleEditor(postid, 0); … … 193 201 var t = this, data, w, h, fw, fh; 194 202 195 if ( t.notsaved(postid) ) 196 return false; 203 if ( t.notsaved(postid) ) { 204 return false; 205 } 197 206 198 207 data = { … … 202 211 }; 203 212 204 if ( 'scale' == action ) {213 if ( 'scale' === action ) { 205 214 w = $('#imgedit-scale-width-' + postid), 206 215 h = $('#imgedit-scale-height-' + postid), … … 216 225 } 217 226 218 if ( fw == t.hold.ow || fh == t.hold.oh )227 if ( fw === t.hold.ow || fh === t.hold.oh ) { 219 228 return false; 229 } 220 230 221 231 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 ) { 225 235 data['do'] = 'restore'; 226 236 } else { … … 238 248 var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0); 239 249 240 if ( '' == history ) 241 return false; 250 if ( '' === history ) { 251 return false; 252 } 242 253 243 254 this.toggleEditor(postid, 1); … … 261 272 } 262 273 263 if ( ret.fw && ret.fh ) 274 if ( ret.fw && ret.fh ) { 264 275 $('#media-dims-' + postid).html( ret.fw + ' × ' + ret.fh ); 265 266 if ( ret.thumbnail ) 276 } 277 278 if ( ret.thumbnail ) { 267 279 $('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail); 268 269 if ( ret.msg ) 280 } 281 282 if ( ret.msg ) { 270 283 $('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>'); 284 } 271 285 272 286 imageEdit.close(postid); … … 317 331 minHeight: 3, 318 332 319 onInit: function( img, c) {333 onInit: function() { 320 334 parent.children().mousedown(function(e){ 321 335 var ratio = false, sel, defRatio; … … 333 347 }, 334 348 335 onSelectStart: function( img, c) {349 onSelectStart: function() { 336 350 imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1); 337 351 }, … … 351 365 setCropSelection : function(postid, c) { 352 366 var sel, min = $('#imgedit-minthumb-' + postid).val() || '128:128', 353 sizer = this.hold ['sizer'];367 sizer = this.hold.sizer; 354 368 min = min.split(':'); 355 369 c = c || 0; … … 378 392 warn = warn || false; 379 393 380 if ( warn && this.notsaved(postid) ) 381 return false; 394 if ( warn && this.notsaved(postid) ) { 395 return false; 396 } 382 397 383 398 this.iasapi = {}; … … 391 406 notsaved : function(postid) { 392 407 var h = $('#imgedit-history-' + postid).val(), 393 history = ( h != '') ? JSON.parse(h) : new Array(),408 history = ( h !== '' ) ? JSON.parse(h) : [], 394 409 pop = this.intval( $('#imgedit-undone-' + postid).val() ); 395 410 396 411 if ( pop < history.length ) { 397 if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) 412 if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) { 398 413 return false; 414 } 399 415 return true; 400 416 } … … 404 420 addStep : function(op, postid, nonce) { 405 421 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() ) : [], 407 423 undone = $('#imgedit-undone-' + postid), 408 424 pop = t.intval(undone.val()); … … 424 440 425 441 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); 430 447 }, 431 448 432 449 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); 437 455 }, 438 456 … … 442 460 h = this.intval( $('#imgedit-sel-height-' + postid).val() ); 443 461 444 if ( $(t).hasClass('disabled') || sel == '' ) 445 return false; 462 if ( $(t).hasClass('disabled') || sel === '' ) { 463 return false; 464 } 446 465 447 466 sel = JSON.parse(sel); 448 467 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; 451 470 this.addStep({ 'c': sel }, postid, nonce); 452 471 } … … 457 476 pop = t.intval( elem.val() ) + 1; 458 477 459 if ( button.hasClass('disabled') ) 478 if ( button.hasClass('disabled') ) { 460 479 return; 480 } 461 481 462 482 elem.val(pop); 463 483 t.refreshEditor(postid, nonce, function() { 464 484 var elem = $('#imgedit-history-' + postid), 465 history = ( elem.val() != '') ? JSON.parse(elem.val()) : new Array();485 history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : []; 466 486 467 487 t.setDisabled($('#image-redo-' + postid), true); … … 474 494 pop = t.intval( elem.val() ) - 1; 475 495 476 if ( button.hasClass('disabled') ) 496 if ( button.hasClass('disabled') ) { 477 497 return; 498 } 478 499 479 500 elem.val(pop); … … 488 509 x = this.intval( elX.val() ), y = this.intval( elY.val() ), 489 510 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; 491 512 492 513 if ( x < 1 ) { … … 528 549 num = Math.round(num); 529 550 530 if ( this.hold.sizer > 0.6 ) 551 if ( this.hold.sizer > 0.6 ) { 531 552 return num; 553 } 532 554 533 555 s = num.toString().slice(-1); 534 556 535 if ( '1' == s )557 if ( '1' === s ) { 536 558 return num - 1; 537 else if ( '9' == s )559 } else if ( '9' === s ) { 538 560 return num + 1; 561 } 539 562 540 563 return num; … … 557 580 558 581 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 ) ) ); 560 583 561 584 if ( r > h ) { 562 585 r = h; 563 if ( n ) 586 if ( n ) { 564 587 $('#imgedit-crop-height-' + postid).val(''); 565 else588 } else { 566 589 $('#imgedit-crop-width-' + postid).val(''); 590 } 567 591 } 568 592 … … 572 596 } 573 597 } 574 } 598 }; 575 599 })(jQuery);
Note: See TracChangeset
for help on using the changeset viewer.