// 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_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_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(); // sarjuuk: 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}]; 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') }]; 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, // sarjuuk: edited for unsupported subdomains # linkBefore + locale.domain + linkAfter null, // more custom {rel: location.href + " domain=" + locale.domain} // also custom ]; 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); // custom start (note: html5 supports placeholder attribute) var inp = $WH.ge('livesearch-generic'); if (inp.value == '') { inp.className = 'search-database'; } inp.onmouseover = function() { if ($WH.trim(this.value) != '') { this.className = ''; } }; inp.onfocus = function() { this.className = ''; }; inp.onblur = function() { if ($WH.trim(this.value) == '') { this.className = 'search-database'; this.value = ''; } }; // 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'; } element.onmouseover = function(d) { $WH.Tooltip.showAtCursor(d, text, 0, 0, className); }; element.onmousemove = $WH.Tooltip.cursorUpdate; element.onmouseout = $WH.Tooltip.hide; } 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'; } 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; } // sarjuuk: 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 + ''; } // sarjuuk: 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 ($.browser.msie) { 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('' + ''); /* Set up the various variables for the controls we just created */ Body = row.find('.comment-form textarea'); AddButton = row.find('.comment-form input[type=submit]'); TextCounter = row.find('.comment-form span.text-counter'); Form = row.find('.comment-form form'); AjaxLoader = row.find('.comment-form .ajax-loader'); FormContainer = row.find('.comment-form'); /* Intercept submits */ Form.submit(function () { Submit(); return false; }); UpdateTextCounter(); /* This is kinda a mess.. Every browser seems to implement keyup, keydown and keypress differently. * - keyup: We need to use keyup to update the text counter for the simple reason we want to update it only when the user stops typing. * - keydown: We need to use keydown to detect the ESC key because it's the only one that works in all browsers for ESC * - keypress: We need to use keypress to detect Enter because it's the only one that 1) Works 2) Allows us to prevent a new line from being entered in the textarea * I find it very funny that in each scenario there is only one of the 3 that works, and that that one is always different from the others. */ Body.keyup(function (e) { UpdateTextCounter(); }); Body.keydown(function (e) { if (e.keyCode == 27) { Close(); return false; } }); // ESC Body.keypress(function (e) { if (e.keyCode == 13) { Submit(); return false; } }); // ENTER if(edit) { post.after(row); post.hide(); Form.find('textarea').text(comment.replies[post.attr('data-idx')].body); } else CommentsTable.append(row); DialogTableRowContainer = row; Form.find('textarea').focus(); } function Open() { if (!Initialized) Initialize(); Active = true; if(!edit) { AddCommentLink.hide(); post.find('.comment-replies').show(); FormContainer.show(); FormContainer.find('textarea').focus(); } } function Close() { Active = false; if(edit) { if(DialogTableRowContainer) DialogTableRowContainer.remove(); post.show(); return; } AddCommentLink.show(); FormContainer.hide(); if (CommentsCount == 0) post.find('.comment-replies').hide(); } function Submit() { if (!Active || Submitting) return; if (Body.val().length < MIN_LENGTH || Body.val().length > MAX_LENGTH) { /* Flash the char counter to attract the attention of the user. */ if (!Flashing) { Flashing = true; TextCounter.animate({ opacity: '0.0' }, 150); TextCounter.animate({ opacity: '1.0' }, 150, null, function() { Flashing = false; }); } return false; } SetSubmitState(); $.ajax({ type: 'POST', url: edit ? '?comment=edit-reply' : '?comment=add-reply', data: { commentId: comment.id, replyId: (edit ? post.attr('data-replyid') : 0), body: Body.val() }, success: function (newReplies) { OnSubmitSuccess(newReplies); }, dataType: 'json', error: function (jqXHR) { OnSubmitFailure(jqXHR.responseText); } }); return true; } function SetSubmitState() { Submitting = true; AjaxLoader.show(); AddButton.attr('disabled', 'disabled'); FormContainer.find('.message-box').remove(); } function ClearSubmitState() { Submitting = false; AjaxLoader.hide(); AddButton.removeAttr('disabled'); } function OnSubmitSuccess(newReplies) { comment.replies = newReplies; Listview.templates.comment.updateReplies(comment); } function OnSubmitFailure(error) { ClearSubmitState(); MessageBox(FormContainer, error); } function UpdateTextCounter() { var text = '(error)'; var cssClass = 'q0'; var chars = Body.val().replace(/(\s+)/g, ' ').replace(/^\s*/, '').replace(/\s*$/, '').length; var charsLeft = MAX_LENGTH - chars; if (chars == 0) text = $WH.sprintf(LANG.replylength1_format, MIN_LENGTH); else if (chars < MIN_LENGTH) text = $WH.sprintf(LANG.replylength2_format, MIN_LENGTH - chars); else { text = $WH.sprintf(charsLeft == 1 ? LANG.replylength4_format : LANG.replylength3_format, charsLeft); if (charsLeft < 120) cssClass = 'q10'; else if (charsLeft < 240) cssClass = 'q5'; else if (charsLeft < 360) cssClass = 'q11'; } TextCounter.html(text).attr('class', cssClass); } } function SetupShowMoreComments(post, comment) { var ShowMoreCommentsLink = post.find('.show-more-replies'); var CommentCell = post.find('.comment-replies'); ShowMoreCommentsLink.click(function () { ShowMoreComments(); }); function ShowMoreComments() { /* Replace link with ajax loader */ ShowMoreCommentsLink.hide(); CommentCell.append(CreateAjaxLoader()); $.ajax({ type: 'GET', url: '?comment=show-replies', data: { id: comment.id }, success: function (replies) { comment.replies = replies; Listview.templates.comment.updateReplies(comment); }, dataType: 'json', error: function () { OnFetchFail(); } }); } function OnFetchFail() { ShowMoreCommentsLink.show(); CommentCell.find('.ajax-loader').remove(); MessageBox(CommentCell, "There was an error fetching the comments. Try refreshing the page."); } } function SetupRepliesControls(post, comment) { var CommentId = post.attr('data-replyid'); var VoteUpControl = post.find('.reply-upvote'); var VoteDownControl = post.find('.reply-downvote'); var FlagControl = post.find('.reply-report'); var CommentScoreText = post.find('.reply-rating'); var CommentActions = post.find('.reply-controls'); var DetachButton = post.find('.reply-detach'); var DeleteButton = post.find('.reply-delete'); var EditButton = post.find('.reply-edit'); var Container = comment.repliesCell; var Voting = false; var Detaching = false; var Deleting = false; EditButton.click(function() { SetupAddEditComment(post, comment, true); }); FlagControl.click(function () { if (Voting || !confirm(LANG.replyreportwarning_tip)) return; Voting = true; $.ajax({ type: 'POST', url: '?comment=flag-reply', data: { id: CommentId }, success: function () { OnFlagSuccessful(); }, error: function (jqXHR) { OnError(jqXHR.responseText); } }); }); VoteUpControl.click(function () { if (VoteUpControl.attr('data-hasvoted') == 'true' || VoteUpControl.attr('data-canvote') != 'true' || Voting) return; Voting = true; $.ajax({ type: 'POST', url: '?comment=upvote-reply', data: { id: CommentId }, success: function () { OnVoteSuccessful(1); }, error: function (jqXHR) { OnError(jqXHR.responseText); } }); }); VoteDownControl.click(function () { if (VoteDownControl.attr('data-hasvoted') == 'true' || VoteDownControl.attr('data-canvote') != 'true' || Voting) return; Voting = true; $.ajax({ type: 'POST', url: '?comment=downvote-reply', data: { id: CommentId }, success: function () { OnVoteSuccessful(-1); }, error: function (jqXHR) { OnError(jqXHR.responseText); } }); }); DetachButton.click(function () { if (Detaching) { MessageBox(CommentActions, LANG.message_cantdetachcomment); return; } if (!confirm(LANG.confirm_detachcomment)) { return; } Detaching = true; $.ajax({ type: 'POST', url: '?comment=detach-reply', data: { id: CommentId }, success: function () { OnDetachSuccessful(); }, error: function (jqXHR) { OnError(jqXHR.responseText); } }); }); DeleteButton.click(function () { if (Deleting) return; if (!confirm(LANG.deletereplyconfirmation_tip)) return; Deleting = true; $.ajax({ type: 'POST', url: '?comment=delete-reply', data: { id: CommentId }, success: function () { OnDeleteSuccessful(); }, error: function (jqXHR) { OnError(jqXHR.responseText); } }); }); function OnVoteSuccessful(ratingChange) { var rating = parseInt(CommentScoreText.text()); rating += ratingChange; CommentScoreText.text(rating); if(ratingChange > 0) VoteUpControl.attr('data-hasvoted', 'true'); else VoteDownControl.attr('data-hasvoted', 'true'); VoteUpControl.attr('data-canvote', 'false'); VoteDownControl.attr('data-canvote', 'false'); if(ratingChange > 0) FlagControl.remove(); Voting = false; } function OnFlagSuccessful() { Voting = false; FlagControl.remove(); } function OnDetachSuccessful() { post.remove(); MessageBox(Container, LANG.message_commentdetached); Detaching = false; } function OnDeleteSuccessful() { post.remove(); Deleting = false; } function OnError(text) { Voting = false; Detaching = false; Deleting = false; if (!text) text = LANG.genericerror; MessageBox(CommentActions, text); } } /* Global comment-related functions */ function co_addYourComment() { tabsContribute.focus(0); var ta = $WH.gE(document.forms['addcomment'], 'textarea')[0]; ta.focus(); } function co_validateForm(f) { var ta = $WH.gE(f, 'textarea')[0]; if (g_user.permissions & 1) { return true; } if (Listview.funcBox.coValidate(ta)) { return true; } return false; } /* Global screenshot-related functions */ function ss_submitAScreenshot() { tabsContribute.focus(1); } function ss_validateForm(f) { if (!f.elements.screenshotfile.value.length) { alert(LANG.message_noscreenshot); return false; } return true; } function ss_appendSticky() { var _ = $WH.ge('infobox-sticky-ss'); var type = g_pageInfo.type; var typeId = g_pageInfo.typeId; var pos = $WH.in_array(lv_screenshots, 1, function(x) { return x.sticky; }); if (pos != -1) { var screenshot = lv_screenshots[pos]; var a = $WH.ce('a'); a.href = '#screenshots:id=' + screenshot.id; a.onclick = function(a) { ScreenshotViewer.show({ screenshots: lv_screenshots, pos: pos }); return $WH.rf2(a); }; var size = (lv_videos && lv_videos.length ? [120, 90] : [150, 150]); var img = $WH.ce('img'), scale = Math.min(size[0] / screenshot.width, size[1] / screenshot.height); img.src = g_staticUrl + '/uploads/screenshots/thumb/' + screenshot.id + '.jpg'; img.width = Math.round(scale * screenshot.width); img.height = Math.round(scale * screenshot.height); img.className = 'border'; $WH.ae(a, img); $WH.ae(_, a); var th = $WH.ge('infobox-screenshots'); var a = $WH.ce('a'); if (!th) { var sections = $('th', _.parentNode); th = sections[sections.length - (lv_videos && lv_videos.length ? 2 : 1)]; } $WH.ae(a, $WH.ct(th.innerText + ' (' + lv_screenshots.length + ')')); a.href = '#screenshots' a.title = $WH.sprintf(LANG.infobox_showall, lv_screenshots.length); a.onclick = function() { tabsRelated.focus((lv_videos && lv_videos.length) || (g_user && g_user.roles & (U_GROUP_ADMIN | U_GROUP_BUREAU | U_GROUP_VIDEO)) ? -2 : -1); return false; }; $WH.ee(th); $WH.ae(th, a); } else { var a; if (g_user.id > 0) { a = ''; } else { a = ''; } _.innerHTML = $WH.sprintf(LANG.infobox_noneyet, a + LANG.infobox_submitone + '') } } var g_screenshots = {}; var ScreenshotViewer = new function() { var screenshots, pos, imgWidth, imgHeight, scale, desiredScale, oldHash, mode = 0, collectionId, container, screen, imgDiv, aPrev, aNext, aCover, aOriginal, divFrom, divCaption, loadingImage, lightboxComponents; function computeDimensions(captionExtraHeight) { var screenshot = screenshots[pos]; var availHeight = Math.max(50, Math.min(618, $WH.g_getWindowSize().h - 72 - captionExtraHeight)); if (mode != 1 || screenshot.id || screenshot.resize) { desiredScale = Math.min(772 / screenshot.width, 618 / screenshot.height); scale = Math.min(772 / screenshot.width, availHeight / screenshot.height); } else { desiredScale = scale = 1; } if (desiredScale > 1) { desiredScale = 1; } if (scale > 1) { scale = 1; } imgWidth = Math.round(scale * screenshot.width); imgHeight = Math.round(scale * screenshot.height); var lbWidth = Math.max(480, imgWidth); Lightbox.setSize(lbWidth + 20, imgHeight + 52 + captionExtraHeight); if ($WH.Browser.ie6) { screen.style.width = lbWidth + 'px'; if (screenshots.length > 1) { aPrev.style.height = aNext.style.height = imgHeight + 'px' } else { aCover.style.height = imgHeight + 'px' } } if (captionExtraHeight) { imgDiv.firstChild.width = imgWidth; imgDiv.firstChild.height = imgHeight; } } function getPound(pos) { var screenshot = screenshots[pos], buff = '#screenshots:'; if (mode == 0) { buff += 'id=' + screenshot.id; } else { buff += collectionId + ':' + (pos + 1); } return buff; } function render(resizing) { if (resizing && (scale == desiredScale) && $WH.g_getWindowSize().h > container.offsetHeight) { return; } container.style.visibility = 'hidden'; var screenshot = screenshots[pos], resized = (screenshot.width > 772 || screenshot.height > 618); computeDimensions(0); var url = (screenshot.url ? screenshot.url: g_staticUrl + '/uploads/screenshots/' + (resized ? 'resized/': 'normal/') + screenshot.id + '.jpg'); var html = ' 1); if (hasFrom1) { var postedOn = new Date(screenshot.date), elapsed = (g_serverTime - postedOn) / 1000; var a = divFrom.firstChild.childNodes[1]; a.href = '?user=' + screenshot.user; a.innerHTML = screenshot.user; var s = divFrom.firstChild.childNodes[3]; $WH.ee(s); g_formatDate(s, elapsed, postedOn); divFrom.firstChild.style.display = ''; } else { divFrom.firstChild.style.display = 'none'; } var s = divFrom.childNodes[1]; $WH.ee(s); if (screenshot.user) { if (hasFrom1) { $WH.ae(s, $WH.ct(' ' + LANG.dash + ' ')); } var a = $WH.ce('a'); a.href = 'javascript:;'; a.onclick = ContactTool.show.bind(ContactTool, { mode: 3, screenshot: screenshot }); a.className = 'icon-report' g_addTooltip(a, LANG.report_tooltip, 'q2'); $WH.ae(a, $WH.ct(LANG.report)); $WH.ae(s, a); } s = divFrom.childNodes[2]; if (hasFrom2) { var buff = ''; if (screenshot.user) { buff = LANG.dash; } buff += (pos + 1) + LANG.lvpage_of + screenshots.length; s.innerHTML = buff; s.style.display = ''; } else { s.style.display = 'none'; } divFrom.style.display = (hasFrom1 || hasFrom2 ? '': 'none'); var hasCaption = (screenshot.caption != null && screenshot.caption.length); var hasSubject = (screenshot.subject != null && screenshot.subject.length && screenshot.type && screenshot.typeId); if (hasCaption || hasSubject) { var html = ''; if (hasSubject) { html += LANG.types[screenshot.type][0] + LANG.colon; html += ''; html += screenshot.subject; html += ''; } if (hasCaption) { if (hasSubject) { html += LANG.dash; } html += (screenshot.noMarkup ? screenshot.caption : Markup.toHtml(screenshot.caption, { mode: Markup.MODE_SIGNATURE })); } divCaption.innerHTML = html; divCaption.style.display = ''; } else { divCaption.style.display = 'none'; } if (screenshots.length > 1) { aPrev.href = getPound(peekPos(-1)); aNext.href = getPound(peekPos(1)); aPrev.style.display = aNext.style.display = ''; aCover.style.display = 'none'; } else { aPrev.style.display = aNext.style.display = 'none'; aCover.style.display = ''; } location.replace(getPound(pos)); } Lightbox.reveal(); if (divCaption.offsetHeight > 18) { computeDimensions(divCaption.offsetHeight - 18); } container.style.visibility = 'visible'; } function peekPos(change) { var foo = pos; foo += change; if (foo < 0) { foo = screenshots.length - 1; } else if (foo >= screenshots.length) { foo = 0; } return foo; } function prevScreenshot() { pos = peekPos(-1); onRender(); return false; } function nextScreenshot() { pos = peekPos(1); onRender(); return false; } function onKeyUp(e) { e = $WH.$E(e); switch (e.keyCode) { case 37: // Left prevScreenshot(); break; case 39: // Right nextScreenshot(); break; } } function onResize() { render(1); } function onHide() { cancelImageLoading(); if (screenshots.length > 1) { $WH.dE(document, 'keyup', onKeyUp); } if (oldHash && mode == 0) { if (oldHash.indexOf(':id=') != -1) { oldHash = '#screenshots'; } location.replace(oldHash); } else { location.replace('#.'); } } function onShow(dest, first, opt) { if (typeof opt.screenshots == 'string') { screenshots = g_screenshots[opt.screenshots]; mode = 1; collectionId = opt.screenshots; } else { screenshots = opt.screenshots; mode = 0; collectionId = null; } container = dest; pos = 0; if (opt.pos && opt.pos >= 0 && opt.pos < screenshots.length) { pos = opt.pos; } if (first) { dest.className = 'screenshotviewer'; screen = $WH.ce('div'); screen.className = 'screenshotviewer-screen'; aPrev = $WH.ce('a'); aNext = $WH.ce('a'); aPrev.className = 'screenshotviewer-prev'; aNext.className = 'screenshotviewer-next'; aPrev.href = 'javascript:;'; aNext.href = 'javascript:;'; var foo = $WH.ce('span'); $WH.ae(foo, $WH.ce('b')); // var b = $WH.ce('b'); // $WH.ae(b, $WH.ct(LANG.previous)); // $WH.ae(foo, b); $WH.ae(aPrev, foo); var foo = $WH.ce('span'); $WH.ae(foo, $WH.ce('b')); // var b = $WH.ce('b'); // $WH.ae(b, $WH.ct(LANG.next)); // $WH.ae(foo, b); $WH.ae(aNext, foo); aPrev.onclick = prevScreenshot; aNext.onclick = nextScreenshot; aCover = $WH.ce('a'); aCover.className = 'screenshotviewer-cover'; aCover.href = 'javascript:;'; aCover.onclick = Lightbox.hide; var foo = $WH.ce('span'); $WH.ae(foo, $WH.ce('b')); // var b = $WH.ce('b'); // $WH.ae(b, $WH.ct(LANG.close)); // $WH.ae(foo, b); $WH.ae(aCover, foo); if ($WH.Browser.ie6) { $WH.ns(aPrev); $WH.ns(aNext); aPrev.onmouseover = aNext.onmouseover = aCover.onmouseover = function() { this.firstChild.style.display = 'block'; }; aPrev.onmouseout = aNext.onmouseout = aCover.onmouseout = function() { this.firstChild.style.display = ''; }; } $WH.ae(screen, aPrev); $WH.ae(screen, aNext); $WH.ae(screen, aCover); imgDiv = $WH.ce('div'); $WH.ae(screen, imgDiv); $WH.ae(dest, screen); var aClose = $WH.ce('a'); aClose.className = 'screenshotviewer-close'; // aClose.className = 'dialog-x'; aClose.href = 'javascript:;'; aClose.onclick = Lightbox.hide; $WH.ae(aClose, $WH.ce('span')); // $WH.ae(aClose, $WH.ct(LANG.close)); $WH.ae(dest, aClose); aOriginal = $WH.ce('a'); aOriginal.className = 'screenshotviewer-original'; // aOriginal.className = 'dialog-arrow'; aOriginal.href = 'javascript:;'; aOriginal.target = '_blank'; $WH.ae(aOriginal, $WH.ce('span')); // $WH.ae(aOriginal, $WH.ct(LANG.original)); $WH.ae(dest, aOriginal); divFrom = $WH.ce('div'); divFrom.className = 'screenshotviewer-from'; var sp = $WH.ce('span'); $WH.ae(sp, $WH.ct(LANG.lvscreenshot_from)); $WH.ae(sp, $WH.ce('a')); $WH.ae(sp, $WH.ct(' ')); $WH.ae(sp, $WH.ce('span')); $WH.ae(divFrom, sp); $WH.ae(divFrom, $WH.ce('span')); $WH.ae(divFrom, $WH.ce('span')); $WH.ae(dest, divFrom); divCaption = $WH.ce('div'); divCaption.className = 'screenshotviewer-caption'; $WH.ae(dest, divCaption); var d = $WH.ce('div'); d.className = 'clear'; $WH.ae(dest, d); } oldHash = location.hash; if (screenshots.length > 1) { $WH.aE(document, 'keyup', onKeyUp); } onRender(); } function onRender() { var screenshot = screenshots[pos]; if (!screenshot.width || !screenshot.height) { if (loadingImage) { loadingImage.onload = null; loadingImage.onerror = null; } else { container.className = ''; lightboxComponents = []; while (container.firstChild) { lightboxComponents.push(container.firstChild); $WH.de(container.firstChild); } } var lightboxTimer = setTimeout(function() { screenshot.width = 126; screenshot.height = 22; computeDimensions(0); screenshot.width = null; screenshot.height = null; var div = $WH.ce('div'); div.style.margin = '0 auto'; div.style.width = '126px'; var img = $WH.ce('img'); img.src = g_staticUrl + '/images/ui/misc/progress-anim.gif'; img.width = 126; img.height = 22; $WH.ae(div, img); $WH.ae(container, div); Lightbox.reveal(); container.style.visiblity = 'visible'; }, 150); loadingImage = new Image(); loadingImage.onload = (function(screen, timer) { clearTimeout(timer); screen.width = this.width; screen.height = this.height; loadingImage = null; restoreLightbox(); render(); }).bind(loadingImage, screenshot, lightboxTimer); loadingImage.onerror = (function(timer) { clearTimeout(timer); loadingImage = null; Lightbox.hide(); restoreLightbox(); }).bind(loadingImage, lightboxTimer); loadingImage.src = (screenshot.url ? screenshot.url : g_staticUrl + '/uploads/screenshots/normal/' + screenshot.id + '.jpg'); } else { render(); } } function cancelImageLoading() { if (!loadingImage) { return; } loadingImage.onload = null; loadingImage.onerror = null; loadingImage = null; restoreLightbox(); } function restoreLightbox() { if (!lightboxComponents) { return; } $WH.ee(container); container.className = 'screenshotviewer'; for (var i = 0; i < lightboxComponents.length; ++i) $WH.ae(container, lightboxComponents[i]); lightboxComponents = null; } this.checkPound = function() { if (location.hash && location.hash.indexOf('#screenshots') == 0) { if (!g_listviews['screenshots']) { // Standalone screenshot viewer var parts = location.hash.split(':'); if (parts.length == 3) { var collection = g_screenshots[parts[1]], p = parseInt(parts[2]); if (collection && p >= 1 && p <= collection.length) { ScreenshotViewer.show({ screenshots: parts[1], pos: p - 1 }); } } } } } this.show = function(opt) { Lightbox.show('screenshotviewer', { onShow: onShow, onHide: onHide, onResize: onResize }, opt); } DomContentLoaded.addEvent(this.checkPound) }; /* Global video-related functions */ var vi_thumbnails = { 1: 'http://i3.ytimg.com/vi/$1/default.jpg' // YouTube }; var vi_siteurls = { 1: 'http://www.youtube.com/watch?v=$1' // YouTube }; var vi_sitevalidation = { 1: /^http:\/\/www\.youtube\.com\/watch\?v=([^& ]{11})/ // YouTube }; function vi_submitAVideo() { tabsContribute.focus(2); } function vi_validateForm(f) { if (!f.elements['videourl'].value.length) { alert(LANG.message_novideo); return false; } var urlmatch = false; for (var i in vi_sitevalidation) { if (f.elements['videourl'].value.match(vi_sitevalidation[i])) { urlmatch = true; break; } } if (!urlmatch) { alert(LANG.message_novideo); return false; } return true; } function vi_appendSticky() { var _ = $WH.ge('infobox-sticky-vi'); var type = g_pageInfo.type; var typeId = g_pageInfo.typeId; var pos = $WH.in_array(lv_videos, 1, function(x) { return x.sticky; }); if (pos != -1) { var video = lv_videos[pos]; var a = $WH.ce('a'); a.href = '#videos:id=' + video.id; a.onclick = function(e) { VideoViewer.show({ videos: lv_videos, pos: pos }); return $WH.rf2(e); }; var img = $WH.ce('img'); img.src = $WH.sprintf(vi_thumbnails[video.videoType], video.videoId); img.className = 'border'; $WH.ae(a, img); $WH.ae(_, a); var th = $WH.ge('infobox-videos'); var a = $WH.ce('a'); if (!th) { var sections = $('th', _.parentNode); th = sections[sections.length - (lv_videos && lv_videos.length ? 2 : 1)]; } $WH.ae(a, $WH.ct(th.innerText + ' (' + lv_videos.length + ')')); a.href = '#videos' a.title = $WH.sprintf(LANG.infobox_showall, lv_videos.length); a.onclick = function() { tabsRelated.focus(-1); return false; }; $WH.ee(th); $WH.ae(th, a); } else { var a; if (g_user.id > 0) { a = '' } else { a = '' } _.innerHTML = $WH.sprintf(LANG.infobox_noneyet, a + LANG.infobox_suggestone + '') } } var g_videos = []; var VideoViewer = new function() { var videos, pos, imgWidth, imgHeight, scale, oldHash, mode = 0, collectionId, pageTitle, // IE flash embed fix container, screen, imgDiv, aPrev, aNext, aCover, aOriginal, divFrom, divCaption; function computeDimensions() { var video = videos[pos]; var captionExtraHeight = Math.max(divCaption.offsetHeight - 18, 0), availHeight = Math.max(50, Math.min(520, $WH.g_getWindowSize().h - 72 - captionExtraHeight)), scale = Math.min(1, availHeight / 520); imgWidth = Math.round(scale * 880); imgHeight = Math.round(scale * 520); aPrev.style.height = aNext.style.height = aCover.style.height = (imgHeight - 95) + 'px'; Lightbox.setSize(Math.max(480, imgWidth) + 20, imgHeight + 52 + captionExtraHeight); } function getPound(pos) { var video = videos[pos], buff = '#videos:'; if (mode == 0) { buff += 'id=' + video.id; } else { buff += collectionId + ':' + (pos + 1); } return buff; } function render(resizing) { if (resizing && (scale == 1) && $WH.g_getWindowSize().h > container.offsetHeight) { return; } container.style.visibility = 'hidden'; var video = videos[pos]; computeDimensions(); if (!resizing) { if (video.videoType == 1) { imgDiv.innerHTML = Markup.toHtml('[youtube=' + video.videoId + ' width=' + imgWidth + ' height=' + imgHeight + ' autoplay=true]', {mode:Markup.MODE_ARTICLE}); } aOriginal.href = $WH.sprintf(vi_siteurls[video.videoType], video.videoId); if (!video.user && typeof g_pageInfo == 'object') { video.user = g_pageInfo.username; } var hasFrom1 = (video.date && video.user), hasFrom2 = (videos.length > 1); if (hasFrom1) { var postedOn = new Date(video.date), elapsed = (g_serverTime - postedOn) / 1000; var a = divFrom.firstChild.childNodes[1]; a.href = '?user=' + video.user; a.innerHTML = video.user; var s = divFrom.firstChild.childNodes[3]; $WH.ee(s); g_formatDate(s, elapsed, postedOn); divFrom.firstChild.style.display = ''; } else { divFrom.firstChild.style.display = 'none'; } var s = divFrom.childNodes[1]; $WH.ee(s); if (video.user) { if (hasFrom1) { $WH.ae(s, $WH.ct(' ' + LANG.dash + ' ')); } var a = $WH.ce('a'); a.href = 'javascript:;'; a.onclick = ContactTool.show.bind(ContactTool, { mode: 5, video: video }); a.className = 'icon-report'; g_addTooltip(a, LANG.report_tooltip, 'q2'); $WH.ae(a, $WH.ct(LANG.report)); $WH.ae(s, a); } s = divFrom.childNodes[2]; if (hasFrom2) { var buff = ''; if (video.user) { buff = LANG.dash; } buff += (pos + 1) + LANG.lvpage_of + videos.length; s.innerHTML = buff; s.style.display = ''; } else { s.style.display = 'none'; } divFrom.style.display = (hasFrom1 || hasFrom2 ? '': 'none'); var hasCaption = (video.caption != null && video.caption.length); var hasSubject = (video.subject != null && video.subject.length && video.type && video.typeId); if (hasCaption || hasSubject) { var html = ''; if (hasSubject) { html += LANG.types[video.type][0] + LANG.colon; html += ''; html += video.subject; html += ''; } if (hasCaption) { if (hasSubject) { html += LANG.dash; } html += (video.noMarkup ? video.caption: Markup.toHtml(video.caption, { mode: Markup.MODE_SIGNATURE })); } divCaption.innerHTML = html; divCaption.style.display = ''; } else { divCaption.style.display = 'none'; } if (videos.length > 1) { aPrev.href = getPound(peekPos(-1)); aNext.href = getPound(peekPos(1)); aPrev.style.display = aNext.style.display = ''; aCover.style.display = 'none'; } else { aPrev.style.display = aNext.style.display = 'none'; aCover.style.display = ''; } location.replace(getPound(pos)); } Lightbox.reveal(); container.style.visibility = 'visible'; setTimeout(fixTitle, 1); } function peekPos(change) { var foo = pos; foo += change; if (foo < 0) { foo = videos.length - 1; } else if (foo >= videos.length) { foo = 0; } return foo; } function prevVideo() { pos = peekPos(-1); render(); return false; } function nextVideo() { pos = peekPos(1); render(); return false; } function fixTitle() { if (pageTitle) { document.title = pageTitle; } } function onKeyUp(e) { e = $WH.$E(e); switch (e.keyCode) { case 37: // Left prevVideo(); break; case 39: // Right nextVideo(); break; } } function onResize() { render(1); } function onHide() { $WH.ee(imgDiv); if (videos.length > 1) { $WH.dE(document, 'keyup', onKeyUp) ; } if (oldHash && mode == 0) { if (oldHash.indexOf(':id=') != -1) { oldHash = '#videos'; } location.replace(oldHash); } else { location.replace('#.'); } fixTitle(); } function onShow(dest, first, opt) { if (typeof opt.videos == 'string') { videos = g_videos[opt.videos]; mode = 1; collectionId = opt.videos; } else { videos = opt.videos; mode = 0; collectionId = null; } container = dest; pos = 0; if (opt.pos && opt.pos >= 0 && opt.pos < videos.length) { pos = opt.pos; } if (first) { dest.className = 'screenshotviewer'; screen = $WH.ce('div'); screen.className = 'screenshotviewer-screen'; aPrev = $WH.ce('a'); aNext = $WH.ce('a'); aPrev.className = 'screenshotviewer-prev'; aNext.className = 'screenshotviewer-next'; aPrev.href = 'javascript:;'; aNext.href = 'javascript:;'; var foo = $WH.ce('span'); var b = $WH.ce('b'); // $WH.ae(b, $WH.ct(LANG.previous)); $WH.ae(foo, b); $WH.ae(aPrev, foo); var foo = $WH.ce('span'); var b = $WH.ce('b'); // $WH.ae(b, $WH.ct(LANG.next)); $WH.ae(foo, b); $WH.ae(aNext, foo); aPrev.onclick = prevVideo; aNext.onclick = nextVideo; aCover = $WH.ce('a'); aCover.className = 'screenshotviewer-cover'; aCover.href = 'javascript:;'; aCover.onclick = Lightbox.hide; var foo = $WH.ce('span'); var b = $WH.ce('b'); $WH.ae(b, $WH.ct(LANG.close)); $WH.ae(foo, b); $WH.ae(aCover, foo); $WH.ae(screen, aPrev); $WH.ae(screen, aNext); $WH.ae(screen, aCover); imgDiv = $WH.ce('div'); $WH.ae(screen, imgDiv); $WH.ae(dest, screen); var aClose = $WH.ce('a'); // aClose.className = 'dialog-x'; aClose.className = 'screenshotviewer-close'; aClose.href = 'javascript:;'; aClose.onclick = Lightbox.hide; // $WH.ae(aClose, $WH.ct(LANG.close)); $WH.ae(aClose, $WH.ce('span')); $WH.ae(dest, aClose); aOriginal = $WH.ce('a'); // aOriginal.className = 'dialog-arrow'; aOriginal.className = 'screenshotviewer-original'; aOriginal.href = 'javascript:;'; aOriginal.target = '_blank'; // $WH.ae(aOriginal, $WH.ct(LANG.original)); $WH.ae(aOriginal, $WH.ce('span')); $WH.ae(dest, aOriginal); divFrom = $WH.ce('div'); divFrom.className = 'screenshotviewer-from'; var sp = $WH.ce('span'); $WH.ae(sp, $WH.ct(LANG.lvscreenshot_from)); $WH.ae(sp, $WH.ce('a')); $WH.ae(sp, $WH.ct(' ')); $WH.ae(sp, $WH.ce('span')); $WH.ae(divFrom, sp); $WH.ae(divFrom, $WH.ce('span')); $WH.ae(divFrom, $WH.ce('span')); $WH.ae(dest, divFrom); divCaption = $WH.ce('div'); divCaption.className = 'screenshotviewer-caption'; $WH.ae(dest, divCaption); var d = $WH.ce('div'); d.className = 'clear'; $WH.ae(dest, d); } oldHash = location.hash; if (videos.length > 1) { $WH.aE(document, 'keyup', onKeyUp); } render(); } this.checkPound = function() { pageTitle = $WH.gE(document, 'title').innerHTML; if (location.hash && location.hash.indexOf('#videos') == 0) { if (!g_listviews['videos']) { // Standalone video viewer var parts = location.hash.split(':'); if (parts.length == 3) { var collection = g_videos[parts[1]], p = parseInt(parts[2]); if (collection && p >= 1 && p <= collection.length) { VideoViewer.show({ videos: parts[1], pos: p - 1 }); } } } } } this.show = function(opt) { Lightbox.show('videoviewer', { onShow: onShow, onHide: onHide, onResize: onResize },opt); return false; } DomContentLoaded.addEvent(this.checkPound) }; var Dialog = function() { var _self = this, _template, _onSubmit = null, _templateName, _funcs = {}, _data, _inited = false, _form = $WH.ce('form'), _elements = {}; _form.onsubmit = function() { _processForm(); return false }; this.show = function(template, opt) { if (template) { _templateName = template; _template = Dialog.templates[_templateName]; _self.template = _template; } else { return; } if (_template.onInit && !_inited) { (_template.onInit.bind(_self, _form, opt))(); } if (opt.onBeforeShow) { _funcs.onBeforeShow = opt.onBeforeShow.bind(_self, _form); } if (_template.onBeforeShow) { _template.onBeforeShow = _template.onBeforeShow.bind(_self, _form); } if (opt.onShow) { _funcs.onShow = opt.onShow.bind(_self, _form); } if (_template.onShow) { _template.onShow = _template.onShow.bind(_self, _form); } if (opt.onHide) { _funcs.onHide = opt.onHide.bind(_self, _form); } if (_template.onHide) { _template.onHide = _template.onHide.bind(_self, _form); } if (opt.onSubmit) { _funcs.onSubmit = opt.onSubmit; } if (_template.onSubmit) _onSubmit = _template.onSubmit.bind(_self, _form); if (opt.data) { _inited = false; _data = {}; $WH.cO(_data, opt.data); } _self.data = _data; Lightbox.show('dialog-' + _templateName, { onShow: _onShow, onHide: _onHide }); }; this.getValue = function(id) { return _getValue(id); }; this.setValue = function(id, value) { _setValue(id, value); }; this.getSelectedValue = function(id) { return _getSelectedValue(id); }; this.getCheckedValue = function(id) { return _getCheckedValue(id); }; function _onShow(dest, first) { if (first || !_inited) { _initForm(dest); } if (_template.onBeforeShow) { _template.onBeforeShow(); } if (_funcs.onBeforeShow) { _funcs.onBeforeShow(); } Lightbox.setSize(_template.width, _template.height); dest.className = 'dialog'; _updateForm(); if (_template.onShow) { _template.onShow(); } if (_funcs.onShow) { _funcs.onShow(); } } function _initForm(dest) { $WH.ee(dest); $WH.ee(_form); var container = $WH.ce('div'); container.className = 'text'; $WH.ae(dest, container); $WH.ae(container, _form); if (_template.title) { var h = $WH.ce('h1'); $WH.ae(h, $WH.ct(_template.title)); $WH.ae(_form, h); } var t = $WH.ce('table'), tb = $WH.ce('tbody'), mergeCell = false; $WH.ae(t, tb); $WH.ae(_form, t); for (var i = 0, len = _template.fields.length; i < len; ++i) { var field = _template.fields[i], element; if (!mergeCell) { tr = $WH.ce('tr'); th = $WH.ce('th'); td = $WH.ce('td'); } field.__tr = tr; if (_data[field.id] == null) { _data[field.id] = (field.value ? field.value: ''); } var options; if (field.options) { options = []; if (field.optorder) { $WH.cO(options, field.optorder); } else { for (var j in field.options) { options.push(j); } } if (field.sort) { options.sort(function(a, b) { return field.sort * $WH.strcmp(field.options[a], field.options[b]); }); } } switch (field.type) { case 'caption': th.colSpan = 2; th.style.textAlign = 'left'; th.style.padding = 0; if (field.compute) { (field.compute.bind(_self, null, _data[field.id], _form, th, tr))(); } else if (field.label) { $WH.ae(th, $WH.ct(field.label)); } $WH.ae(tr, th); $WH.ae(tb, tr); continue; break; case 'textarea': var f = element = $WH.ce('textarea'); f.name = field.id; if (field.disabled) { f.disabled = true; } f.rows = field.size[0]; f.cols = field.size[1]; td.colSpan = 2; if (field.label) { th.colSpan = 2; th.style.textAlign = 'left'; th.style.padding = 0; td.style.padding = 0; $WH.ae(th, $WH.ct(field.label)); $WH.ae(tr, th); $WH.ae(tb, tr); tr = $WH.ce('tr'); } $WH.ae(td, f); break; case 'select': var f = element = $WH.ce('select'); f.name = field.id; if (field.size) { f.size = field.size; } if (field.disabled) { f.disabled = true; } if (field.multiple) { f.multiple = true; } for (var j = 0, len2 = options.length; j < len2; ++j) { var o = $WH.ce('option'); o.value = options[j]; $WH.ae(o, $WH.ct(field.options[options[j]])); $WH.ae(f, o) } $WH.ae(td, f); break; case 'dynamic': td.colSpan = 2; td.style.textAlign = 'left'; td.style.padding = 0; if (field.compute) (field.compute.bind(_self, null, _data[field.id], _form, td, tr))(); $WH.ae(tr, td); $WH.ae(tb, tr); element = td; break; case 'checkbox': case 'radio': var k = 0; element = []; for (var j = 0, len2 = options.length; j < len2; ++j) { var s = $WH.ce('span'), f, l, uniqueId = 'sdfler46' + field.id + '-' + options[j]; if (j > 0 && !field.noInputBr) { $WH.ae(td, $WH.ce('br')); } if ($WH.Browser.ie6 && field.type == 'radio') { l = $WH.ce("
' + '' + '
' + '' + '' + '' + '
' + '' + '' + '' + '' + '
' + 'Text counter placeholder' + '
' + '
' + '