wp/wp-admin/js/image-edit.js
author ymh <ymh.work@gmail.com>
Mon, 14 Oct 2019 18:28:13 +0200
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
permissions -rw-r--r--
upgrade wordpress to 5.2.3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     1
/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     2
 * The functions necessary for editing images.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     4
 * @since 2.9.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     5
 * @output wp-admin/js/image-edit.js
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     6
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     8
 /* global imageEditL10n, ajaxurl, confirm */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
     9
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
(function($) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    11
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    12
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    13
	 * Contains all the methods to initialise and control the image editor.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    14
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
	 * @namespace imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
	var imageEdit = window.imageEdit = {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	iasapi : {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	hold : {},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	postid : '',
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
	_view : false,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    23
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    24
	 * Handle crop tool clicks.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    25
	 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    26
	handleCropToolClick: function( postid, nonce, cropButton ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    27
		var img = $( '#image-preview-' + postid ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
			selection = this.iasapi.getSelection();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    29
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    30
		// Ensure selection is available, otherwise reset to full image.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    31
		if ( isNaN( selection.x1 ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    32
			this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': img.innerWidth(), 'y2': img.innerHeight(), 'width': img.innerWidth(), 'height': img.innerHeight() } );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    33
			selection = this.iasapi.getSelection();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    34
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    35
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    36
		// If we don't already have a selection, select the entire image.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    37
		if ( 0 === selection.x1 && 0 === selection.y1 && 0 === selection.x2 && 0 === selection.y2 ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    38
			this.iasapi.setSelection( 0, 0, img.innerWidth(), img.innerHeight(), true );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    39
			this.iasapi.setOptions( { show: true } );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    40
			this.iasapi.update();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    41
		} else {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    42
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    43
			// Otherwise, perform the crop.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    44
			imageEdit.crop( postid, nonce , cropButton );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    45
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    46
	},
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    47
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    48
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    49
	 * Converts a value to an integer.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    50
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    51
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    52
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    53
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    54
	 * @param {number} f The float value that should be converted.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    56
	 * @return {number} The integer representation from the float value.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    57
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	intval : function(f) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    59
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    60
		 * Bitwise OR operator: one of the obscure ways to truncate floating point figures,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    61
		 * worth reminding JavaScript doesn't have a distinct "integer" type.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    62
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		return f | 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    66
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    67
	 * Adds the disabled attribute and class to a single form element or a field set.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    70
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
	 * @param {jQuery}         el The element that should be modified.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
	 * @param {bool|number}    s  The state for the element. If set to true
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
	 *                            the element is disabled,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
	 *                            otherwise the element is enabled.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
	 *                            The function is sometimes called with a 0 or 1
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
	 *                            instead of true or false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    80
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    81
	setDisabled : function( el, s ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    82
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    83
		 * `el` can be a single form element or a fieldset. Before #28864, the disabled state on
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    84
		 * some text fields  was handled targeting $('input', el). Now we need to handle the
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    85
		 * disabled state on buttons too so we can just target `el` regardless if it's a single
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    86
		 * element or a fieldset because when a fieldset is disabled, its descendants are disabled too.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
		if ( s ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    89
			el.removeClass( 'disabled' ).prop( 'disabled', false );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		} else {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
			el.addClass( 'disabled' ).prop( 'disabled', true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    96
	 * Initializes the image editor.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   100
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   102
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	init : function(postid) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		var t = this, old = $('#image-editor-' + t.postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			x = t.intval( $('#imgedit-x-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
			y = t.intval( $('#imgedit-y-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
		if ( t.postid !== postid && old.length ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
			t.close(t.postid);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
		t.hold.w = t.hold.ow = x;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
		t.hold.h = t.hold.oh = y;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
		t.hold.xy_ratio = x / y;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
		t.hold.sizer = parseFloat( $('#imgedit-sizer-' + postid).val() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		t.postid = postid;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
		$('#imgedit-response-' + postid).empty();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		$('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
			var k = e.keyCode;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
			// Key codes 37 thru 40 are the arrow keys.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
			if ( 36 < k && k < 41 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
				$(this).blur();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   129
			// The key code 13 is the enter key.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
			if ( 13 === k ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
				e.preventDefault();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
				e.stopPropagation();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   138
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
	 * Toggles the wait/load icon in the editor.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   140
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   141
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   142
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   143
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   144
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   145
	 * @param {number} toggle Is 0 or 1, fades the icon in then 1 and out when 0.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   146
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   147
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   148
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	toggleEditor : function(postid, toggle) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		var wait = $('#imgedit-wait-' + postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   152
		if ( toggle ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   153
			wait.fadeIn( 'fast' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			wait.fadeOut('fast');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   159
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   160
	 * Shows or hides the image edit help box.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   161
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   162
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   163
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   164
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   165
	 * @param {HTMLElement} el The element to create the help window in.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   166
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   167
	 * @returns {boolean} Always returns false.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   168
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	toggleHelp : function(el) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   170
		var $el = $( el );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   171
		$el
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   172
			.attr( 'aria-expanded', 'false' === $el.attr( 'aria-expanded' ) ? 'true' : 'false' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   173
			.parents( '.imgedit-group-top' ).toggleClass( 'imgedit-help-toggled' ).find( '.imgedit-help' ).slideToggle( 'fast' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   174
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   178
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   179
	 * Gets the value from the image edit target.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   180
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   181
	 * The image edit target contains the image sizes where the (possible) changes
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
	 * have to be applied to.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   183
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   184
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   185
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   186
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   187
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   188
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   189
	 * @returns {string} The value from the imagedit-save-target input field when available,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   190
	 *                   or 'full' when not available.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   191
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	getTarget : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   196
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   197
	 * Recalculates the height or width and keeps the original aspect ratio.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   198
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   199
	 * If the original image size is exceeded a red exclamation mark is shown.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   200
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   201
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   202
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   203
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   204
	 * @param {number}         postid The current post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   205
	 * @param {number}         x      Is 0 when it applies the y-axis
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   206
	 *                                and 1 when applicable for the x-axis.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   207
	 * @param {jQuery}         el     Element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   208
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   209
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   210
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   211
	scaleChanged : function( postid, x, el ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
		warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   215
		if ( false === this.validateNumeric( el ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   216
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   217
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   218
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
		if ( x ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
			h1 = ( w.val() !== '' ) ? Math.round( w.val() / this.hold.xy_ratio ) : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			h.val( h1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			w1 = ( h.val() !== '' ) ? Math.round( h.val() * this.hold.xy_ratio ) : '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			w.val( w1 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   227
		if ( ( h1 && h1 > this.hold.oh ) || ( w1 && w1 > this.hold.ow ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
			warn.css('visibility', 'visible');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   229
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
			warn.css('visibility', 'hidden');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   234
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   235
	 * Gets the selected aspect ratio.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   238
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   239
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   240
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   241
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   242
	 * @returns {string} The aspect ratio.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   243
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	getSelRatio : function(postid) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
		var x = this.hold.w, y = this.hold.h,
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			X = this.intval( $('#imgedit-crop-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
			Y = this.intval( $('#imgedit-crop-height-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   249
		if ( X && Y ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
			return X + ':' + Y;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   251
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   253
		if ( x && y ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
			return x + ':' + y;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   255
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		return '1:1';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   260
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   261
	 * Removes the last action from the image edit history.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   262
	 * The history consist of (edit) actions performed on the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   264
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   265
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   266
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   267
	 * @param {number} postid  The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   268
	 * @param {number} setSize 0 or 1, when 1 the image resets to its original size.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
	 * @returns {string} JSON string containing the history or an empty string if no history exists.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   271
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	filterHistory : function(postid, setSize) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   273
		// Apply undo state to history.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
		var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = [];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
		if ( history !== '' ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   277
			// Read the JSON string with the image edit history.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			history = JSON.parse(history);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
			pop = this.intval( $('#imgedit-undone-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			if ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
				while ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
					history.pop();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
					pop--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   287
			// Reset size to it's original state.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			if ( setSize ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				if ( !history.length ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
					this.hold.w = this.hold.ow;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
					this.hold.h = this.hold.oh;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
					return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   295
				// Restore original 'o'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
				o = history[history.length - 1];
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   297
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   298
				// c = 'crop', r = 'rotate', f = 'flip'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
				o = o.c || o.r || o.f || false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
				if ( o ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   302
					// fw = Full image width
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
					this.hold.w = o.fw;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
					// fh = Full image height
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
					this.hold.h = o.fh;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   309
			// Filter the last step/action from the history.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
			for ( n in history ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
				i = history[n];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
				if ( i.hasOwnProperty('c') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
					op[n] = { 'c': { 'x': i.c.x, 'y': i.c.y, 'w': i.c.w, 'h': i.c.h } };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
				} else if ( i.hasOwnProperty('r') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
					op[n] = { 'r': i.r.r };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
				} else if ( i.hasOwnProperty('f') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
					op[n] = { 'f': i.f.f };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
			return JSON.stringify(op);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	},
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   325
	 * Binds the necessary events to the image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   326
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   327
	 * When the image source is reloaded the image will be reloaded.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   328
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   329
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   330
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   331
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   332
	 * @param {number}   postid   The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   333
	 * @param {string}   nonce    The nonce to verify the request.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   334
	 * @param {function} callback Function to execute when the image is loaded.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   335
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   336
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   337
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	refreshEditor : function(postid, nonce, callback) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
		var t = this, data, img;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
		t.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			'action': 'imgedit-preview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
			'history': t.filterHistory(postid, 1),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			'rand': t.intval(Math.random() * 1000000)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   350
		img = $( '<img id="image-preview-' + postid + '" alt="" />' )
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   351
			.on( 'load', { history: data.history }, function( event ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   352
				var max1, max2,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   353
					parent = $( '#imgedit-crop-' + postid ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   354
					t = imageEdit,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   355
					historyObj;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   356
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   357
				// Checks if there already is some image-edit history.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   358
				if ( '' !== event.data.history ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   359
					historyObj = JSON.parse( event.data.history );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   360
					// If last executed action in history is a crop action.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   361
					if ( historyObj[historyObj.length - 1].hasOwnProperty( 'c' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   362
						/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   363
						 * A crop action has completed and the crop button gets disabled
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   364
						 * ensure the undo button is enabled.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   365
						 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   366
						t.setDisabled( $( '#image-undo-' + postid) , true );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   367
						// Move focus to the undo button to avoid a focus loss.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   368
						$( '#image-undo-' + postid ).focus();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   369
					}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   370
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
				parent.empty().append(img);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
				// w, h are the new full size dims
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
				max1 = Math.max( t.hold.w, t.hold.h );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
				max2 = Math.max( $(img).width(), $(img).height() );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   377
				t.hold.sizer = max1 > max2 ? max2 / max1 : 1;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
				t.initCrop(postid, img, parent);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
				if ( (typeof callback !== 'undefined') && callback !== null ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
					callback();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
				if ( $('#imgedit-history-' + postid).val() && $('#imgedit-undone-' + postid).val() === '0' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).removeAttr('disabled');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
				} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
					$('input.imgedit-submit-btn', '#imgedit-panel-' + postid).prop('disabled', true);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
				}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
				t.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			})
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
			.on('error', function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
				$('#imgedit-crop-' + postid).empty().append('<div class="error"><p>' + imageEditL10n.error + '</p></div>');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
				t.toggleEditor(postid, 0);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
			})
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
			.attr('src', ajaxurl + '?' + $.param(data));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	},
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   399
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   400
	 * Performs an image edit action.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   401
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   402
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   403
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   404
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   405
	 * @param  {number}  postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
	 * @param  {string}  nonce  The nonce to verify the request.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
	 * @param  {string}  action The action to perform on the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
	 *                          The possible actions are: "scale" and "restore".
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
	 * @returns {boolean|void} Executes a post request that refreshes the page
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   411
	 *                         when the action is performed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   412
	 *                         Returns false if a invalid action is given,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   413
	 *                         or when the action cannot be performed.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   414
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
	action : function(postid, nonce, action) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
		var t = this, data, w, h, fw, fh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   418
		if ( t.notsaved(postid) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   420
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
			'postid': postid
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   428
		if ( 'scale' === action ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
			w = $('#imgedit-scale-width-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
			h = $('#imgedit-scale-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
			fw = t.intval(w.val()),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
			fh = t.intval(h.val());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			if ( fw < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
				w.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
			} else if ( fh < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
				h.focus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
				return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   442
			if ( fw === t.hold.ow || fh === t.hold.oh ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
				return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
			data['do'] = 'scale';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
			data.fwidth = fw;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
			data.fheight = fh;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
		} else if ( 'restore' === action ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
			data['do'] = 'restore';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
		t.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
		$.post(ajaxurl, data, function(r) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
			$('#image-editor-' + postid).empty().append(r);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
			t.toggleEditor(postid, 0);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
			// refresh the attachment model so that changes propagate
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
			if ( t._view ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
				t._view.refresh();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   462
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   467
	 * Stores the changes that are made to the image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   468
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   469
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   470
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   471
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   472
	 * @param {number}  postid   The post id to get the image from the database.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   473
	 * @param {string}  nonce    The nonce to verify the request.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   474
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
	 * @returns {boolean|void}  If the actions are successfully saved a response message is shown.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   476
	 *                          Returns false if there is no image editing history,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   477
	 *                          thus there are not edit-actions performed on the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   478
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	save : function(postid, nonce) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
		var data,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
			target = this.getTarget(postid),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
			history = this.filterHistory(postid, 0),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
			self = this;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
		if ( '' === history ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		this.toggleEditor(postid, 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			'history': history,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
			'target': target,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
			'context': $('#image-edit-context').length ? $('#image-edit-context').val() : null,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
			'do': 'save'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		};
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   499
		// Post the image edit data to the backend.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		$.post(ajaxurl, data, function(r) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   501
			// Read the response.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
			var ret = JSON.parse(r);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   504
			// If a response is returned, close the editor and show an error.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
			if ( ret.error ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   506
				$('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p></div>');
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				imageEdit.close(postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   511
			if ( ret.fw && ret.fh ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
				$('#media-dims-' + postid).html( ret.fw + ' &times; ' + ret.fh );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   513
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   515
			if ( ret.thumbnail ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				$('.thumbnail', '#thumbnail-head-' + postid).attr('src', ''+ret.thumbnail);
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   517
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
			if ( ret.msg ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
				$('#imgedit-response-' + postid).html('<div class="updated"><p>' + ret.msg + '</p></div>');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
			if ( self._view ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
				self._view.save();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
				imageEdit.close(postid);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   527
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   531
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   532
	 * Creates the image edit window.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   533
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   534
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   535
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   536
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   537
	 * @param {number} postid   The post id for the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   538
	 * @param {string} nonce    The nonce to verify the request.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   539
	 * @param {object} view     The image editor view to be used for the editing.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   540
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   541
	 * @returns {void|promise} Either returns void if the button was already activated
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   542
	 *                         or returns an instance of the image editor, wrapped in a promise.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   543
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   544
	open : function( postid, nonce, view ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   545
		this._view = view;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   546
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   547
		var dfd, data, elem = $('#image-editor-' + postid), head = $('#media-head-' + postid),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
			btn = $('#imgedit-open-btn-' + postid), spin = btn.siblings('.spinner');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   550
		/*
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   551
		 * Instead of disabling the button, which causes a focus loss and makes screen
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   552
		 * readers announce "unavailable", return if the button was already clicked.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   553
		 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   554
		if ( btn.hasClass( 'button-activated' ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   555
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   556
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   557
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   558
		spin.addClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
		data = {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
			'action': 'image-editor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
			'_ajax_nonce': nonce,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			'postid': postid,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
			'do': 'open'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
		};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
		dfd = $.ajax({
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   568
			url:  ajaxurl,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   569
			type: 'post',
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   570
			data: data,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   571
			beforeSend: function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   572
				btn.addClass( 'button-activated' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   573
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
		}).done(function( html ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
			elem.html( html );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
			head.fadeOut('fast', function(){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
				elem.fadeIn('fast');
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   578
				btn.removeClass( 'button-activated' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
				spin.removeClass( 'is-active' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
			});
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   581
			// Initialise the Image Editor now that everything is ready.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   582
			imageEdit.init( postid );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
		return dfd;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   588
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   589
	 * Initializes the cropping tool and sets a default cropping selection.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   590
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   591
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   592
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   593
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   594
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   595
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   596
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   597
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
	imgLoaded : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
		var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   601
		// Ensure init has run even when directly loaded.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   602
		if ( 'undefined' === typeof this.hold.sizer ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   603
			this.init( postid );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   604
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   605
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
		this.initCrop(postid, img, parent);
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   607
		this.setCropSelection( postid, { 'x1': 0, 'y1': 0, 'x2': 0, 'y2': 0, 'width': img.innerWidth(), 'height': img.innerHeight() } );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   608
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		this.toggleEditor(postid, 0);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   610
		// Editor is ready, move focus to the first focusable element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   611
		$( '.imgedit-wrap .imgedit-help-toggle' ).eq( 0 ).focus();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   614
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   615
	 * Initializes the cropping tool.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   616
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   617
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   618
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   619
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   620
	 * @param {number}      postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   621
	 * @param {HTMLElement} image  The preview image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   622
	 * @param {HTMLElement} parent The preview image container.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   623
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   624
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   625
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
	initCrop : function(postid, image, parent) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
		var t = this,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
			selW = $('#imgedit-sel-width-' + postid),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   629
			selH = $('#imgedit-sel-height-' + postid),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
			$img;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
		t.iasapi = $(image).imgAreaSelect({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
			parent: parent,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
			instance: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
			handles: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
			keys: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
			minWidth: 3,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
			minHeight: 3,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   640
			/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   641
			 * Sets the CSS styles and binds events for locking the aspect ratio.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   642
			 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   643
			 * @ignore
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   644
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   645
			 * @param {jQuery} img The preview image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   646
			 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
			onInit: function( img ) {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   648
				// Ensure that the imgAreaSelect wrapper elements are position:absolute.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
				// (even if we're in a position:fixed modal)
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
				$img = $( img );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
				$img.next().css( 'position', 'absolute' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
					.nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   653
				/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   654
				 * Binds mouse down event to the cropping container.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   655
				 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   656
				 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   657
				 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   658
				parent.children().on( 'mousedown, touchstart', function(e){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
					var ratio = false, sel, defRatio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
					if ( e.shiftKey ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
						sel = t.iasapi.getSelection();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
						defRatio = t.getSelRatio(postid);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
						ratio = ( sel && sel.width && sel.height ) ? sel.width + ':' + sel.height : defRatio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
					t.iasapi.setOptions({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
						aspectRatio: ratio
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
					});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
				});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   673
			/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   674
			 * Event triggered when starting a selection.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   675
			 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   676
			 * @ignore
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   677
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   678
			 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   679
			 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   680
			onSelectStart: function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
				imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
			},
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   683
			/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   684
			 * Event triggered when the selection is ended.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   685
			 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   686
			 * @ignore
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   687
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   688
			 * @param {object} img jQuery object representing the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   689
			 * @param {object} c   The selection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   690
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   691
			 * @returns {object}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   692
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			onSelectEnd: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
				imageEdit.setCropSelection(postid, c);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   697
			/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   698
			 * Event triggered when the selection changes.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   699
			 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   700
			 * @ignore
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   701
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   702
			 * @param {object} img jQuery object representing the image.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   703
			 * @param {object} c   The selection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   704
			 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   705
			 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   706
			 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
			onSelectChange: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
				var sizer = imageEdit.hold.sizer;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
				selW.val( imageEdit.round(c.width / sizer) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
				selH.val( imageEdit.round(c.height / sizer) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   715
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   716
	 * Stores the current crop selection.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   717
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   718
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   719
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   720
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   721
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   722
	 * @param {object} c      The selection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   723
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   724
	 * @returns {boolean}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   725
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
	setCropSelection : function(postid, c) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   727
		var sel;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   728
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   729
		c = c || 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
		if ( !c || ( c.width < 3 && c.height < 3 ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   732
			this.setDisabled( $( '.imgedit-crop', '#imgedit-panel-' + postid ), 1 );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   733
			this.setDisabled( $( '#imgedit-crop-sel-' + postid ), 1 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
			$('#imgedit-sel-width-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
			$('#imgedit-sel-height-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
			$('#imgedit-selection-' + postid).val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		sel = { 'x': c.x1, 'y': c.y1, 'w': c.width, 'h': c.height };
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
		this.setDisabled($('.imgedit-crop', '#imgedit-panel-' + postid), 1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
		$('#imgedit-selection-' + postid).val( JSON.stringify(sel) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   745
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   746
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   747
	 * Closes the image editor.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   748
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   749
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   750
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   751
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   752
	 * @param {number}  postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   753
	 * @param {bool}    warn   Warning message.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   754
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   755
	 * @returns {void|bool} Returns false if there is a warning.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   756
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
	close : function(postid, warn) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		warn = warn || false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   760
		if ( warn && this.notsaved(postid) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   762
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
		this.iasapi = {};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
		this.hold = {};
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
		// If we've loaded the editor in the context of a Media Modal, then switch to the previous view,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
		// whatever that might have been.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
		if ( this._view ){
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   770
			this._view.back();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   771
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
		// In case we are not accessing the image editor in the context of a View, close the editor the old-skool way
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
		else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
			$('#image-editor-' + postid).fadeOut('fast', function() {
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   776
				$( '#media-head-' + postid ).fadeIn( 'fast', function() {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   777
					// Move focus back to the Edit Image button. Runs also when saving.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   778
					$( '#imgedit-open-btn-' + postid ).focus();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   779
				});
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
				$(this).empty();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
			});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   787
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   788
	 * Checks if the image edit history is saved.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   789
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   790
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   791
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   792
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   793
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   794
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   795
	 * @returns {boolean} Returns true if the history is not saved.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   796
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	notsaved : function(postid) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		var h = $('#imgedit-history-' + postid).val(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
			history = ( h !== '' ) ? JSON.parse(h) : [],
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
			pop = this.intval( $('#imgedit-undone-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
		if ( pop < history.length ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
			if ( confirm( $('#imgedit-leaving-' + postid).html() ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
				return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			return true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   811
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   812
	 * Adds an image edit action to the history.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   813
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   814
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   815
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   816
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   817
	 * @param {object} op     The original position.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   818
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   819
	 * @param {string} nonce  The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   820
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   821
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   822
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	addStep : function(op, postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
		var t = this, elem = $('#imgedit-history-' + postid),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   825
			history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [],
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   826
			undone = $( '#imgedit-undone-' + postid ),
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   827
			pop = t.intval( undone.val() );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
		while ( pop > 0 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
			history.pop();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
			pop--;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
		undone.val(0); // reset
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		history.push(op);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
		elem.val( JSON.stringify(history) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
			t.setDisabled($('#image-undo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
			t.setDisabled($('#image-redo-' + postid), false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   844
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   845
	 * Rotates the image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   846
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   847
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   848
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   849
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   850
	 * @param {string} angle  The angle the image is rotated with.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   851
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   852
	 * @param {string} nonce  The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   853
	 * @param {object} t      The target element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   854
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   855
	 * @returns {boolean}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   856
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
	rotate : function(angle, postid, nonce, t) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
		if ( $(t).hasClass('disabled') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
		this.addStep({ 'r': { 'r': angle, 'fw': this.hold.h, 'fh': this.hold.w }}, postid, nonce);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   865
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   866
	 * Flips the image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   867
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   868
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   869
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   870
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   871
	 * @param {number} axis   The axle the image is flipped on.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   872
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   873
	 * @param {string} nonce  The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   874
	 * @param {object} t      The target element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   875
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   876
	 * @returns {boolean}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   877
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
	flip : function (axis, postid, nonce, t) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
		if ( $(t).hasClass('disabled') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
		this.addStep({ 'f': { 'f': axis, 'fw': this.hold.w, 'fh': this.hold.h }}, postid, nonce);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   886
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   887
	 * Crops the image.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   888
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   889
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   890
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   891
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   892
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   893
	 * @param {string} nonce  The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   894
	 * @param {object} t      The target object.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   895
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   896
	 * @returns {void|boolean} Returns false if the crop button is disabled.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   897
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	crop : function (postid, nonce, t) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
		var sel = $('#imgedit-selection-' + postid).val(),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
			w = this.intval( $('#imgedit-sel-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
			h = this.intval( $('#imgedit-sel-height-' + postid).val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
		if ( $(t).hasClass('disabled') || sel === '' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
			return false;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
		sel = JSON.parse(sel);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
		if ( sel.w > 0 && sel.h > 0 && w > 0 && h > 0 ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   909
			sel.fw = w;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
			sel.fh = h;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
			this.addStep({ 'c': sel }, postid, nonce);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   915
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   916
	 * Undoes an image edit action.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   917
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   918
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   919
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   920
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   921
	 * @param {number} postid   The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   922
	 * @param {string} nonce    The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   923
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   924
	 * @returns {void|false} Returns false if the undo button is disabled.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   925
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	undo : function (postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
		var t = this, button = $('#image-undo-' + postid), elem = $('#imgedit-undone-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
			pop = t.intval( elem.val() ) + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
		if ( button.hasClass('disabled') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
		elem.val(pop);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
			var elem = $('#imgedit-history-' + postid),
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   937
				history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
			t.setDisabled($('#image-redo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
			t.setDisabled(button, pop < history.length);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   941
			// When undo gets disabled, move focus to the redo button to avoid a focus loss.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   942
			if ( history.length === pop ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   943
				$( '#image-redo-' + postid ).focus();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   944
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   948
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   949
	 * Reverts a undo action.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   950
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   951
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   952
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   953
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   954
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   955
	 * @param {string} nonce  The nonce.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   956
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   957
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   958
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	redo : function(postid, nonce) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
		var t = this, button = $('#image-redo-' + postid), elem = $('#imgedit-undone-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
			pop = t.intval( elem.val() ) - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
		if ( button.hasClass('disabled') ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
		elem.val(pop);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
		t.refreshEditor(postid, nonce, function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
			t.setDisabled($('#image-undo-' + postid), true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
			t.setDisabled(button, pop > 0);
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   971
			// When redo gets disabled, move focus to the undo button to avoid a focus loss.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   972
			if ( 0 === pop ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   973
				$( '#image-undo-' + postid ).focus();
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   974
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   978
	/**
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   979
	 * Sets the selection for the height and width in pixels.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   980
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   981
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   982
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   983
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   984
	 * @param {number} postid The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   985
	 * @param {jQuery} el     The element containing the values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   986
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   987
	 * @returns {void|boolean} Returns false when the x or y value is lower than 1,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   988
	 *                         void when the value is not numeric or when the operation
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   989
	 *                         is successful.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   990
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   991
	setNumSelection : function( postid, el ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
		var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
			x = this.intval( elX.val() ), y = this.intval( elY.val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
			img = $('#image-preview-' + postid), imgh = img.height(), imgw = img.width(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   995
			sizer = this.hold.sizer, x1, y1, x2, y2, ias = this.iasapi;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   997
		if ( false === this.validateNumeric( el ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   998
			return;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   999
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1000
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
		if ( x < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
			elX.val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		if ( y < 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
			elY.val('');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
		if ( x && y && ( sel = ias.getSelection() ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
			x2 = sel.x1 + Math.round( x * sizer );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
			y2 = sel.y1 + Math.round( y * sizer );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
			x1 = sel.x1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
			y1 = sel.y1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			if ( x2 > imgw ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
				x1 = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
				x2 = imgw;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
				elX.val( Math.round( x2 / sizer ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
			if ( y2 > imgh ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
				y1 = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
				y2 = imgh;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
				elY.val( Math.round( y2 / sizer ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
			ias.setSelection( x1, y1, x2, y2 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
			ias.update();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
			this.setCropSelection(postid, ias.getSelection());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1035
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1036
	 * Rounds a number to a whole.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1037
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1038
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1039
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1040
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1041
	 * @param {number} num The number.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1042
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1043
	 * @returns {number} The number rounded to a whole number.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1044
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
	round : function(num) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
		var s;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
		num = Math.round(num);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
		if ( this.hold.sizer > 0.6 ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1050
			return num;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1052
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1053
		s = num.toString().slice(-1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1054
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
		if ( '1' === s ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1056
			return num - 1;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
		} else if ( '9' === s ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1058
			return num + 1;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1060
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1061
		return num;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1062
	},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1063
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1064
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1065
	 * Sets a locked aspect ratio for the selection.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1066
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1067
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1068
	 * @since    2.9.0
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1069
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1070
	 * @param {number} postid     The post id.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1071
	 * @param {number} n          The ratio to set.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1072
	 * @param {jQuery} el         The element containing the values.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1073
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1074
	 * @returns {void}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1075
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1076
	setRatioSelection : function(postid, n, el) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1077
		var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
			y = this.intval( $('#imgedit-crop-height-' + postid).val() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
			h = $('#image-preview-' + postid).height();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1081
		if ( false === this.validateNumeric( el ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1082
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1085
		if ( x && y ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1086
			this.iasapi.setOptions({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1087
				aspectRatio: x + ':' + y
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1088
			});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1089
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1090
			if ( sel = this.iasapi.getSelection(true) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1091
				r = Math.ceil( sel.y1 + ( ( sel.x2 - sel.x1 ) / ( x / y ) ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
				if ( r > h ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1094
					r = h;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
					if ( n ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1096
						$('#imgedit-crop-height-' + postid).val('');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
					} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1098
						$('#imgedit-crop-width-' + postid).val('');
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1099
					}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
				this.iasapi.setSelection( sel.x1, sel.y1, sel.x2, r );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
				this.iasapi.update();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1105
		}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1106
	},
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1107
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1108
	/**
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1109
	 * Validates if a value in a jQuery.HTMLElement is numeric.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1110
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1111
	 * @memberof imageEdit
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1112
	 * @since    4.6
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1113
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1114
	 * @param {jQuery} el The html element.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1115
	 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1116
	 * @returns {void|boolean} Returns false if the value is not numeric,
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1117
	 *                         void when it is.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1118
	 */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1119
	validateNumeric: function( el ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1120
		if ( ! this.intval( $( el ).val() ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1121
			$( el ).val( '' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1122
			return false;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
  1123
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1124
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
})(jQuery);