MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
Linha 349: | Linha 349: | ||
loadMapOnIFrame(coord, mapFrame[0]); | loadMapOnIFrame(coord, mapFrame[0]); | ||
}); | }); | ||
}); | |||
/** Testes mapa */ | |||
function loadMapScripts() { | |||
if (typeof L === 'undefined') { | |||
var leafletCss = document.createElement('link'); | |||
leafletCss.rel = 'stylesheet'; | |||
leafletCss.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css'; | |||
document.head.appendChild(leafletCss); | |||
var leafletScript = document.createElement('script'); | |||
leafletScript.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'; | |||
leafletScript.onload = function() { | |||
renderPopupMap(); | |||
}; | |||
document.head.appendChild(leafletScript); | |||
} else { | |||
renderPopupMap(); | |||
} | |||
} | |||
function renderPopupMap() { | |||
$('.map_frame').each(function() { | |||
var coord = $(this).closest('.map_show').find('.map_frame_coord').text(); | |||
var [x, y, z] = coord.split(','); // Extraímos as coordenadas | |||
var mapBox = $(this).find('.map_box'); | |||
mapBox.html('<div id="map-popup" style="width: 100%; height: 100%;"></div>'); // Cria o div para o mapa | |||
// Inicializa o mapa | |||
var map = L.map('map-popup').setView([y, x], z); // Ajuste as coordenadas conforme necessário (inverter x e y se for o caso) | |||
// Carrega os tiles do mapa (substitua a URL conforme sua necessidade) | |||
L.tileLayer('https://ravenquest.wiki.br/tiles/{z}/{x}/{y}.png', { | |||
maxZoom: 4, | |||
minZoom: 0, | |||
tileSize: 256, | |||
attribution: 'Mapa do RavenQuest' | |||
}).addTo(map); | |||
// Adiciona um marcador na coordenada (se necessário) | |||
if (x && y) { | |||
L.marker([y, x]).addTo(map); | |||
} | |||
}); | |||
} | |||
function showMap(container) { | |||
$('.map_frame', container).css('display', 'block'); // Exibe o pop-up | |||
$('.map_overlay', container).css('display', 'inline'); // Exibe a sobreposição preta | |||
configPopupMap(container); // Configura o mapa dentro do pop-up | |||
} | |||
$('.map_show').click(function() { | |||
var display = $('.map_frame', this).css('display'); | |||
if (display == 'none') { | |||
showMap(this); // Chama a função para exibir o mapa | |||
} | |||
return false; | |||
}); | }); |
Edição das 18h09min de 23 de março de 2025
/* Abrir Spoilers */ $(document).ready(function(){ $('.showspoiler').click(function(){ var a = $('.spoiler').css('display'); if (a == "none"){ $('.showspoiler').text("Clique para fechar todos os spoilers"); $('div.spoiler').css({'display': 'block'}); } else { $('.showspoiler').text("Clique para abrir todos os spoilers"); $('div.spoiler').css({'display': 'none'}); } }); }); /* Sempre mostra Spoilers */ $(document).ready(function(){ $('[data-sempre-mostrar]').click(function(){ if($.cookie('sempre-mostrar-spoilers') === "true") { $.cookie('sempre-mostrar-spoilers', "false", { expires: 360, path: '/' }); } else { $.cookie('sempre-mostrar-spoilers', "true", { expires: 360, path: '/' }); } $('#spoil').toggle(); $('.showhide').toggle(); }); }); /* Quest Spoils */ $(document).ready(function(){ var url = location.hash; if (url.length > 0 || $.cookie('sempre-mostrar-spoilers') === "true"){ $('.showhide').click(function(){ $('#spoil').toggle(); $('.showhide').toggle(); }); } else { $('#spoil').toggle(); $('.showhide').toggle(); $('.showhide').click(function(){ $('#spoil').toggle(); $('.showhide').toggle(); }); } }); /* Tirar ícone de links externos */ $('.mapa > a').removeClass('external text'); $('#siteNotice a').removeClass('external text'); /* Tirar atributo title de links */ $('.tooltip > a').removeAttr('title'); /* Transcrições NPCs */ $(document).ready(function() { $('#show2, #show3').click(function() { $('.hide').toggle(); }); }); /* Criaturas */ $(document).ready(function () { var height = $('#hab').height(); if (height >= 50) { $('#hab').addClass('hide'); $('#show').removeClass('hide'); } $('#show').click(function () { $('.hide').toggle(); $('.showhab').toggle(); $('#NPC').addClass('hide'); }); }); /** Cria component DIV. */ function createComponent(id, css, doc, target, callback) { var params = { "name": "div", "id": id, "css": css }; iframeInsertComponents(params, doc, target, callback); } /** Cria component LINK que carrega CSS. */ function createCss(doc, target, href, callback) { var params = { "name": "link", "rel": "stylesheet", "href": href }; iframeInsertComponents(params, doc, target, callback); } /** Cria component Script que carrega JavaScript. */ function createScript(doc, target, code, callback) { var params = { "name": "script", "type": "text/javascript", "code": code }; iframeInsertComponents(params, doc, target, callback); } /** Cria component STYLE que carrega CSS na HEAD. */ function createStyle(doc, target, css, callback) { var params = { "name": "style", "css": css }; iframeInsertComponents(params, doc, target, callback); } /** Checa se a Variavel existe */ function isDefined(variable) { return typeof variable !== 'undefined'; } /** Algumas telas utiliza iFrames e precisa injetar JavaScripts para funcionar corretamente */ function iframeInsertComponents(params, doc, target, callback) { //doc, target, src, callback var s = doc.createElement(params.name); if (params.name == "script") { s.type = params.type; } if (params.name == "link") { s.rel = params.rel; } if (params.name == "div") { s.id = params.id; if (params.css != null) { Object.entries(params.css).forEach(function(arr, i) { $(s).css(arr[0], arr[1]); }); } } if(callback) { if (s.readyState){ //IE s.onreadystatechange = function(){ if (s.readyState == "loaded" || s.readyState == "complete"){ s.onreadystatechange = null; callback(); } }; } else { //Others s.onload = function(){ callback(); }; } } if (params.name == "style") { Object.entries(params.css).forEach(function(arr, i) { var attrs = ""; Object.entries(arr[1]).forEach(function(attr, i) { attrs += '\n' + attr[0] + ': ' + attr[1]; }); if (i === 0) { s.innerText = arr[0] + ' {' + attrs + '\n}'; } }); } if (params.name == "script") { if (params.code.src != null && params.code.src != "") { s.src = params.src; } if (params.code.code != null) { console.log(params.code.code); var re = new RegExp('\n', 'g'); s.innerText = params.code.code.replace(re, '');//.split('<br>').join('\n'); } } if (params.name == "link") { s.href = params.href; } target.appendChild(s); } /* Abas */ $(document).ready(function(){ $('.showDiv').on('click', function () { $(this).siblings(); $('.targetDiv').hide(); $('.targetDiv2').hide(); $('#div' + $(this).data('target')).show(); }); }); /* Abas Menu*/ $(document).ready(function () { $('.mostrar-aba').click(function () { var aba_id = $(this).attr('data-aba'); var check = $("#aba-" + aba_id).css('display'); if (check == "block") { $("#aba-" + aba_id).removeClass('atual'); } else { $('.aba').removeClass('atual'); $("#aba-" + aba_id).addClass('atual'); } }); $('.mostrar-todas-abas').click(function () { var check = $('.aba').css('display'); if (check == "block") { $('.aba').removeClass('atual'); } else { $('div.aba').toggleClass('atual'); } }); var url = location.href; hash = url.split('#')[1]; if ((hash != null || hash != undefined) && hash.length > 0){ $("#aba-" + hash).addClass('atual'); } }); /* Toggle Diálogos */ $(document).ready(function(){ $('[data-dialog-text]').hide(); $('[data-dialog-show]').on('click', function() { $element = $(this).parents('[data-dialog]').children('[data-dialog-text]') if($element.is(":hidden")) { $element.show(); } else { $element.hide(); } }); }); /* Mapa */ if (mw.config.values.wgPageName === 'Mapa') { $(document).ready(function(){ var url = location.hash; $(".map_wiki").append('<div id="map" style="width: 100%; height: 100%;"></div>'); loadMapScripts(); }); } /* Mapa Popup */ /** Abre o popup de mapa de Monstros e NPCs */ $('.map_show').click(function() { var display = $('.map_frame',this).css('display'); if (display == 'none') { showMap(this); } return false; }); /** Fecha o mapa ao clicar na parte Preta (Overlay) */ $('.map_overlay').click(function() { $('.map_show').each(function( index ) { hideMap($('.map_show')[index]); }); return false; }); $('.map_logobox').click(function(event){ event.stopPropagation(); }); /** Configura o Popup (LightBox) de Mapa */ function configPopupMap(container) { /** Configura o Mapa. */ $('.map_box').each(function( index ) { $(this).html("") }); var coord = $('.map_frame_coord',container).text(); window.history.replaceState("map", null, "#" + coord + ":1"); $(".map_box", container).css("width", "100%").css("height", "100%") $(".map_box", container).append('<div id="map" style="width: 100%; height: 100%;"></div>'); /** Transforma a logo do Ravendawn Wiki em um link para a página do Mapa com as coordenadas da localiação */ $(".map_logobox",container).append('<a href="https://ravenquest.wiki.br/wiki/mapa#'+coord+':1" class="map_logo" target="_blank" title="Ver no mapa do Ravendawn Wiki"></a>'); loadMapScripts(); } /** Função que faz o popup em lightbox do Mapa apareça. */ function showMap(container) { $('.map_frame',container).css('display', 'inline'); $('.map_overlay',container).css('display', 'inline'); configPopupMap(container); } /** Função que faz o popup em lightbox do Mapa desaparecer. */ function hideMap(container) { $('.map_frame',container).css('display', 'none'); $('.map_overlay',container).css('display', 'none'); } /* Mapa Infobox Hunt */ $('.map_hunt').ready(function(){ var coord = $('.map_hunt_coord',this).text(); /** Transforma a logo do Ravenquest Wiki em um link para a página do Mapa com as coordenadas da localiação */ $(".map_logobox",this).append('<a href="https://www.ravenquest.wiki.br/wiki/mapa#'+coord+':1" class="map_logo" target="_blank" title="Ver no mapa do Ravenquest Wiki"></a>'); /** Box do Map */ var mapBox = $(".map_hunt_box",this); mapBox.html(""); /** Cria o iFrame que conterá o Mapa */ mapBox.append('<iframe id="mapa_frame" scrolling="no" frameborder="0" width="100%" height="310" style="border-radius:8px"></iframe>'); /** Pega o Map iFrame */ var mapFrame = $("#mapa_frame",mapBox); /** Seta as Coordenadas do Mapa */ // mapFrame.attr("src", mapFrame.contents().get(0).URL + "#" + coord + ":1"); mapFrame.ready(function() { //let iframeMap = mapFrame[0]; //if (iframeMap !== null) { // loadMapOnIFrame(coord, mapFrame[0]); //} loadMapOnIFrame(coord, mapFrame[0]); }); }); /* Mapa Infobox Geo */ $('.map_hunt_geo').ready(function(){ var coord = $('.map_hunt_coord_geo',this).text(); /** Transforma a logo do Ravenquest Wiki em um link para a página do Mapa com as coordenadas da localiação */ $(".map_logobox",this).append('<a href="https://www.ravenquest.wiki.br/wiki/mapa#'+coord+':1" class="map_logo" target="_blank" title="Ver no mapa do Ravenquest Wiki"></a>'); /** Box do Map */ var mapBox = $(".map_hunt_box_geo",this); mapBox.html(""); /** Cria o iFrame que conterá o Mapa */ mapBox.append('<iframe id="mapa_frame" scrolling="no" frameborder="0" width="100%" height="430" style="border-radius:8px"></iframe>'); /** Pega o Map iFrame */ var mapFrame = $("#mapa_frame",mapBox); /** Seta as Coordenadas do Mapa */ // mapFrame.attr("src", mapFrame.contents().get(0).URL + "#" + coord + ":1"); mapFrame.ready(function() { //let iframeMap = mapFrame[0]; //if (iframeMap !== null) { // loadMapOnIFrame(coord, mapFrame[0]); //} loadMapOnIFrame(coord, mapFrame[0]); }); }); /** Testes mapa */ function loadMapScripts() { if (typeof L === 'undefined') { var leafletCss = document.createElement('link'); leafletCss.rel = 'stylesheet'; leafletCss.href = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css'; document.head.appendChild(leafletCss); var leafletScript = document.createElement('script'); leafletScript.src = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js'; leafletScript.onload = function() { renderPopupMap(); }; document.head.appendChild(leafletScript); } else { renderPopupMap(); } } function renderPopupMap() { $('.map_frame').each(function() { var coord = $(this).closest('.map_show').find('.map_frame_coord').text(); var [x, y, z] = coord.split(','); // Extraímos as coordenadas var mapBox = $(this).find('.map_box'); mapBox.html('<div id="map-popup" style="width: 100%; height: 100%;"></div>'); // Cria o div para o mapa // Inicializa o mapa var map = L.map('map-popup').setView([y, x], z); // Ajuste as coordenadas conforme necessário (inverter x e y se for o caso) // Carrega os tiles do mapa (substitua a URL conforme sua necessidade) L.tileLayer('https://ravenquest.wiki.br/tiles/{z}/{x}/{y}.png', { maxZoom: 4, minZoom: 0, tileSize: 256, attribution: 'Mapa do RavenQuest' }).addTo(map); // Adiciona um marcador na coordenada (se necessário) if (x && y) { L.marker([y, x]).addTo(map); } }); } function showMap(container) { $('.map_frame', container).css('display', 'block'); // Exibe o pop-up $('.map_overlay', container).css('display', 'inline'); // Exibe a sobreposição preta configPopupMap(container); // Configura o mapa dentro do pop-up } $('.map_show').click(function() { var display = $('.map_frame', this).css('display'); if (display == 'none') { showMap(this); // Chama a função para exibir o mapa } return false; });