MediaWiki:BibleGet.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 9:
console.log("There are " + $('.bibleQuoteRef').length + " bible quotes on this page");
$('.bibleQuoteRef').each(function(){
let $spanel = $(this);
let version = $(this).attr('data-version');
let ref = $(this).attr('data-ref');
let inline = ($(this).attr('data-inline') == "true");
 
if(bibleQuoteCollection.includes(version+"/"+ref)){
//we already have an instance of this bible quote, avoid creating new div
Line 18 ⟶ 20:
//however since the ajax calls are asynchronous, we probably won't have the actual div at the bottom of the page yet
//so let's look for it inside the mouseover event
if(inline){
$spanel.on('mouseenter', function(){
let $bGetTIP = $("div[data-version='"+version+"'][data-ref='"+ref+"']");
console.log('I found ' + $bGetTIP.length + ' div(s) at the bottom of the page with this bible quote');
$bGetTIP.removeClass('hidden');
let top = $span.offset().top;
let left = $span.offset().left + $span.outerWidth() + 15;
$bGetTIP.css({"top":top,"left":left});
if($bGetTIP.hasClass('sticky') || $bGetTIP.is(':offscreen') ){
console.log('This element would have been offscreen!');
//how far off the bottom of the screen are we?
let rect = $bGetTIP[0].getBoundingClientRect();
let excessHeight = (rect.y + rect.height) - window.innerHeight;
//if this amount is less than the distance from the top of the screen,
// then let's just move our div up by that much
if(!$bGetTIP.hasClass('sticky') && excessHeight < rect.y){
let newTop = top - excessHeight;
$bGetTIP.css({"top":newTop});
} else {
if(!$bGetTIP.hasClass('sticky')){
$bGetTIP.addClass('sticky');
$bGetTIP.append($('<div>',{class:'closeButton',text:'x'}));
$bGetTIP.on('click','.closeButton',function(){
$bGetTIP.addClass('hidden');
$bGetTIP.css({"top":'',"left":''});
});
}
//distance of the top of the current window from the top of the document
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
}
//distance of the top of the current window from the top of the document
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
}
});
});
/*
$spanel.on('mouseleavemousemove', function(){
/*
let top = $span.on('mousemove', functionoffset(){.top;
let topleft = $span.offset().topleft + $span.outerWidth();
let left = $spanbGetTIP.offsetcss().{"top":top,"left + $span.outerWidth(":left});
$bGetTIP.css({"top":top,"left":left});
}); */
*/
$spanel.on('mouseentermouseleave', function(){
let $bGetTIP = $("div[data-version='"+version+"'][data-ref='"+ref+"']");
$span.on('mouseleave', function(){
//console.log('I found ' + $bGetTIP.length + ' div(s) at the bottom of the page with this bible quote');
let $bGetTIP = $("div[data-version='"+version+"'][data-ref='"+ref+"']");
if(!$bGetTIP.hasClass('sticky') ){
//console.log('I found ' + $bGetTIP.length + ' div(s) at the bottom of the page with this bible quote');
setTimeout(function(){
if(!$bGetTIP.hasClass('sticky') ){
setTimeout(function $bGetTIP.addClass('hidden'){ ;
$bGetTIP.addClasscss({"top":'hidden',"left":''});
$bGetTIP.css({"top":'',"left":''},500);
},500);
});
});
} else {
bibleQuoteCollection.push(version+"/"+ref);
Line 83 ⟶ 86:
console.log(data);
if(data.hasOwnProperty('html')){
let $bGetTIP = $if('<div>', inline){
"class":let "bibleGetQuote"$bGetTIP = $('<div>', {
"data-versionclass": version"bibleGetQuote",
"data-refversion": refversion,
"htmldata-ref": data.htmlref,
}); "html": data.html
});
$bGetTIP.append($('<p>',{"text": " — powered by BibleGet I/O","css":{"font-size":".9em","text-align":"right","font-style":"italic","font-weight":"bold","color":"gray"}}));
//$('body').append($bGetTIP);
BibleQuotesDomElements //$('body').pushappend($bGetTIP);
BibleQuotesDomElements.push($bGetTIP);
/*
$span.on('mouseenter', function(){
$bGetTIPel.removeClasson('hiddenmouseenter', function();{
let top = $spanbGetTIP.offsetremoveClass('hidden').top;
let lefttop = $span.offset().left + $span.outerWidth() + 15top;
let left = $bGetTIPspan.cssoffset({"top":top,").left":left} + $span.outerWidth() + 15;
if( $bGetTIP.hasClasscss('sticky') || $bGetTIP.is('{"top":offscreen'top,"left":left}) ){;
consoleif($bGetTIP.loghasClass('Thissticky') element was|| $bGetTIP.is(':offscreen!'); ){
console.log('This element was offscreen!');
//how far off the bottom of the screen are we?
let //how rectfar =off $bGetTIP[0].getBoundingClientRect();the bottom of the screen are we?
let rect = $bGetTIP[0].getBoundingClientRect();
let excessHeight = (rect.y + rect.height) - window.innerHeight;
//if this amount is less than the distance from the top of the screen,
//if thenthis let'samount justis moveless ourthan divthe updistance byfrom thatthe muchtop of the screen,
// then let's just move our div up by that much
if(!$bGetTIP.hasClass('sticky') && excessHeight < rect.y){
let newTop = top - excessHeight;
$bGetTIP.css({"top": let newTop}) = top - excessHeight;
} else $bGetTIP.css({"top":newTop});
if(!$bGetTIP.hasClass('sticky'))} else {
if(!$bGetTIP.addClasshasClass('sticky');){
$bGetTIP.appendaddClass($('<div>',{class:'closeButton',text:'xsticky'}));
$bGetTIP.onappend($('click<div>',{class:'.closeButton',function(text:'x'}){);
$bGetTIP.addClasson('hiddenclick','.closeButton',function();{
$bGetTIP.cssaddClass({"top":'hidden',"left":''});
$bGetTIP.css({"top":'',"left":''});
/* });
}
//ifdistance thisof amountthe istop less thanof the distancecurrent window from the top of the screen,document
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
}
//distance of the top of the current window from the top of the document
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
}
});
});
/*
$el.on('mousemove', function(){
/*
let top = $span.on('mousemove', functionoffset(){.top;
let topleft = $span.offset().topleft + $span.outerWidth();
let left = $spanbGetTIP.offsetcss().{"top":top,"left + $span.outerWidth(":left});
$bGetTIP.css({"top":top,"left":left});
}); */
*/
$el.on('mouseleave', function(){
if(!$spanbGetTIP.onhasClass('mouseleavesticky',) function(){
if setTimeout(!$bGetTIP.hasClassfunction('sticky'){ ){
setTimeout(function $bGetTIP.addClass('hidden'){ ;
$bGetTIP.addClasscss({"top":'hidden',"left":''});
$bGetTIP.css({"top":'',"left":''},500);
},500);
});
}); else {
$el.append(data.html);
}
}
//console.log("Injected Bible quote for ref = " + ref + " with value obtained from BibleGet service:");