Code Duplication    Length = 56-56 lines in 2 locations

controls/js/script-legacy.js 1 location

@@ 2563-2618 (lines=56) @@
2560
	 * @param {wp.media.controller.Cropper} controller
2561
	 * @returns {Object} Options
2562
	 */
2563
	calculateImageSelectOptions: function( attachment, controller ) {
2564
2565
		'use strict';
2566
2567
		var control    = controller.get( 'control' ),
2568
		    flexWidth  = !! parseInt( control.params.flex_width, 10 ),
2569
		    flexHeight = !! parseInt( control.params.flex_height, 10 ),
2570
		    realWidth  = attachment.get( 'width' ),
2571
		    realHeight = attachment.get( 'height' ),
2572
		    xInit      = parseInt( control.params.width, 10 ),
2573
		    yInit      = parseInt( control.params.height, 10 ),
2574
		    ratio      = xInit / yInit,
2575
		    xImg       = realWidth,
2576
		    yImg       = realHeight,
2577
		    x1,
2578
		    y1,
2579
		    imgSelectOptions;
2580
2581
		controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) );
2582
2583
		if ( xImg / yImg > ratio ) {
2584
			yInit = yImg;
2585
			xInit = yInit * ratio;
2586
		} else {
2587
			xInit = xImg;
2588
			yInit = xInit / ratio;
2589
		}
2590
2591
		x1 = ( xImg - xInit ) / 2;
2592
		y1 = ( yImg - yInit ) / 2;
2593
2594
		imgSelectOptions = {
2595
			handles:     true,
2596
			keys:        true,
2597
			instance:    true,
2598
			persistent:  true,
2599
			imageWidth:  realWidth,
2600
			imageHeight: realHeight,
2601
			x1:          x1,
2602
			y1:          y1,
2603
			x2:          xInit + x1,
2604
			y2:          yInit + y1
2605
		};
2606
2607
		if ( false === flexHeight && false === flexWidth ) {
2608
			imgSelectOptions.aspectRatio = xInit + ':' + yInit;
2609
		}
2610
		if ( false === flexHeight ) {
2611
			imgSelectOptions.maxHeight = yInit;
2612
		}
2613
		if ( false === flexWidth ) {
2614
			imgSelectOptions.maxWidth = xInit;
2615
		}
2616
2617
		return imgSelectOptions;
2618
	},
2619
2620
	/**
2621
	 * Return whether the image must be cropped, based on required dimensions.

controls/js/script.js 1 location

@@ 2522-2577 (lines=56) @@
2519
	 * @param {wp.media.controller.Cropper} controller
2520
	 * @returns {Object} Options
2521
	 */
2522
	calculateImageSelectOptions: function( attachment, controller ) {
2523
2524
		'use strict';
2525
2526
		var control    = controller.get( 'control' ),
2527
		    flexWidth  = !! parseInt( control.params.flex_width, 10 ),
2528
		    flexHeight = !! parseInt( control.params.flex_height, 10 ),
2529
		    realWidth  = attachment.get( 'width' ),
2530
		    realHeight = attachment.get( 'height' ),
2531
		    xInit      = parseInt( control.params.width, 10 ),
2532
		    yInit      = parseInt( control.params.height, 10 ),
2533
		    ratio      = xInit / yInit,
2534
		    xImg       = realWidth,
2535
		    yImg       = realHeight,
2536
		    x1,
2537
		    y1,
2538
		    imgSelectOptions;
2539
2540
		controller.set( 'canSkipCrop', ! control.mustBeCropped( flexWidth, flexHeight, xInit, yInit, realWidth, realHeight ) );
2541
2542
		if ( xImg / yImg > ratio ) {
2543
			yInit = yImg;
2544
			xInit = yInit * ratio;
2545
		} else {
2546
			xInit = xImg;
2547
			yInit = xInit / ratio;
2548
		}
2549
2550
		x1 = ( xImg - xInit ) / 2;
2551
		y1 = ( yImg - yInit ) / 2;
2552
2553
		imgSelectOptions = {
2554
			handles:     true,
2555
			keys:        true,
2556
			instance:    true,
2557
			persistent:  true,
2558
			imageWidth:  realWidth,
2559
			imageHeight: realHeight,
2560
			x1:          x1,
2561
			y1:          y1,
2562
			x2:          xInit + x1,
2563
			y2:          yInit + y1
2564
		};
2565
2566
		if ( false === flexHeight && false === flexWidth ) {
2567
			imgSelectOptions.aspectRatio = xInit + ':' + yInit;
2568
		}
2569
		if ( false === flexHeight ) {
2570
			imgSelectOptions.maxHeight = yInit;
2571
		}
2572
		if ( false === flexWidth ) {
2573
			imgSelectOptions.maxWidth = xInit;
2574
		}
2575
2576
		return imgSelectOptions;
2577
	},
2578
2579
	/**
2580
	 * Return whether the image must be cropped, based on required dimensions.