9 957 octets ajoutés
, 19 octobre 2016 à 20:06
var citations = function() { var delaiAff = .1; var delaiCach = .2;
var livres = { "Gen": "Genèse", "Exo": "Exode", "Lev": "Lévitique", "Nom": "Nombres",
"Deu": "Deutéronome", "Jos": "Josué", "Jug": "Juges", "Rut": "Ruth", "USa": "1_Samuel",
"DSa": "2_Samuel", "URo": "1_Rois", "DRo": "2_Rois", "UCh": "1_Chroniques", "DCh": "2_Chroniques",
"Esd": "Esdras", "Neh": "Néhémie", "Est": "Esther", "Job": "Job", "Psa": "Psaumes",
"Pro": "Proverbes", "Ecc": "Prédicateur", "Can": "Cantique_des_cantiques", "Esa": "Ésaïe",
"Jer": "Jérémie", "Lam": "Les_lamentations_de_Jérémie", "Eze": "Ézéchiel", "Dan": "Daniel",
"Ose": "Osée", "Joe": "Joël", "Amo": "Amos", "Abd": "Abdias", "Jon": "Jonas", "Mic": "Michée",
"Nah": "Nahum", "Hab": "Habakuk", "Sop": "Sophonie", "Agg": "Aggée", "Zac": "Zacharie",
"Mal": "Malachie", "Mat": "Matthieu", "Mar": "Marc", "Luc": "Luc", "Jea": "Jean",
"Act": "Actes", "Rom": "Romains", "UCo": "1_Corinthiens", "DCo": "2_Corinthiens",
"Gal": "Galates", "Eph": "Éphésiens", "Phi": "Philippiens", "Col": "Colossiens",
"UTh": "1_Thessaloniciens", "DTh": "2_Thessaloniciens", "UTi": "1_Timothée", "DTi": "2_Timothée",
"Tit": "Tite", "Phm": "Philémon", "Heb": "Hébreux", "Jac": "Jacques", "UPi": "1_Pierre",
"DPi": "2_Pierre", "UJe": "1_Jean", "DJe": "2_Jean", "TJe": "3_Jean", "Jud": "Jude", "Apo": "Apocalypse" };
var cache = {}; var encours = false;
var getChap = function(livre,chap) {
if (!cache[livre + chap]) {
$.ajax({ url: mw.util.wikiScript('index'),
data: {"title":"Bible:"+livres[livre]+"/Chap_"+chap,"action":"render"},
async: false,dataType: 'html'}).done(function(data) {
cache[livre + chap] = data.replace('<p><br />\n</p>\n<hr />\n<ol class="references">','<hr />\n<ol class="references">');
}); }
return cache[livre + chap]; };
var afficheCitation = function(e) {
var target = $(e.data.target);
$(".tb-citat").trigger("hide");
var txt = target.data("citation");
var tlarg = $(window).width(); var thaut = $(window).height();
var larg = 2*tlarg/3-60; var haut = thaut/2-30;
if (!txt) {
target.data("citation", $(chargeCont(target.get(0))));
txt = target.data("citation"); txt.appendTo(document.body).css({"width": larg,"height": haut}); }
window.setTimeout(function() {
if (encours) {
encours=false;
var nvers = 200,nchap = 200;
txt.find(".tb-verset").each( function() {
$(this).css("z-index",nvers-$(this).text()); $(this).width(18); });
txt.find(".tb-chapitre").each( function() {
$(this).css("z-index",nchap); $(this).width(18); nchap = nchap-1; });
var timer; var orig = $(e.target);
txt.hover(function(){window.clearTimeout(timer);},
function(){ timer = window.setTimeout(function(){
txt.hide().unbind("mouseenter, mouseleave"); orig.unbind("mouseenter, mouseleave"); }, delaiCach*1000); });
orig.hover(function(){window.clearTimeout(timer);}, function(){
timer = window.setTimeout(function(){
txt.hide().unbind("mouseenter, mouseleave"); orig.unbind("mouseenter, mouseleave"); }, delaiCach*1000); });
var posX = (e.pageX-larg/2>10)?(e.pageX+larg/2+50>tlarg?tlarg-larg-50:e.pageX-larg/2):10;
var bas = orig.offset().top + orig.height() + 5;
var posY = (thaut+$(document).scrollTop()-bas>haut)?bas:orig.offset().top-haut-5;
txt.css({"left": posX + "px", "top": posY + "px"})
.show().scrollTop(txt.find(".surligne").position().top+txt.scrollTop()-haut/3); }},0);};
var chargeCont = function(target) {
var refer = $(target).children(".tb-cit-ref").attr("title"); var livr = refer.substring(0,3);
var refdeb = refer.substring(3).split("a")[0]; var reffin = refer.substring(3).split("a")[1] || refdeb;
var chapdeb = refdeb.split("v")[0]; var versdeb = refdeb.split("v")[1] || "1-180";
var chapfin = reffin.split("v")[0]; var versfin = reffin.split("v")[1] || "1-180";
var content = '<div class="tb-citat"><div>';
for (var i=parseInt(chapdeb);i<=parseInt(chapfin);i++) {
var data = getChap(livr,i); var versets = "1-180";
if (i == chapdeb) versets = versdeb;
if (i == chapfin) versets = versfin;
if (i == chapdeb && chapdeb != chapfin && versets.indexOf("-")==-1) versets += "-180";
if (i == chapfin && chapdeb != chapfin && versets.indexOf("-")==-1) versets = "1-" + versets;
for (var j in versets.split(",")) {
var vd = versets.split(",")[j].split("-")[0]; var vf = versets.split(",")[j].split("-")[1] || vd;
for (var v=parseInt(vd);v<=parseInt(vf);v++) {
var pos = data.indexOf('<span id="' + livr + i + 'v' + v + '"');
if (pos>=0) {
var fini = data.indexOf('"deb-vers">',data.indexOf('"deb-vers">',pos)+11);
var fin = fini==-1?-1:data.lastIndexOf('<span',fini);
if (fin == -1) fin = data.indexOf('<hr />',pos);
var txtv = data.substring(pos,fin); var debr = 0; var rempl = "";
while (txtv.indexOf('</p>',debr)>=0) {
rempl += '<span class="surligne">' + txtv.substring(debr,txtv.indexOf('</p>', debr)) + '</span></p>';
debr = txtv.indexOf('<p>',debr)+3; if (debr>2) rempl += '<p>'; else debr=txtv.length; }
rempl += '<span class="surligne">' + txtv.substring(debr) + '</span>';
data = data.substring(0,pos) + rempl + data.substring(fin); }}}
content += '<p><span class="tb-chapitre">' + i + '</span>' + data.substring(3); }
return content + '</div></div>'; }
$(".tb-cit").each(function () {
var delai; $(this).on("mouseenter", {"target": this}, function(e) {
var ev = e; delai = window.setTimeout(function() {encours=true; afficheCitation(ev);}, delaiAff*1000);
}).on("mouseleave", function() {window.clearTimeout(delai); encours=false;}); });
};
$(document).ready( function() { citations(); });
$(document).ready( function() { var nvers = 200,nchap = 200;
$(".tb-verset").each( function() { $(this).css("z-index",nvers-$(this).text()); $(this).width(18); });
$(".tb-chapitre").each( function() { $(this).css("z-index",nchap); $(this).width(18); nchap = nchap-1; }); });
$(document).ready(function() {
$(".ns-7100 .tb-toc ul>li").on("click",function() {
var ouvert = $(this).find("a.tb-ouv").length;
$(".ns-7100 .tb-toc ul>li>ul>li>a").removeClass("tb-ouv");
if (ouvert==0) $(this).find("a").addClass("tb-ouv"); });
});
function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';');
for(var i = 0; i <ca.length; i++) { var c = ca[i];
while (c.charAt(0)==' ') { c = c.substring(1); }
if (c.indexOf(name) == 0) { return c.substring(name.length,c.length); }
} return ""; }
$("#pt-login").on("click",function(){document.cookie = "taille=";document.cookie = "refsoul=";});
$("#pt-logout").on("click",function(){document.cookie = "taille=";document.cookie = "refsoul=";});
$(document).ready(function() {
if (!getCookie("taille")) {
$.ajax({ url: mw.util.wikiScript('api')+"?action=query&meta=userinfo&uiprop=options&format=json",async: false,dataType: 'json'}).done(function(data) {
var td = data.query.userinfo.options["userjs-police"]; if (!td) td=16; document.cookie = "taille=" + td; $("#content").css("font-size",getCookie("taille")+"px"); }); }
$("#p-police-moins").click(function() { var taille = getCookie("taille");
taille = parseInt(taille,10) - 2; document.cookie = "taille=" + taille;
$("#content").css("font-size",getCookie("taille")+"px");
$.ajax({ url: mw.util.wikiScript('api')+"?action=query&meta=tokens&format=json",async: true,dataType: 'json'}).done(function(data) {
var tok = data.query.tokens.csrftoken;
$.ajax({ url: mw.util.wikiScript('api')+"?action=options", type: 'POST',data: {"token": tok, "change": "userjs-police="+taille},
async: true,dataType: 'html'}).done(function(data) { }); }); });
$("#p-police-plus").click(function() {
var taille = getCookie("taille"); taille = parseInt(taille,10) + 2; document.cookie = "taille=" + taille;
$("#content").css("font-size",getCookie("taille")+"px");
$.ajax({ url: mw.util.wikiScript('api')+"?action=query&meta=tokens&format=json",async: true,dataType: 'json'}).done(function(data) {
var tok = data.query.tokens.csrftoken;
$.ajax({ url: mw.util.wikiScript('api')+"?action=options", type: 'POST',data: {"token": tok, "change": "userjs-police="+taille},
async: true,dataType: 'html'}).done(function(data) { }); }); }); });
function souligneRefs(actif) { if (actif!=0) {
$("#p-souligne-refs h3").css("border-bottom","0px dotted"); $(".tb-cit a").css("border-bottom","1px dotted"); }
else { $("#p-souligne-refs h3").css("border-bottom","1px dotted"); $(".tb-cit a").css("border-bottom","0px dotted"); }
}
$(document).ready(function() { if (!getCookie("refsoul")) {
$.ajax({ url: mw.util.wikiScript('api')+"?action=query&meta=userinfo&uiprop=options&format=json",async: false,dataType: 'json'}).done(function(data) {
var rs = data.query.userinfo.options["userjs-refsoul"]; if (!rs) rs=0; document.cookie = "refsoul=" + rs; }); }
souligneRefs(getCookie("refsoul")); $("#p-souligne-refs").click(function() {
var rs= getCookie("refsoul"); if (rs==0) rs=1; else rs=0; document.cookie = "refsoul=" + rs; souligneRefs(getCookie("refsoul"));
$.ajax({ url: mw.util.wikiScript('api')+"?action=query&meta=tokens&format=json",async: true,dataType: 'json'}).done(function(data) {
var tok = data.query.tokens.csrftoken;
$.ajax({ url: mw.util.wikiScript('api')+"?action=options", type: 'POST',data: {"token": tok, "change": "userjs-refsoul="+rs},
async: true,dataType: 'html'}).done(function(data) { }); }); }); });