Mudanças entre as edições de "MediaWiki:Common.js"

De History Reborn Wiki
Ir para navegação Ir para pesquisar
(Criou página com '→‎Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki: // Este pedaço bugou o stylesheet // ~ Alphard /** var tocImgHid = stylepath + '/common/images/Arr_r.png'; var tocImgSho = stylepath + '/common/images/Arr_d.png'; function tocTree() { mw.util.addCSS('a.toctogHidden img, a.toctogShown img, a.toctogNull img {width:12px;height:12px;} #toc li a {padding-right:3px;} a.toctogNull img {visibility:hidden;}...')
 
Etiqueta: Revertido
Linha 1: Linha 1:
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
/* Any JavaScript here will be loaded for all users on every page load. */
// Este pedaço bugou o stylesheet
 
// ~ Alphard
if (typeof DP == 'undefined') DP = {};
 
if (typeof DP.Tooltips == 'undefined') DP.Tooltips = new function () { // Reminder: Keep in sync with the equivalent code in dp.js
    var URL_QUERY_BASE = 'http://{mode}.divine-pride.net/tooltip/';
    var URL_QUERY_BASE_DEBUG = 'http://localhost:4312/tooltip/';
 
    var TYPES = {
        item: {
            type: 'item',
            url: 'database/item/{key}'
        },
        monster: {
            type: 'monster',
            url: 'database/monster/{key}'
        },
        npc: {
            type: 'npc',
            url: 'database/npc/{key}'
        },
        skill: {
            type: 'skill',
            url: 'database/skill/{key}'
        },
        efst: {
            type: 'efst',
            url: 'database/efst/{key}'
        },
        title: {
            type: 'title',
            url: 'database/title/{key}'
        },
        achievement: {
            type: 'achievement',
            url: 'database/achievement/{key}'
        },
        map: {
            type: 'map',
            url: 'database/map/{key}'
        },
        quest: {
            type: 'quest',
            url: 'database/quest/{key}'
        }
    };
 
    var URL_PATTERN_BASE_DEBUG = new RegExp('^http://localhost:..../(.+)');
    var URL_PATTERN_BASE = new RegExp('^http://(.*)\\.divine-pride\\.net/(.+)');
    var URL_PATTERN_SELF = new RegExp('www\\.divine-pride\\.net/Scripts/tooltip\\.js'); // Used to get region from the <script> tag
    var URL_PATTERNS = [
{
    regex: new RegExp('^database/item/([0-9]+)/?.*$'),
    params: {
        type: 'item'
    }
},
{
    regex: new RegExp('^database/npc/([0-9]+)/?.*$'),
    params: {
        type: 'npc'
    }
},
{
    regex: new RegExp('^database/monster/([0-9]+)/?.*$'),
    params: {
        type: 'monster'
    }
},
{
    regex: new RegExp('^database/skill/([0-9]+)/?.*$'),
    params: {
        type: 'skill'
    }
},
{
    regex: new RegExp('^database/efst/([0-9]+)/?.*$'),
    params: {
        type: 'efst'
    }
},
{
    regex: new RegExp('^database/quest/([0-9]+)/?.*$'),
    params: {
        type: 'quest'
    }
},
{
    regex: new RegExp('^database/title/([0-9]+)/?.*$'),
    params: {
        type: 'title'
    }
},
{
    regex: new RegExp('^database/achievement/([0-9]+)/?.*$'),
    params: {
        type: 'achievement'
    }
},
{
    regex: new RegExp('^database/map/([a-zA-Z0-9\_]+)/?.*$'),
    params: {
        type: 'map'
    }
}
];
 
    var DELAY_LOADING = 500; // ms
    var dataCache = {};
 
    // State
    var loadingTimer;
    var currentLink;
    var currentParams;
 
    function construct() {
        $.documentReady(initialize);
    }
 
    function initialize() {
        setTimeout(getCss, 1);
        setTimeout(bindEvents, 1);
    }
 
    function getCss() {
 
        var scripts = document.getElementsByTagName('script');
        var currentScript = scripts[scripts.length - 1];
        var scriptRegion;
 
        if (currentScript && currentScript.src.match(URL_PATTERN_SELF)) {
            scriptRegion = RegExp.$1;
        }
 
        $.getStyle('https://www.novaragnarok.com/forum/dp.css');
    }
 
    function bindEvents() {
 
        $.bindEvent(document, 'mouseover', function (e) {
            e = $.normalizeEvent(e);
            if (e.target && e.target.nodeName.toUpperCase() == 'A') {
                linkMouseOver(e.target);
            }
        });
 
        $.bindEvent(document, 'mouseout', function (e) {
            e = $.normalizeEvent(e);
            if (e.target && e.target.nodeName.toUpperCase() == 'A') {
                linkMouseOut(e.target);
            }
        });
    }
 
    function linkMouseOver(link) {
 
        var params = {};
 
        if (!parseUrl(link, params))
        {
            parseUrlDebug(link, params);
        }
 
        if (!params.key || currentLink == link) {
            return;
        }
 
        currentLink = link;
        currentParams = params;
 
        var data = getTooltip(params);
        if (data != null) {
            showTooltip(data);
        }
    }
 
    function linkMouseOut(link) {
 
        if (link != currentLink) {
            return;
        }
 
        Tooltip.hide();
 
        currentLink = null;
        currentParams = null;
    }
 
    function parseUrl(link, params) {
        if (!link.href.match(URL_PATTERN_BASE)) {
            return false;
        }
        if (link.href.indexOf("#") !== -1) {
            return false;
        }
 
        var mode = RegExp.$1;
        var path = RegExp.$2;
        for (var i = 0; i < URL_PATTERNS.length; ++i) {
 
            var urlPattern = URL_PATTERNS[i];
            if (!path.match(urlPattern.regex)) {
                continue;
            }
 
            var key = RegExp.$1;
            if (key.indexOf('/') != -1) { // Folder and key shouldn't contain any slashes
                continue;
            }
 
            params.mode = mode;
            params.key = key;
 
            // Copy pattern's params
            for (var i in urlPattern.params) {
                params[i] = urlPattern.params[i];
            }
 
            params.tooltipType = getTooltipType(params.type);
            return true;
        }
 
        return false;
    }
 
    function parseUrlDebug(link, params) {
        var urlMatch = link.href.match(URL_PATTERN_BASE_DEBUG);
        if (!urlMatch) {
            return;
        }
        if (link.href.indexOf("#") !== -1) {
            return;
        }
 
        var path = urlMatch[1];
        for (var i = 0; i < URL_PATTERNS.length; ++i) {
 
            var urlPattern = URL_PATTERNS[i];
            var keyMatch = path.match(urlPattern.regex);
            if (!keyMatch) {
                continue;
            }
 
            var key = keyMatch[1];
            if (key.indexOf('/') != -1) { // Folder and key shouldn't contain any slashes
                continue;
            }
           
            params.mode = "www";
            params.key = key;
 
            // Copy pattern's params
            for (var i in urlPattern.params) {
                params[i] = urlPattern.params[i];
            }
 
            URL_QUERY_BASE = URL_QUERY_BASE_DEBUG;
            params.tooltipType = getTooltipType(params.type);
            return;
        }
    }
 
    function requestTooltip(params) {
        var url = (URL_QUERY_BASE + params.tooltipType.url)
.replace('{mode}', params.mode)
.replace('{key}', params.key)
.replace('{server}', params.server);
        $.getScript(url);
    }
 
    function registerData(data) {
        clearTimeout(loadingTimer);
 
        var params = data.params;
 
        saveData(params, data);
 
        if (currentParams != null && getCacheKeyFromParams(params) == getCacheKeyFromParams(currentParams)) {
            showTooltip(data);
        }
    }
 
    function getTooltip(params) {
 
        var data = loadData(params);
 
        if (data == null) { // Fetch data if not already cached
 
            clearTimeout(loadingTimer);
            loadingTimer = setTimeout(showLoading, DELAY_LOADING);
            requestTooltip(params);
            return null;
        }
 
        return data;
    }
 
    function showLoading() {
 
        if (currentLink != null) {
            Tooltip.show(currentLink, '<div class="dp-tooltip"><div class="loading"></div></div>');
        }
    }
 
    function showTooltip(data) {
 
        if (currentLink != null) {
            Tooltip.show(currentLink, data.tooltipHtml);
        }
    }
 
    // Utilities
    function getTooltipType(type) {
        return TYPES[type];
    }
 
    function saveData(params, data) {
        var cacheKey = getCacheKeyFromParams(params);
        dataCache[cacheKey] = data;
    }
 
    function loadData(params) {
 
        var cacheKey = getCacheKeyFromParams(params);
        return dataCache[cacheKey];
    }
 
    function getCacheKeyFromParams(params) {
        return [
params.region,
params.locale,
params.type,
params.key
].join('-');
    }
 
    // Public methods
    this.registerData = registerData;
 
 
 
    // HTML Helpers
    var $ = {
 
        create: function (nodeName) {
            return document.createElement(nodeName);
        },
 
        getScript: function (url) {
 
            var script = $.create('script');
            script.type = 'text/javascript';
            script.src = url;
 
            document.body.appendChild(script);
        },
 
        getStyle: function (url) {
 
            var link = $.create('link');
            link.rel = 'stylesheet';
            link.type = 'text/css';
            link.href = url;
 
            document.body.appendChild(link);
        },
 
        documentReady: function (callback) {
 
            if (document.readyState == 'complete') {
                callback();
                return;
            }
 
            var occurred = false;
 
            $.bindEvent(document, 'DOMContentLoaded', function () {
 
                if (!occurred) {
                    occurred = true;
                    callback();
                }
            });
 
            $.bindEvent(document, 'readystatechange', function () {
 
                if (document.readyState == 'complete' && !occurred) {
                    occurred = true;
                    callback();
                }
            });
 
        },
 
        bindEvent: function (node, eventType, callback) {
            if (node.addEventListener) {
                node.addEventListener(eventType, callback, true); // Must be true to work in Opera
            } else {
                node.attachEvent('on' + eventType, callback);
            }
        },
 
        normalizeEvent: function (e) {
            var ev = {};
            ev.target = (e.target ? e.target : e.srcElement);
            ev.which = (e.which ? e.which : e.button);
            return ev;
        },
 
        getWindowSize: function () {
 
            var w = 0;
            var h = 0;
 
            if (document.documentElement && document.documentElement.clientHeight) {
                w = document.documentElement.clientWidth;
                h = document.documentElement.clientHeight;
            } else if (document.body && document.body.clientHeight) {
                w = document.body.clientWidth;
                h = document.body.clientHeight;
            } else if (window.innerHeight) {
                w = window.innerWidth;
                h = window.innerHeight;
            }
 
            return {
                w: w,
                h: h
            };
        },
 
        getScrollPosition: function () {
 
            var x = 0;
            var y = 0;
 
            if (window.pageXOffset || window.pageYOffset) {
                x = window.pageXOffset;
                y = window.pageYOffset;
            } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
                x = document.body.scrollLeft;
                y = document.body.scrollTop;
            } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                x = document.documentElement.scrollLeft;
                y = document.documentElement.scrollTop;
            }
 
            return {
                x: x,
                y: y
            };
        },
 
        getOffset: function (node) {
 
            var x = 0;
            var y = 0;
 
            while (node) {
                x += node.offsetLeft;
                y += node.offsetTop;
 
                var p = node.parentNode;
 
                while (p && p != node.offsetParent && p.offsetParent) {
                    if (p.scrollLeft || p.scrollTop) {
                        x -= (p.scrollLeft | 0);
                        y -= (p.scrollTop | 0);
                        break;
                    }
                    p = p.parentNode;
                }
                node = node.offsetParent;
            }
 
            return {
                x: x,
                y: y
            };
        },
 
        getViewport: function () {
            var windowSize = $.getWindowSize();
            var scroll = $.getScrollPosition();
 
            return {
                l: scroll.x,
                t: scroll.y,
                r: scroll.x + windowSize.w,
                b: scroll.y + windowSize.h
            };
        }
    };
 
    $.Browser = {};
    $.Browser.ie = !!(window.attachEvent && !window.opera);
    $.Browser.ie6 = $.Browser.ie && navigator.userAgent.indexOf("MSIE 6.0") != -1;
 
 
 
    // Helper class that handles displaying tooltips
    var Tooltip = new function () {
 
        var PADDING = 5;
 
        var tooltipWrapper;
        var tooltipContent;


/**  var tocImgHid = stylepath + '/common/images/Arr_r.png';
        function initialize() {
  var tocImgSho = stylepath + '/common/images/Arr_d.png';
 
            tooltipWrapper = $.create('div');
            tooltipWrapper.className = 'dp-tooltip-wrapper';
 
            tooltipContent = $.create('div');
            tooltipContent.className = 'dp-tooltip-wrapper-inner';
 
            tooltipWrapper.appendChild(tooltipContent);
            document.body.appendChild(tooltipWrapper);
 
            hide();
        }
 
        function show(node, html) {
 
            if (tooltipWrapper == null) {
                initialize();
            }
 
            tooltipWrapper.style.visibility = 'hidden';
            tooltipWrapper.style.display = 'block';
            tooltipContent.innerHTML = html;
 
            var viewport = $.getViewport();
            var offset = $.getOffset(node);
 
            var x = offset.x + node.offsetWidth + PADDING;
            var y = offset.y - tooltipWrapper.offsetHeight - PADDING;
 
            if (y < viewport.t) {
                y = viewport.t;
            }
 
            if (x + tooltipWrapper.offsetWidth > viewport.r) {
                x = offset.x - tooltipWrapper.offsetWidth - PADDING;
            }
 
            reveal(x, y);
        }
 
        function hide() {
 
            if (tooltipWrapper == null) {
                return;
            }
 
            tooltipWrapper.style.display = 'none';
        }
 
        function reveal(x, y) {
 
            tooltipWrapper.style.left = x + 'px';
            tooltipWrapper.style.top = y + 'px';
 
            tooltipWrapper.style.visibility = 'visible';
        }
 
        // Public methods
        this.show = show;
        this.hide = hide;
 
    };
 
    construct();
 
};
 
function addCommasToNumber(nStr)
        {
            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }
 
 
 
// This function is used to automatically copy the Navi information to the user clipboard.
// The data parameters are received from the Template:NaviLink.
function copyNaviLink() {
    if ($('.naviText').length > 0) {
        $('.naviText').each(function () {
            var naviLink = $(this);
            var copiedMessage = naviLink.next();
 
            var map = naviLink.attr('data-map');
            var x = naviLink.attr('data-x');
            var y = naviLink.attr('data-y');
 
            naviLink.click({ map: map, x: x, y: y }, function () {
                // Context is used to keep the right 'this' reference, it's needed for setTimeOut to work properly.
                var context = $(this);
var copiedText = ["@navi", map, x, y].filter(Boolean).join(" ");
                // Temporary input used to select the text and copy, it's removed after the copy is done.
                var inputTemp = document.createElement("input");
                inputTemp.setAttribute("value", copiedText);
                document.body.appendChild(inputTemp);
                inputTemp.select();
                document.execCommand("copy");
                inputTemp.remove();
                // Switches the text to indicate that the navi was copied and timesout after 2 seconds getting back to normal.
                context.css("display", "none");
                context.next().css("display", "inline-block");
                setTimeout(function () {
                    context.css("display", "inline-block");
                    context.next().css("display", "none");
                }, 2000);
            }
            );
        });
    }
};
 
$(document).ready(function() {
    //novaMarketPrices();
    copyNaviLink();
})
 
// Credits to iRO Wiki for the table of contents
var tocImgHid = 'https://www.novaragnarok.com/wiki/images/a/ad/Arr_r.png';
var tocImgSho = 'https://www.novaragnarok.com/wiki/images/f/f0/Arr_d.png';


function tocTree() {
function tocTree() {
Linha 50: Linha 679:
     if(cul[j].parentNode == a.parentNode) cul[j].style.display = disp
     if(cul[j].parentNode == a.parentNode) cul[j].style.display = disp
   }
   }
} */
/**
* Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
*              [[Wikipedia:NavFrame]].
* Maintainers: [[User:R. Koot]]
*/
var autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
window.collapseTable = function ( tableIndex ) {
    var Button = document.getElementById( 'collapseButton' + tableIndex );
    var Table = document.getElementById( 'collapsibleTable' + tableIndex );
    if ( !Table || !Button ) {
        return false;
    }
    var Rows = Table.rows;
    var i;
    if ( Button.firstChild.data === collapseCaption ) {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = 'none';
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = Rows[0].style.display;
        }
        Button.firstChild.data = collapseCaption;
    }
};
function createCollapseButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
    var i;
    function handleButtonLink( index, e ) {
        window.collapseTable( index );
        e.preventDefault();
    }
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            if ( !HeaderRow ) continue;
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
            var Button    = document.createElement( 'span' );
            var ButtonLink = document.createElement( 'a' );
            var ButtonText = document.createTextNode( collapseCaption );
            Button.className = 'collapseButton';  /* Styles are declared in Common.css */
            ButtonLink.style.color = Header.style.color;
            ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );
            Button.appendChild( document.createTextNode( '[' ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( ']' ) );
            Header.insertBefore( Button, Header.firstChild );
            tableIndex++;
        }
    }
    for ( i = 0;  i < tableIndex; i++ ) {
        if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) {
            window.collapseTable( i );
        }
        else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) {
            var element = NavigationBoxes[i];
            while ((element = element.parentNode)) {
                if ( $( element ).hasClass( 'outercollapse' ) ) {
                    window.collapseTable ( i );
                    break;
                }
            }
        }
    }
}
$( createCollapseButtons );
/** Test if an element has a certain class **************************************
*
* Description: Uses regular expressions and caching for better performance.
* Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
*/
var hasClass = (function() {
    var reCache = {};
    return function( element, className ) {
        return ( reCache[className] ? reCache[className] : ( reCache[className] = new RegExp( "(?:\\s|^)" + className + "(?:\\s|$)" ) ) ).test( element.className );
    };
})();
/** Hideable notes  *********************************************************
* This is based off of code from Wikipedia's Common.js (http://en.wikipedia.org/wiki/MediaWiki:Common.js)
*/
function showNotes( spanIndex )
{
    var Button = document.getElementById( "showNoteLink" + spanIndex );
    var Span = document.getElementById( "showNotes" + spanIndex );
    if (!Span || !Button)
    {
        return false;
    }
    if (Button.firstChild.data == "[show]")
    {
        Span.style.display = "inline";
        Button.firstChild.data = " [hide]";
    }
    else
    {
        Span.style.display = "none";
        Button.firstChild.data = "[show]";
    }
}
function createShowNotesLinks()
{
    var spanIndex = 0;
    var Spans = document.getElementsByTagName( "span" );
    var CurrentSpan = new Object();
    for ( var i = 0; i < Spans.length; i++ )
    {
        if ( hasClass( Spans[i], "hiddenNotes" ) )
        {
            CurrentSpan = Spans[i];
            CurrentSpan.setAttribute( "id", "showNotes" + spanIndex );
            var Button    = document.createElement( "span" );
            var ButtonLink = document.createElement( "a" );
            var ButtonText = document.createTextNode( "[show]" );
            ButtonLink.setAttribute( "id", "showNoteLink" + spanIndex );
            ButtonLink.setAttribute( "href", "javascript:" );
            addHandler( ButtonLink,  "click", new Function( "evt", "showNotes(" + spanIndex + " ); return killEvt( evt );") );
            ButtonLink.appendChild( ButtonText );
            Button.appendChild(document.createTextNode( " " ));
            Button.appendChild(ButtonLink);
            CurrentSpan.parentNode.insertBefore( Button, CurrentSpan.nextSibling );
            CurrentSpan.style.display="none";
            spanIndex++;
        }
    }
}
$( createShowNotesLinks );
/* Any JavaScript here will be loaded for all users on every page load. */
/* Test if an element has a certain class **************************************
* Note: this is straight out of Wikipedia's Common.js (http://en.wikipedia.org/wiki/MediaWiki:Common.js)
*/
var hasClass = (function () {
    var reCache = {};
    return function (element, className) {
        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
    };
})();
// Navi Copy JQuery Code by Kaddy!
$('.navi-copy').each(function(index, element) {
if ($("#navi-copy-textarea").attr('exists') != "true") {
txtdiv = '<textarea style="height:1px;width:1px; position:absolute;left:-1000px;" id="navi-copy-textarea" exists="true">Filler Text</textarea><style>.navi-copy-text { cursor:pointer; color:#006400; padding:1px; display:inline-block; } .navi-copy-text:hover { color:#c1a1f1; } .navi-copied { text-align:center; border:1px dotted #2899e8; border-radius:3px; color:#006400; display:inline-block; } .navi-copy {  display:inline-block; } </style>';
$("body").append(txtdiv);
}
var map = $(element).children().get(0).innerHTML;
var x = $(element).children().get(1).innerHTML;
var y = $(element).children().get(2).innerHTML;
var newhtml = "<div class=\"navi-copy-text\" onclick=\"CopyNaviLink(this, '"+map+"','"+x+"','"+y+"');\">("+map+" "+x+", "+y+")</div><div class=\"navi-copied\" style=\"display:none;\">Copiado</div>";
$(element).html(newhtml);
});
function CopyNaviLink(ele, map, x, y) {
element = $(ele);
sibling = element.siblings();
width = element.width();
height = element.height()+0;
sibling.css('width',width);
sibling.css('height',height);
element.css('display','none');
sibling.css('display','inline-block');
setTimeout(function() {
    sibling.fadeOut().delay(300).css('display','none');
element.css('display','inline-block');
}, 1400);
var ClipBoardText = "/navi "+map+" "+x+"/"+y;
var textarea = document.getElementById('navi-copy-textarea');
$('#navi-copy-textarea').text(ClipBoardText);
$("#navi-copy-textarea").select();
document.execCommand('copy');
}
}

