<commit_before>/*
 *
 * Copyright (c) 2010 <NAME> (<a href="http://cloudgen.w0ng.hk">Cloudgen Examplet Store</a>)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * note by dubin
 * for use with new wasp (jquery newer versions: modified the three .live calls to .on() according to http://www.west-wind.com/weblog/posts/2013/Jun/12/Replacing-jQuerylive-with-jQueryon
 * this was needed as new jquery no longer supports live().
 * Also needed to reference container_div_for_adding_rows, which is a div surrounding the table to which rows are added
 */
(function($){if(typeof $.fn.btnAddRow== "undefined"){
	var ExpandableTableList=[],className="ExpandableTable";
	function ExpandableTable(target,maxRow){
		if(target) this.init(target,maxRow);
	}
	ExpandableTable.prototype.init=function(target,maxRow){
		ExpandableTableList.push(this);
		this.target=$(target).data(className,this);
		this.maxRow=maxRow;
		this.seed=Math.round(Math.random()*10000);
		this.onAddRow=[];
		return this;
	};
	ExpandableTable.prototype.live=function(){
		if (!this.goLive){
			var t=this;
			this.update();
			$("#container_div_for_adding_rows")
			.on("click", ".addRow"+this.seed, function(){
				var newRow=t.addRow();
			});
			$("#container_div_for_adding_rows")
			.on("click", ".delRow"+this.seed, function(){
				var oj=$(this).closest("."+t.cloneClass),
				o=oj.clone();
				oj.hide().find("*").each(function(i,v){
					if($(v).data("destroy"));
					for(var k in $(v).data("destroy")){
						$(v).data("destroy")[k](v);
					}
				});
				oj.remove();
				$(".addRow"+t.seed)
				.attr("disabled",false);
				t.update();
				if(t.deleteCallBack && $.isFunction(t.deleteCallBack)) 
					t.deleteCallBack(o);
			});
			$("#container_div_for_adding_rows")
			.on("keyup", ".autoAdd"+this.seed, function(){
				if((this.nodeName.toLowerCase()=="textarea" && $(this).html()!="") ||
				(this.nodeName.toLowerCase()=="textarea" && $(this).val()!="") ||
				(this.nodeName.toLowerCase()=="input" && $(this).val()!="")) t.addRow();
			});
			this.goLive=true;
		}
		return this;;
	};
	ExpandableTable.prototype.updateRowNumber=function(){
		var t=this;
		if(t.rowNumColumn){
			$("."+t.cloneClass,t.target).each(function(j,u){
				var n=j+1;
				$("."+t.rowNumColumn,$(u)).each(function(i,v){
					if($(v).is(":text, textarea")) 
						$(v).val(n);
					else
						$(v).text(n);
				});
			});
		}
		return t;
	};
	ExpandableTable.prototype.updateInputBoxName=function(){
		$("."+this.cloneClass,this.target).each(function(j,t){
			var n=j+1;
			$("input,textarea",$(t)).each(function(i,v){
				if($(v).attr("name")!=""){
					var newName=$(v).attr("name").replace(/\d+$/,"")+n;
					$(v).attr("name",newName);
				}
			});
		});
		return this;
	};
	ExpandableTable.prototype.updateInputBoxId=function(){
		var t=this;
		$("."+t.cloneClass,this.target).each(function(j,u){
			var n=j+1;
			$("input,textarea",$(u)).each(function(i,v){
				if($(v).attr("id")!=""){
					var newId=$(v).attr("id").replace(/\d+$/,"")+n;
					$(v).removeAttr("id").attr("id",newId);
				}
			});
		});
		return this;
	};
	ExpandableTable.prototype.updateOddRowCSS=function(){
		if(this.oddRowCSS){
			this.target.find("."+this.oddRowCSS).removeClass(this.oddRowCSS);
			this.target.find("tr:odd").addClass(this.oddRowCSS);
		}
		return this;
	};
	ExpandableTable.prototype.updateEvenRowCSS=function(){
		if(this.evenRowCSS){
			this.target.find("."+this.evenRowCSS).removeClass(this.evenRowCSS);
			this.target.find("tr:even").addClass(this.evenRowCSS);
		}
		return this;
	};
	ExpandableTable.prototype.updateRowCount=function(){
		if(this.displayRowCountTo){
			var count=$("."+this.cloneClass,this.target).size();
			$("."+this.displayRowCountTo,this.target).each(function(i,v){
				var nn=v.nodeName.toLowerCase();
				if(nn=="input" || nn=="textarea") 
					$(v).val(count);
				else
					$(v).html(count);
			});
		}
		return this;
	};
	ExpandableTable.prototype.update=function(){
		var t=this;
		this.delRowButtons=$(".delRow"+this.seed,this.target);
		if(this.delRowButtons.size()==1)
			this.delRowButtons.hide();
		else {
			if(this.autoAddRow)
				this.delRowButtons.not(":last").show();
			else
				this.delRowButtons.show();
		}
		if(this.autoAddRow) {
			this.target.find(".autoAdd"+this.seed).removeClass("autoAdd"+t.seed);
			this.target
			.find("."+t.cloneClass+":last")
			.find("input,textarea")
			.addClass("autoAdd"+this.seed);
		}
		if(this.inputBoxAutoNumber) {
			this.updateInputBoxName();
			this.updateInputBoxId();
		}
		if(this.inputBoxAutoId) {
			this.updateInputBoxId();
		}
		if(this.hideFirstOnly && this.hideFirstOnly!=""){
			$("."+this.cloneClass).eq(0).find("."+this.hideFirstOnly).hide();
			$("."+this.cloneClass).not(":first").find("."+this.hideFirstOnly).show();
		}
		if(this.showFirstOnly && this.showFirstOnly!=""){
			$("."+this.cloneClass).eq(0).find("."+this.showFirstOnly).show();
			$("."+this.cloneClass).not(":first").find("."+this.showFirstOnly).hide();
		}
		this.updateRowNumber()
		.updateOddRowCSS()
		.updateEvenRowCSS()
		.updateRowCount();
		return this;
	};
	ExpandableTable.prototype.addRow=function(){
		var newRow;
		if(!this.maxRow || (this.maxRow && $("."+this.cloneClass).size()<this.maxRow)){
			this.delRowButtons.show();
			var lastRow=$("."+this.cloneClass+":last",this.target);
			this.newRow=newRow=lastRow.clone();
			newRow.find("input:text").val("");
			newRow.find("textarea").text("");
			//newRow.find("select").val('');//added by <NAME> 8-30-13; works, but not generic : so that any new select box is set to the option with value of ''
			newRow.find("select").val([]);//added by <NAME> 8-30-13; works fine, deselects the options in any new select box: see http://stackoverflow.com/questions/1280499/jquery-set-select-index
			if(this.autoAddRow) newRow.find("."+this.cloneClass).hide();
			newRow.insertAfter(lastRow);
			if(this.ignoreClass && this.ignoreClass!=""){
				newRow.find("."+this.ignoreClass).each(function(){
					if(this.nodeName.toLowerCase()=="input" &&
						($(this).attr("type").toLowerCase()=="text"
						|| $(this).attr("type").toLowerCase()=="hidden"
					)) $(this).val("");
					else if(this.nodeName.toLowerCase()=="td") $(this).html(" ");
					else if($(this).html()!="") $(this).text("");
				});
			}
			newRow.find("input:hidden").not("."+this.cloneClass).val("");
			if(this.hideFirstOnly && this.hideFirstOnly!=""){
				newRow.find("."+this.hideFirstOnly).show();
			}
			if(this.showFirstOnly && this.showFirstOnly!=""){<commit_msg>fixed jquery.table.addrow.js to add new select box with proper selection of first entry<commit_after>/*
 *
 * Copyright (c) 2010 <NAME> (<a href="http://cloudgen.w0ng.hk">Cloudgen Examplet Store</a>)
 * Licensed under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * note by dubin
 * for use with new wasp (jquery newer versions: modified the three .live calls to .on() according to http://www.west-wind.com/weblog/posts/2013/Jun/12/Replacing-jQuerylive-with-jQueryon
 * this was needed as new jquery no longer supports live().
 * Also needed to reference container_div_for_adding_rows, which is a div surrounding the table to which rows are added
 */
(function($){if(typeof $.fn.btnAddRow== "undefined"){
	var ExpandableTableList=[],className="ExpandableTable";
	function ExpandableTable(target,maxRow){
		if(target) this.init(target,maxRow);
	}
	ExpandableTable.prototype.init=function(target,maxRow){
		ExpandableTableList.push(this);
		this.target=$(target).data(className,this);
		this.maxRow=maxRow;
		this.seed=Math.round(Math.random()*10000);
		this.onAddRow=[];
		return this;
	};
	ExpandableTable.prototype.live=function(){
		if (!this.goLive){
			var t=this;
			this.update();
			$("#container_div_for_adding_rows")
			.on("click", ".addRow"+this.seed, function(){
				var newRow=t.addRow();
			});
			$("#container_div_for_adding_rows")
			.on("click", ".delRow"+this.seed, function(){
				var oj=$(this).closest("."+t.cloneClass),
				o=oj.clone();
				oj.hide().find("*").each(function(i,v){
					if($(v).data("destroy"));
					for(var k in $(v).data("destroy")){
						$(v).data("destroy")[k](v);
					}
				});
				oj.remove();
				$(".addRow"+t.seed)
				.attr("disabled",false);
				t.update();
				if(t.deleteCallBack && $.isFunction(t.deleteCallBack)) 
					t.deleteCallBack(o);
			});
			$("#container_div_for_adding_rows")
			.on("keyup", ".autoAdd"+this.seed, function(){
				if((this.nodeName.toLowerCase()=="textarea" && $(this).html()!="") ||
				(this.nodeName.toLowerCase()=="textarea" && $(this).val()!="") ||
				(this.nodeName.toLowerCase()=="input" && $(this).val()!="")) t.addRow();
			});
			this.goLive=true;
		}
		return this;;
	};
	ExpandableTable.prototype.updateRowNumber=function(){
		var t=this;
		if(t.rowNumColumn){
			$("."+t.cloneClass,t.target).each(function(j,u){
				var n=j+1;
				$("."+t.rowNumColumn,$(u)).each(function(i,v){
					if($(v).is(":text, textarea")) 
						$(v).val(n);
					else
						$(v).text(n);
				});
			});
		}
		return t;
	};
	ExpandableTable.prototype.updateInputBoxName=function(){
		$("."+this.cloneClass,this.target).each(function(j,t){
			var n=j+1;
			$("input,textarea",$(t)).each(function(i,v){
				if($(v).attr("name")!=""){
					var newName=$(v).attr("name").replace(/\d+$/,"")+n;
					$(v).attr("name",newName);
				}
			});
		});
		return this;
	};
	ExpandableTable.prototype.updateInputBoxId=function(){
		var t=this;
		$("."+t.cloneClass,this.target).each(function(j,u){
			var n=j+1;
			$("input,textarea",$(u)).each(function(i,v){
				if($(v).attr("id")!=""){
					var newId=$(v).attr("id").replace(/\d+$/,"")+n;
					$(v).removeAttr("id").attr("id",newId);
				}
			});
		});
		return this;
	};
	ExpandableTable.prototype.updateOddRowCSS=function(){
		if(this.oddRowCSS){
			this.target.find("."+this.oddRowCSS).removeClass(this.oddRowCSS);
			this.target.find("tr:odd").addClass(this.oddRowCSS);
		}
		return this;
	};
	ExpandableTable.prototype.updateEvenRowCSS=function(){
		if(this.evenRowCSS){
			this.target.find("."+this.evenRowCSS).removeClass(this.evenRowCSS);
			this.target.find("tr:even").addClass(this.evenRowCSS);
		}
		return this;
	};
	ExpandableTable.prototype.updateRowCount=function(){
		if(this.displayRowCountTo){
			var count=$("."+this.cloneClass,this.target).size();
			$("."+this.displayRowCountTo,this.target).each(function(i,v){
				var nn=v.nodeName.toLowerCase();
				if(nn=="input" || nn=="textarea") 
					$(v).val(count);
				else
					$(v).html(count);
			});
		}
		return this;
	};
	ExpandableTable.prototype.update=function(){
		var t=this;
		this.delRowButtons=$(".delRow"+this.seed,this.target);
		if(this.delRowButtons.size()==1)
			this.delRowButtons.hide();
		else {
			if(this.autoAddRow)
				this.delRowButtons.not(":last").show();
			else
				this.delRowButtons.show();
		}
		if(this.autoAddRow) {
			this.target.find(".autoAdd"+this.seed).removeClass("autoAdd"+t.seed);
			this.target
			.find("."+t.cloneClass+":last")
			.find("input,textarea")
			.addClass("autoAdd"+this.seed);
		}
		if(this.inputBoxAutoNumber) {
			this.updateInputBoxName();
			this.updateInputBoxId();
		}
		if(this.inputBoxAutoId) {
			this.updateInputBoxId();
		}
		if(this.hideFirstOnly && this.hideFirstOnly!=""){
			$("."+this.cloneClass).eq(0).find("."+this.hideFirstOnly).hide();
			$("."+this.cloneClass).not(":first").find("."+this.hideFirstOnly).show();
		}
		if(this.showFirstOnly && this.showFirstOnly!=""){
			$("."+this.cloneClass).eq(0).find("."+this.showFirstOnly).show();
			$("."+this.cloneClass).not(":first").find("."+this.showFirstOnly).hide();
		}
		this.updateRowNumber()
		.updateOddRowCSS()
		.updateEvenRowCSS()
		.updateRowCount();
		return this;
	};
	ExpandableTable.prototype.addRow=function(){
		var newRow;
		if(!this.maxRow || (this.maxRow && $("."+this.cloneClass).size()<this.maxRow)){
			this.delRowButtons.show();
			var lastRow=$("."+this.cloneClass+":last",this.target);
			this.newRow=newRow=lastRow.clone();
			newRow.find("input:text").val("");
			newRow.find("textarea").text("");
			newRow.find("select").val('');//10-13-13; Dubin; seems to work fine, and works well on firefox AND safari ; added by <NAME> 8-30-13; works, but not generic : so that any new select box is set to the option with value of ''
			//newRow.find("select").val([]);//commented out on 10-13-13 by Dubin; worked badly on firefox; added by <NAME> 8-30-13; works fine, deselects the options in any new select box: see http://stackoverflow.com/questions/1280499/jquery-set-select-index
			if(this.autoAddRow) newRow.find("."+this.cloneClass).hide();
			newRow.insertAfter(lastRow);
			if(this.ignoreClass && this.ignoreClass!=""){
				newRow.find("."+this.ignoreClass).each(function(){
					if(this.nodeName.toLowerCase()=="input" &&
						($(this).attr("type").toLowerCase()=="text"
						|| $(this).attr("type").toLowerCase()=="hidden"
					)) $(this).val("");
					else if(this.nodeName.toLowerCase()=="td") $(this).html(" ");
					else if($(this).html()!="") $(this).text("");
				});
			}
			newRow.find("input:hidden").not("."+this.cloneClass).val("");
			if(this.hideFirstOnly && this.hideFirstOnly!=""){
				newRow.find("."+this.hideFirstOnly).show();
			}
			if(this.showFirstOnly && this.showFirstOnly!=""){
{'fraction_non_alphanumeric': 0.2227310261992343, 'fraction_numerical': 0.006756249530816005, 'mean_word_length': 4.341619887730554, 'pattern_counts': {'":': 12, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '7659204', 'n_tokens_mistral': 5551, 'n_tokens_neox': 4820, 'n_words': 634}