<commit_before>/**
 * jquery.djtch.js - Dynamic Javascript Templating in Client-side HTML
 * 
 * Requires jquery (>= 1.3) and jquery.forms
 * 
 * @author <EMAIL>.delg<EMAIL>
 */
jQuery.djtch = {
	options: {
		preUpdateHook: null,
		postUpdateHook: null
	},
	setup: function(options) {
		jQuery.extend(this.options, options || {});
	},
	anchor: function(seed, item) {
		var id = jQuery(item).attr('id');
		var pattern = ".dj-anchor" + (id ? '#' + id : '');
		var context = seed;
		while (context.length > 0) {
			var res = context.is(pattern) ? context : context.find(pattern);
			if (res.length > 0) return res;
			if (!context.parent()) break;
			context = context.parent().closest('.dj-context,.dj-anchor');
		}
		return jQuery(pattern);
	},
	content: function(item) {
		var x = jQuery(item);
		return x.hasClass('.dj-children') ? x.children() : x;
	},
	update: function(seed, html) {
		//alert(html);
		var anchor = this.anchor;
		var content = this.content;
		var newStuff = jQuery(html);
		if (this.options.preUpdateHook) {
			this.options.preUpdateHook(newStuff);
		}
		newStuff.djtchEnable();
		newStuff.find('.dj-replace').each(function(i) {
			anchor(seed, this).replaceWith(content(this));
		}).end().find('.dj-append').each(function(i) {
			anchor(seed, this).append(content(this));
		}).end().find('.dj-prepend').each(function(i) {
			anchor(seed, this).prepend(content(this));
		}).end().find('.dj-after').each(function(i) {
			anchor(seed, this).after(content(this));
		}).end().find('.dj-before').each(function(i) {
			anchor(seed, this).before(content(this));
		});
		if (this.options.postUpdateHook) {
			this.options.postUpdateHook();
		}
	},
	stopScrollHandler: function() {
		jQuery(window).unbind('scroll', this.handlers.activeScroll);
	},
	handlers: {
		linkClicked: function() {
			var link = jQuery(this);
			jQuery.get(link.attr('href'), function(html) {
				jQuery.djtch.update(link, html);
				if (link.hasClass('.dj-once')) link.unbind('click');
			});
			return false;
		},
		deleteLinkClicked: function() {
			var link = jQuery(this);
			if (confirm(link.attr('confirm') || 'Really delete this?')) {
				jQuery.post(link.attr('href'),
					jQuery.param({ _method: 'delete' }),
					function(html, status) {
						jQuery.djtch.update(link, html);
					}
				);
			};
			return false;
		},
		activeScroll: function(event) {
			var win = jQuery(window);
			var link = event.data;
			if (link && link.attr('href')) {
				var doc = jQuery(document);
				if (win.scrollTop() + 1.1 * win.height() > doc.height()) {
					jQuery.djtch.stopScrollHandler();
					jQuery.get(link.attr('href'), function(html){
						jQuery.djtch.update(link, html);
					});
				}
			} else {
				jQuery.djtch.stopScrollHandler();
			}
			return false;
		},
		formSubmitted: function() {
			var input = jQuery(this);
			var form = input.closest('form');
			form.ajaxSubmit({
				url: form.attr('action'),
				beforeSerialize: function(object, options) {
				    options.data[input.attr('name')] =
					input.attr('value');
				    return true;
				},
				success: function(html, status) {
					jQuery.djtch.update(form, html);
				}
			})
			return false;
		}
	}
};

jQuery.fn.extend({
	djtchLink: function() {
		return this.click(jQuery.djtch.handlers.linkClicked);
	},
	djtchDeleteLink: function() {
		return this.click(jQuery.djtch.handlers.deleteLinkClicked);
	},
	djtchOnScrollLink: function() {
		if (this.length > 0) {
			var ev = 'scroll';
			var fn = jQuery.djtch.handlers.activeScroll;
			jQuery(window).unbind(ev, fn).bind(ev, this, fn).triggerHandler(ev);
		}
		return this.hide().after(this.text());
	},
	djtchForm: function() {
		return this.find('input[type=submit]')
			.click(jQuery.djtch.handlers.formSubmitted).end();
	},
	djtchEnable: function() {
		return this
			.find('.dj-link').djtchLink().end()
			.find('.dj-delete').djtchDeleteLink().end()
			.find('.dj-scroll').djtchOnScrollLink().end()
			.find('.dj-form').djtchForm().end();
	}
});<commit_msg>updated djtch from Plexus project<commit_after>/**
 * jquery.djtch.js - Dynamic Javascript Templating in Client-side HTML
 * 
 * Requires jquery (>= 1.3) and jquery.forms
 * 
 * @author <EMAIL>
 */
