diff --git a/src/wp-admin/js/image-edit.js b/src/wp-admin/js/image-edit.js
index 6af28dc..aa8c8d8 100644
a
|
b
|
|
1 | 1 | /* global imageEditL10n, ajaxurl, confirm */ |
| 2 | /** |
| 3 | * @summary The functions necessary for editing images. |
| 4 | * |
| 5 | * @since 2.8.5 |
| 6 | */ |
2 | 7 | |
3 | 8 | (function($) { |
4 | | var imageEdit = window.imageEdit = { |
| 9 | |
| 10 | /** |
| 11 | * Contains all the methods to initialise and control the image editor. |
| 12 | * |
| 13 | * @namespace imageEdit |
| 14 | */ |
| 15 | var imageEdit = window.imageEdit = { |
5 | 16 | iasapi : {}, |
6 | 17 | hold : {}, |
7 | 18 | postid : '', |
8 | 19 | _view : false, |
9 | 20 | |
| 21 | /** |
| 22 | * @summary Converts a value to an integer. |
| 23 | * |
| 24 | * @memberof imageEdit |
| 25 | * @since 2.8.5 |
| 26 | * |
| 27 | * @param {number} f The float value should be converted. |
| 28 | * |
| 29 | * @return {number} The integer representation from the float value. |
| 30 | */ |
10 | 31 | intval : function(f) { |
11 | 32 | /* |
12 | 33 | * Bitwise OR operator: one of the obscure ways to truncate floating point figures, |
… |
… |
var imageEdit = window.imageEdit = { |
14 | 35 | */ |
15 | 36 | return f | 0; |
16 | 37 | }, |
17 | | |
| 38 | /** |
| 39 | * @summary Adds the disabled attribute and class to a single form element |
| 40 | * or a field set. |
| 41 | * |
| 42 | * @memberof imageEdit |
| 43 | * @since 2.9 |
| 44 | * |
| 45 | * @param {jQuery} el The element that should be modified. |
| 46 | * @param {bool|number} s The state for the element. If set to true |
| 47 | * the element is disabled, |
| 48 | * else the element is enabled. |
| 49 | * The function is sometimes called with a 0 or 1 |
| 50 | * instead of true or false. |
| 51 | * |
| 52 | * @returns {void} |
| 53 | */ |
18 | 54 | setDisabled : function( el, s ) { |
19 | 55 | /* |
20 | 56 | * `el` can be a single form element or a fieldset. Before #28864, the disabled state on |
… |
… |
var imageEdit = window.imageEdit = { |
29 | 65 | } |
30 | 66 | }, |
31 | 67 | |
| 68 | /** |
| 69 | * @summary Initializes the image editor. |
| 70 | * |
| 71 | * @memberof imageEdit |
| 72 | * @since 2.9 |
| 73 | * |
| 74 | * @param {number} postid The post id. |
| 75 | * |
| 76 | * @returns {void} |
| 77 | */ |
32 | 78 | init : function(postid) { |
33 | 79 | var t = this, old = $('#image-editor-' + t.postid), |
34 | 80 | x = t.intval( $('#imgedit-x-' + postid).val() ), |
… |
… |
var imageEdit = window.imageEdit = { |
48 | 94 | $('input[type="text"]', '#imgedit-panel-' + postid).keypress(function(e) { |
49 | 95 | var k = e.keyCode; |
50 | 96 | |
| 97 | // Key codes 37 till 40 are the arrow keys. |
51 | 98 | if ( 36 < k && k < 41 ) { |
52 | 99 | $(this).blur(); |
53 | 100 | } |
54 | 101 | |
| 102 | // The key code 13 is the enter key. |
55 | 103 | if ( 13 === k ) { |
56 | 104 | e.preventDefault(); |
57 | 105 | e.stopPropagation(); |
… |
… |
var imageEdit = window.imageEdit = { |
60 | 108 | }); |
61 | 109 | }, |
62 | 110 | |
| 111 | /** |
| 112 | * @summary Toggles the wait/load icon in the editor. |
| 113 | * |
| 114 | * @memberof imageEdit |
| 115 | * @since 2.9 |
| 116 | * |
| 117 | * @param {number} postid The post id. |
| 118 | * @param {number} toggle Is 0 or 1, fades the icon in then 1 and out when 0. |
| 119 | * |
| 120 | * @returns {void} |
| 121 | */ |
63 | 122 | toggleEditor : function(postid, toggle) { |
64 | 123 | var wait = $('#imgedit-wait-' + postid); |
65 | 124 | |
… |
… |
var imageEdit = window.imageEdit = { |
70 | 129 | } |
71 | 130 | }, |
72 | 131 | |
| 132 | /** |
| 133 | * @summary Shows or hides the image edit help box. |
| 134 | * |
| 135 | * @memberof imageEdit |
| 136 | * @since 2.9 |
| 137 | * |
| 138 | * @param {HTMLElement} el The element to create the help window in. |
| 139 | * |
| 140 | * @returns {boolean} Always returns false. |
| 141 | */ |
73 | 142 | toggleHelp : function(el) { |
74 | 143 | var $el = $( el ); |
75 | 144 | $el |
… |
… |
var imageEdit = window.imageEdit = { |
79 | 148 | return false; |
80 | 149 | }, |
81 | 150 | |
| 151 | /** |
| 152 | * @summary Gets the value from the image edit target. |
| 153 | * |
| 154 | * The image edit target contains the image sizes where the (possible) changes |
| 155 | * have to be applied to. |
| 156 | * |
| 157 | * @memberof imageEdit |
| 158 | * @since 2.9 |
| 159 | * |
| 160 | * @param {number} postid The post id. |
| 161 | * |
| 162 | * @returns {string} The value from the imagedit-save-target input field when available, |
| 163 | * or 'full' when not available. |
| 164 | */ |
82 | 165 | getTarget : function(postid) { |
83 | 166 | return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full'; |
84 | 167 | }, |
85 | 168 | |
| 169 | /** |
| 170 | * @summary Recalculates the height or width and keeps the original aspect ratio. |
| 171 | * |
| 172 | * If the original image size is exceeded a red exclamation mark is shown. |
| 173 | * |
| 174 | * @memberof imageEdit |
| 175 | * @since 2.9 |
| 176 | * |
| 177 | * @param {number} postid The current post id. |
| 178 | * @param {number} x Is 0 when it applies the y-axis |
| 179 | * and 1 when applicable for the x-axis. |
| 180 | * @param {jQuery} el Element. |
| 181 | * |
| 182 | * @returns {void} |
| 183 | */ |
86 | 184 | scaleChanged : function( postid, x, el ) { |
87 | 185 | var w = $('#imgedit-scale-width-' + postid), h = $('#imgedit-scale-height-' + postid), |
88 | 186 | warn = $('#imgedit-scale-warn-' + postid), w1 = '', h1 = ''; |
… |
… |
var imageEdit = window.imageEdit = { |
106 | 204 | } |
107 | 205 | }, |
108 | 206 | |
| 207 | /** |
| 208 | * @summary Gets the selected aspect ratio. |
| 209 | * |
| 210 | * @memberof imageEdit |
| 211 | * @since 2.9 |
| 212 | * |
| 213 | * @param {number} postid The post id. |
| 214 | * |
| 215 | * @returns {string} The aspect ratio. |
| 216 | */ |
109 | 217 | getSelRatio : function(postid) { |
110 | 218 | var x = this.hold.w, y = this.hold.h, |
111 | 219 | X = this.intval( $('#imgedit-crop-width-' + postid).val() ), |
… |
… |
var imageEdit = window.imageEdit = { |
122 | 230 | return '1:1'; |
123 | 231 | }, |
124 | 232 | |
| 233 | /** |
| 234 | * @summary Removes the last action from the image edit history |
| 235 | * The history consist of (edit)actions performed on the image. |
| 236 | * |
| 237 | * @memberof imageEdit |
| 238 | * @since 2.9 |
| 239 | * |
| 240 | * @param {number} postid The post id. |
| 241 | * @param {number} setSize 0 or 1, when 1 the image resets to its original size. |
| 242 | * |
| 243 | * @returns {string} JSON string containing the history or an empty string if no history exists. |
| 244 | */ |
125 | 245 | filterHistory : function(postid, setSize) { |
126 | | // apply undo state to history |
| 246 | // Apply undo state to history. |
127 | 247 | var history = $('#imgedit-history-' + postid).val(), pop, n, o, i, op = []; |
128 | 248 | |
129 | 249 | if ( history !== '' ) { |
| 250 | // Read the JSON string with the image edit history. |
130 | 251 | history = JSON.parse(history); |
131 | 252 | pop = this.intval( $('#imgedit-undone-' + postid).val() ); |
132 | 253 | if ( pop > 0 ) { |
… |
… |
var imageEdit = window.imageEdit = { |
136 | 257 | } |
137 | 258 | } |
138 | 259 | |
| 260 | // Reset size to it's original state. |
139 | 261 | if ( setSize ) { |
140 | 262 | if ( !history.length ) { |
141 | 263 | this.hold.w = this.hold.ow; |
… |
… |
var imageEdit = window.imageEdit = { |
143 | 265 | return ''; |
144 | 266 | } |
145 | 267 | |
146 | | // restore |
| 268 | // Restore original 'o'. |
147 | 269 | o = history[history.length - 1]; |
| 270 | |
| 271 | // c = 'crop', r = 'rotate', f = 'flip' |
148 | 272 | o = o.c || o.r || o.f || false; |
149 | 273 | |
150 | 274 | if ( o ) { |
| 275 | // fw = Full image width |
151 | 276 | this.hold.w = o.fw; |
| 277 | // fh = Full image height |
152 | 278 | this.hold.h = o.fh; |
153 | 279 | } |
154 | 280 | } |
155 | 281 | |
156 | | // filter the values |
| 282 | // Filter the last step/action from the history. |
157 | 283 | for ( n in history ) { |
158 | 284 | i = history[n]; |
159 | 285 | if ( i.hasOwnProperty('c') ) { |
… |
… |
var imageEdit = window.imageEdit = { |
168 | 294 | } |
169 | 295 | return ''; |
170 | 296 | }, |
171 | | |
| 297 | /** |
| 298 | * @summary Binds the necessary events to the image. |
| 299 | * |
| 300 | * When the image source is reloaded the image will be reloaded. |
| 301 | * |
| 302 | * @memberof imageEdit |
| 303 | * @since 2.9 |
| 304 | * |
| 305 | * @param {number} postid The post id. |
| 306 | * @param {string} nonce The nonce to verify the request. |
| 307 | * @param {function} callback Function executed when the image is loaded. |
| 308 | * |
| 309 | * @returns {void} |
| 310 | */ |
172 | 311 | refreshEditor : function(postid, nonce, callback) { |
173 | 312 | var t = this, data, img; |
174 | 313 | |
… |
… |
var imageEdit = window.imageEdit = { |
188 | 327 | t = imageEdit, |
189 | 328 | historyObj; |
190 | 329 | |
| 330 | // Checks if there already is some image-edit history. |
191 | 331 | if ( '' !== event.data.history ) { |
192 | 332 | historyObj = JSON.parse( event.data.history ); |
193 | 333 | // If last executed action in history is a crop action. |
… |
… |
var imageEdit = window.imageEdit = { |
230 | 370 | }) |
231 | 371 | .attr('src', ajaxurl + '?' + $.param(data)); |
232 | 372 | }, |
233 | | |
| 373 | /** |
| 374 | * @summary Performs an image edit action. |
| 375 | * |
| 376 | * @memberof imageEdit |
| 377 | * @since 2.9 |
| 378 | * |
| 379 | * @param {number} postid The post id. |
| 380 | * @param {string} nonce The nonce to verify the request. |
| 381 | * @param {string} action The action to perform on the image. |
| 382 | * The possible actions are: "scale" and "restore". |
| 383 | * |
| 384 | * @returns {boolean|void} Executes a post request that refreshes the page |
| 385 | * when the action is performed. |
| 386 | * Returns false if a invalid action is given, |
| 387 | * or when the action cannot be performed. |
| 388 | */ |
234 | 389 | action : function(postid, nonce, action) { |
235 | 390 | var t = this, data, w, h, fw, fh; |
236 | 391 | |
… |
… |
var imageEdit = window.imageEdit = { |
282 | 437 | }); |
283 | 438 | }, |
284 | 439 | |
| 440 | /** |
| 441 | * @summary Stores the changes that are made to the image. |
| 442 | * |
| 443 | * @memberof imageEdit |
| 444 | * @since 2.9 |
| 445 | * |
| 446 | * @param {number} postid The post id to get the image from the database. |
| 447 | * @param {string} nonce The nonce to verify the request. |
| 448 | * |
| 449 | * @returns {boolean|void} If the actions are successfully saved a response message is shown. |
| 450 | * Returns false if there is no image editing history, |
| 451 | * thus there are not edit-actions performed on the image. |
| 452 | */ |
285 | 453 | save : function(postid, nonce) { |
286 | 454 | var data, |
287 | 455 | target = this.getTarget(postid), |
… |
… |
var imageEdit = window.imageEdit = { |
302 | 470 | 'context': $('#image-edit-context').length ? $('#image-edit-context').val() : null, |
303 | 471 | 'do': 'save' |
304 | 472 | }; |
305 | | |
| 473 | // Post the image edit data to the backend. |
306 | 474 | $.post(ajaxurl, data, function(r) { |
| 475 | // Read the response. |
307 | 476 | var ret = JSON.parse(r); |
308 | 477 | |
| 478 | // If a response is returned, close the editor and show an error. |
309 | 479 | if ( ret.error ) { |
310 | 480 | $('#imgedit-response-' + postid).html('<div class="error"><p>' + ret.error + '</p></div>'); |
311 | 481 | imageEdit.close(postid); |
… |
… |
var imageEdit = window.imageEdit = { |
332 | 502 | }); |
333 | 503 | }, |
334 | 504 | |
| 505 | /** |
| 506 | * @summary Creates the image edit window. |
| 507 | * |
| 508 | * @memberof imageEdit |
| 509 | * @since 2.9 |
| 510 | * |
| 511 | * @param {number} postid The post id for the image. |
| 512 | * @param {string} nonce The nonce to verify the request. |
| 513 | * @param {object} view The image editor view to be used for the editing. |
| 514 | * |
| 515 | * @returns {void|promise} Either returns void if the button was already activated |
| 516 | * or returns an instance of the image editor, wrapped in a promise. |
| 517 | */ |
335 | 518 | open : function( postid, nonce, view ) { |
336 | 519 | this._view = view; |
337 | 520 | |
… |
… |
var imageEdit = window.imageEdit = { |
376 | 559 | return dfd; |
377 | 560 | }, |
378 | 561 | |
| 562 | /** |
| 563 | * @summary Initializes the cropping tool and sets a default cropping selection. |
| 564 | * |
| 565 | * @memberof imageEdit |
| 566 | * @since 2.9 |
| 567 | * |
| 568 | * @param {number} postid The post id. |
| 569 | * |
| 570 | * @returns {void} |
| 571 | */ |
379 | 572 | imgLoaded : function(postid) { |
380 | 573 | var img = $('#image-preview-' + postid), parent = $('#imgedit-crop-' + postid); |
381 | 574 | |
… |
… |
var imageEdit = window.imageEdit = { |
386 | 579 | $( '.imgedit-wrap .imgedit-help-toggle' ).eq( 0 ).focus(); |
387 | 580 | }, |
388 | 581 | |
| 582 | /** |
| 583 | * @summary Initializes the cropping tool. |
| 584 | * |
| 585 | * @memberof imageEdit |
| 586 | * @since 2.9 |
| 587 | * |
| 588 | * @param {number} postid The post id. |
| 589 | * @param {HTMLElement} image The preview image. |
| 590 | * @param {HTMLElement} parent The preview image container. |
| 591 | * |
| 592 | * @returns {void} |
| 593 | */ |
389 | 594 | initCrop : function(postid, image, parent) { |
390 | 595 | var t = this, |
391 | 596 | selW = $('#imgedit-sel-width-' + postid), |
… |
… |
var imageEdit = window.imageEdit = { |
400 | 605 | minWidth: 3, |
401 | 606 | minHeight: 3, |
402 | 607 | |
| 608 | /** |
| 609 | * @summary Sets the CSS styles and binds events for locking the aspect ratio. |
| 610 | * |
| 611 | * @param {jQuery} img The preview image. |
| 612 | */ |
403 | 613 | onInit: function( img ) { |
404 | | // Ensure that the imgareaselect wrapper elements are position:absolute |
| 614 | // Ensure that the imgAreaSelect wrapper elements are position:absolute |
405 | 615 | // (even if we're in a position:fixed modal) |
406 | 616 | $img = $( img ); |
407 | 617 | $img.next().css( 'position', 'absolute' ) |
408 | 618 | .nextAll( '.imgareaselect-outer' ).css( 'position', 'absolute' ); |
409 | | |
| 619 | /** |
| 620 | * @summary Binds mouse down event to the cropping container. |
| 621 | * |
| 622 | * @returns {void} |
| 623 | */ |
410 | 624 | parent.children().mousedown(function(e){ |
411 | 625 | var ratio = false, sel, defRatio; |
412 | 626 | |
… |
… |
var imageEdit = window.imageEdit = { |
422 | 636 | }); |
423 | 637 | }, |
424 | 638 | |
| 639 | /** |
| 640 | * @summary Event triggered when starting a selection. |
| 641 | * |
| 642 | * @returns {void} |
| 643 | */ |
425 | 644 | onSelectStart: function() { |
426 | 645 | imageEdit.setDisabled($('#imgedit-crop-sel-' + postid), 1); |
427 | 646 | }, |
428 | | |
| 647 | /** |
| 648 | * @summary Event triggered when the selection is ended. |
| 649 | * |
| 650 | * @param {object} img jQuery object representing the image. |
| 651 | * @param {object} c The selection. |
| 652 | * |
| 653 | * @returns {object} |
| 654 | */ |
429 | 655 | onSelectEnd: function(img, c) { |
430 | 656 | imageEdit.setCropSelection(postid, c); |
431 | 657 | }, |
432 | 658 | |
| 659 | /** |
| 660 | * @summary Event triggered when the selection changed. |
| 661 | * |
| 662 | * @param {object} img jQuery object representing the image. |
| 663 | * @param {object} c The selection. |
| 664 | * |
| 665 | * @returns {void} |
| 666 | */ |
433 | 667 | onSelectChange: function(img, c) { |
434 | 668 | var sizer = imageEdit.hold.sizer; |
435 | 669 | selW.val( imageEdit.round(c.width / sizer) ); |
… |
… |
var imageEdit = window.imageEdit = { |
438 | 672 | }); |
439 | 673 | }, |
440 | 674 | |
| 675 | /** |
| 676 | * @summary Stores the current crop selection. |
| 677 | * |
| 678 | * @memberof imageEdit |
| 679 | * @since 2.9 |
| 680 | * |
| 681 | * @param {number} postid The post id. |
| 682 | * @param {object} c The selection. |
| 683 | * |
| 684 | * @returns {boolean} |
| 685 | */ |
441 | 686 | setCropSelection : function(postid, c) { |
442 | 687 | var sel; |
443 | 688 | |
… |
… |
var imageEdit = window.imageEdit = { |
457 | 702 | $('#imgedit-selection-' + postid).val( JSON.stringify(sel) ); |
458 | 703 | }, |
459 | 704 | |
| 705 | |
| 706 | /** |
| 707 | * @summary Closes the image editor. |
| 708 | * |
| 709 | * @memberof imageEdit |
| 710 | * @since 2.9 |
| 711 | * |
| 712 | * @param {number} postid The post id. |
| 713 | * @param {bool} warn Warning message. |
| 714 | * |
| 715 | * @returns {void|bool} Returns false if there is a warning. |
| 716 | */ |
460 | 717 | close : function(postid, warn) { |
461 | 718 | warn = warn || false; |
462 | 719 | |
… |
… |
var imageEdit = window.imageEdit = { |
487 | 744 | |
488 | 745 | }, |
489 | 746 | |
| 747 | /** |
| 748 | * @summary Checks if the image edit history is saved. |
| 749 | * |
| 750 | * @memberof imageEdit |
| 751 | * @since 2.9 |
| 752 | * |
| 753 | * @param {number} postid The post id. |
| 754 | * |
| 755 | * @returns {boolean} Returns true if the history is not saved. |
| 756 | */ |
490 | 757 | notsaved : function(postid) { |
491 | 758 | var h = $('#imgedit-history-' + postid).val(), |
492 | 759 | history = ( h !== '' ) ? JSON.parse(h) : [], |
… |
… |
var imageEdit = window.imageEdit = { |
501 | 768 | return false; |
502 | 769 | }, |
503 | 770 | |
| 771 | /** |
| 772 | * @summary Adds a image edit action to the history. |
| 773 | * |
| 774 | * @memberof imageEdit |
| 775 | * @since 2.9 |
| 776 | * |
| 777 | * @param {object} op The original position. |
| 778 | * @param {number} postid The post id. |
| 779 | * @param {string} nonce The nonce. |
| 780 | * |
| 781 | * @returns {void} |
| 782 | */ |
504 | 783 | addStep : function(op, postid, nonce) { |
505 | 784 | var t = this, elem = $('#imgedit-history-' + postid), |
506 | 785 | history = ( elem.val() !== '' ) ? JSON.parse( elem.val() ) : [], |
… |
… |
var imageEdit = window.imageEdit = { |
522 | 801 | }); |
523 | 802 | }, |
524 | 803 | |
| 804 | /** |
| 805 | * @summary Rotates the image. |
| 806 | * |
| 807 | * @memberof imageEdit |
| 808 | * @since 2.9 |
| 809 | * |
| 810 | * @param {string} angle The angle the image is rotated with. |
| 811 | * @param {number} postid The post id. |
| 812 | * @param {string} nonce The nonce |
| 813 | * @param {object} t The target element. |
| 814 | * |
| 815 | * @returns {boolean} |
| 816 | */ |
525 | 817 | rotate : function(angle, postid, nonce, t) { |
526 | 818 | if ( $(t).hasClass('disabled') ) { |
527 | 819 | return false; |
… |
… |
var imageEdit = window.imageEdit = { |
530 | 822 | this.addStep({ 'r': { 'r': angle, 'fw': this.hold.h, 'fh': this.hold.w }}, postid, nonce); |
531 | 823 | }, |
532 | 824 | |
| 825 | /** |
| 826 | * @summary Flips the image. |
| 827 | * |
| 828 | * @memberof imageEdit |
| 829 | * @since 2.9 |
| 830 | * |
| 831 | * @param {number} axis The axle the image is flipped on. |
| 832 | * @param {number} postid The post id. |
| 833 | * @param {string} nonce The nonce. |
| 834 | * @param {object} t The target element. |
| 835 | * |
| 836 | * @returns {boolean} |
| 837 | */ |
533 | 838 | flip : function (axis, postid, nonce, t) { |
534 | 839 | if ( $(t).hasClass('disabled') ) { |
535 | 840 | return false; |
… |
… |
var imageEdit = window.imageEdit = { |
538 | 843 | this.addStep({ 'f': { 'f': axis, 'fw': this.hold.w, 'fh': this.hold.h }}, postid, nonce); |
539 | 844 | }, |
540 | 845 | |
| 846 | /** |
| 847 | * @summary Crops the image. |
| 848 | * |
| 849 | * @memberof imageEdit |
| 850 | * @since 2.9 |
| 851 | * |
| 852 | * @param {number} postid The post id. |
| 853 | * @param {string} nonce The nonce. |
| 854 | * @param {object} t The target object. |
| 855 | * |
| 856 | * @returns {void|boolean} Returns false if the crop button is disabled. |
| 857 | */ |
541 | 858 | crop : function (postid, nonce, t) { |
542 | 859 | var sel = $('#imgedit-selection-' + postid).val(), |
543 | 860 | w = this.intval( $('#imgedit-sel-width-' + postid).val() ), |
… |
… |
var imageEdit = window.imageEdit = { |
555 | 872 | } |
556 | 873 | }, |
557 | 874 | |
| 875 | /** |
| 876 | * @summary Undoes a image edit action. |
| 877 | * |
| 878 | * @memberof imageEdit |
| 879 | * @since 2.9 |
| 880 | * |
| 881 | * @param {number} postid The post id. |
| 882 | * @param {string} nonce The nonce. |
| 883 | * |
| 884 | * @returns {void|false} Returns false if the undo button is disabled. |
| 885 | */ |
558 | 886 | undo : function (postid, nonce) { |
559 | 887 | var t = this, button = $('#image-undo-' + postid), elem = $('#imgedit-undone-' + postid), |
560 | 888 | pop = t.intval( elem.val() ) + 1; |
… |
… |
var imageEdit = window.imageEdit = { |
577 | 905 | }); |
578 | 906 | }, |
579 | 907 | |
| 908 | /** |
| 909 | * Reverts a undo action. |
| 910 | * |
| 911 | * @memberof imageEdit |
| 912 | * @since 2.9 |
| 913 | * |
| 914 | * @param {number} postid The post id. |
| 915 | * @param {string} nonce The nonce. |
| 916 | * |
| 917 | * @returns {void} |
| 918 | */ |
580 | 919 | redo : function(postid, nonce) { |
581 | 920 | var t = this, button = $('#image-redo-' + postid), elem = $('#imgedit-undone-' + postid), |
582 | 921 | pop = t.intval( elem.val() ) - 1; |
… |
… |
var imageEdit = window.imageEdit = { |
596 | 935 | }); |
597 | 936 | }, |
598 | 937 | |
| 938 | /** |
| 939 | * @summary Sets the selection for the height and width in pixels. |
| 940 | * |
| 941 | * @memberof imageEdit |
| 942 | * @since 2.9 |
| 943 | * |
| 944 | * @param {number} postid The post id. |
| 945 | * @param {jQuery} el The element containing the values. |
| 946 | * |
| 947 | * @returns {void|boolean} Returns false when the x or y value is lower than 1, |
| 948 | * void when the value is not numeric or when the operation |
| 949 | * is successful. |
| 950 | */ |
599 | 951 | setNumSelection : function( postid, el ) { |
600 | 952 | var sel, elX = $('#imgedit-sel-width-' + postid), elY = $('#imgedit-sel-height-' + postid), |
601 | 953 | x = this.intval( elX.val() ), y = this.intval( elY.val() ), |
… |
… |
var imageEdit = window.imageEdit = { |
640 | 992 | } |
641 | 993 | }, |
642 | 994 | |
| 995 | /** |
| 996 | * Rounds a number to a whole. |
| 997 | * |
| 998 | * @memberof imageEdit |
| 999 | * @since 2.9 |
| 1000 | * |
| 1001 | * @param {number} num The number. |
| 1002 | * |
| 1003 | * @returns {number} The number rounded to a whole number. |
| 1004 | */ |
643 | 1005 | round : function(num) { |
644 | 1006 | var s; |
645 | 1007 | num = Math.round(num); |
… |
… |
var imageEdit = window.imageEdit = { |
659 | 1021 | return num; |
660 | 1022 | }, |
661 | 1023 | |
| 1024 | /** |
| 1025 | * Sets a locked aspect ratio for the selection. |
| 1026 | * |
| 1027 | * @memberof imageEdit |
| 1028 | * @since 2.9 |
| 1029 | * |
| 1030 | * @param {number} postid The post id. |
| 1031 | * @param {number} n The ratio to set. |
| 1032 | * @param {jQuery} el The element containing the values. |
| 1033 | * |
| 1034 | * @returns {void} |
| 1035 | */ |
662 | 1036 | setRatioSelection : function(postid, n, el) { |
663 | 1037 | var sel, r, x = this.intval( $('#imgedit-crop-width-' + postid).val() ), |
664 | 1038 | y = this.intval( $('#imgedit-crop-height-' + postid).val() ), |
… |
… |
var imageEdit = window.imageEdit = { |
691 | 1065 | } |
692 | 1066 | }, |
693 | 1067 | |
| 1068 | /** |
| 1069 | * Validates if a value in a jQuery.HTMLElement is numeric. |
| 1070 | * |
| 1071 | * @memberof imageEdit |
| 1072 | * @since 4.6 |
| 1073 | * |
| 1074 | * @param {jQuery} el The html element. |
| 1075 | * |
| 1076 | * @returns {void|boolean} Returns false if the value is not numeric, |
| 1077 | * void when it is. |
| 1078 | */ |
694 | 1079 | validateNumeric: function( el ) { |
695 | 1080 | if ( ! this.intval( $( el ).val() ) ) { |
696 | 1081 | $( el ).val( '' ); |