dev
Forums: Index > Code review > Code Review/AjaxRC


Could someone please review the changes to AjaxRC/beta.js. The diff between the latest in /beta.js and the current version of AjaxRC/code.js can be found at http://dev.wikia.com/?diff=11481&oldid=11398 . The changes made are listed below:

--Kangaroopowah (Talk) 00:18, April 22, 2013 (UTC)

I am currently testing AjaxRC/beta.js live at w:c:terraria:MediaWiki:Common.js. Everything seems to be working well.
  • I can confirm that ajaxCallAgain functionality has been restored (see my comment on the talk page).
  • Confirm that the change to localStorage key is working without any issues.
  • Conforming to jQuery style guidelines — changes look okay to me.
Bug: However, I am seeing a bug unrelated to these changes that should be addressed. The problem occurs in the block of code that does the actual HTML replacement for the refresh:
/**
 * Does the actual refresh
 */
function loadPageData() {
	var cC = '#mw-content-text';
	$( cC ).load( location.href + " " + cC + " > *", function () {
		ajaxTimer = setTimeout( loadPageData, ajRefresh );
	} );
}
Analysis: The problem here is that we're fetching #mw-content-text > * with Ajax. However, this only fetches child nodes of #mw-content-text — text nodes are not retrieved. This causes a problem when AjaxRC is run on certain pages where the #mw-content-text container contains not only nodes, but also text nodes. For instance, the following behavior can be currently observed at the w:c:terraria:Special:Log page:
Before the ajax refresh, the following content appears at the top.
(Latest | Earliest) View (newer 100 | older 100) (20 | 50 | 100 | 250 | 500)
After the ajax refresh, the text nodes are lost and it becomes:
Earliestolder 1002050100250500
Possible solution: To address this bug, I would suggest replacing the loadPageData() function with:
/**
 * Does the actual refresh
 */
function loadPageData() {
	var $temp = $( '<div>' );
	$temp.load( location.href + " #mw-content-text", function () {
		var $newContent = $temp.children( '#mw-content-text' );
		if ( $newContent.length ) {
			$( '#mw-content-text' ).replaceWith( $newContent );
		}
		ajaxTimer = setTimeout( loadPageData, ajRefresh );
	} );
}
On Ajax, this grabs #mw-content-text from the server and places it into a virtual temporary container. Then, in the callback, we replace the current #mw-content-text in the DOM with the new #mw-content-text from the temporary container. 20px_Rin_Tohsaka_Avatar.png Mathmagician ƒ(♫) 02:11 UTC, Monday, 22 April 2013
I'm fine pushing it for now, but long term, I'd like to change the way AjaxRC loads its pages to make it much simpler and hopefully, bug-free. --Kangaroopowah (Talk) 04:20, April 22, 2013 (UTC)