<commit_before>// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f(){ log.history = log.history || []; log.history.push(arguments); if(this.console) { var args = arguments, newarr; args.callee = args.callee.caller; newarr = [].slice.call(args); if (typeof console.log === 'object') log.apply.call(console.log, console, newarr); else console.log.apply(console, newarr);}};

// make it safe to use console.log always
(function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;!!(d=c.pop());){a[d]=a[d]||b;}})
(function(){try{console.log();return window.console;}catch(a){return (window.console={});}}());


// place any jQuery/helper plugins in here, instead of separate, slower script files.

/*
 * Form Collection
 */
(function($, Backbone, _){
	
	var FormCollectionModel = Backbone.Model.extend({
		"label" : ExposeTranslation.get('add_new'),
		"initialize": function() {
			
			if (!this.get("label"))
			{
				this.set({"label": this.label});
			}
		}
	});

	var FormCollectionView = Backbone.View.extend({
		
		"id" : (Math.random() * (10 * 100)),
		"icon" : function () {
			return $('<i />').addClass('icon-plus-sign');
		},
		"addlink" : function(){
			return $('<a />').attr('href', '#').attr('id', this.id).addClass("add_form_collection_link").html(this.icon()).append(' ' + this.model.get("label"));
		},
		"initialize" : function(){
			this.model.set({'label' : this.options.label});
			
			var el = this.el;
			var l = this.addlink().on('click', function(e){
				e.preventDefault();
				
				var add = new AddView({"el" : el})
			});
			
			$(this.el).append(l);
		}
	});
	
	var AddView = Backbone.View.extend({
		"initialize" : function(){
			
			var el = $(this.el);

			var prototype = el.attr('data-prototype');

		    var form = $(prototype.replace(/__name__/g, el.children('.content').length));
		    
		    $form = $('<div />').addClass('content');
		    
		    for(var i = 0; i < form.length; i ++)
		    {
		    	$form.append(form[i]);
		    }

		    $(this.el).find('.add_form_collection_link').before($form);
		    
		    Loader.call();
			
			var del = new DeleteView({"el" : $form});
			
			return del;
		}
	});
	
	var DeleteView = Backbone.View.extend({
		"template" : '<a class="pull-right" href="#"> <%=label%></a>',
		"icon" : '<i class="icon-remove"></i> ',
		"initialize" : function(){
			
			var template = $(_.template(this.template, {"label" : this.icon + ExposeTranslation.get('delete')})).on('click', this.destroy);
			
			$(this.el).prepend(template);
		},
		"destroy" : function(){
			$(this.el).remove();
		}
	});

	$.fn.formCollection = function(options) {

		var view = new FormCollectionView($.extend({"model": new FormCollectionModel, "el" : this}, options));
	
		return view;
	};
<commit_msg>Re-factored the FormCollection plugin to be more stable<commit_after>// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function f(){ log.history = log.history || []; log.history.push(arguments); if(this.console) { var args = arguments, newarr; args.callee = args.callee.caller; newarr = [].slice.call(args); if (typeof console.log === 'object') log.apply.call(console.log, console, newarr); else console.log.apply(console, newarr);}};

// make it safe to use console.log always
(function(a){function b(){}for(var c="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),d;!!(d=c.pop());){a[d]=a[d]||b;}})
(function(){try{console.log();return window.console;}catch(a){return (window.console={});}}());


// place any jQuery/helper plugins in here, instead of separate, slower script files.

/*
 * Form Collection
 */
(function($, Backbone, _){
		
	var MasterView = Backbone.View.extend({
		"tagName"	: "div",
		"className"	: "content",
		"icon" : '<i class="icon-plus-sign" />',
		"addlink" : '<a href="#" class="add_form_collection_link"><%= icon %> <%= label %></a>',

		"initialize": function () {
			
			var $this = this;
			
			var add_link = $(this.createAddLink()).on("click", function() { $this.addForm($this) });
			this.$el.append(add_link);
        },
        "createAddLink" : function(){
        	return _.template(this.addlink, {"icon" : this.icon, "label" : this.options.label});
        },
        "addForm" : function($this) {
        	
        	var prototype  = $this.$el.attr('data-prototype');

		    var form = $(prototype.replace(/__name__/g, $this.$el.children('.content').length));
		    
		    
		    if(typeof form[1] !== undefined)
		   	{
		    	var script = $(form[1]);
		    	
		    	$.globalEval(script.html());
		   	}
		    
		    var view = new FormCollectionView({"el" : form});
		    
		    $this.$el.prepend(view.render().el);
		    
		    Loader.call();
		    
		    return view;
        }
	});
	

	var FormCollectionView = Backbone.View.extend({
		
		"template" : '<a class="pull-right remove-form" href="#"><%= icon %> <%=label%></a>',
		
		"icon" : '<i class="icon-remove"></i> ',
		
		"events" : {
			"click a.remove-form" : "destroy"
		},
		"render" : function(){
			
			var $this = this;
			
			var template = _.template(this.template, {"icon" : this.icon, "label" : ExposeTranslation.get('delete')});
			
			var tmpl = $(template).on("click", function(){
				$this.destroy($this);
			});
			
			this.$el.prepend(tmpl);
				
			return this;
		},
		"destroy" : function($this) {

			$this.$el.remove();
			
			return this;
		}
	});
	
	$.fn.formCollection = function(options) {
		
		var view = new MasterView($.extend({"el" : this}, options));
	
		return view;
	};

{'fraction_non_alphanumeric': 0.20976027397260275, 'fraction_numerical': 0.0027397260273972603, 'mean_word_length': 3.5208978328173375, 'pattern_counts': {'":': 4, '<': 23, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '247399', 'n_tokens_mistral': 2203, 'n_tokens_neox': 1929, 'n_words': 362}