wp/wp-admin/js/image-edit.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
   120 		t.hold.xy_ratio = x / y;
   120 		t.hold.xy_ratio = x / y;
   121 		t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
   121 		t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
   122 		t.postid = postid;
   122 		t.postid = postid;
   123 		$('#imgedit-response-' + postid).empty();
   123 		$('#imgedit-response-' + postid).empty();
   124 
   124 
   125 		$('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) {
   125 		$('#imgedit-panel-' + postid).on( 'keypress', 'input[type="text"]', function(e) {
   126 			var k = e.keyCode;
   126 			var k = e.keyCode;
   127 
   127 
   128 			// Key codes 37 through 40 are the arrow keys.
   128 			// Key codes 37 through 40 are the arrow keys.
   129 			if ( 36 < k && k < 41 ) {
   129 			if ( 36 < k && k < 41 ) {
   130 				$(this).blur();
   130 				$(this).trigger( 'blur' );
   131 			}
   131 			}
   132 
   132 
   133 			// The key code 13 is the Enter key.
   133 			// The key code 13 is the Enter key.
   134 			if ( 13 === k ) {
   134 			if ( 13 === k ) {
   135 				e.preventDefault();
   135 				e.preventDefault();
   300 					history.pop();
   300 					history.pop();
   301 					pop--;
   301 					pop--;
   302 				}
   302 				}
   303 			}
   303 			}
   304 
   304 
   305 			// Reset size to it's original state.
   305 			// Reset size to its original state.
   306 			if ( setSize ) {
   306 			if ( setSize ) {
   307 				if ( !history.length ) {
   307 				if ( !history.length ) {
   308 					this.hold.w = this.hold.ow;
   308 					this.hold.w = this.hold.ow;
   309 					this.hold.h = this.hold.oh;
   309 					this.hold.h = this.hold.oh;
   310 					return '';
   310 					return '';
   382 						 * A crop action has completed and the crop button gets disabled
   382 						 * A crop action has completed and the crop button gets disabled
   383 						 * ensure the undo button is enabled.
   383 						 * ensure the undo button is enabled.
   384 						 */
   384 						 */
   385 						t.setDisabled( $( '#image-undo-' + postid) , true );
   385 						t.setDisabled( $( '#image-undo-' + postid) , true );
   386 						// Move focus to the undo button to avoid a focus loss.
   386 						// Move focus to the undo button to avoid a focus loss.
   387 						$( '#image-undo-' + postid ).focus();
   387 						$( '#image-undo-' + postid ).trigger( 'focus' );
   388 					}
   388 					}
   389 				}
   389 				}
   390 
   390 
   391 				parent.empty().append(img);
   391 				parent.empty().append(img);
   392 
   392 
   400 				if ( (typeof callback !== 'undefined') && callback !== null ) {
   400 				if ( (typeof callback !== 'undefined') && callback !== null ) {
   401 					callback();
   401 					callback();
   402 				}
   402 				}
   403 
   403 
   404 				if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === '0' ) {
   404 				if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === '0' ) {
   405 					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
   405 					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', false);
   406 				} else {
   406 				} else {
   407 					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
   407 					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
   408 				}
   408 				}
   409 
   409 
   410 				t.toggleEditor(postid, 0);
   410 				t.toggleEditor(postid, 0);
   456 			h = $('#imgedit-scale-height-' + postid),
   456 			h = $('#imgedit-scale-height-' + postid),
   457 			fw = t.intval(w.val()),
   457 			fw = t.intval(w.val()),
   458 			fh = t.intval(h.val());
   458 			fh = t.intval(h.val());
   459 
   459 
   460 			if ( fw < 1 ) {
   460 			if ( fw < 1 ) {
   461 				w.focus();
   461 				w.trigger( 'focus' );
   462 				return false;
   462 				return false;
   463 			} else if ( fh < 1 ) {
   463 			} else if ( fh < 1 ) {
   464 				h.focus();
   464 				h.trigger( 'focus' );
   465 				return false;
   465 				return false;
   466 			}
   466 			}
   467 
   467 
   468 			if ( fw === t.hold.ow || fh === t.hold.oh ) {
   468 			if ( fw === t.hold.ow || fh === t.hold.oh ) {
   469 				return false;
   469 				return false;
   687 
   687 
   688 			if ( ! elementToSetFocusTo.length ) {
   688 			if ( ! elementToSetFocusTo.length ) {
   689 				elementToSetFocusTo = $( '.imgedit-wrap' ).find( ':tabbable:first' );
   689 				elementToSetFocusTo = $( '.imgedit-wrap' ).find( ':tabbable:first' );
   690 			}
   690 			}
   691 
   691 
   692 			elementToSetFocusTo.focus();
   692 			elementToSetFocusTo.trigger( 'focus' );
   693 		}, 100 );
   693 		}, 100 );
   694 	},
   694 	},
   695 
   695 
   696 	/**
   696 	/**
   697 	 * Initializes the cropping tool.
   697 	 * Initializes the cropping tool.
   865 		// close the editor the old-school way.
   865 		// close the editor the old-school way.
   866 		else {
   866 		else {
   867 			$('#image-editor-' + postid).fadeOut('fast', function() {
   867 			$('#image-editor-' + postid).fadeOut('fast', function() {
   868 				$( '#media-head-' + postid ).fadeIn( 'fast', function() {
   868 				$( '#media-head-' + postid ).fadeIn( 'fast', function() {
   869 					// Move focus back to the Edit Image button. Runs also when saving.
   869 					// Move focus back to the Edit Image button. Runs also when saving.
   870 					$( '#imgedit-open-btn-' + postid ).focus();
   870 					$( '#imgedit-open-btn-' + postid ).trigger( 'focus' );
   871 				});
   871 				});
   872 				$(this).empty();
   872 				$(this).empty();
   873 			});
   873 			});
   874 		}
   874 		}
   875 
   875 
  1005 		if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
  1005 		if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
  1006 			sel.fw = w;
  1006 			sel.fw = w;
  1007 			sel.fh = h;
  1007 			sel.fh = h;
  1008 			this.addStep({ 'c': sel }, postid, nonce);
  1008 			this.addStep({ 'c': sel }, postid, nonce);
  1009 		}
  1009 		}
       
  1010 
       
  1011 		// Clear the selection fields after cropping.
       
  1012 		$('#imgedit-sel-width-' + postid).val('');
       
  1013 		$('#imgedit-sel-height-' + postid).val('');
  1010 	},
  1014 	},
  1011 
  1015 
  1012 	/**
  1016 	/**
  1013 	 * Undoes an image edit action.
  1017 	 * Undoes an image edit action.
  1014 	 *
  1018 	 *
  1036 
  1040 
  1037 			t.setDisabled($('#image-redo-' + postid), true);
  1041 			t.setDisabled($('#image-redo-' + postid), true);
  1038 			t.setDisabled(button, pop < history.length);
  1042 			t.setDisabled(button, pop < history.length);
  1039 			// When undo gets disabled, move focus to the redo button to avoid a focus loss.
  1043 			// When undo gets disabled, move focus to the redo button to avoid a focus loss.
  1040 			if ( history.length === pop ) {
  1044 			if ( history.length === pop ) {
  1041 				$( '#image-redo-' + postid ).focus();
  1045 				$( '#image-redo-' + postid ).trigger( 'focus' );
  1042 			}
  1046 			}
  1043 		});
  1047 		});
  1044 	},
  1048 	},
  1045 
  1049 
  1046 	/**
  1050 	/**
  1067 		t.refreshEditor(postid, nonce, function() {
  1071 		t.refreshEditor(postid, nonce, function() {
  1068 			t.setDisabled($('#image-undo-' + postid), true);
  1072 			t.setDisabled($('#image-undo-' + postid), true);
  1069 			t.setDisabled(button, pop > 0);
  1073 			t.setDisabled(button, pop > 0);
  1070 			// When redo gets disabled, move focus to the undo button to avoid a focus loss.
  1074 			// When redo gets disabled, move focus to the undo button to avoid a focus loss.
  1071 			if ( 0 === pop ) {
  1075 			if ( 0 === pop ) {
  1072 				$( '#image-undo-' + postid ).focus();
  1076 				$( '#image-undo-' + postid ).trigger( 'focus' );
  1073 			}
  1077 			}
  1074 		});
  1078 		});
  1075 	},
  1079 	},
  1076 
  1080 
  1077 	/**
  1081 	/**