<commit_before>/**
 * Basic javascript functionality for ajax with the silverstripe framework.
 *
 * NOTE: the funny syntax below allows the module to
 * be loaded with or without RequireJS/AMD.
 * See: https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
 *
 * @author <NAME> <<EMAIL>>
 * @date 04.03.2014
 * @package silverstripe-ajax
 * @subpackage javascript
 */
(function (root, factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD. Register as an anonymous module.
		define(['jquery'], factory);
	} else {
		// Browser globals
		factory(root.jQuery);
	}
}(this, function ($) {

	// Plugins and configuration ///////////////////////////////////////////////////////////////////////////////////////

	// TODO: there needs to be an easy way to override these globally
	var config = {
		EVENTS_KEY:     'events',
		REGIONS_KEY:    'regions',
		MESSAGES_KEY:   'messages',

		checkForFullPage: /<html|<body|<!doctype|<script/i,

		statusCodes: {
			100: 'Continue',
			101: 'Switching Protocols',
			200: 'OK',
			201: 'Created',
			202: 'Accepted',
			203: 'Non-Authoritative Information',
			204: 'No Content',
			205: 'Reset Content',
			206: 'Partial Content',
			301: 'Moved Permanently',
			302: 'Found',
			303: 'See Other',
			304: 'Not Modified',
			305: 'Use Proxy',
			307: 'Temporary Redirect',
			400: 'Bad Request',
			401: 'Unauthorized',
			403: 'Forbidden',
			404: 'Not Found',
			405: 'Method Not Allowed',
			406: 'Not Acceptable',
			407: 'Proxy Authentication Required',
			408: 'Request Timeout',
			409: 'Conflict',
			410: 'Gone',
			411: 'Length Required',
			412: 'Precondition Failed',
			413: 'Request Entity Too Large',
			414: 'Request-URI Too Long',
			415: 'Unsupported Media Type',
			416: 'Request Range Not Satisfiable',
			417: 'Expectation Failed',
			422: 'Unprocessable Entity',
			500: 'Internal Server Error',
			501: 'Not Implemented',
			502: 'Bad Gateway',
			503: 'Service Unavailable',
			504: 'Gateway Timeout',
			505: 'HTTP Version Not Supported',
		}
	};


	$(document).ready(function () {

		// handle automatic ajax elements //////////////////////////////////////////////////////////////////////////////

		$(document)
			.on('click', 'a.ajax, a[data-target=ajax]', function() { // Links
				var $link = $(this).addClass('ajax-loading');

				$.ajax({
					url: this.href
				}).always(function () {
						$link.removeClass('ajax-loading');
					});

				return false;
			})
			.on('submit', 'form.ajax, form[data-target=ajax]', function(){ // Forms
				var $form = $(this).addClass('ajax-loading'),
					$clicked = $form.find('.ajax-clicked').removeClass('ajax-clicked'),
					params = $form.serialize();

				// include the button in the response if appropriate
				if ($clicked.length > 0 && $clicked.prop('name')) {
					params += (params.length > 0 ? '&' : '') + encodeURIComponent($clicked.prop('name'))
						+ '=' + encodeURIComponent($clicked.val());
				}

				// send the request
				$.ajax({
					url:    $form.prop('action'),
					type:   $form.prop('method'),
					data:   params
				}).always(function(){
						$form.removeClass('ajax-loading');
						$clicked.removeClass('ajax-loading');
					});

				return false;
			})
			.on('click', 'form.ajax input[type=submit], form[data-target=ajax] input[type=submit]', function(){ // Form buttons
				// this allows us to know which button (if any was clicked)<commit_msg>Also allow `button` to trigger form actions (not only "input")<commit_after>/**
 * Basic javascript functionality for ajax with the silverstripe framework.
 *
 * NOTE: the funny syntax below allows the module to
 * be loaded with or without RequireJS/AMD.
 * See: https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
 *
 * @author <NAME> <<EMAIL>>
 * @date 04.03.2014
 * @package silverstripe-ajax
 * @subpackage javascript
 */
(function (root, factory) {
	if (typeof define === 'function' && define.amd) {
		// AMD. Register as an anonymous module.
		define(['jquery'], factory);
	} else {
		// Browser globals
		factory(root.jQuery);
	}
}(this, function ($) {

	// Plugins and configuration ///////////////////////////////////////////////////////////////////////////////////////

	// TODO: there needs to be an easy way to override these globally
	var config = {
		EVENTS_KEY:     'events',
		REGIONS_KEY:    'regions',
		MESSAGES_KEY:   'messages',

		checkForFullPage: /<html|<body|<!doctype|<script/i,

		statusCodes: {
			100: 'Continue',
			101: 'Switching Protocols',
			200: 'OK',
			201: 'Created',
			202: 'Accepted',
			203: 'Non-Authoritative Information',
			204: 'No Content',
			205: 'Reset Content',
			206: 'Partial Content',
			301: 'Moved Permanently',
			302: 'Found',
			303: 'See Other',
			304: 'Not Modified',
			305: 'Use Proxy',
			307: 'Temporary Redirect',
			400: 'Bad Request',
			401: 'Unauthorized',
			403: 'Forbidden',
			404: 'Not Found',
			405: 'Method Not Allowed',
			406: 'Not Acceptable',
			407: 'Proxy Authentication Required',
			408: 'Request Timeout',
			409: 'Conflict',
			410: 'Gone',
			411: 'Length Required',
			412: 'Precondition Failed',
			413: 'Request Entity Too Large',
			414: 'Request-URI Too Long',
			415: 'Unsupported Media Type',
			416: 'Request Range Not Satisfiable',
			417: 'Expectation Failed',
			422: 'Unprocessable Entity',
			500: 'Internal Server Error',
			501: 'Not Implemented',
			502: 'Bad Gateway',
			503: 'Service Unavailable',
			504: 'Gateway Timeout',
			505: 'HTTP Version Not Supported',
		}
	};


	$(document).ready(function () {

		// handle automatic ajax elements //////////////////////////////////////////////////////////////////////////////

		$(document)
			.on('click', 'a.ajax, a[data-target=ajax]', function() { // Links
				var $link = $(this).addClass('ajax-loading');

				$.ajax({
					url: this.href
				}).always(function () {
						$link.removeClass('ajax-loading');
					});

				return false;
			})
			.on('submit', 'form.ajax, form[data-target=ajax]', function(){ // Forms
				var $form = $(this).addClass('ajax-loading'),
					$clicked = $form.find('.ajax-clicked').removeClass('ajax-clicked'),
					params = $form.serialize();

				// include the button in the response if appropriate
				if ($clicked.length > 0 && $clicked.prop('name')) {
					params += (params.length > 0 ? '&' : '') + encodeURIComponent($clicked.prop('name'))
						+ '=' + encodeURIComponent($clicked.val());
				}

				// send the request
				$.ajax({
					url:    $form.prop('action'),
					type:   $form.prop('method'),
					data:   params
				}).always(function(){
						$form.removeClass('ajax-loading');
						$clicked.removeClass('ajax-loading');
					});

				return false;
			})
			.on('click', 
				'form.ajax input[type=submit], form[data-target=ajax] input[type=submit], ' +
				'form.ajax button[type=submit], form[data-target=ajax] button[type=submit]', function(){ // Form buttons
				// this allows us to know which button (if any was clicked)
{'fraction_non_alphanumeric': 0.20621225194132872, 'fraction_numerical': 0.0365257405809606, 'mean_word_length': 2.701436934539649, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 2, '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': '6299378', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2108, 'n_words': 586}