<commit_before>
// Sparky.fn

(function(window) {
	var Sparky = window.Sparky;

	// Stops Sparky from parsing the node.
	Sparky.fn.ignore = function ignore() {
		this.interrupt();
	};
})(this);

(function(window) {
	var Sparky = window.Sparky;

	// Logs nodes, scopes and data.
	Sparky.fn.log = function(node) {
		var sparky = this;

		function log(node, scope) {
			console.group('scope change');
			console.log('node ', node);
			console.log('scope', scope);
			console.log('data', sparky.data);
			console.log('fn', sparky.fn);
			console.groupEnd();
		}

		this.on('scope', log);

		console.group('initialisation');
		console.log('node ', node);
		console.groupEnd();
	};
})(this);

(function(window) {
	"use strict";

	var assign = Object.assign;
	var Sparky = window.Sparky;
	var dom    = Sparky.dom;

	assign(Sparky.fn, {
		"remove-hidden": function onReadyUnhide(node) {
			this.on('scope', function() {
				window.requestAnimationFrame(function() {
					dom.classes(node).remove('hidden');
				});
			});
		}
	});
})(this);

(function(window) {
	"use strict";

	var assign = Object.assign;
	var Sparky = window.Sparky;

	assign(Sparky.fn, {
		html: function html(node) {
			this.on('scope', function(sparky, html) {
				node.innerHTML = html;
			});
		}
	});
})(this);

(function() {
	"use strict";

	function preventDefault(e) {
		e.preventDefault();
	}

	Sparky.scope = function(node) {
		console.warn('Sparky: Sparky.scope() deprecated in favour of Sparky.getScope()')
		return Sparky.getScope(node);
	};

	Sparky.setScope = function(node, scope) {
		if (!window.jQuery) {
			throw new Error('data-fn="store-scope" requires jQuery.');
		}

		window.jQuery && jQuery.data(node, 'scope', scope);
	};

	Sparky.getScope = function(node) {
		if (!window.jQuery) {
			throw new Error('data-fn="store-scope" requires jQuery.');
		}

		return jQuery.data(node, 'scope');
	};

	Object.assign(Sparky.fn, {
		"prevent-click": function(node) {
			node.addEventListener('click', preventDefault);
			this.on('destroy', function() {
				node.removeEventListener('click', preventDefault);
			});
		},

		"prevent-submit": function(node) {
			node.addEventListener('submit', preventDefault);
			this.on('destroy', function() {
				node.removeEventListener('submit', preventDefault);
			});
		},

		"scope": function(node) {
			this.on('scope', function(sparky, scope) {
				Sparky.setScope(node, scope);
			});
		}
	});
})();

<commit_msg>ajax-on-submit<commit_after>
// Sparky.fn

(function(window) {
	var Sparky = window.Sparky;

	// Stops Sparky from parsing the node.
	Sparky.fn.ignore = function ignore() {
		this.interrupt();
	};
})(this);

(function(window) {
	var Sparky = window.Sparky;

	// Logs nodes, scopes and data.
	Sparky.fn.log = function(node) {
		var sparky = this;

		function log(node, scope) {
			console.group('scope change');
			console.log('node ', node);
			console.log('scope', scope);
			console.log('data', sparky.data);
			console.log('fn', sparky.fn);
			console.groupEnd();
		}

		this.on('scope', log);

		console.group('initialisation');
		console.log('node ', node);
		console.groupEnd();
	};
})(this);

(function(window) {
	"use strict";

	var assign = Object.assign;
	var Sparky = window.Sparky;
	var dom    = Sparky.dom;

	assign(Sparky.fn, {
		"remove-hidden": function onReadyUnhide(node) {
			this.on('scope', function() {
				window.requestAnimationFrame(function() {
					dom.classes(node).remove('hidden');
				});
			});
		}
	});
})(this);

(function(window) {
	"use strict";

	var assign = Object.assign;
	var Sparky = window.Sparky;

	assign(Sparky.fn, {
		html: function html(node) {
			this.on('scope', function(sparky, html) {
				node.innerHTML = html;
			});
		}
	});
})(this);

(function() {
	"use strict";

	function preventDefault(e) {
		e.preventDefault();
	}

	Sparky.scope = function(node) {
		console.warn('Sparky: Sparky.scope() deprecated in favour of Sparky.getScope()')
		return Sparky.getScope(node);
	};

	Sparky.setScope = function(node, scope) {
		if (!window.jQuery) {
			throw new Error('data-fn="store-scope" requires jQuery.');
		}

		window.jQuery && jQuery.data(node, 'scope', scope);
	};

	Sparky.getScope = function(node) {
		if (!window.jQuery) {
			throw new Error('data-fn="store-scope" requires jQuery.');
		}

		return jQuery.data(node, 'scope');
	};

	Object.assign(Sparky.fn, {
		"prevent-click": function(node) {
			node.addEventListener('click', preventDefault);
			this.on('destroy', function() {
				node.removeEventListener('click', preventDefault);
			});
		},

		"prevent-submit": function(node) {
			node.addEventListener('submit', preventDefault);
			this.on('destroy', function() {
				node.removeEventListener('submit', preventDefault);
			});
		},

		"ajax-on-submit": function(node) {
			var method = node.getAttribute('method') || 'POST';
			var url = node.getAttribute('action');

			if (!Fn.isDefined(url)) {
				throw new Error('Sparky: fn ajax-on-submit requires an action="url" attribute.');
			}

			var submit;

			node.addEventListener('submit', preventDefault);

			this
			.on('scope', function(sparky, scope) {
				console.log('SCOPE');
				if (submit) { node.removeEventListener(submit); }
				submit = function(e) {
					console.log('SUBMIT', scope);
					jQuery.ajax({
						type: method.toLowerCase(),
						url:  url,
						data: JSON.stringify(scope),
						dataType: 'json'
					})
					.then(function(value) {
						console.log(value);
					});
				};
				node.addEventListener('submit', submit);
			})
			.on('destroy', function() {
				node.removeEventListener('submit', submit);
			});
		},

		"scope": function(node) {
			this.on('scope', function(sparky, scope) {
				Sparky.setScope(node, scope);
			});
		}
	});
})();


{'fraction_non_alphanumeric': 0.18253138075313807, 'fraction_numerical': 0.0, 'mean_word_length': 3.6642276422764226, 'pattern_counts': {'":': 9, '<': 3, '<?xml version=': 0, '>': 3, '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': '456274', 'n_tokens_mistral': 2294, 'n_tokens_neox': 1955, 'n_words': 371}