<commit_before>
window.Microblog = window.Microblog || {}

;(function($) {
	
	Microblog.Timeline = function () {
		var feed = null;
		
		var refreshTimer = null;
		var refreshTime = 20000;
		var pendingUpdate = false;
		var pendingLoad = false;
		
		var postContainer = $('<div>');
		
		var loading = false;
		
		var maxId = 0, lastId = 0;
		
		var currentOffset = null;
		
		var calcMaxMinPosts = function () {
			
			if (!currentOffset) {
				currentOffset = $('input[name=postOffset]').val();
			}
			
			$('div.microPost').each(function (index) {
				var postId = parseInt($(this).attr('data-id'));
				if (postId > maxId) {
					maxId = postId;
				}
				
				if ($(this).hasClass('toplevel')) {
					lastId = postId;
				}
			})
		}

		var refreshTimeline = function (since, reschedule) {
			if (pendingUpdate) {
				return pendingUpdate;
			}

			calcMaxMinPosts();

			if (!since) {
				since = maxId;
			}

			loading = true;

			pendingUpdate = getPosts({since: since, replies: 1});
			
			if (!pendingUpdate) {
				return;
			}

			pendingUpdate.done(function () {
				pendingUpdate = null;
				loading = false;
				if (feed.hasClass('autorefresh')) {
					if (reschedule) {
						setTimeout(function () {
							refreshTimeline(false, reschedule);
						}, refreshTime);
					}
				}
			})
			return pendingUpdate;
		}

		var morePosts = function () {
			calcMaxMinPosts();
			
			if (pendingLoad) {
				return pendingLoad;
			}

			if (lastId > 0) {
				// see what we're sorting by
				var sortBy = $('input[name=timelineSort]').val();
				var params = {};
				if (sortBy) {
					params.sort = sortBy;
				}
				if (currentOffset) {
					params.offset = currentOffset;
				}
				var restrict = {before: lastId};
				pendingLoad = getPosts(params, true).done(function () {
					pendingLoad = null;
				});
				return pendingLoad;
			}
		}

		var getPosts = function (params, append, callback) {
			var url = $('input[name=timelineUpdateUrl]').val();
			if (!url) {
				return;
			}
			return $.get(url, params, function (data) {
				postContainer.empty();
				if (data && data.length > 0) {
					postContainer.append(data);
					
					currentOffset = postContainer.find('input[name=postOffset]').val();
					
					postContainer.find('div.microPost').each (function () {
						var me = $(this);
						// first see if we're already inside another post's replies. If so, we don't move it
						if (me.parent().hasClass('postReplies')) {
							return;
						}

						var wrapper = $('<div class="newposts">');
						var parentId = parseInt(me.attr('data-parent'));
						if (!parentId) {
							if (append) {
								wrapper.appendTo(feed);
							} else {
								wrapper.prependTo(feed);
							}
						} else {
							var target = $('#post' + parentId);
							if (target.length) {
								var targetReplies = target.find('>.microPostContent>.postReplies');
								wrapper.prependTo(targetReplies);
							}
						}
						wrapper.append(me);
						wrapper.effect("highlight", {}, 3000);
						// done here because we've just removed and re-added to the dom?
//						wrapper.find('textarea.expandable').autogrow();
					})

					/*
					$('.fileUploadForm').fileupload('disable');
					$('.fileUploadForm').fileupload('enable');
					*/
					if ($.fileupload && $('.fileUploadForm').length) {
						$('.fileUploadForm').fileupload(
							'option',
							'dropZone',
							$('textarea.postContent')<commit_msg>FIX Changed the selector for postReplies to be inserted on ajax reload<commit_after>
window.Microblog = window.Microblog || {}

;(function($) {
	
	Microblog.Timeline = function () {
		var feed = null;
		
		var refreshTimer = null;
		var refreshTime = 20000;
		var pendingUpdate = false;
		var pendingLoad = false;
		
		var postContainer = $('<div>');
		
		var loading = false;
		
		var maxId = 0, lastId = 0;
		
		var currentOffset = null;
		
		var calcMaxMinPosts = function () {
			
			if (!currentOffset) {
				currentOffset = $('input[name=postOffset]').val();
			}
			
			$('div.microPost').each(function (index) {
				var postId = parseInt($(this).attr('data-id'));
				if (postId > maxId) {
					maxId = postId;
				}
				
				if ($(this).hasClass('toplevel')) {
					lastId = postId;
				}
			})
		}

		var refreshTimeline = function (since, reschedule) {
			if (pendingUpdate) {
				return pendingUpdate;
			}

			calcMaxMinPosts();

			if (!since) {
				since = maxId;
			}

			loading = true;

			pendingUpdate = getPosts({since: since, replies: 1});
			
			if (!pendingUpdate) {
				return;
			}

			pendingUpdate.done(function () {
				pendingUpdate = null;
				loading = false;
				if (feed.hasClass('autorefresh')) {
					if (reschedule) {
						setTimeout(function () {
							refreshTimeline(false, reschedule);
						}, refreshTime);
					}
				}
			})
			return pendingUpdate;
		}

		var morePosts = function () {
			calcMaxMinPosts();
			
			if (pendingLoad) {
				return pendingLoad;
			}

			if (lastId > 0) {
				// see what we're sorting by
				var sortBy = $('input[name=timelineSort]').val();
				var params = {};
				if (sortBy) {
					params.sort = sortBy;
				}
				if (currentOffset) {
					params.offset = currentOffset;
				}
				var restrict = {before: lastId};
				pendingLoad = getPosts(params, true).done(function () {
					pendingLoad = null;
				});
				return pendingLoad;
			}
		}

		var getPosts = function (params, append, callback) {
			var url = $('input[name=timelineUpdateUrl]').val();
			if (!url) {
				return;
			}
			return $.get(url, params, function (data) {
				postContainer.empty();
				if (data && data.length > 0) {
					postContainer.append(data);
					
					currentOffset = postContainer.find('input[name=postOffset]').val();
					
					postContainer.find('div.microPost').each (function () {
						var me = $(this);
						// first see if we're already inside another post's replies. If so, we don't move it
						if (me.parent().hasClass('postReplies')) {
							return;
						}

						var wrapper = $('<div class="newposts">');
						var parentId = parseInt(me.attr('data-parent'));
						if (!parentId) {
							if (append) {
								wrapper.appendTo(feed);
							} else {
								wrapper.prependTo(feed);
							}
						} else {
							var target = $('#post' + parentId);
							if (target.length) {
								var targetReplies = target.find('.postReplies:first');
								wrapper.prependTo(targetReplies);
							}
						}
						wrapper.append(me);
						wrapper.effect("highlight", {}, 3000);
						// done here because we've just removed and re-added to the dom?
//						wrapper.find('textarea.expandable').autogrow();
					})

					/*
					$('.fileUploadForm').fileupload('disable');
					$('.fileUploadForm').fileupload('enable');
					*/
					if ($.fileupload && $('.fileUploadForm').length) {
						$('.fileUploadForm').fileupload(
							'option',
							'dropZone',
							$('textarea.postContent')
{'fraction_non_alphanumeric': 0.15317667536988686, 'fraction_numerical': 0.0040615027560197275, 'mean_word_length': 2.480565371024735, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '3587989', 'n_tokens_mistral': 3093, 'n_tokens_neox': 2132, 'n_words': 474}