jQuery.djtch = {
	options: {
		preUpdateHook: null,
		postUpdateHook: null
	},
	setup: function(options) {
		jQuery.extend(this.options, options || {});
	},
	anchor: function(seed, item) {
		var id = jQuery(item).attr('id');
		var pattern = ".dj-anchor" + (id ? '#' + id : '');
		var context = seed;
		while (context.length > 0) {
			var res = context.is(pattern) ? context : context.find(pattern);
			if (res.length > 0) return res;
			if (!context.parent()) break;
			context = context.parent().closest('.dj-context,.dj-anchor');
		}
		return jQuery(pattern);
	},
	content: function(item) {
		var x = jQuery(item);
		return x.hasClass('.dj-children') ? x.children() : x;
	},
	update: function(seed, html) {
		//alert(html);
		var anchor = this.anchor;
		var content = this.content;
		var newStuff = jQuery(html);
		if (this.options.preUpdateHook) {
			this.options.preUpdateHook(newStuff);
		}
		newStuff.djtchEnable();
		newStuff.find('.dj-replace').each(function(i) {
			anchor(seed, this).replaceWith(content(this));
		}).end().find('.dj-append').each(function(i) {
			anchor(seed, this).append(content(this));
		}).end().find('.dj-prepend').each(function(i) {
			anchor(seed, this).prepend(content(this));
		}).end().find('.dj-after').each(function(i) {
			anchor(seed, this).after(content(this));
		}).end().find('.dj-before').each(function(i) {
			anchor(seed, this).before(content(this));
		});
		if (this.options.postUpdateHook) {
			this.options.postUpdateHook();
		}
	},
	stopScrollHandler: function() {
		jQuery(window).unbind('scroll', this.handlers.activeScroll);
	},
	handlers: {
		linkClicked: function() {
			var link = jQuery(this);
			jQuery.get(link.attr('href'), function(html) {
				jQuery.djtch.update(link, html);
				if (link.hasClass('.dj-once')) link.unbind('click');
			});
			return false;
		},
		deleteLinkClicked: function() {
			var link = jQuery(this);
			if (confirm(link.attr('confirm') || 'Really delete this?')) {
				jQuery.post(link.attr('href'),
					jQuery.param({ _method: 'delete' }),
					function(html, status) {
						jQuery.djtch.update(link, html);
					}
				);
			};
			return false;
		},
		activeScroll: function(event) {
			var win = jQuery(window);
			var link = event.data;
			if (link && link.attr('href')) {
				var doc = jQuery(document);
				if (win.scrollTop() + 1.1 * win.height() > doc.height()) {
					jQuery.djtch.stopScrollHandler();
					jQuery.get(link.attr('href'), function(html){
						jQuery.djtch.update(link, html);
					});
				}
			} else {
				jQuery.djtch.stopScrollHandler();
			}
			return false;
		},
		formSubmitted: function() {
			var input = jQuery(this);
			var form = input.closest('form');
			var multi = (form.attr('enctype') ==
				     'multipart/form-data');
			var iname = input.attr('name');
			var ivalue = input.attr('value');
			form.ajaxSubmit({
				url: form.attr('action'),
				beforeSerialize: function(object, options) {
				    if (multi) options.data[iname] = ivalue;
				    return true;
				},
				beforeSubmit: function(data, object, options) {
				    data.push({ name: iname, value: ivalue });
				    return true;
				},
				success: function(html, status) {
				    jQuery.djtch.update(form, html);
				}
			})
			return false;
		}
	}
};

jQuery.fn.extend({
	djtchLink: function() {
		return this.click(jQuery.djtch.handlers.linkClicked);
	},
	djtchDeleteLink: function() {
		return this.click(jQuery.djtch.handlers.deleteLinkClicked);
	},
	djtchOnScrollLink: function() {
		if (this.length > 0) {
			var ev = 'scroll';
			var fn = jQuery.djtch.handlers.activeScroll;
			jQuery(window).unbind(ev, fn).bind(ev, this, fn).triggerHandler(ev);
		}
		return this.hide().after(this.text());
	},
	djtchForm: function() {
	    return this.find('input[type=submit]')
		.click(jQuery.djtch.handlers.formSubmitted).end();
	},
	djtchEnable: function() {
		return this
			.find('.dj-link').djtchLink().end()
			.find('.dj-delete').djtchDeleteLink().end()
			.find('.dj-scroll').djtchOnScrollLink().end()
			.find('.dj-form').djtchForm().end();
	}
});
{'fraction_non_alphanumeric': 0.19024449580343025, 'fraction_numerical': 0.0017029558447877388, 'mean_word_length': 3.5779510022271714, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 16, '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': '4804310', 'n_tokens_mistral': 3399, 'n_tokens_neox': 2866, 'n_words': 495}