// Needed for IE because it's dumb
'abbr article aside audio canvas details figcaption figure footer header hgroup mark menu meter nav output progress section summary time video'.replace(/\w+/g,function(n){document.createElement(n)})
/*********/
/* ROLES */
/*********/
var U_GROUP_TESTER = 0x1;
var U_GROUP_ADMIN = 0x2;
var U_GROUP_EDITOR = 0x4;
var U_GROUP_MOD = 0x8;
var U_GROUP_BUREAU = 0x10;
var U_GROUP_DEV = 0x20;
var U_GROUP_VIP = 0x40;
var U_GROUP_BLOGGER = 0x80;
var U_GROUP_PREMIUM = 0x100;
var U_GROUP_LOCALIZER = 0x200;
var U_GROUP_SALESAGENT = 0x400;
var U_GROUP_SCREENSHOT = 0x800;
var U_GROUP_VIDEO = 0x1000;
var U_GROUP_APIONLY = 0x2000;
var U_GROUP_PENDING = 0x4000;
/******************/
/* ROLE SHORTCUTS */
/******************/
var U_GROUP_STAFF = U_GROUP_ADMIN | U_GROUP_EDITOR | U_GROUP_MOD | U_GROUP_BUREAU | U_GROUP_DEV | U_GROUP_BLOGGER | U_GROUP_LOCALIZER | U_GROUP_SALESAGENT;
var U_GROUP_EMPLOYEE = U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_DEV;
var U_GROUP_GREEN_TEXT = U_GROUP_MOD | U_GROUP_BUREAU | U_GROUP_DEV;
var U_GROUP_PREMIUMISH = U_GROUP_PREMIUM | U_GROUP_EDITOR;
var U_GROUP_MODERATOR = U_GROUP_ADMIN | U_GROUP_MOD | U_GROUP_BUREAU;
var U_GROUP_COMMENTS_MODERATOR = U_GROUP_BUREAU | U_GROUP_MODERATOR | U_GROUP_LOCALIZER;
var U_GROUP_PREMIUM_PERMISSIONS = U_GROUP_PREMIUM | U_GROUP_STAFF | U_GROUP_VIP;
var g_users = {};
var g_customColors = {};
function g_isUsernameValid(username) {
return (username.match(/[^a-z0-9]/i) == null && username.length >= 4 && username.length <= 16);
}
var User = new function() {
var self = this;
/**********/
/* PUBLIC */
/**********/
self.hasPermissions = function(roles) {
if (!roles) {
return true;
}
return !!(g_user.roles & roles);
}
/**********/
/* PRIVATE */
/**********/
};
function Ajax(url, opt) {
if (!url) {
return;
}
var _;
try { _ = new XMLHttpRequest() }
catch(e) {
try { _ = new ActiveXObject("Msxml2.XMLHTTP") }
catch(e) {
try { _ = new ActiveXObject("Microsoft.XMLHTTP") }
catch(e) {
if (window.createRequest) {
_ = window.createRequest();
}
else {
alert(LANG.message_ajaxnotsupported);
return;
}
}
}
}
this.request = _;
$WH.cO(this, opt);
this.method = this.method || (this.params && 'POST') || 'GET';
_.open(this.method, url, this.async == null ? true : this.async);
_.onreadystatechange = Ajax.onReadyStateChange.bind(this);
if (this.method.toUpperCase() == 'POST') {
_.setRequestHeader('Content-Type', (this.contentType || 'application/x-www-form-urlencoded') + '; charset=' + (this.encoding || 'UTF-8'));
}
_.send(this.params);
}
Ajax.onReadyStateChange = function() {
if (this.request.readyState == 4) {
if (this.request.status == 0 || (this.request.status >= 200 && this.request.status < 300)) {
this.onSuccess != null && this.onSuccess(this.request, this);
}
else {
this.onFailure != null && this.onFailure(this.request, this);
}
if (this.onComplete != null) {
this.onComplete(this.request, this);
}
}
};
var DomContentLoaded = new function() {
var _now = [];
var _del = [];
this.now = function() {
$WH.array_apply(_now, function(f) {
f();
});
};
this.delayed = function() {
$WH.array_apply(_del, function(f) {
f();
});
DomContentLoaded = null;
};
this.addEvent = function(f) {
_now.push(f);
};
this.addDelayedEvent = function(f) {
_del.push(f);
}
};
/*
Global functions related to DOM manipulation, events & forms that jQuery doesn't already provide
*/
function g_addCss(css) {
var style = $WH.ce('style');
style.type = 'text/css';
if (style.styleSheet) { // ie
style.styleSheet.cssText = css;
}
else {
$WH.ae(style, $WH.ct(css));
}
var a = $WH.gE(document, 'head')[0];
$WH.ae(a, style);
}
function g_setTextNodes(n, text) {
if (n.nodeType == 3) {
n.nodeValue = text;
}
else {
for (var i = 0; i < n.childNodes.length; ++i) {
g_setTextNodes(n.childNodes[i], text);
}
}
}
function g_setInnerHtml(n, text, nodeType) {
if (n.nodeName.toLowerCase() == nodeType) {
n.innerHTML = text;
}
else {
for (var i = 0; i < n.childNodes.length; ++i) {
g_setInnerHtml(n.childNodes[i], text, nodeType);
}
}
}
function g_getFirstTextContent(node) {
for (var i = 0; i < node.childNodes.length; ++i) {
if (node.childNodes[i].nodeName == '#text') {
return node.childNodes[i].nodeValue;
}
var ret = g_getFirstTextContent(node.childNodes[i]);
if (ret) {
return ret;
}
}
return false;
}
function g_getTextContent(el) {
var txt = '';
for (var i = 0; i < el.childNodes.length; ++i) {
if (el.childNodes[i].nodeValue) {
txt += el.childNodes[i].nodeValue;
}
else if (el.childNodes[i].nodeName == 'BR') {
if ($WH.Browser.ie67) {
txt += '\r';
}
else {
txt += '\n';
}
}
txt += g_getTextContent(el.childNodes[i]);
}
return txt;
}
function g_toggleDisplay(el) {
el = $(el);
el.toggle();
if (el.is(':visible')) {
return true;
}
return false;
}
function g_enableScroll(enabled) {
if (!enabled) {
$WH.aE(document, 'mousewheel', g_enableScroll.F);
$WH.aE(window, 'DOMMouseScroll', g_enableScroll.F)
}
else {
$WH.dE(document, 'mousewheel', g_enableScroll.F);
$WH.dE(window, 'DOMMouseScroll', g_enableScroll.F)
}
}
g_enableScroll.F = function(e) {
if (e.stopPropagation) {
e.stopPropagation();
}
if (e.preventDefault) {
e.preventDefault();
}
e.returnValue = false;
e.cancelBubble = true;
return false;
};
// from http://blog.josh420.com/archives/2007/10/setting-cursor-position-in-a-textbox-or-textarea-with-javascript.aspx
function g_setCaretPosition(elem, caretPos) {
if (!elem) {
return;
}
if (elem.createTextRange) {
var range = elem.createTextRange();
range.move('character', caretPos);
range.select();
}
else if (elem.selectionStart != undefined) {
elem.focus();
elem.setSelectionRange(caretPos, caretPos);
}
else {
elem.focus();
}
}
function g_insertTag(where, tagOpen, tagClose, repFunc) {
var n = $WH.ge(where);
n.focus();
if (n.selectionStart != null) {
var
s = n.selectionStart,
e = n.selectionEnd,
sL = n.scrollLeft,
sT = n.scrollTop;
var selectedText = n.value.substring(s, e);
if (typeof repFunc == 'function') {
selectedText = repFunc(selectedText);
}
n.value = n.value.substr(0, s) + tagOpen + selectedText + tagClose + n.value.substr(e);
n.selectionStart = n.selectionEnd = e + tagOpen.length;
n.scrollLeft = sL;
n.scrollTop = sT;
}
else if (document.selection && document.selection.createRange) {
var range = document.selection.createRange();
if (range.parentElement() != n) {
return;
}
var selectedText = range.text;
if (typeof repFunc == 'function') {
selectedText = repFunc(selectedText);
}
range.text = tagOpen + selectedText + tagClose;
/*
range.moveEnd("character", -tagClose.length);
range.moveStart("character", range.text.length);
range.select();
*/
}
if (n.onkeyup) {
n.onkeyup();
}
}
function g_onAfterTyping(input, func, delay) {
var timerId;
var ldsgksdgnlk623 = function() {
if (timerId) {
clearTimeout(timerId);
timerId = null;
}
timerId = setTimeout(func, delay);
};
input.onkeyup = ldsgksdgnlk623;
}
function g_onClick(el, func) {
var firstEvent = 0;
function rightClk(n) {
if (firstEvent) {
if (firstEvent != n) {
return;
}
}
else {
firstEvent = n;
}
func(true);
}
el.onclick = function(e) {
e = $WH.$E(e);
if (e._button == 2) { // middle click
return true;
}
return false;
}
el.oncontextmenu = function() {
rightClk(1);
return false;
};
el.onmouseup = function(e) {
e = $WH.$E(e);
if (e._button == 3 || e.shiftKey || e.ctrlKey) { // Right/Shift/Ctrl
rightClk(2);
}
else if (e._button == 1) { // Left
func(false);
}
return false;
}
}
function g_isLeftClick(e) {
e = $WH.$E(e);
return (e && e._button == 1);
}
function g_preventEmptyFormSubmission() { // Used on the homepage and in the top bar
if (!$.trim(this.elements[0].value)) {
return false;
}
}
var PageTemplate = new function()
{
var self = this;
/**********/
/* PUBLIC */
/**********/
self.init = function()
{
// Top links
initUserMenu();
initFeedbackLink();
initLanguageMenu();
initFilterDisclosure(); // aowow: custom (visibility toggle for filters was removed at some point)
// UI before page contents
initFloatingStuff();
initTopTabs();
initTopBar();
initBreadcrumb();
inited = true;
}
self.get = function(name)
{
return opt[name];
}
self.set = function(options)
{
if(!options)
return;
var old = {};
$.extend(old, opt);
$.extend(opt, options);
opt.activeTab = parseInt(opt.activeTab);
if(inited) // Update UI on the fly if already created
{
if(opt.activeTab != old.activeTab)
{
updateTopTabs();
updateTopBar();
}
if(opt.breadcrumb != old.breadcrumb)
{
updateBreadcrumb();
}
}
}
self.getBreadcrumb = function()
{
return $bread;
}
self.updateBreadcrumb = function()
{
updateBreadcrumb();
}
self.expandBreadcrumb = function()
{
return expandBreadcrumb();
}
/***********/
/* PRIVATE */
/***********/
var inited = false;
var opt = {};
var $bread;
var $tabs;
var checkedMenuItems = [];
function construct()
{
createDomElements(); // Create nodes for which getters are available
addBrowserClasses();
}
function createDomElements()
{
$bread = $('
');
}
function addBrowserClasses()
{
// This is done before the tag is loaded, so class names are added to the tag instead
if($WH.Browser.ie6) $(document.documentElement).addClass('ie6 ie67 ie678');
if($WH.Browser.ie7) $(document.documentElement).addClass('ie7 ie67 ie678');
if($WH.Browser.ie8) $(document.documentElement).addClass('ie8 ie678');
}
function initUserMenu()
{
var $link = $('#toplinks-user');
if(!$link.length)
return;
$link.attr('href', '?user=' + g_user.name);
var menu = [];
// User Page
var userPage = ['user-page', LANG.userpage, '?user=' + g_user.name, null, {checkedUrl: new RegExp('user=' + g_user.name + '$', 'i')}];
menu.push(userPage);
// Settings
// var settings = ['settings', LANG.settings, 'http://' + window.location.hostname + '?account', null, {icon: g_staticUrl + '/images/icons/cog.gif', checkedUrl: /account/i}];
var settings = ['settings', LANG.settings, '?account', null, {icon: g_staticUrl + '/images/icons/cog.gif', checkedUrl: /account/i}];
menu.push(settings);
// Reputation
var reputation = ['reputation', LANG.reputation, '?reputation'];
menu.push(reputation);
// Guides
var guides = ['guides', 'My Guides', '?my-guides'];
menu.push(guides);
addCharactersMenu(menu);
addProfilesMenu(menu);
// Premium Upgrade
var premiumUpgrade;
if(!g_user.premium)
{
premiumUpgrade = ['premium-upgrade', LANG.premiumupgrade, '?premium', null, {className: 'q7', checkedUrl: /premium/i}];
menu.push(premiumUpgrade);
}
// Sign Out
menu.push(['sign-out', LANG.signout, '?account=signout']);
Menu.add($link, menu);
$link.addClass('hassubmenu');
}
function addCharactersMenu(userMenu)
{
if(!g_user.characters || !g_user.characters.length)
return;
// Menu will be generated on the fly
var characters = ['characters', LANG.tab_characters, '?user=' + g_user.name + '#characters', null, {onBeforeShow: generateCharactersSubmenu} ];
userMenu.push(characters);
}
function addProfilesMenu(userMenu)
{
if(!g_user.profiles || !g_user.profiles.length)
return;
// Menu will be generated on the fly
var profiles = ['profiles', LANG.tab_profiles, '?user=' + g_user.name + '#profiles', null, {onBeforeShow: generateProfilesSubmenu} ];
userMenu.push(profiles);
}
function generateCharactersSubmenu(menuItem)
{
var submenu = [];
// Sort by realm, region, name
g_user.characters.sort(function(a, b)
{
return $WH.strcmp(a.realmname, b.realmname) || $WH.strcmp(a.region, b.region) || $WH.strcmp(a.name, b.name);
});
var lastKey;
$.each(g_user.characters, function(idx, character)
{
if(!character.region || !character.realm || !character.name)
return;
// Group by realm+region
var key = character.region + character.realm;
if(key != lastKey)
{
var heading = [, character.realmname + ' (' + character.region.toUpperCase() + ')', g_getProfileRealmUrl(character)];
submenu.push(heading);
lastKey = key;
}
var menuItem = [character.id, character.name, g_getProfileUrl(character), null,
{
className: (character.pinned ? 'icon-star-right ' : '') + 'c' + character.classs,
// tinyIcon: $WH.g_getProfileIcon(character.race, character.classs, character.gender, character.level, character.id, 'tiny')
// aowow: profileId should not be nessecary here
tinyIcon: $WH.g_getProfileIcon(character.race, character.classs, character.gender, character.level, 0, 'tiny')
}];
submenu.push(menuItem);
});
menuItem[MENU_IDX_SUB] = submenu;
}
function generateProfilesSubmenu(menuItem)
{
var submenu = [];
// Sort by name
g_user.profiles.sort(function(a, b)
{
return $WH.strcmp(a.name, b.name);
});
$.each(g_user.profiles, function(idx, profile)
{
var menuItem = [profile.id, profile.name, g_getProfileUrl(profile), null,
{
className: 'c' + profile.classs,
tinyIcon: $WH.g_getProfileIcon(profile.race, profile.classs, profile.gender, profile.level, profile.icon, 'tiny')
}];
submenu.push(menuItem);
});
submenu.push([0, LANG.menu_newprofile, '?profile&new', null, {tinyIcon: 'inv_misc_questionmark'}]);
menuItem[MENU_IDX_SUB] = submenu;
}
function initFeedbackLink()
{
$('#toplinks-feedback')
.attr('href', 'javascript:;')
.click(function()
{
ContactTool.show();
});
}
function initLanguageMenu()
{
var linkBefore = 'http://';
var linkAfter = location.pathname + location.search + location.hash;
var localeId = Locale.getId();
var menu = [];
var currentLocale;
$.each(Locale.getAllByName(), function(idx, locale)
{
var menuItem = [
locale.id,
locale.description,
g_host + '/?locale=' + locale.id, // aowow: edited for unsupported subdomains # linkBefore + locale.domain + linkAfter
null, // more custom
null // also custom
];
if (typeof g_pageInfo != 'undefined' && g_pageInfo.type && g_types[g_pageInfo.type])
menuItem[4] = {rel: g_types[g_pageInfo.type] + '=' + g_pageInfo.typeId + " domain=" + locale.domain};
if(locale.id == localeId)
{
menuItem.checked = true;
currentLocale = locale;
}
menu.push(menuItem);
});
setLanguageMenu($('#toplinks-language'), menu, currentLocale);
$(document).ready(function()
{
setLanguageMenu($('#footer-links-language'), menu, currentLocale);
});
}
function setLanguageMenu($node, menu, locale)
{
$node.attr('href', 'javascript:;');
// $node.text(locale.description);
$node.addClass('hassubmenu');
Menu.add($node, menu);
}
function initFloatingStuff()
{
// Expand button
$('#header-expandsite')
.attr('href', 'javascript:;')
.click(expandButtonClick);
}
function initTopTabs()
{
var $topTabs = $('#toptabs');
if(!$topTabs.length)
return;
$tabs = $('
');
$.each(mn_path, function(idx, menuItem)
{
var $dt = $('' + menuItem[MENU_IDX_NAME].charAt(0) + '' + menuItem[MENU_IDX_NAME].substr(1) + '');
var $a = $dt.children('a');
Menu.linkifyItem(menuItem, $a);
$dt.appendTo($tabs);
});
updateTopTabs();
$tabs.appendTo($topTabs);
}
function initTopBar()
{
var $topBar = $('#topbar');
if(!$topBar.length)
return;
// Search
var $search = $('div.topbar-search', $topBar);
// aowow: custom start
$('#livesearch-generic').attr('placeholder', LANG.searchdb);
// aowow: custom end
// Icon
var $icon = $('').attr('href', 'javascript:;');
$icon.click(searchIconClick)
.appendTo($search);
$('form', $search).submit(g_preventEmptyFormSubmission);
LiveSearch.attach($('input', $search));
var windowSize = $WH.g_getWindowSize();
if(windowSize.w && windowSize.w < 1024)
$('div.topbar-search input').css('width', '180px');
updateTopBar();
}
function initBreadcrumb()
{
// (Already created)
updateBreadcrumb();
$bread.appendTo($('#main-precontents'));
}
function initFilterDisclosure()
{
if (opt.filter == null)
return;
var
_ = $WH.ge('main-precontents'),
d = $WH.ce('div'),
a = $WH.ce('a');
d.className = 'path-right';
a.href = 'javascript:;';
a.id = 'fi_toggle';
$WH.ns(a);
a.onclick = fi_toggle;
if (opt.filter) {
a.className = 'disclosure-on';
$WH.ae(a, $WH.ct(LANG.fihide));
}
else {
a.className = 'disclosure-off';
$WH.ae(a, $WH.ct(LANG.fishow));
}
$WH.ae(d, a);
$WH.ae(_, d);
}
function updateTopTabs()
{
if(!$tabs)
return;
var $as = $('a', $tabs);
$.each(mn_path, function(idx, menuItem)
{
var $a = $($as.get(idx));
var isActiveTab = (menuItem[MENU_IDX_ID] == opt.activeTab);
if(isActiveTab)
{
$a.addClass('active');
Menu.remove($a);
}
else
{
$a.removeClass('active');
if(menuItem[MENU_IDX_SUB])
Menu.add($a, menuItem[MENU_IDX_SUB]);
}
});
}
function updateTopBar()
{
var $buttons = $('#topbar div.topbar-buttons');
if(!$buttons.length)
return;
$buttons.empty();
switch(opt.activeTab)
{
case 0: // Database
Menu.addButtons($buttons,[
[0, LANG.menu_browse, null, mn_database], // Browse
Menu.findItem(mn_tools, [8]), // Utilities
Menu.findItem(mn_tools, [8, 4]) // Random Page
]);
break;
case 1: // Tools
// Create "Calculators" group to decrease width used
var calculators = [
[, LANG.calculators],
Menu.findItem(mn_tools, [0]), // Talent Calculator
Menu.findItem(mn_tools, [2]), // Hunter Pet Calculator
Menu.findItem(mn_tools, [3]) // Item Comparison
];
// MoP link
if (mn_tools[2][0] == 10) {
var tmp = calculators[3];
calculators[3] = Menu.findItem(mn_tools, [10]);
calculators[4] = tmp;
Menu.addButtons($buttons, Menu.implode(calculators));
Menu.addButtons($buttons, Menu.implode(mn_tools.slice(4))); // Skip first 4 menu items
} else {
Menu.addButtons($buttons, Menu.implode(calculators));
Menu.addButtons($buttons, Menu.implode(mn_tools.slice(3))); // Skip first 4 menu items
}
break;
case 2: // More
Menu.addButtons($buttons, Menu.implode(mn_more));
break;
case 3: // Community
Menu.addButtons($buttons, Menu.implode(mn_community));
Menu.addButtons($buttons, [
Menu.findItem(mn_tools, [8]) // Utilities
]);
break;
case 4: // Staff
Menu.addButtons($buttons, Menu.implode(mn_staff));
break;
case 5: // News
Menu.addButtons($buttons, Menu.implode(mn_news));
break;
case 6: // Guides
var entries = [ [ 1, 'List of guides', '?guides' ], [ 2, 'Write new guide', '?guide=new' ] ];
if(g_user.id)
entries.push([ 3, 'My guides', '?my-guides' ]);
Menu.addButtons($buttons, entries);
break;
}
}
function updateBreadcrumb()
{
if(!opt.breadcrumb || !opt.breadcrumb.length) // Empty
{
$bread.hide();
return;
}
$bread.empty();
// Uncheck previously checked menu items, if any
if(checkedMenuItems.length)
{
$.each(checkedMenuItems, function() {this.checked = false;Menu.updateItem(this)});
checkedMenuItems = [];
}
var path = Menu.getFullPath(mn_path, opt.breadcrumb);
if(!path.length)
return;
var lastIdx = (path.length - 1);
$.each(path, function(idx, menuItem)
{
var menuOpt = Menu.getItemOpt(menuItem);
menuItem.checked = true;
checkedMenuItems.push(menuItem);
Menu.updateItem(menuItem);
var $span = expandBreadcrumb();
var $textHolder = $span;
if(menuItem[MENU_IDX_URL])
{
$textHolder = $('', {
href: Menu.getItemUrl(menuItem)
}).appendTo($span);
}
if(menuOpt.breadcrumb)
$textHolder.text(menuOpt.breadcrumb);
else
$textHolder.text(menuItem[MENU_IDX_NAME]);
Menu.add($textHolder, menuItem.parentMenu);
$span.appendTo($bread);
// Add ellipsis as appropriate
if(idx == lastIdx && menuItem[MENU_IDX_SUB])
{
$span.addClass('breadcrumb-arrow');
var $ellipsis = $('...');
Menu.add($ellipsis, menuItem[MENU_IDX_SUB]);
$ellipsis.appendTo($bread);
}
});
$bread.trigger('update'); // Some features rely on this event to add stuff to the breadcrumb
$bread.show();
}
function expandBreadcrumb()
{
$bread.children('span:last').addClass('breadcrumb-arrow');
return $('').appendTo($bread);
}
// EVENTS
function expandButtonClick()
{
$('#sidebar, #header-expandsite').remove();
if($('#layout').hasClass('nosidebar'))
return;
// Free room allocated for the sidebar
$('#wrapper').animate(
{'margin-right': '10px'},
333,
null,
function()
{
$('#wrapper').css('margin-right', '0px');
$('#layout').addClass('nosidebar');
}
);
}
function searchIconClick()
{
$(this).prev('form').submit().children('input').focus();
}
construct();
}
/*
Global functions related to UI elements and effects
*/
function g_getReputationPlusAchievementText(gold, silver, copper, reputation) {
// var achievements = g_getAchievementText(gold, silver, copper, true);
var repText = $('').addClass('wsach-pts');
repText.mouseover(function(event) {
$WH.Tooltip.showAtCursor(event, LANG.reputationtip, 0, 0, 'q');
}).mousemove(function(event) {
$WH.Tooltip.cursorUpdate(event);
}).mouseout(function() {
$WH.Tooltip.hide();
});
repText.css('color', 'white');
repText.text($WH.number_format(reputation));
var ret = $('');
ret.append(' (');
ret.append(repText);
// ret.append(' – ');
// ret.append(achievements);
ret.append(')');
return ret;
}
function g_addTooltip(element, text, className) {
if (!className && text.indexOf('') == -1) {
className = 'q';
}
$WH.Tooltip.simple(element, text, className);
}
function g_addStaticTooltip(icon, text, className) {
if (!className && text.indexOf('') == -1) {
className = 'q';
}
icon.onmouseover = function(d) {
$WH.Tooltip.show(icon, text, 0, 0, className);
};
icon.onmouseout = $WH.Tooltip.hide;
}
function g_formatTimeElapsed(delay) {
function OMG(value, unit, abbrv) {
if (abbrv && LANG.timeunitsab[unit] == '') {
abbrv = 0;
}
if (abbrv) {
return value + ' ' + LANG.timeunitsab[unit];
}
else {
return value + ' ' + (value == 1 ? LANG.timeunitssg[unit] : LANG.timeunitspl[unit]);
}
}
var
range = [31557600, 2629800, 604800, 86400, 3600, 60, 1],
subunit = [1, 3, 3, -1, 5, -1, -1];
delay = Math.max(delay, 1);
for (var i = 3, len = range.length; i < len; ++i) {
if (delay >= range[i]) {
var i1 = i;
var v1 = Math.floor(delay / range[i1]);
if (subunit[i1] != -1) {
var i2 = subunit[i1];
delay %= range[i1];
var v2 = Math.floor(delay / range[i2]);
if (v2 > 0) {
return OMG(v1, i1, 1) + ' ' + OMG(v2, i2, 1);
}
}
return OMG(v1, i1, 0);
}
}
return '(n/a)';
}
function g_GetStaffColorFromRoles(roles) {
if (roles & U_GROUP_ADMIN) {
return 'comment-blue';
}
if (roles & U_GROUP_GREEN_TEXT) { // Mod, Bureau, Dev
return 'comment-green';
}
if (roles & U_GROUP_VIP) { // VIP
return 'comment-gold';
}
if (roles & U_GROUP_PREMIUMISH) { // Premium, Editor
return 'comment-gold';
}
return '';
}
function g_formatDate(sp, elapsed, theDate, time, alone) {
var today = new Date();
var event_day = new Date();
event_day.setTime(today.getTime() - (1000 * elapsed));
var txt;
var event_day_midnight = new Date(event_day.getYear(), event_day.getMonth(), event_day.getDate());
var today_midnight = new Date(today.getYear(), today.getMonth(), today.getDate());
var delta = (today_midnight.getTime() - event_day_midnight.getTime());
delta /= 1000;
delta /= 86400;
delta = Math.round(delta);
if (elapsed >= 2592000) { /* More than a month ago */
txt = LANG.date_on + g_formatDateSimple(theDate, time);
}
else if (delta > 1) {
txt = $WH.sprintf(LANG.ddaysago, delta);
if (sp) {
var _ = new Date();
_.setTime(theDate.getTime() + (g_localTime - g_serverTime));
sp.className += ' tip';
sp.title = _.toLocaleString();
}
}
else if (elapsed >= 43200) {
if (today.getDay() == event_day.getDay()) {
txt = LANG.today;
}
else {
txt = LANG.yesterday;
}
txt = g_formatTimeSimple(event_day, txt);
if (sp) {
var _ = new Date();
_.setTime(theDate.getTime() + (g_localTime - g_serverTime));
sp.className += ' tip';
sp.title = _.toLocaleString();
}
}
else { /* Less than 12 hours ago */
var txt = $WH.sprintf(LANG.date_ago, g_formatTimeElapsed(elapsed));
if (sp) {
var _ = new Date();
_.setTime(theDate.getTime() + (g_localTime - g_serverTime));
sp.className += ' tip';
sp.title = _.toLocaleString();
}
}
if (alone == 1) {
txt = txt.substr(0, 1).toUpperCase() + txt.substr(1);
}
if (sp) {
$WH.ae(sp, $WH.ct(txt));
}
else {
return txt;
}
}
function g_formatDateSimple(d, time) {
function __twoDigits(n) {
return (n < 10 ? '0' + n : n);
}
var
b = "",
day = d.getDate(),
month = d.getMonth() + 1,
year = d.getFullYear();
if (year <= 1970) {
b += LANG.unknowndate_stc;
}
else {
b += $WH.sprintf(LANG.date_simple, __twoDigits(day), __twoDigits(month), year);
}
if (time != null) {
b = g_formatTimeSimple(d, b);
}
return b;
}
function g_formatTimeSimple(d, txt, noPrefix) {
function __twoDigits(n) {
return (n < 10 ? '0' + n : n);
}
var
hours = d.getHours(),
minutes = d.getMinutes();
if (txt == null) {
txt = '';
}
txt += (noPrefix ? ' ' : LANG.date_at);
if (hours == 12) {
txt += LANG.noon;
}
else if (hours == 0) {
txt += LANG.midnight;
}
else if (hours > 12) {
txt += (hours - 12) + ':' + __twoDigits(minutes) + ' ' + LANG.pm;
}
else {
txt += hours + ':' + __twoDigits(minutes) + ' ' + LANG.am;
}
return txt;
}
function g_createGlow(txt, cn) {
var s = $WH.ce('span');
for (var i = -1; i <= 1; ++i) {
for (var j = -1; j <= 1; ++j) {
var d = $WH.ce('div');
d.style.position = 'absolute';
d.style.whiteSpace = 'nowrap';
d.style.left = i + 'px';
d.style.top = j + 'px';
if (i == 0 && j == 0) {
d.style.zIndex = 4;
}
else {
d.style.color = 'black';
d.style.zIndex = 2;
}
//$WH.ae(d, $WH.ct(txt));
d.innerHTML = txt;
$WH.ae(s, d);
}
}
s.style.position = 'relative';
s.className = 'glow' + (cn != null ? ' ' + cn : '');
var ph = $WH.ce('span');
ph.style.visibility = 'hidden';
$WH.ae(ph, $WH.ct(txt));
$WH.ae(s, ph);
return s;
}
function g_createProgressBar(opt) {
if (opt == null) {
opt = {};
}
if (typeof opt.text == 'undefined') {
opt.text = ' ';
}
if (opt.color == null) {
opt.color = 'rep0';
}
if (opt.width == null || opt.width > 100) {
opt.width = 100;
}
var el, div;
if (opt.hoverText) {
el = $WH.ce('a');
el.href = 'javascript:;';
}
else {
el = $WH.ce('span');
}
el.className = 'progressbar';
if (opt.text || opt.hoverText) {
div = $WH.ce('div');
div.className = 'progressbar-text';
if (opt.text) {
var del = $WH.ce('del');
$WH.ae(del, $WH.ct(opt.text));
$WH.ae(div, del);
}
if (opt.hoverText) {
var ins = $WH.ce('ins');
$WH.ae(ins, $WH.ct(opt.hoverText));
$WH.ae(div, ins);
}
$WH.ae(el, div);
}
div = $WH.ce('div');
div.className = 'progressbar-' + opt.color;
div.style.width = opt.width + '%';
if (opt.height) {
div.style.height = opt.height;
}
$WH.ae(div, $WH.ct(String.fromCharCode(160)));
$WH.ae(el, div);
if (opt.text) {
var div = $WH.ce('div');
div.className = 'progressbar-text progressbar-hidden';
$WH.ae(div, $WH.ct(opt.text));
$WH.ae(el, div);
}
return el;
}
function g_createReputationBar(totalRep) {
var P = g_createReputationBar.P;
if (!totalRep) {
totalRep = 0;
}
totalRep += 42000;
if (totalRep < 0) {
totalRep = 0;
}
else if (totalRep > 84999) {
totalRep = 84999;
}
var
currentRep = totalRep,
maxRep,
standing = 0;
for (var i = 0, len = P.length; i < len; ++i) {
if (P[i] > currentRep) {
break;
}
if (i < len - 1) {
currentRep -= P[i];
standing = i + 1;
}
}
maxRep = P[standing];
var opt = {
text: g_reputation_standings[standing],
hoverText: currentRep + ' / ' + maxRep,
color: 'rep' + standing,
width: parseInt(currentRep / maxRep * 100)
};
return g_createProgressBar(opt);
}
g_createReputationBar.P = [36000, 3000, 3000, 3000, 6000, 12000, 21000, 999];
function g_createAchievementBar(points, outOf, overall, bonus) {
if (!points) {
points = 0;
}
var opt = {
text: points + (bonus > 0 ? '(+' + bonus + ')' : '') + (outOf > 0 ? ' / ' + outOf : ''),
color: (overall ? 'rep7' : 'ach' + (outOf > 0 ? 0 : 1)),
width: (outOf > 0 ? parseInt(points / outOf * 100) : 100)
};
return g_createProgressBar(opt);
}
function g_getMoneyHtml(money, side, costItems, costCurrency, achievementPoints) {
var
ns = 0,
html = '';
if (side == 1 || side == 'alliance') {
side = 1;
}
else if (side == 2 || side == 'horde') {
side = 2;
}
else {
side = 3;
}
if (money >= 10000) {
ns = 1;
var display = Math.floor(money / 10000);
html += '' + $WH.number_format(display) + '';
money %= 10000;
}
if (money >= 100) {
if (ns) {
html += ' ';
}
else {
ns = 1;
}
var display = Math.floor(money / 100);
html += '' + display + '';
money %= 100;
}
if (money >= 1) {
if (ns) {
html += ' ';
}
else {
ns = 1;
}
html += '' + money + '';
}
if (costItems != null) {
for (var i = 0; i < costItems.length; ++i) {
if (ns) {
html += ' ';
}
else {
ns = 1;
}
var itemId = costItems[i][0];
var count = costItems[i][1];
var icon = (g_items[itemId] && g_items[itemId].icon ? g_items[itemId].icon : 'inv_misc_questionmark');
html += '' + count + '';
}
}
if (costCurrency != null) {
for (var i = 0; i < costCurrency.length; ++i) {
if (ns) {
html += ' ';
}
else {
ns = 1;
}
var currencyId = costCurrency[i][0];
var count = costCurrency[i][1];
var icon = (g_gatheredcurrencies[currencyId] && g_gatheredcurrencies[currencyId].icon ? g_gatheredcurrencies[currencyId].icon : ['inv_misc_questionmark', 'inv_misc_questionmark']);
if (side == 3 && icon[0] == icon[1]) {
side = 1;
}
// aowow: custom start
if (currencyId == 103) { // arena
html += '' + $WH.number_format(count) + '';
}
else if (currencyId == 104) { // honor
html += '' + (side == 3 ? '' : '') + $WH.number_format(count) + (side == 3 ? '' : '') + '';
}
else { // tokens
html += '' + count + '';
}
// aowow: custom end
// html += '' + (side == 3 ? '' : '') + count + (side == 3 ? '' : '') + '';
}
}
if (achievementPoints > 0) {
if (ns) {
html += ' ';
}
else {
ns = 1;
}
html += '' + $WH.number_format(achievementPoints) + '';
}
return html;
}
function g_GetExpansionClassName(expansion) {
switch (expansion) {
case 0:
return null;
case 1:
return "icon-bc-right";
case 2:
return "icon-wotlk-right";
}
return null;
}
function g_pickerWheel(evt) {
evt = $WH.$E(evt);
if (evt._wheelDelta < 0) {
this.scrollTop += 27;
}
else {
this.scrollTop -= 27;
}
}
function g_setSelectedLink(n, group) {
if (!g_setSelectedLink.groups) {
g_setSelectedLink.groups = {};
}
var _ = g_setSelectedLink.groups;
if (_[group]) {
_[group].className = _[group].className.replace('selected', '');
}
n.className += ' selected';
_[group] = n;
}
function g_setCheckedRow(n, group) {
if (!g_setCheckedRow.groups) {
g_setCheckedRow.groups = {};
}
var _ = g_setCheckedRow.groups;
if (_[group]) {
_[group].className = _[group].className.replace('checked', '');
}
n.className += ' checked';
_[group] = n;
}
function g_addPages(d, opt) {
function createPageSquare(n, customText) {
var foo;
if (n == opt.page) {
foo = $WH.ce('span');
foo.className = 'selected';
}
else {
foo = $WH.ce('a');
foo.href = (n > 1 ? opt.url + opt.sep + n + opt.pound : opt.url + opt.pound);
}
$WH.ae(foo, $WH.ct(customText != null ? customText : n));
return foo;
}
if (!opt.pound) {
opt.pound = '';
}
if (!opt.sep) {
opt.sep = '.';
}
if (opt.allOrNothing && opt.nPages <= 1) {
return;
}
var leftAligned = (opt.align && opt.align == 'left');
var
divPages = $WH.ce('div'),
pagesNumbers,
para = $WH.ce('var');
divPages.className = 'pages';
if (leftAligned) {
divPages.className += ' pages-left';
}
// Pages
if (opt.nPages > 1) {
pagesNumbers = $WH.ce('div');
pagesNumbers.className = 'pages-numbers';
var minPage = Math.max(2, opt.page - 2);
var maxPage = Math.min(opt.nPages - 1, opt.page + 2);
var elements = []; // Temporarily stored in an array so the order can be reversed when left-aligned.
if (opt.page != opt.nPages) {
elements.push(createPageSquare(opt.page + 1, LANG.lvpage_next + String.fromCharCode(8250)));
}
elements.push(createPageSquare(opt.nPages));
if (maxPage < opt.nPages - 1) {
var sp = $WH.ce('span');
$WH.ae(sp, $WH.ct('...'));
elements.push(sp);
}
for (var i = maxPage; i >= minPage; --i) {
elements.push(createPageSquare(i));
}
if (minPage > 2) {
var sp = $WH.ce('span');
$WH.ae(sp, $WH.ct('...'));
elements.push(sp);
}
elements.push(createPageSquare(1));
if (opt.page != 1) {
elements.push(createPageSquare(opt.page - 1, String.fromCharCode(8249) + LANG.lvpage_previous));
}
if (leftAligned) {
elements.reverse();
}
for (var i = 0, len = elements.length; i < len; ++i) {
$WH.ae(pagesNumbers, elements[i]);
}
pagesNumbers.firstChild.style.marginRight = '0';
pagesNumbers.lastChild.style.marginLeft = '0';
}
// Number of items
var para = $WH.ce('var');
$WH.ae(para, $WH.ct($WH.sprintf(LANG[opt.wording[opt.nItems == 1 ? 0 : 1]], opt.nItems)));
if (opt.nPages > 1) { // Go to page
var sp = $WH.ce('span');
$WH.ae(sp, $WH.ct(String.fromCharCode(8211)));
$WH.ae(para, sp);
var pageIcon = $WH.ce('a');
pageIcon.className = 'gotopage';
pageIcon.href = 'javascript:;';
$WH.ns(pageIcon);
if ($WH.Browser.ie) {
$WH.ae(pageIcon, $WH.ct(' '));
}
pageIcon.onclick = function() {
var n = prompt($WH.sprintf(LANG.prompt_gotopage, 1, opt.nPages), opt.page);
if (n != null) {
n |= 0;
if (n != opt.page && n >= 1 && n <= opt.nPages) {
document.location.href = (n > 1 ? opt.url + opt.sep + n + opt.pound : opt.url + opt.pound);
}
}
};
pageIcon.onmouseover = function(event) {
$WH.Tooltip.showAtCursor(event, LANG.tooltip_gotopage, 0, 0, 'q2');
};
pageIcon.onmousemove = $WH.Tooltip.cursorUpdate;
pageIcon.onmouseout = $WH.Tooltip.hide;
$WH.ae(para, pageIcon);
}
if (leftAligned) {
$WH.ae(divPages, para);
if (pagesNumbers) {
$WH.ae(divPages, pagesNumbers);
}
}
else {
if (pagesNumbers) {
$WH.ae(divPages, pagesNumbers);
}
$WH.ae(divPages, para);
}
$WH.ae(d, divPages);
}
function g_disclose(el, _this) {
_this.className = 'disclosure-' + (g_toggleDisplay(el) ? 'on' : 'off');
return false;
}
/* Displays a warning when the user attempts to leave the page if some elements are modified, unless the user leaves the page
* by submitting the form.
*
* The jQuery form object must be passed as first argument; the second argument is an array of jQuery objects of fields that
* are being watched for changes. The third argument is the warning message shown.
*
* This function must be called in the on ready event.
*/
function g_setupChangeWarning(form, elements, warningMessage) {
/* Still skip IE since it triggers this when anchor links are clicked. */
if ($WH.Browser.ie) {
return;
}
if (!form) {
return;
}
function ShowWarning() { return warningMessage; }
form.submit(function() { window.onbeforeunload = null; });
var initialText = [];
for (var idx in elements) {
var text = elements[idx];
if (!text) {
continue;
}
initialText[idx] = text.val();
text.keydown(function() {
for (var idx in elements) {
var text = elements[idx];
if (!text) {
continue;
}
if (text.val() != initialText[idx]) {
window.onbeforeunload = ShowWarning;
return;
}
window.onbeforeunload = null;
}
});
}
}
DomContentLoaded.addEvent(function () {
$WH.array_apply($WH.gE(document, 'dfn'), function(x){
var text = x.title;
x.title = '';
x.className += ' tip';
if (text.indexOf('LANG.') == 0) { // custom for less redundant texts
text = eval(text);
}
g_addTooltip(x, text, 'q');
});
// if i understand this right, this code binds an onCopy eventHandler to every child node of class="text"-nodes with the attribute unselectable="on"
// causing the text to disappear for 1ms, causing the empty node to be copied ... w/e, i'm not going to use this
/*
$('.text').bind('copy', function() {
$('*[unselectable]', this).each(function(i, v) {
var txt = $(v).text();
$(v).text('');
setTimeout(function() { $(v).text(txt) }, 1);
});
});
*/
});
function SetupReplies(post, comment)
{
SetupAddEditComment(post, comment, false);
SetupShowMoreComments(post, comment);
post.find('.comment-reply-row').each(function () { SetupRepliesControls($(this), comment); });
post.find('.comment-reply-row').hover(function () { $(this).find('span').attr('data-hover', 'true'); }, function () { $(this).find('span').attr('data-hover', 'false'); });
}
function SetupAddEditComment(post, comment, edit)
{
/* Variables that will be set by Initialize() */
var Form = null;
var Body = null;
var AddButton = null;
var TextCounter = null;
var AjaxLoader = null;
var FormContainer = null;
var DialogTableRowContainer = null;
/* Constants */
var MIN_LENGTH = 15;
var MAX_LENGTH = 600;
/* State keeping booleans */
var Initialized = false;
var Active = false;
var Flashing = false;
var Submitting = false;
/* Shortcuts */
var CommentsTable = post.find('.comment-replies > table');
var AddCommentLink = post.find('.add-reply');
var CommentsCount = comment.replies.length;
if(edit)
Open();
else
AddCommentLink.click(function () { Open(); });
function Initialize()
{
if (Initialized)
return;
Initialized = true;
var row = $('
');
if(edit)
row.addClass('comment-reply-row').addClass('reply-edit-row');
row.html(' | ' +
'