<commit_before>(function($){
	$.fn.QuickSelect = function(options){
		options = $.extend(true, {
			iconUp: "&#9650;",
			iconDown: "&#9660;",
			minElemsBeforeGoingUp: 3,
			openEffect: "fadeIn",
			closeEffect: "hide"
		}, options);
		$(this).filter("select").each(function(){
			var thisElem = $(this);

			if(typeof thisElem.data("qs-initialized") !== "undefined") return;
			thisElem.data("qs-initialized", true);

			var newDiv = function(_class, divOpts){
				if(typeof _class == "object"){
					divOpts = _class;
					_class = undefined;
				}
				if(typeof _class == "undefined") _class = "";
				divOpts = $.extend(true, {
					"class": _class
				}, divOpts);
				return $("<div>", divOpts);
			}

			thisElem.hide();
			var tabAnchor = $("<a>",{"class":"qs-anchor", "href": "#"}).insertAfter(thisElem);

			var main = newDiv('qs').appendTo(tabAnchor);
			var fixed = newDiv('qs-fixed').appendTo(main);
			var dropdown = newDiv('qs-dropdown').hide().appendTo(main);

			var viewportArrow = newDiv('qs-viewport-arrow').appendTo(fixed);
			var arrow = newDiv("qs-arrow").appendTo(viewportArrow);
			var viewportContainer = newDiv("qs-viewport-container").appendTo(viewportArrow);
			var viewport = newDiv("qs-viewport").appendTo(viewportContainer);
			var shadowViewport = newDiv("qs-shadow-viewport").appendTo(viewportContainer);

			
			var adjustViewport = function(){
				viewportContainer.css({
					marginRight: arrow.outerWidth(true)+"px"
				});
			}
			adjustViewport();

			arrow.html(options.iconDown);

			var thisOptions = thisElem.children('option');


			var getText = function(option){
				var text = option.text();
				if(text.length == 0) text = "&nbsp;";
				return text;
			}
			var getSelected = function(){
				var selected = thisOptions.filter(function(){
					return $(this).prop("selected") === true;
				});
				if(selected.length === 0){
					selected = thisOptions.first().prop("selected", true);
				}
				return selected;
			}
			var setSelected = function(opt, _trigger){
				var trigger;
				if(typeof _trigger === "undefined") {
					trigger = true;
				} else {
					trigger = _trigger;
				}

				var ret = $();
				
				thisOptions.each(function(){
					if($(this).is(opt)){
						if($(this).prop("selected") === true) trigger = false;
						$(this).prop("selected", true);
						ret = $(this);
						$(this).data("qs-mirror").addClass('selected').siblings().removeClass('selected');
						viewport.html(getText(opt));
					} else {
						$(this).prop("selected", false);
					}
				});
				
				if(trigger) thisElem.trigger("change", [true]);

				return ret;
			}
			var setHover = function(option){
				option.addClass('hover').siblings().removeClass('hover');
			}

			var getFirstOptionsHeight = function(){
				var height = 0;
				dropdown.children(".qs-option").slice( 0, options.minElemsBeforeGoingUp ).each(function(){
					height += $(this).outerHeight(true);
				});
				return height;
			}

			var heightAsManyOptionsAsPossible = function(heightAvailable){
				var height = 0;
				dropdown.children(".qs-option").each(function(){
					var thisHeight = $(this).outerHeight(true);
					if(thisHeight + height < heightAvailable){
						height += thisHeight;
					}
				});
				return height;
			}
<commit_msg>Use selected attribute in the original select.<commit_after>(function($){
	$.fn.QuickSelect = function(options){
		options = $.extend(true, {
			iconUp: "&#9650;",
			iconDown: "&#9660;",
			minElemsBeforeGoingUp: 3,
			openEffect: "fadeIn",
			closeEffect: "hide"
		}, options);
		$(this).filter("select").each(function(){
			var thisElem = $(this);

			if(typeof thisElem.data("qs-initialized") !== "undefined") return;
			thisElem.data("qs-initialized", true);

			var newDiv = function(_class, divOpts){
				if(typeof _class == "object"){
					divOpts = _class;
					_class = undefined;
				}
				if(typeof _class == "undefined") _class = "";
				divOpts = $.extend(true, {
					"class": _class
				}, divOpts);
				return $("<div>", divOpts);
			}

			thisElem.hide();
			var tabAnchor = $("<a>",{"class":"qs-anchor", "href": "#"}).insertAfter(thisElem);

			var main = newDiv('qs').appendTo(tabAnchor);
			var fixed = newDiv('qs-fixed').appendTo(main);
			var dropdown = newDiv('qs-dropdown').hide().appendTo(main);

			var viewportArrow = newDiv('qs-viewport-arrow').appendTo(fixed);
			var arrow = newDiv("qs-arrow").appendTo(viewportArrow);
			var viewportContainer = newDiv("qs-viewport-container").appendTo(viewportArrow);
			var viewport = newDiv("qs-viewport").appendTo(viewportContainer);
			var shadowViewport = newDiv("qs-shadow-viewport").appendTo(viewportContainer);

			
			var adjustViewport = function(){
				viewportContainer.css({
					marginRight: arrow.outerWidth(true)+"px"
				});
			}
			adjustViewport();

			arrow.html(options.iconDown);

			var thisOptions = thisElem.children('option');


			var getText = function(option){
				var text = option.text();
				if(text.length == 0) text = "&nbsp;";
				return text;
			}
			var getSelected = function(){
				var selected = thisOptions.filter(function(){
					return $(this).prop("selected") === true;
				});
				if(selected.length === 0){
					selected = thisOptions.first().prop("selected", true);
				}
				return selected;
			}
			var setSelected = function(opt, _trigger){
				var trigger;
				if(typeof _trigger === "undefined") {
					trigger = true;
				} else {
					trigger = _trigger;
				}

				var ret = $();
				
				thisOptions.each(function(){
					if($(this).is(opt)){
						if($(this).prop("selected") === true) trigger = false;
						$(this).prop("selected", true);
						$(this).attr("selected", "");
						ret = $(this);
						$(this).data("qs-mirror").addClass('selected').siblings().removeClass('selected');
						viewport.html(getText(opt));
					} else {
						$(this).removeAttr('selected');
						$(this).prop("selected", false);
					}
				});
				
				if(trigger) thisElem.trigger("change", [true]);

				return ret;
			}
			var setHover = function(option){
				option.addClass('hover').siblings().removeClass('hover');
			}

			var getFirstOptionsHeight = function(){
				var height = 0;
				dropdown.children(".qs-option").slice( 0, options.minElemsBeforeGoingUp ).each(function(){
					height += $(this).outerHeight(true);
				});
				return height;
			}

			var heightAsManyOptionsAsPossible = function(heightAvailable){
				var height = 0;
				dropdown.children(".qs-option").each(function(){
					var thisHeight = $(this).outerHeight(true);
					if(thisHeight + height < heightAvailable){
						height += thisHeight;
					}
				});
				return height;
			}

{'fraction_non_alphanumeric': 0.17819990954319312, 'fraction_numerical': 0.004221317654153475, 'mean_word_length': 3.4256170780520345, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 7, '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': '2719172', 'n_tokens_mistral': 2669, 'n_tokens_neox': 2049, 'n_words': 386}