Edição das 21h47min de 15 de março de 2022

/* Any JavaScript here will be loaded for all users on every page load. */

if (typeof DP == 'undefined') DP = {};

if (typeof DP.Tooltips == 'undefined') DP.Tooltips = new function () { // Reminder: Keep in sync with the equivalent code in dp.js
    var URL_QUERY_BASE = 'http://{mode}.divine-pride.net/tooltip/';
    var URL_QUERY_BASE_DEBUG = 'http://localhost:4312/tooltip/';

    var TYPES = {
        item: {
            type: 'item',
            url: 'database/item/{key}'
        },
        monster: {
            type: 'monster',
            url: 'database/monster/{key}'
        },
        npc: {
            type: 'npc',
            url: 'database/npc/{key}'
        },
        skill: {
            type: 'skill',
            url: 'database/skill/{key}'
        },
        efst: {
            type: 'efst',
            url: 'database/efst/{key}'
        },
        title: {
            type: 'title',
            url: 'database/title/{key}'
        },
        achievement: {
            type: 'achievement',
            url: 'database/achievement/{key}'
        },
        map: {
            type: 'map',
            url: 'database/map/{key}'
        },
        quest: {
            type: 'quest',
            url: 'database/quest/{key}'
        }
    };

    var URL_PATTERN_BASE_DEBUG = new RegExp('^http://localhost:..../(.+)');
    var URL_PATTERN_BASE = new RegExp('^http://(.*)\\.divine-pride\\.net/(.+)');
    var URL_PATTERN_SELF = new RegExp('www\\.divine-pride\\.net/Scripts/tooltip\\.js'); // Used to get region from the <script> tag
    var URL_PATTERNS = [
		{
		    regex: new RegExp('^database/item/([0-9]+)/?.*$'),
		    params: {
		        type: 'item'
		    }
		},
		{
		    regex: new RegExp('^database/npc/([0-9]+)/?.*$'),
		    params: {
		        type: 'npc'
		    }
		},
		{
		    regex: new RegExp('^database/monster/([0-9]+)/?.*$'),
		    params: {
		        type: 'monster'
		    }
		},
		{
		    regex: new RegExp('^database/skill/([0-9]+)/?.*$'),
		    params: {
		        type: 'skill'
		    }
		},
		{
		    regex: new RegExp('^database/efst/([0-9]+)/?.*$'),
		    params: {
		        type: 'efst'
		    }
		},
		{
		    regex: new RegExp('^database/quest/([0-9]+)/?.*$'),
		    params: {
		        type: 'quest'
		    }
		},
		{
		    regex: new RegExp('^database/title/([0-9]+)/?.*$'),
		    params: {
		        type: 'title'
		    }
		},
		{
		    regex: new RegExp('^database/achievement/([0-9]+)/?.*$'),
		    params: {
		        type: 'achievement'
		    }
		},
		{
		    regex: new RegExp('^database/map/([a-zA-Z0-9\_]+)/?.*$'),
		    params: {
		        type: 'map'
		    }
		}
	];

    var DELAY_LOADING = 500; // ms
    var dataCache = {};

    // State
    var loadingTimer;
    var currentLink;
    var currentParams;

    function construct() {
        $.documentReady(initialize);
    }

    function initialize() {
        setTimeout(getCss, 1);
        setTimeout(bindEvents, 1);
    }

    function getCss() {

        var scripts = document.getElementsByTagName('script');
        var currentScript = scripts[scripts.length - 1];
        var scriptRegion;

        if (currentScript && currentScript.src.match(URL_PATTERN_SELF)) {
            scriptRegion = RegExp.$1;
        }

        $.getStyle('https://www.novaragnarok.com/forum/dp.css');
    }

    function bindEvents() {

        $.bindEvent(document, 'mouseover', function (e) {
            e = $.normalizeEvent(e);
            if (e.target && e.target.nodeName.toUpperCase() == 'A') {
                linkMouseOver(e.target);
            }
        });

        $.bindEvent(document, 'mouseout', function (e) {
            e = $.normalizeEvent(e);
            if (e.target && e.target.nodeName.toUpperCase() == 'A') {
                linkMouseOut(e.target);
            }
        });
    }

    function linkMouseOver(link) {

        var params = {};

        if (!parseUrl(link, params))
        {
            parseUrlDebug(link, params);
        }

        if (!params.key || currentLink == link) {
            return;
        }

        currentLink = link;
        currentParams = params;

        var data = getTooltip(params);
        if (data != null) {
            showTooltip(data);
        }
    }

    function linkMouseOut(link) {

        if (link != currentLink) {
            return;
        }

        Tooltip.hide();

        currentLink = null;
        currentParams = null;
    }

    function parseUrl(link, params) {
        if (!link.href.match(URL_PATTERN_BASE)) {
            return false;
        }
        if (link.href.indexOf("#") !== -1) {
            return false;
        }

        var mode = RegExp.$1;
        var path = RegExp.$2;
        for (var i = 0; i < URL_PATTERNS.length; ++i) {

            var urlPattern = URL_PATTERNS[i];
            if (!path.match(urlPattern.regex)) {
                continue;
            }

            var key = RegExp.$1;
            if (key.indexOf('/') != -1) { // Folder and key shouldn't contain any slashes
                continue;
            }

            params.mode = mode;
            params.key = key;

            // Copy pattern's params
            for (var i in urlPattern.params) {
                params[i] = urlPattern.params[i];
            }

            params.tooltipType = getTooltipType(params.type);
            return true;
        }

        return false;
    }

    function parseUrlDebug(link, params) {
        var urlMatch = link.href.match(URL_PATTERN_BASE_DEBUG);
        if (!urlMatch) {
            return;
        }
        if (link.href.indexOf("#") !== -1) {
            return;
        }

        var path = urlMatch[1];
        for (var i = 0; i < URL_PATTERNS.length; ++i) {

            var urlPattern = URL_PATTERNS[i];
            var keyMatch = path.match(urlPattern.regex);
            if (!keyMatch) {
                continue;
            }

            var key = keyMatch[1];
            if (key.indexOf('/') != -1) { // Folder and key shouldn't contain any slashes
                continue;
            }
            
            params.mode = "www";
            params.key = key;

            // Copy pattern's params
            for (var i in urlPattern.params) {
                params[i] = urlPattern.params[i];
            }

            URL_QUERY_BASE = URL_QUERY_BASE_DEBUG;
            params.tooltipType = getTooltipType(params.type);
            return;
        }
    }

    function requestTooltip(params) {
        var url = (URL_QUERY_BASE + params.tooltipType.url)
			.replace('{mode}', params.mode)
			.replace('{key}', params.key)
			.replace('{server}', params.server);
        $.getScript(url);
    }

    function registerData(data) {
        clearTimeout(loadingTimer);

        var params = data.params;

        saveData(params, data);

        if (currentParams != null && getCacheKeyFromParams(params) == getCacheKeyFromParams(currentParams)) {
            showTooltip(data);
        }
    }

    function getTooltip(params) {

        var data = loadData(params);

        if (data == null) { // Fetch data if not already cached

            clearTimeout(loadingTimer);
            loadingTimer = setTimeout(showLoading, DELAY_LOADING);
            requestTooltip(params);
            return null;
        }

        return data;
    }

    function showLoading() {

        if (currentLink != null) {
            Tooltip.show(currentLink, '<div class="dp-tooltip"><div class="loading"></div></div>');
        }
    }

    function showTooltip(data) {

        if (currentLink != null) {
            Tooltip.show(currentLink, data.tooltipHtml);
        }
    }

    // Utilities
    function getTooltipType(type) {
        return TYPES[type];
    }

    function saveData(params, data) {
        var cacheKey = getCacheKeyFromParams(params);
        dataCache[cacheKey] = data;
    }

    function loadData(params) {

        var cacheKey = getCacheKeyFromParams(params);
        return dataCache[cacheKey];
    }

    function getCacheKeyFromParams(params) {
        return [
			params.region,
			params.locale,
			params.type,
			params.key
		].join('-');
    }

    // Public methods
    this.registerData = registerData;



    // HTML Helpers
    var $ = {

        create: function (nodeName) {
            return document.createElement(nodeName);
        },

        getScript: function (url) {

            var script = $.create('script');
            script.type = 'text/javascript';
            script.src = url;

            document.body.appendChild(script);
        },

        getStyle: function (url) {

            var link = $.create('link');
            link.rel = 'stylesheet';
            link.type = 'text/css';
            link.href = url;

            document.body.appendChild(link);
        },

        documentReady: function (callback) {

            if (document.readyState == 'complete') {
                callback();
                return;
            }

            var occurred = false;

            $.bindEvent(document, 'DOMContentLoaded', function () {

                if (!occurred) {
                    occurred = true;
                    callback();
                }
            });

            $.bindEvent(document, 'readystatechange', function () {

                if (document.readyState == 'complete' && !occurred) {
                    occurred = true;
                    callback();
                }
            });

        },

        bindEvent: function (node, eventType, callback) {
            if (node.addEventListener) {
                node.addEventListener(eventType, callback, true); // Must be true to work in Opera
            } else {
                node.attachEvent('on' + eventType, callback);
            }
        },

        normalizeEvent: function (e) {
            var ev = {};
            ev.target = (e.target ? e.target : e.srcElement);
            ev.which = (e.which ? e.which : e.button);
            return ev;
        },

        getWindowSize: function () {

            var w = 0;
            var h = 0;

            if (document.documentElement && document.documentElement.clientHeight) {
                w = document.documentElement.clientWidth;
                h = document.documentElement.clientHeight;
            } else if (document.body && document.body.clientHeight) {
                w = document.body.clientWidth;
                h = document.body.clientHeight;
            } else if (window.innerHeight) {
                w = window.innerWidth;
                h = window.innerHeight;
            }

            return {
                w: w,
                h: h
            };
        },

        getScrollPosition: function () {

            var x = 0;
            var y = 0;

            if (window.pageXOffset || window.pageYOffset) {
                x = window.pageXOffset;
                y = window.pageYOffset;
            } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
                x = document.body.scrollLeft;
                y = document.body.scrollTop;
            } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
                x = document.documentElement.scrollLeft;
                y = document.documentElement.scrollTop;
            }

            return {
                x: x,
                y: y
            };
        },

        getOffset: function (node) {

            var x = 0;
            var y = 0;

            while (node) {
                x += node.offsetLeft;
                y += node.offsetTop;

                var p = node.parentNode;

                while (p && p != node.offsetParent && p.offsetParent) {
                    if (p.scrollLeft || p.scrollTop) {
                        x -= (p.scrollLeft | 0);
                        y -= (p.scrollTop | 0);
                        break;
                    }
                    p = p.parentNode;
                }
                node = node.offsetParent;
            }

            return {
                x: x,
                y: y
            };
        },

        getViewport: function () {
            var windowSize = $.getWindowSize();
            var scroll = $.getScrollPosition();

            return {
                l: scroll.x,
                t: scroll.y,
                r: scroll.x + windowSize.w,
                b: scroll.y + windowSize.h
            };
        }
    };

    $.Browser = {};
    $.Browser.ie = !!(window.attachEvent && !window.opera);
    $.Browser.ie6 = $.Browser.ie && navigator.userAgent.indexOf("MSIE 6.0") != -1;



    // Helper class that handles displaying tooltips
    var Tooltip = new function () {

        var PADDING = 5;

        var tooltipWrapper;
        var tooltipContent;

        function initialize() {

            tooltipWrapper = $.create('div');
            tooltipWrapper.className = 'dp-tooltip-wrapper';

            tooltipContent = $.create('div');
            tooltipContent.className = 'dp-tooltip-wrapper-inner';

            tooltipWrapper.appendChild(tooltipContent);
            document.body.appendChild(tooltipWrapper);

            hide();
        }

        function show(node, html) {

            if (tooltipWrapper == null) {
                initialize();
            }

            tooltipWrapper.style.visibility = 'hidden';
            tooltipWrapper.style.display = 'block';
            tooltipContent.innerHTML = html;

            var viewport = $.getViewport();
            var offset = $.getOffset(node);

            var x = offset.x + node.offsetWidth + PADDING;
            var y = offset.y - tooltipWrapper.offsetHeight - PADDING;

            if (y < viewport.t) {
                y = viewport.t;
            }

            if (x + tooltipWrapper.offsetWidth > viewport.r) {
                x = offset.x - tooltipWrapper.offsetWidth - PADDING;
            }

            reveal(x, y);
        }

        function hide() {

            if (tooltipWrapper == null) {
                return;
            }

            tooltipWrapper.style.display = 'none';
        }

        function reveal(x, y) {

            tooltipWrapper.style.left = x + 'px';
            tooltipWrapper.style.top = y + 'px';

            tooltipWrapper.style.visibility = 'visible';
        }

        // Public methods
        this.show = show;
        this.hide = hide;

    };

    construct();

};

