Board Thread:Code Review/@comment-168424-20151003020735/@comment-11733175-20151004093419

I had a quick go at clean up, chnaging the code style slightly and running it through jshint. One odd thing I spotted was it seems to have an external dependency somewhere (see ), so that needs to be resolved before moving it here.

I'm a little confused what the issue is with the performance - there's nothing particularly bad, nor is it very long. Is there any chance of the author being able to expand on what the concerns might be if they're still around? If the concern is due to it all being imported I use a complicated lazy loading setup on RS Wiki to only load what's needed, but that's a reaction to having 20-30 imported scripts,s some of them rather large, so it's not something that's necessary for every wiki. It's about being sensible in what you are loading.

I have no idea what the security issues are, but I haven't looked too closely at what's going on and I haven't checked them template at all.

/*jshint jquery:true, browser:true, devel:true, camelcase:true, curly:false, undef:true, bitwise:true, eqeqeq:true, forin:true, immed:true, latedef:true, newcap:true, noarg:true, unused:true, regexp:true, strict:true, trailing:true, maxcomplexity:10 */

//FIXME: this is absurdly expensive atm for all the pages not used on

function wwAjaxTables { // patching in changes to table sorting and alt rows function ajaxTableInit { var ts = window.ts = window.ts || {}; ts.ahClass = /class="ajaxHide"/gim; ts.crlf = /\r\n/g; ts.image_path = ''; ts.image_none = '';

ts.makeSortable = function (table) { var $table = $(table), firstRow;

if ($table.find("tr").length) { firstRow = !!$table.find("th").length ? $table.find("tr:has(th)").eq(0) : $table.find("tr").eq(0); }

if (!firstRow) { return; }

var ts = window.ts; firstRow.children(":not('.unsortable')") .append(                   '  ' +                    '' +                        ' ' +                            '' +                        ' ' +                    ''                ); };   }

// attempts to 'late bind' all the mw, wikia, and ww infrastructure // would have had at page load time function getTableData(tablePage, tableNum) { $("body") .bind("ajaxSend", function {                $(this).css("cursor", "wait");            }) .bind("ajaxComplete", function {                $(this).css("cursor", "auto");            });

$.get('http://' + location.hostname + '/' + tablePage + '?action=render', function (data) {           if (data) {                var ts = window.ts;

data = data .replace(ts.crlf, "") .replace(ts.ahClass, 'class="ajaxHide-active"') .replace('class="darktable"', "");

$("#ajaxTable" + tableNum).find("td").eq(0) .html(data) .find("table.sortable").each(function {                        ts.makeSortable($(this));                    });

$("#stl" + tableNum).html(                   '[edit] ' +                    '[hide]'                );

// external dependency? ttMouseOver(0); }       });    }

function hideTable(tableNum) { $("#ajaxTable" + tableNum).find("tr").eq(1).hide; $("#htl" + tableNum).click(function {            showTable(tableNum);        }); $("#htl" + tableNum).text("show"); }

function showTable(tableNum) { $("#ajaxTable" + tableNum).find("tr").eq(1).show; $("#htl" + tableNum).click(function {            hideTable(tableNum);        }); $("#htl" + tableNum).text("hide"); }

function loadTableData(tableNum) { var thisTable = document.getElementById("ajaxTable" + tableNum); var loadPage = thisTable.className.substring(thisTable.className.indexOf("targetPage-") + 11); getTableData(loadPage, tableNum); }

function addAjaxDisplayLink { $("#WikiaArticle table.ajax").each(function (i) {           $(this).attr("id", "ajaxTable" + i);            $(this).find("td").eq(1).parent.hide;            $(this).find("td").eq(0).parent.show;

if (this.getElementsByTagName("th").length) { this.getElementsByTagName("th")[0].innerHTML = ' ' + this.getElementsByTagName("th")[0].innerHTML; }

if ($(this).find("td").eq(0).hasClass("showLinkHere")) { $(this).find("td").eq(0).html($(this).find("td").eq(0).html.replace("[link]", '').replace("[/link]", "")); } else { $("#stl" + i).html('[show data]'); }       });    }

ajaxTableInit; window.ts.loadTableData = loadTableData; addAjaxDisplayLink; }

// needs to represent the 'bare minimum' needed to evaluate if needs to load function wwAjaxTablesInit { if ($("table.ajax").length) { wwAjaxTables; } }

$(wwAjaxTablesInit);