Sort with text node patched

by morchard

HTML

<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<div>Sort the blue node to before the orange node and release. The sort will be cancelled, and the blue node will return to after the text node.</div>
<br/>
<div class="container">
    <div class="sortable-child child-orange"></div>
    text
    <div class="sortable-child child-blue"></div>
</div>

CSS

.container {
    height: 50px;
    width: 155px;
    border: 1px solid black;
    padding: 5px;
}

.sortable-child {
    display: inline-block;
    height: 50px;
    width: 50px;
    margin: 0 5px;
}

.child-orange {
    background-color: orange;
}

.child-blue {
    background-color: blue;
}

JavaScript

$.widget("ui.sortable", $.extend({}, $.ui.sortable.prototype, {
    _mouseStart: function(event, overrideHandle, noActivation) {

		var i, body,
			o = this.options;

		this.currentContainer = this;

		//We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
		this.refreshPositions();

		//Create and append the visible helper
		this.helper = this._createHelper(event);

		//Cache the helper size
		this._cacheHelperProportions();

		/*
		 * - Position generation -
		 * This block generates everything position related - it's the core of draggables.
		 */

		//Cache the margins of the original element
		this._cacheMargins();

		//Get the next scrolling parent
		this.scrollParent = this.helper.scrollParent();

		//The element's absolute position on the page minus margins
		this.offset = this.currentItem.offset();
		this.offset = {
			top: this.offset.top - this.margins.top,
			left: this.offset.left - this.margins.left
		};

		$.extend(this.offset, {
			click: { //Where the click happened, relative to the element
				left: event.pageX - this.offset.left,
				top: event.pageY - this.offset.top
			},
			parent: this._getParentOffset(),
			relative: this._getRelativeOffset() //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helper
		});

		// Only after we got the offset, we can change the helper's position to absolute
		// TODO: Still need to figure out a way to make relative sorting possible
		this.helper.css("position", "absolute");
		this.cssPosition = this.helper.css("position");

		//Generate the original position
		this.originalPosition = this._generatePosition(event);
		this.originalPageX = event.pageX;
		this.originalPageY = event.pageY;

		//Adjust the mouse offset relative to the helper if "cursorAt" is supplied
		(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt));

		//Cache the former DOM position
        /** PATCH START **/
		this.domPosition...