<commit_before>﻿async = (function($){
	var self = {};
	self.REGEX = new RegExp('^https?://'+ document.domain +'(/.*)', 'i');
	self.container = '#content'; /* CSS selector for where to put the returned HTML data */
	self.debug = false;
	self.compile = true; /* auto include scripts into HTML? */
	self._loading = false; /* current URI being loaded */
	self.bind = function(){
		$('#admin-bar a').on('click',function(e){e.stopImmediatePropagation();});
		$('#preview-bar a').on('click',function(e){e.stopImmediatePropagation();});
		$('a'+
		':not(.admin-tools-hide-preview)'+
		':not([class^="editable"])'+
		':not([href^="/blog/edit"])'+
		':not([href^="/blog/add"])'+
		':not([href^="/events/add"])'+
		':not([href^="/user/logout"])'+
		':not(.admin-tools a)').on('click', function(e){
			e.preventDefault();
			e.stopImmediatePropagation();
			return async.link(this.href, false);
		});
	};
	self.link = function(target, pop_state){
		if (!self.REGEX.test(target) && !pop_state) {
			if (self.debug) console.log('Caught external link.');
			window.open(target,'_blank');
			return false;
		}
		if (self.debug) console.log('Caught internal link.');
		var uri, $container = $($(self.container)[0]), $document = $(document);
		if (pop_state) { uri = target; }
		else { uri = self.REGEX.exec(target)[1]; }
		if (self.debug) console.log('URI: '+ uri);
		if (uri != $container.attr('data-path')){
			self._loading = uri.split('?')[0];
			$document.trigger('async_start');
			$.getJSON('/admin/api/async?page='+ encodeURIComponent(uri)).success(function(res){
				if (self.debug) console.log(res);
				if (res.success) {
					if (self._loading !== res.data.path) return false;
					$document.trigger({type:'async_pre', data:res.data});
					$container.html(res.data.html + (self.compile?res.data.page.scripts.join(''):''));
					$document.trigger({type:'async_post', data:res.data});
					if (self.debug) console.log('Async load successful');
					document.cookie = 'elefant_last_page='+ res.data.path;
					self.bind();
					$container.attr('data-path',uri);
					if (!pop_state) {
						history.pushState({data:uri}, res.data.page.title, uri);
					}
					$('head title').text(res.data.page.title);
					$document.trigger('async_success');
					self._loading = false;
				} else {
					if (self.debug) console.log(res);
					$document.trigger({type:'async_error', data:res});
				}
			}).fail(function(){
				if (self.debug) console.log('Async load unsuccessful');
				$document.trigger('async_fail');
			}).always(function(){
				$document.trigger('async_end');
			});
		}
		return false;
	};
	console.log('Async wrapper loaded.');
	return self;
}(jQuery));

window.onpopstate = function(e){
	if (e.state) async.link(e.state.data, true);
};
$(document).ready(async.bind);<commit_msg>Fixed script vs HTML load order issue<commit_after>﻿var async = (function($){
	var self = {};
	self.REGEX = new RegExp('^https?://'+ document.domain +'(/.*)', 'i');
	self.container = '#content'; // CSS selector for where to put the returned HTML data
	self.debug = false;
	self.compile = true; // auto include scripts into HTML?
	self._loading = false; // current URI being loaded, internal use
	self.bind = function(){
		function catch_link(e){
			e.preventDefault();
			e.stopImmediatePropagation();
			return async.link(this.href, false);
		}
		$('a'+
		':not([class*="editable"])'+
		':not([href^="/blog/edit"])'+
		':not([href^="/blog/add"])'+
		':not([href^="/events/add"])'+
		':not([href^="/user/logout"])'+
		'').on('click', catch_link);
		
		$('#admin-bar a').off('click', catch_link);
		$('#preview-bar a').off('click', catch_link);
	};
	self.link = function(target, pop_state){
		if (!self.REGEX.test(target) && !pop_state) {
			if (self.debug) console.log('Caught external link.');
			window.open(target,'_blank');
			return false;
		}
		if (self.debug) console.log('Caught internal link.');
		var uri, $container = $($(self.container)[0]), $document = $(document);
		if (pop_state) { uri = target; }
		else { uri = self.REGEX.exec(target)[1]; }
		if (self.debug) console.log('URI: '+ uri);
		if (uri != $container.attr('data-path')){
			self._loading = uri.split('?')[0];
			$document.trigger('async_start');
			$.getJSON('/site/api/async?page='+ encodeURIComponent(uri)).success(function(res){
				if (self.debug) console.log(res);
				if (res.success) {
					if (self._loading !== res.data.path) return false;
					$document.trigger({type:'async_pre', data:res.data});
					$container.html(
						(self.compile?res.data.page.head:'')
						+ res.data.html
						+ (self.compile?res.data.page.tail:'')
					);
					$document.trigger({type:'async_post', data:res.data});
					if (self.debug) console.log('Async load successful');
					document.cookie = 'elefant_last_page='+ res.data.path;
					self.bind();
					$container.attr('data-path',uri);
					if (!pop_state) {
						history.pushState({data:uri}, res.data.page.title, uri);
					}
					$('head title').text(res.data.page.title);
					$document.trigger('async_success');
					self._loading = false;
				} else {
					if (self.debug) console.log(res);
					$document.trigger({type:'async_error', data:res});
				}
			}).fail(function(){
				if (self.debug) console.log('Async load unsuccessful');
				$document.trigger('async_fail');
			}).always(function(){
				$document.trigger('async_end');
			});
		}
		return false;
	};
	console.log('Async wrapper loaded.');
	return self;
}(jQuery));

window.onpopstate = function(e){
	if (e.state) async.link(e.state.data, true);
};
$(document).ready(async.bind);
{'fraction_non_alphanumeric': 0.21706263498920086, 'fraction_numerical': 0.0010799136069114472, 'mean_word_length': 4.024412296564195, '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': '6583136', 'n_tokens_mistral': 2039, 'n_tokens_neox': 2001, 'n_words': 346}