Difference between revisions of "MediaWiki:Common.js"

From Final Fantasy XIV Online Wiki
Jump to navigation Jump to search
 
(18 intermediate revisions by the same user not shown)
Line 7: Line 7:
*/
*/


var isInViewport = function () {
// hide il_fixed when it overlaps with feed
         console.log('version 0.2')
/*
var feedIsInViewport = function () {
         // console.log('version 1.0')
         var elem = document.getElementById("taboola-below-article-thumbnails")
         var elem = document.getElementById("taboola-below-article-thumbnails")
var distance = elem.getBoundingClientRect();
var distance = elem.getBoundingClientRect();
        console.log('distance', distance)
return (
return (
distance.top >= 0 &&
distance.top <= (window.innerHeight || document.documentElement.clientHeight)
distance.left >= 0 &&
distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
distance.right <= (window.innerWidth || document.documentElement.clientWidth)
);
);
};
};


window.addEventListener("scroll", function(){
window.addEventListener("scroll", function(){
     console.log('scrolling')
     // console.log('scrolling')
     if (isInViewport()) {
     if (document.getElementById("IL_INSEARCH") && document.getElementById("taboola-below-article-thumbnails")){
        console.log('it is in viewport!')
      if (feedIsInViewport()) {
    } else {
          // console.log('it is in viewport!')
        console.log('it is not in viewport')
          var il_fixed= $("#IL_INSEARCH");
          il_fixed.addClass('displaynone');
      } else {
          // console.log('it is not in viewport')
          var il_fixed = $("#IL_INSEARCH");
          il_fixed.removeClass('displaynone');
      }
     }
     }
})
})
/*
$(window).scroll(function () {
    console.log('scrolling')
    if (isInViewport($('#taboola-below-article-thumbnails'))) {
        console.log('it is in viewport!')
    } else {
        console.log('it is not in viewport')
    }
});
*/
*/
window.addEventListener("load", function(){
var positionAdDivs= function () {
  // console.log('version 2.7')
  var fixed = $("#IL_INSEARCH");
 
  var fixed_position = $("#IL_INSEARCH").offset().top;
  var fixed_height = $("#IL_INSEARCH").height();
  var toCross = $("#taboola-below-article-thumbnails")
  var toCross_position = $("#taboola-below-article-thumbnails").offset().top;
  var toCross_height = $("#taboola-below-article-thumbnails").height();
/*
  console.log('fixed_position', fixed_position)
  console.log('fixed_height', fixed_height)
  console.log('toCross_position', toCross_position)
  console.log('toCross_height', toCross_height)
*/
  if (fixed_position + fixed_height  < toCross_position) {
    // console.log('fixed_position', fixed_position)
  } else if (fixed_position > toCross_position + toCross_height) {
    console.log('remove displaynone class')
    console.log('fixed_position', fixed_position)
    console.log('fixed_height', fixed_height)
    console.log('toCross_position', toCross_position)
    console.log('toCross_height', toCross_height)
    fixed.removeClass('displaynone');
  } else {
    var fixed_classes = fixed.attr('class')
    if (fixed_classes.includes('displaynone')){
      console.log('already has displaynone class!', 'fixed_position', fixed_position)
    } else {
      console.log('add displaynone class!')
      console.log('fixed_position', fixed_position)
      console.log('fixed_height', fixed_height)
      console.log('toCross_position', toCross_position)
      console.log('toCross_height', toCross_height)
      fixed.addClass('displaynone');
    }
  }
  /*
  if (fixed_position + fixed_height  < toCross_position) {
    var fixed_classes = fixed.attr('class')
    console.log('fixed_classes', fixed_classes)
    if (fixed_classes.includes('displaynone')){
      console.log('remove displaynone class!')
      fixed.removeClass('displaynone')
    } else {
      console.log('already removed displaynone class')
    }
 
  } else {
    var fixed_classes = fixed.attr('class')
    console.log('fixed_classes', fixed_classes)
   
    if (fixed_classes.includes('displaynone')){
      console.log('already has displaynone class')
    } else {
      console.log('add displaynone class!')
      fixed.addClass('displaynone')
    }
  }
  */
 
};
// if fixed_position is Not found, do nothing
if (!$("#IL_INSEARCH").offset()){
// otherwise start the interval
} else {
  setInterval(positionAdDivs, 200);
}
});

Latest revision as of 13:24, 29 January 2021

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

// Scripts to use when viewing articles
/* if (mw.config.get('wgIsArticle') || window.location.href.indexOf('action=submit') > -1 || mw.config.get('wgNamespaceNumber') == -1) {
    mw.loader.load( '/index.php?title=MediaWiki:CollapsibleTables.js&action=raw&ctype=text/javascript' );
}
*/

// hide il_fixed when it overlaps with feed
/* 
var feedIsInViewport = function () {
        // console.log('version 1.0')
        var elem = document.getElementById("taboola-below-article-thumbnails")
	var distance = elem.getBoundingClientRect();
	return (
		distance.top <= (window.innerHeight || document.documentElement.clientHeight)
	);
};

window.addEventListener("scroll", function(){
    // console.log('scrolling')
    if (document.getElementById("IL_INSEARCH") && document.getElementById("taboola-below-article-thumbnails")){
      if (feedIsInViewport()) {
          // console.log('it is in viewport!')
          var il_fixed= $("#IL_INSEARCH");
          il_fixed.addClass('displaynone');
      } else {
          // console.log('it is not in viewport')
          var il_fixed = $("#IL_INSEARCH");
          il_fixed.removeClass('displaynone');
      }
    }
})
*/