function addCommasToNumber(nStr)
        {
            nStr += '';
            x = nStr.split('.');
            x1 = x[0];
            x2 = x.length > 1 ? '.' + x[1] : '';
            var rgx = /(\d+)(\d{3})/;
            while (rgx.test(x1)) {
                x1 = x1.replace(rgx, '$1' + ',' + '$2');
            }
            return x1 + x2;
        }



// This function is used to automatically copy the Navi information to the user clipboard.
// The data parameters are received from the Template:NaviLink.
function copyNaviLink() {
    if ($('.naviText').length > 0) {
        $('.naviText').each(function () {
            var naviLink = $(this);
            var copiedMessage = naviLink.next();

            var map = naviLink.attr('data-map');
            var x = naviLink.attr('data-x');
            var y = naviLink.attr('data-y');

            naviLink.click({ map: map, x: x, y: y }, function () {
                // Context is used to keep the right 'this' reference, it's needed for setTimeOut to work properly. 
                var context = $(this);
		var copiedText = ["@navi", map, x, y].filter(Boolean).join(" ");
                // Temporary input used to select the text and copy, it's removed after the copy is done.
                var inputTemp = document.createElement("input");
                inputTemp.setAttribute("value", copiedText);
                document.body.appendChild(inputTemp);
                inputTemp.select();
                document.execCommand("copy");
                inputTemp.remove();
                // Switches the text to indicate that the navi was copied and timesout after 2 seconds getting back to normal.
                context.css("display", "none");
                context.next().css("display", "inline-block");
                setTimeout(function () {
                    context.css("display", "inline-block");
                    context.next().css("display", "none");
                }, 2000);
            }
            );
        });
    }
};

