X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/fa11948979fd6a4ea5705dc613b239699a459db3..refs/tags/wordpress-3.8:/wp-admin/js/image-edit.js diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js index 88eb2922..9eaf51bf 100644 --- a/wp-admin/js/image-edit.js +++ b/wp-admin/js/image-edit.js @@ -1,7 +1,7 @@ -var imageEdit; +/* global imageEditL10n, ajaxurl, confirm */ (function($) { -imageEdit = { +var imageEdit = window.imageEdit = { iasapi : {}, hold : {}, postid : '', @@ -20,28 +20,30 @@ imageEdit = { } }, - init : function(postid, nonce) { + init : function(postid) { var t = this, old = $('#image-editor-' + t.postid), x = t.intval( $('#imgedit-x-' + postid).val() ), y = t.intval( $('#imgedit-y-' + postid).val() ); - if ( t.postid != postid && old.length ) + if ( t.postid !== postid && old.length ) { t.close(t.postid); + } - t.hold['w'] = t.hold['ow'] = x; - t.hold['h'] = t.hold['oh'] = y; - t.hold['xy_ratio'] = x / y; - t.hold['sizer'] = parseFloat( $('#imgedit-sizer-' + postid).val() ); + t.hold.w = t.hold.ow = x; + t.hold.h = t.hold.oh = y; + t.hold.xy_ratio = x / y; + t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() ); t.postid = postid; $('#imgedit-response-' + postid).empty(); $('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) { var k = e.keyCode; - if ( 36 < k && k < 41 ) - $(this).blur() + if ( 36 < k && k < 41 ) { + $(this).blur(); + } - if ( 13 == k ) { + if ( 13 === k ) { e.preventDefault(); e.stopPropagation(); return false; @@ -52,10 +54,11 @@ imageEdit = { toggleEditor : function(postid, toggle) { var wait = $('#imgedit-wait-' + postid); - if ( toggle ) + if ( toggle ) { wait.height( $('#imgedit-panel-' + postid).height() ).fadeIn('fast'); - else + } else { wait.fadeOut('fast'); + } }, toggleHelp : function(el) { @@ -72,29 +75,32 @@ imageEdit = { warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = ''; if ( x ) { - h1 = (w.val() != '') ? Math.round( w.val() / this.hold['xy_ratio'] ) : ''; + h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : ''; h.val( h1 ); } else { - w1 = (h.val() != '') ? Math.round( h.val() * this.hold['xy_ratio'] ) : ''; + w1 = ( h.val() !== '' ) ? Math.round( h.val() * this.hold.xy_ratio ) : ''; w.val( w1 ); } - if ( ( h1 && h1 > this.hold['oh'] ) || ( w1 && w1 > this.hold['ow'] ) ) + if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) { warn.css('visibility', 'visible'); - else + } else { warn.css('visibility', 'hidden'); + } }, getSelRatio : function(postid) { - var x = this.hold['w'], y = this.hold['h'], + var x = this.hold.w, y = this.hold.h, X = this.intval( $('#imgedit-crop-width-' + postid).val() ), Y = this.intval( $('#imgedit-crop-height-' + postid).val() ); - if ( X && Y ) + if ( X && Y ) { return X + ':' + Y; + } - if ( x && y ) + if ( x && y ) { return x + ':' + y; + } return '1:1'; }, @@ -103,7 +109,7 @@ imageEdit = { // apply undo state to history var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = []; - if ( history != '' ) { + if ( history !== '' ) { history = JSON.parse(history); pop = this.intval( $('#imgedit-undone-' + postid).val() ); if ( pop > 0 ) { @@ -115,8 +121,8 @@ imageEdit = { if ( setSize ) { if ( !history.length ) { - this.hold['w'] = this.hold['ow']; - this.hold['h'] = this.hold['oh']; + this.hold.w = this.hold.ow; + this.hold.h = this.hold.oh; return ''; } @@ -125,8 +131,8 @@ imageEdit = { o = o.c || o.r || o.f || false; if ( o ) { - this.hold['w'] = o.fw; - this.hold['h'] = o.fh; + this.hold.w = o.fw; + this.hold.h = o.fh; } } @@ -167,18 +173,20 @@ imageEdit = { // w, h are the new full size dims max1 = Math.max( t.hold.w, t.hold.h ); max2 = Math.max( $(img).width(), $(img).height() ); - t.hold['sizer'] = max1 > max2 ? max2 / max1 : 1; + t.hold.sizer = max1 > max2 ? max2 / max1 : 1; t.initCrop(postid, img, parent); t.setCropSelection(postid, 0); - if ( (typeof callback != "unknown") && callback != null ) + if ( (typeof callback !== 'undefined') && callback !== null ) { callback(); + } - if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() == 0 ) + if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === '0' ) { $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled'); - else + } else { $('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true); + } t.toggleEditor(postid, 0); }) @@ -192,8 +200,9 @@ imageEdit = { action : function(postid, nonce, action) { var t = this, data, w, h, fw, fh; - if ( t.notsaved(postid) ) + if ( t.notsaved(postid) ) { return false; + } data = { 'action': 'image-editor', @@ -201,7 +210,7 @@ imageEdit = { 'postid': postid }; - if ( 'scale' == action ) { + if ( 'scale' === action ) { w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid), fw = t.intval(w.val()), @@ -215,13 +224,14 @@ imageEdit = { return false; } - if ( fw == t.hold.ow || fh == t.hold.oh ) + if ( fw === t.hold.ow || fh === t.hold.oh ) { return false; + } data['do'] = 'scale'; - data['fwidth'] = fw; - data['fheight'] = fh; - } else if ( 'restore' == action ) { + data.fwidth = fw; + data.fheight = fh; + } else if ( 'restore' === action ) { data['do'] = 'restore'; } else { return false; @@ -237,8 +247,9 @@ imageEdit = { save : function(postid, nonce) { var data, target = this.getTarget(postid), history = this.filterHistory(postid, 0); - if ( '' == history ) + if ( '' === history ) { return false; + } this.toggleEditor(postid, 1); data = { @@ -260,14 +271,17 @@ imageEdit = { return; } - if ( ret.fw && ret.fh ) + if ( ret.fw && ret.fh ) { $('#media-dims-' + postid).html( ret.fw + ' × ' + ret.fh ); + } - if ( ret.thumbnail ) + if ( ret.thumbnail ) { $('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail); + } - if ( ret.msg ) + if ( ret.msg ) { $('#imgedit-response-' + postid).html('
' + ret.msg + '