MediaWiki:BibleGet.js: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 26: Line 26:
let left = $span.offset().left + $span.outerWidth() + 15;
let left = $span.offset().left + $span.outerWidth() + 15;
$bGetTIP.css({"top":top,"left":left});
$bGetTIP.css({"top":top,"left":left});
if($bGetTIP.is(':offscreen') ){
if($bGetTIP.hasClass('sticky') || $bGetTIP.is(':offscreen') ){
console.log('This element was offscreen!');
console.log('This element would have been offscreen!');
//how far off the bottom of the screen are we?
//how far off the bottom of the screen are we?
let rect = $bGetTIP[0].getBoundingClientRect();
let rect = $bGetTIP[0].getBoundingClientRect();
Line 33: Line 33:
//if this amount is less than the distance from the top of the screen,
//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
// then let's just move our div up by that much
if(excessHeight < rect.y){
if(!$bGetTIP.hasClass('sticky') && excessHeight < rect.y){
let newTop = top - excessHeight;
let newTop = top - excessHeight;
$bGetTIP.css({"top":newTop});
$bGetTIP.css({"top":newTop});
} else {
} else {
$bGetTIP.addClass('sticky');
if(!$bGetTIP.hasClass('sticky')){
$bGetTIP.addClass('sticky');  
$bGetTIP.append($('<div>',{class:'closeButton',text:'x'}));
$bGetTIP.on('click','.closeButton',function(){
setTimeout(function(){
//$bGetTIP.find('.closeButton').remove();
$bGetTIP.addClass('hidden');
//$bGetTIP.removeClass('sticky');
$bGetTIP.css({"top":'',"left":''});
},500);
});
}
//distance of the top of the current window from the top of the document
//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;
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
$bGetTIP.css({"top":newTop});
$bGetTIP.append($('<div>',{class:'closeButton',text:'x'}));
}
}
}
}
Line 93: Line 103:
let left = $span.offset().left + $span.outerWidth() + 15;
let left = $span.offset().left + $span.outerWidth() + 15;
$bGetTIP.css({"top":top,"left":left});
$bGetTIP.css({"top":top,"left":left});
if($bGetTIP.is(':offscreen') ){
if($bGetTIP.hasClass('sticky') || $bGetTIP.is(':offscreen') ){
console.log('This element was offscreen!');
console.log('This element was offscreen!');
//how far off the bottom of the screen are we?
//how far off the bottom of the screen are we?
Line 100: Line 110:
//if this amount is less than the distance from the top of the screen,
//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
// then let's just move our div up by that much
if(excessHeight < rect.y){
if(!$bGetTIP.hasClass('sticky') && excessHeight < rect.y){
let newTop = top - excessHeight;
let newTop = top - excessHeight;
$bGetTIP.css({"top":newTop});
$bGetTIP.css({"top":newTop});
} else {
} else {
$bGetTIP.addClass('sticky');
if(!$bGetTIP.hasClass('sticky')){
$bGetTIP.addClass('sticky');
$bGetTIP.append($('<div>',{class:'closeButton',text:'x'}));
$bGetTIP.on('click','.closeButton',function(){
setTimeout(function(){
//$bGetTIP.find('.closeButton').remove();
$bGetTIP.addClass('hidden');
//$bGetTIP.removeClass('sticky');
$bGetTIP.css({"top":'',"left":''});
},500);
});
}
//distance of the top of the current window from the top of the document
//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;
let newTop = (window.pageYOffset || (document.documentElement || document.body.parentNode || document.body).scrollTop) + 20;
$bGetTIP.css({"top":newTop});
$bGetTIP.css({"top":newTop});
$bGetTIP.append($('<div>',{class:'closeButton',text:'x'}));
}
}
}
}