$(document).ready(function() {
    //novaMarketPrices();
    copyNaviLink();
})

// Credits to iRO Wiki for the table of contents
var tocImgHid = 'https://www.novaragnarok.com/wiki/images/a/ad/Arr_r.png';
var tocImgSho = 'https://www.novaragnarok.com/wiki/images/f/f0/Arr_d.png';

function tocTree() {
  mw.util.addCSS('a.toctogHidden img, a.toctogShown img, a.toctogNull img {width:12px;height:12px;} #toc li a {padding-right:3px;} a.toctogNull img {visibility:hidden;}');

  var toc = document.getElementById('toc');
  if(!toc) return
  var li = toc.getElementsByTagName('li');
  for(var i=0;i<li.length;i++) {
    var cul = li[i].getElementsByTagName('ul');
    var a = document.createElement('a');
     if(cul.length == 0) {
       a.setAttribute('class','toctogNull');
     } else {
       a.setAttribute('class','toctogShown');
       a.setAttribute('id','toctog-a-' + i );
       a.setAttribute('href','javascript:tocTreeToggle("' + i + '");');
     }
     var img = document.createElement('img');
      img.setAttribute('src',tocImgHid);
      img.setAttribute('id','toctog-i-' + i );
     a.appendChild(img);
    li[i].insertBefore(a,li[i].firstChild);
    if(cul.length != 0) tocTreeToggle(i)
  }
}
if(wgNamespaceNumber != -1 && wgArticleId != 0) 
    $(tocTree)

function tocTreeToggle(id) {
  var a = document.getElementById('toctog-a-' + id);
  var img = document.getElementById('toctog-i-' + id);
  var cul = a.parentNode.getElementsByTagName('ul');
  var disp;
  if(a.getAttribute('class') == 'toctogShown') {
    disp = 'none';
    a.setAttribute('class','toctogHidden');
    img.setAttribute('src',tocImgHid);
  } else {
    disp = 'block';
    a.setAttribute('class','toctogShown');
    img.setAttribute('src',tocImgSho);
  }
  for(var j=0;j<cul.length;j++) {
    if(cul[j].parentNode == a.parentNode) cul[j].style.display = disp
  }
}