Code Duplication    Length = 66-77 lines in 2 locations

js/jquery-ui.js 2 locations

@@ 1441-1517 (lines=77) @@
1438
1439
	},
1440
1441
	_generatePosition: function(event) {
1442
1443
		var containment, co, top, left,
1444
			o = this.options,
1445
			scroll = this.cssPosition === "absolute" && !( this.scrollParent[ 0 ] !== document && $.contains( this.scrollParent[ 0 ], this.offsetParent[ 0 ] ) ) ? this.offsetParent : this.scrollParent,
1446
			pageX = event.pageX,
1447
			pageY = event.pageY;
1448
1449
		//Cache the scroll
1450
		if (!this.offset.scroll) {
1451
			this.offset.scroll = {top : scroll.scrollTop(), left : scroll.scrollLeft()};
1452
		}
1453
1454
		/*
1455
		 * - Position constraining -
1456
		 * Constrain the position to a mix of grid, containment.
1457
		 */
1458
1459
		// If we are not dragging yet, we won't check for options
1460
		if ( this.originalPosition ) {
1461
			if ( this.containment ) {
1462
				if ( this.relative_container ){
1463
					co = this.relative_container.offset();
1464
					containment = [
1465
						this.containment[ 0 ] + co.left,
1466
						this.containment[ 1 ] + co.top,
1467
						this.containment[ 2 ] + co.left,
1468
						this.containment[ 3 ] + co.top
1469
					];
1470
				}
1471
				else {
1472
					containment = this.containment;
1473
				}
1474
1475
				if(event.pageX - this.offset.click.left < containment[0]) {
1476
					pageX = containment[0] + this.offset.click.left;
1477
				}
1478
				if(event.pageY - this.offset.click.top < containment[1]) {
1479
					pageY = containment[1] + this.offset.click.top;
1480
				}
1481
				if(event.pageX - this.offset.click.left > containment[2]) {
1482
					pageX = containment[2] + this.offset.click.left;
1483
				}
1484
				if(event.pageY - this.offset.click.top > containment[3]) {
1485
					pageY = containment[3] + this.offset.click.top;
1486
				}
1487
			}
1488
1489
			if(o.grid) {
1490
				//Check for grid elements set to 0 to prevent divide by 0 error causing invalid argument errors in IE (see ticket #6950)
1491
				top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY;
1492
				pageY = containment ? ((top - this.offset.click.top >= containment[1] || top - this.offset.click.top > containment[3]) ? top : ((top - this.offset.click.top >= containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
1493
1494
				left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX;
1495
				pageX = containment ? ((left - this.offset.click.left >= containment[0] || left - this.offset.click.left > containment[2]) ? left : ((left - this.offset.click.left >= containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
1496
			}
1497
1498
		}
1499
1500
		return {
1501
			top: (
1502
				pageY -																	// The absolute mouse position
1503
				this.offset.click.top	-												// Click offset (relative to the element)
1504
				this.offset.relative.top -												// Only for relative positioned nodes: Relative offset from element to offset parent
1505
				this.offset.parent.top +												// The offsetParent's offset without borders (offset + border)
1506
				( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : this.offset.scroll.top )
1507
			),
1508
			left: (
1509
				pageX -																	// The absolute mouse position
1510
				this.offset.click.left -												// Click offset (relative to the element)
1511
				this.offset.relative.left -												// Only for relative positioned nodes: Relative offset from element to offset parent
1512
				this.offset.parent.left +												// The offsetParent's offset without borders (offset + border)
1513
				( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : this.offset.scroll.left )
1514
			)
1515
		};
1516
1517
	},
1518
1519
	_clear: function() {
1520
		this.helper.removeClass("ui-draggable-dragging");
@@ 4559-4624 (lines=66) @@
4556
4557
	},
4558
4559
	_generatePosition: function(event) {
4560
4561
		var top, left,
4562
			o = this.options,
4563
			pageX = event.pageX,
4564
			pageY = event.pageY,
4565
			scroll = this.cssPosition === "absolute" && !(this.scrollParent[0] !== document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
4566
4567
		// This is another very weird special case that only happens for relative elements:
4568
		// 1. If the css position is relative
4569
		// 2. and the scroll parent is the document or similar to the offset parent
4570
		// we have to refresh the relative offset during the scroll so there are no jumps
4571
		if(this.cssPosition === "relative" && !(this.scrollParent[0] !== document && this.scrollParent[0] !== this.offsetParent[0])) {
4572
			this.offset.relative = this._getRelativeOffset();
4573
		}
4574
4575
		/*
4576
		 * - Position constraining -
4577
		 * Constrain the position to a mix of grid, containment.
4578
		 */
4579
4580
		if(this.originalPosition) { //If we are not dragging yet, we won't check for options
4581
4582
			if(this.containment) {
4583
				if(event.pageX - this.offset.click.left < this.containment[0]) {
4584
					pageX = this.containment[0] + this.offset.click.left;
4585
				}
4586
				if(event.pageY - this.offset.click.top < this.containment[1]) {
4587
					pageY = this.containment[1] + this.offset.click.top;
4588
				}
4589
				if(event.pageX - this.offset.click.left > this.containment[2]) {
4590
					pageX = this.containment[2] + this.offset.click.left;
4591
				}
4592
				if(event.pageY - this.offset.click.top > this.containment[3]) {
4593
					pageY = this.containment[3] + this.offset.click.top;
4594
				}
4595
			}
4596
4597
			if(o.grid) {
4598
				top = this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1];
4599
				pageY = this.containment ? ( (top - this.offset.click.top >= this.containment[1] && top - this.offset.click.top <= this.containment[3]) ? top : ((top - this.offset.click.top >= this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
4600
4601
				left = this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0];
4602
				pageX = this.containment ? ( (left - this.offset.click.left >= this.containment[0] && left - this.offset.click.left <= this.containment[2]) ? left : ((left - this.offset.click.left >= this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
4603
			}
4604
4605
		}
4606
4607
		return {
4608
			top: (
4609
				pageY -																// The absolute mouse position
4610
				this.offset.click.top -													// Click offset (relative to the element)
4611
				this.offset.relative.top	-											// Only for relative positioned nodes: Relative offset from element to offset parent
4612
				this.offset.parent.top +												// The offsetParent's offset without borders (offset + border)
4613
				( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ))
4614
			),
4615
			left: (
4616
				pageX -																// The absolute mouse position
4617
				this.offset.click.left -												// Click offset (relative to the element)
4618
				this.offset.relative.left	-											// Only for relative positioned nodes: Relative offset from element to offset parent
4619
				this.offset.parent.left +												// The offsetParent's offset without borders (offset + border)
4620
				( ( this.cssPosition === "fixed" ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ))
4621
			)
4622
		};
4623
4624
	},
4625
4626
	_rearrange: function(event, i, a, hardRefresh) {
4627