<commit_before>// jQuery List DragSort v0.4
// Website: http://dragsort.codeplex.com/
// License: http://dragsort.codeplex.com/license

(function(jQuery) {

	jQuery.fn.dragsort = function(options) {
		var opts = jQuery.extend({}, jQuery.fn.dragsort.defaults, options);
		var lists = [];
		var list = null, lastPos = null;
		if (this.selector)
			jQuery("head").append("<style type='text/css'>" + (this.selector.split(",").join(" " + opts.dragSelector + ",") + " " + opts.dragSelector) + " { cursor: pointer; }</style>");

		this.each(function(i, cont) {

			if (jQuery(cont).is("table") && jQuery(cont).children().size() == 1 && jQuery(cont).children().is("tbody"))
				cont = jQuery(cont).children().get(0);

			var newList = {
				draggedItem: null,
				placeHolderItem: null,
				pos: null,
				offset: null,
				offsetLimit: null,
				scroll: null,
				container: cont,

				init: function() {
					jQuery(this.container).attr("data-listIdx", i).mousedown(this.grabItem).find(opts.dragSelector).css("cursor", "pointer");
					jQuery(this.container).children(opts.itemSelector).each(function(j) { jQuery(this).attr("data-itemIdx", j); });
				},

				grabItem: function(e) {
					if (e.which != 1 || jQuery(e.target).is(opts.dragSelectorExclude))
						return;

					var elm = e.target;
					while (!jQuery(elm).is("[data-listIdx='" + jQuery(this).attr("data-listIdx") + "'] " + opts.dragSelector)) {
						if (elm == this) return;
						elm = elm.parentNode;
					}

					if (list != null && list.draggedItem != null)
						list.dropItem();

					jQuery(e.target).css("cursor", "move");

					list = lists[jQuery(this).attr("data-listIdx")];
					list.draggedItem = jQuery(elm).closest(opts.itemSelector);
					var mt = parseInt(list.draggedItem.css("marginTop"));
					var ml = parseInt(list.draggedItem.css("marginLeft"));
					list.offset = list.draggedItem.offset();
					list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
					list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;

					if (!opts.dragBetween) {
						var containerHeight = jQuery(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + jQuery(list.container).children(opts.itemSelector).size() * list.draggedItem.outerWidth() / jQuery(list.container).outerWidth())) * list.draggedItem.outerHeight() : jQuery(list.container).outerHeight();
						list.offsetLimit = jQuery(list.container).offset();
						list.offsetLimit.right = list.offsetLimit.left + jQuery(list.container).outerWidth() - list.draggedItem.outerWidth();
						list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
					}

					var h = list.draggedItem.height();
					var w = list.draggedItem.width();
					var orig = list.draggedItem.attr("style");
					list.draggedItem.attr("data-origStyle", orig ? orig : "");
					if (opts.itemSelector == "tr") {
						list.draggedItem.children().each(function() { jQuery(this).width(jQuery(this).width()); });
						list.placeHolderItem = list.draggedItem.clone().attr("data-placeHolder", true);
						list.draggedItem.after(list.placeHolderItem);
						list.placeHolderItem.children().each(function() { jQuery(this).css({ borderWidth:0, width: jQuery(this).width() + 1, height: jQuery(this).height() + 1 }).html("&nbsp;"); });
					} else {
						list.draggedItem.after(opts.placeHolderTemplate);
						list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeHolder", true);
					}
					list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });

					jQuery(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });

					list.scroll = { moveX: 0, moveY: 0, maxX: jQuery(document).width() - jQuery(window).width(), maxY: jQuery(document).height() - jQuery(window).height() };
					list.scroll.scrollY = window.setInterval(function() {
						if (opts.scrollContainer != window) {
							jQuery(opts.scrollContainer).scrollTop(jQuery(opts.scrollContainer).scrollTop() + list.scroll.moveY);
							return;
						}
						var t = jQuery(opts.scrollContainer).scrollTop();
						if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
							jQuery(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
							list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
						}
					}, 10);
					list.scroll.scrollX = window.setInterval(function() {
						if (opts.scrollContainer != window) {
							jQuery(opts.scrollContainer).scrollLeft(jQuery(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
							return;
						}
						var l = jQuery(opts.scrollContainer).scrollLeft();
						if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
							jQuery(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
							list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
						}
					}, 10);

					list.setPos(e.pageX, e.pageY);
					jQuery(document).bind("selectstart", list.stopBubble); //stop ie text selection
					jQuery(document).bind("mousemove", list.swapItems);
					jQuery(document).bind("mouseup", list.dropItem);
					if (opts.scrollContainer != window)
						jQuery(window).bind("DOMMouseScroll mousewheel", list.wheel);
					return false; //stop moz text selection
				},

				setPos: function(x, y) {
					var top = y - this.offset.top;
					var left = x - this.offset.left;

					if (!opts.dragBetween) {
						top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
						left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
					}

					this.draggedItem.parents().each(function() {
						if (jQuery(this).css("position") != "static" && (!$.browser.mozilla || jQuery(this).css("display") != "table")) {
							var offset = jQuery(this).offset();
							top -= offset.top;
							left -= offset.left;
							return false;
						}
					});

					if (opts.scrollContainer == window) {
						y -= jQuery(window).scrollTop();
						x -= jQuery(window).scrollLeft();
						y = Math.max(0, y - jQuery(window).height() + 5) + Math.min(0, y - 5);
						x = Math.max(0, x - jQuery(window).width() + 5) + Math.min(0, x - 5);
					} else {
						var cont = jQuery(opts.scrollContainer);
						var offset = cont.offset();
						y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
						x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
					}

					list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
					list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);

					this.draggedItem.css({ top: top, left: left });
				},

				wheel: function(e) {
					if (($.browser.safari || $.browser.mozilla) && list && opts.scrollContainer != window) {
						var cont = jQuery(opts.scrollContainer);
						var offset = cont.offset();
						if (e.pageX > offset.left && e.pageX < offset.left + cont.width() && e.pageY > offset.top && e.pageY < offset.top + cont.height()) {
							var delta = e.detail ? e.detail * 5 : e.wheelDelta / -2;
							cont.scrollTop(cont.scrollTop() + delta);
							e.preventDefault();
						}
					}
				},

				buildPositionTable: function() {
					var item = this.draggedItem == null ? null : this.draggedItem.get(0);
					var pos = [];
					jQuery(this.container).children(opts.itemSelector).each(function(i, elm) {
						if (elm != item) {
							var loc = jQuery(elm).offset();
							loc.right = loc.left + jQuery(elm).width();
							loc.bottom = loc.top + jQuery(elm).height();
							loc.elm = elm;
							pos.push(loc);
						}
					});
					this.pos = pos;
				},

				dropItem: function() {
					if (list.draggedItem == null)
						return;

					jQuery(list.container).find(opts.dragSelector).css("cursor", "pointer");
					list.placeHolderItem.before(list.draggedItem);

					//list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
					//list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
					var orig = list.draggedItem.attr("data-origStyle");
					list.draggedItem.attr("style", orig);
					if (orig == "")
						list.draggedItem.removeAttr("style");
					list.draggedItem.removeAttr("data-origStyle");
					list.placeHolderItem.remove();

					jQuery("[data-dropTarget]").remove();

					window.clearInterval(list.scroll.scrollY);
					window.clearInterval(list.scroll.scrollX);

					var changed = false;
					jQuery(lists).each(function() {
						jQuery(this.container).children(opts.itemSelector).each(function(j) {
							if (parseInt(jQuery(this).attr("data-itemIdx")) != j) {
								changed = true;
								jQuery(this).attr("data-itemIdx", j);
							}
						});
					});
					if (changed)
						opts.dragEnd.apply(list.draggedItem);
					list.draggedItem = null;
					jQuery(document).unbind("selectstart", list.stopBubble);
					jQuery(document).unbind("mousemove", list.swapItems);<commit_msg>* Fix bug in dragsort where is was testing for changes in the lists postions of items, but ignoring whether or not the item was now in a different list<commit_after>// jQuery List DragSort v0.4
// Website: http://dragsort.codeplex.com/
// License: http://dragsort.codeplex.com/license

(function(jQuery) {

	jQuery.fn.dragsort = function(options) {
		var opts = jQuery.extend({}, jQuery.fn.dragsort.defaults, options);
		var lists = [];
		var list = null, lastPos = null;
		if (this.selector)
			jQuery("head").append("<style type='text/css'>" + (this.selector.split(",").join(" " + opts.dragSelector + ",") + " " + opts.dragSelector) + " { cursor: pointer; }</style>");

		this.each(function(i, cont) {

			if (jQuery(cont).is("table") && jQuery(cont).children().size() == 1 && jQuery(cont).children().is("tbody"))
				cont = jQuery(cont).children().get(0);

			var newList = {
				draggedItem: null,
				placeHolderItem: null,
				pos: null,
				offset: null,
				offsetLimit: null,
				scroll: null,
				container: cont,

				init: function() {
					jQuery(this.container).attr("data-listIdx", i).mousedown(this.grabItem).find(opts.dragSelector).css("cursor", "pointer");
					jQuery(this.container).children(opts.itemSelector).each(function(j) { jQuery(this).attr("data-itemIdx", j); });
				},

				grabItem: function(e) {
					if (e.which != 1 || jQuery(e.target).is(opts.dragSelectorExclude))
						return;

					var elm = e.target;
					while (!jQuery(elm).is("[data-listIdx='" + jQuery(this).attr("data-listIdx") + "'] " + opts.dragSelector)) {
						if (elm == this) return;
						elm = elm.parentNode;
					}

					if (list != null && list.draggedItem != null)
						list.dropItem();

					jQuery(e.target).css("cursor", "move");

					list = lists[jQuery(this).attr("data-listIdx")];
					list.draggedItem = jQuery(elm).closest(opts.itemSelector);
					var mt = parseInt(list.draggedItem.css("marginTop"));
					var ml = parseInt(list.draggedItem.css("marginLeft"));
					list.offset = list.draggedItem.offset();
					list.offset.top = e.pageY - list.offset.top + (isNaN(mt) ? 0 : mt) - 1;
					list.offset.left = e.pageX - list.offset.left + (isNaN(ml) ? 0 : ml) - 1;

					if (!opts.dragBetween) {
						var containerHeight = jQuery(list.container).outerHeight() == 0 ? Math.max(1, Math.round(0.5 + jQuery(list.container).children(opts.itemSelector).size() * list.draggedItem.outerWidth() / jQuery(list.container).outerWidth())) * list.draggedItem.outerHeight() : jQuery(list.container).outerHeight();
						list.offsetLimit = jQuery(list.container).offset();
						list.offsetLimit.right = list.offsetLimit.left + jQuery(list.container).outerWidth() - list.draggedItem.outerWidth();
						list.offsetLimit.bottom = list.offsetLimit.top + containerHeight - list.draggedItem.outerHeight();
					}

					var h = list.draggedItem.height();
					var w = list.draggedItem.width();
					var orig = list.draggedItem.attr("style");
					list.draggedItem.attr("data-origStyle", orig ? orig : "");
					if (opts.itemSelector == "tr") {
						list.draggedItem.children().each(function() { jQuery(this).width(jQuery(this).width()); });
						list.placeHolderItem = list.draggedItem.clone().attr("data-placeHolder", true);
						list.draggedItem.after(list.placeHolderItem);
						list.placeHolderItem.children().each(function() { jQuery(this).css({ borderWidth:0, width: jQuery(this).width() + 1, height: jQuery(this).height() + 1 }).html("&nbsp;"); });
					} else {
						list.draggedItem.after(opts.placeHolderTemplate);
						list.placeHolderItem = list.draggedItem.next().css({ height: h, width: w }).attr("data-placeHolder", true);
					}
					list.draggedItem.css({ position: "absolute", opacity: 0.8, "z-index": 999, height: h, width: w });

					jQuery(lists).each(function(i, l) { l.createDropTargets(); l.buildPositionTable(); });

					list.scroll = { moveX: 0, moveY: 0, maxX: jQuery(document).width() - jQuery(window).width(), maxY: jQuery(document).height() - jQuery(window).height() };
					list.scroll.scrollY = window.setInterval(function() {
						if (opts.scrollContainer != window) {
							jQuery(opts.scrollContainer).scrollTop(jQuery(opts.scrollContainer).scrollTop() + list.scroll.moveY);
							return;
						}
						var t = jQuery(opts.scrollContainer).scrollTop();
						if (list.scroll.moveY > 0 && t < list.scroll.maxY || list.scroll.moveY < 0 && t > 0) {
							jQuery(opts.scrollContainer).scrollTop(t + list.scroll.moveY);
							list.draggedItem.css("top", list.draggedItem.offset().top + list.scroll.moveY + 1);
						}
					}, 10);
					list.scroll.scrollX = window.setInterval(function() {
						if (opts.scrollContainer != window) {
							jQuery(opts.scrollContainer).scrollLeft(jQuery(opts.scrollContainer).scrollLeft() + list.scroll.moveX);
							return;
						}
						var l = jQuery(opts.scrollContainer).scrollLeft();
						if (list.scroll.moveX > 0 && l < list.scroll.maxX || list.scroll.moveX < 0 && l > 0) {
							jQuery(opts.scrollContainer).scrollLeft(l + list.scroll.moveX);
							list.draggedItem.css("left", list.draggedItem.offset().left + list.scroll.moveX + 1);
						}
					}, 10);

					list.setPos(e.pageX, e.pageY);
					jQuery(document).bind("selectstart", list.stopBubble); //stop ie text selection
					jQuery(document).bind("mousemove", list.swapItems);
					jQuery(document).bind("mouseup", list.dropItem);
					if (opts.scrollContainer != window)
						jQuery(window).bind("DOMMouseScroll mousewheel", list.wheel);
					return false; //stop moz text selection
				},

				setPos: function(x, y) {
					var top = y - this.offset.top;
					var left = x - this.offset.left;

					if (!opts.dragBetween) {
						top = Math.min(this.offsetLimit.bottom, Math.max(top, this.offsetLimit.top));
						left = Math.min(this.offsetLimit.right, Math.max(left, this.offsetLimit.left));
					}

					this.draggedItem.parents().each(function() {
						if (jQuery(this).css("position") != "static" && (!$.browser.mozilla || jQuery(this).css("display") != "table")) {
							var offset = jQuery(this).offset();
							top -= offset.top;
							left -= offset.left;
							return false;
						}
					});

					if (opts.scrollContainer == window) {
						y -= jQuery(window).scrollTop();
						x -= jQuery(window).scrollLeft();
						y = Math.max(0, y - jQuery(window).height() + 5) + Math.min(0, y - 5);
						x = Math.max(0, x - jQuery(window).width() + 5) + Math.min(0, x - 5);
					} else {
						var cont = jQuery(opts.scrollContainer);
						var offset = cont.offset();
						y = Math.max(0, y - cont.height() - offset.top) + Math.min(0, y - offset.top);
						x = Math.max(0, x - cont.width() - offset.left) + Math.min(0, x - offset.left);
					}

					list.scroll.moveX = x == 0 ? 0 : x * opts.scrollSpeed / Math.abs(x);
					list.scroll.moveY = y == 0 ? 0 : y * opts.scrollSpeed / Math.abs(y);

					this.draggedItem.css({ top: top, left: left });
				},

				wheel: function(e) {
					if (($.browser.safari || $.browser.mozilla) && list && opts.scrollContainer != window) {
						var cont = jQuery(opts.scrollContainer);
						var offset = cont.offset();
						if (e.pageX > offset.left && e.pageX < offset.left + cont.width() && e.pageY > offset.top && e.pageY < offset.top + cont.height()) {
							var delta = e.detail ? e.detail * 5 : e.wheelDelta / -2;
							cont.scrollTop(cont.scrollTop() + delta);
							e.preventDefault();
						}
					}
				},

				buildPositionTable: function() {
					var item = this.draggedItem == null ? null : this.draggedItem.get(0);
					var pos = [];
					jQuery(this.container).children(opts.itemSelector).each(function(i, elm) {
						if (elm != item) {
							var loc = jQuery(elm).offset();
							loc.right = loc.left + jQuery(elm).width();
							loc.bottom = loc.top + jQuery(elm).height();
							loc.elm = elm;
							pos.push(loc);
						}
					});
					this.pos = pos;
				},

				dropItem: function() {
					if (list.draggedItem == null)
						return;

					jQuery(list.container).find(opts.dragSelector).css("cursor", "pointer");
					list.placeHolderItem.before(list.draggedItem);

					//list.draggedItem.attr("style", "") doesn't work on IE8 and jQuery 1.5 or lower
					//list.draggedItem.removeAttr("style") doesn't work on chrome and jQuery 1.6 (works jQuery 1.5 or lower)
					var orig = list.draggedItem.attr("data-origStyle");
					list.draggedItem.attr("style", orig);
					if (orig == "")
						list.draggedItem.removeAttr("style");
					list.draggedItem.removeAttr("data-origStyle");
					list.placeHolderItem.remove();

					jQuery("[data-dropTarget]").remove();

					window.clearInterval(list.scroll.scrollY);
					window.clearInterval(list.scroll.scrollX);

          // The test below can only work if you are not
          // dragging between lists
					var changed = opts.dragBetween;
					jQuery(lists).each(function() {
						jQuery(this.container).children(opts.itemSelector).each(function(j) {
							if (parseInt(jQuery(this).attr("data-itemIdx")) != j) {
								changed = true;
								jQuery(this).attr("data-itemIdx", j);
							}
						});
					});
					if (changed)
						opts.dragEnd.apply(list.draggedItem);
					list.draggedItem = null;
					jQuery(document).unbind("selectstart", list.stopBubble);
					jQuery(document).unbind("mousemove", list.swapItems);
{'fraction_non_alphanumeric': 0.17645456526476355, 'fraction_numerical': 0.0066463281760732185, 'mean_word_length': 3.114074406095921, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995746', 'n_tokens_mistral': 7478, 'n_tokens_neox': 5827, 'n_words': 1083}