<commit_before>/**
 * Add or edit an article
 */

require(['jquery'], function($) {
	$(document).ready( function() {
		$("#news_title").on('keyup blur', function() {
			var value = $(this).val();

			if (value === '') {
				$("#news_url").val(value);
				return;
			}

			// Traitement de la valeur
			value = value.toLowerCase();
			value = value.replace(/[^a-z0-9.]/gi, '-');
			value = value.replace(/-{2,}/g, '-');
			value = value.replace(/(^-|-$)/g, '');

			if (value === '') {
				//Titre invalide
				return;
			}

			$("#news_url").val(value);
		});
	});<commit_msg>Adds onbeforeunload on News edition page<commit_after>/**
 * Add or edit an article
 */

require(['jquery'], function($) {
	$(document).ready( function() {
		$("#news_title").on('keyup blur', function() {
			var value = $(this).val();

			if (value === '') {
				$("#news_url").val(value);
				return;
			}

			// Traitement de la valeur
			value = value.toLowerCase();
			value = value.replace(/[^a-z0-9.]/gi, '-');
			value = value.replace(/-{2,}/g, '-');
			value = value.replace(/(^-|-$)/g, '');

			if (value === '') {
				//Titre invalide
				return;
			}

			$("#news_url").val(value);
		});
		
		// Prevents user from accidentally refreshing or leaving the page
		window.onbeforeunload = function() {
			return "Warning: if you leave without saving, all modifications will be lost.";
		};
		
		$('.wity-app button[type="submit"]').click(function() {
			window.onbeforeunload = null;
		});
	});
{'fraction_non_alphanumeric': 0.23290453622207177, 'fraction_numerical': 0.004062288422477996, 'mean_word_length': 2.9518716577540105, 'pattern_counts': {'":': 0, '<': 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': '5972579', 'n_tokens_mistral': 597, 'n_tokens_neox': 505, 'n_words': 108}