MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
do you not like let
(Shift weird crafting problem from Common.css to Common.js)
(do you not like let)
 
(21 intermediate revisions by 3 users not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */


// Fency hovers for recipes
// Even More fancy hovers for recipes
$(function() {
$(function () {
// Tooltip only Text
  // Tooltip only Text
    $('.masterTooltip').hover(function(){
  $('.masterTooltip').hover(
        // Hover over code
    function () {
        var title = $(this).attr('title');
      // Hide non-JS
        $(this).data('tipText', title).removeAttr('title');
      $(this).data('tipText', $(this).attr('title')).removeAttr('title');
        $('<p class="tooltip">' + title + '</p>')
 
        //.text(title + "\n1")
      //Custom Tooltip
        .appendTo('body')
      var title = $(this).attr('data-title');
        .show();
      var lore = $(this).attr('data-lore');
     }, function() {
      var tooltip = '<p class="tooltip">' + parseFormatCodes(title);
        // Hover out code
      if (lore) tooltip += '<br><span class="lore format-5">' + parseFormatCodes(lore) + '</span>';
        $(this).attr('title', $(this).data('tipText'));
      tooltip += '</p>';
        $('.tooltip').remove();
      $(tooltip).appendTo('body');
     }).mousemove(function(e) {
     },
         var mousex = e.pageX + 20; //Get X coordinates
    function () {
         var mousey = e.pageY - 40; //Get Y coordinates
      // Hover out
         $('.tooltip').css({ top: mousey, left: mousex });
      $('.tooltip').remove();
     }).mousemove(
      function(e) {
         var mousex = e.pageX + 20;
         var mousey = e.pageY - 40;
         var tooltip = $('.tooltip');
        if (mousex + tooltip.width() >= $(window).width()) mousex -= tooltip.width() + 40;
        tooltip.css({
          top: mousey,
          left: mousex,
        });
      });
  // Hide the stupid empty newlines after crafting grids
  $('.crafting + p br:only-child').parent().hide();
 
 
  //Code For books
  $('.pageactive').each(function (_, page) {
    setupPage($(page));
  });
  $('.book_leftarrow').click(function () {
    setupPage($(this).siblings('.pageactive').removeClass('pageactive').prev());
  });
  $('.book_rightarrow').click(function () {
    setupPage($(this).siblings('.pageactive').removeClass('pageactive').next());
  });
 
 
  //Code for Cycling
  $('.cyclist > :not(:first-child)').hide();
  setInterval(function() {
    if (!!$('.cyclist').filter(function() { return $(this).is(":hover"); }).length) return;
    $('.cyclist > :not(:hidden)').hide().each(function() {
      var elem = $(this);
      elem.next().show();
      if (elem.is(':last-child')) elem.siblings().first().show();
     });
     });
  $('.crafting + p br:only-child').parent().hide();
  }, 2000);
});
});
function parseFormatCodes (text) {
  var spans = 0;
  var res = '';
  for (var i = 0; i < text.length; i++) {
    if (text[i] == '\\') {
      res += text[i+1];
      i++;
    } else if (/&[0-9a-fl-o]/.test(text.substring(i,i+2))) {
      res += '<span class="format-' + text[i+1] + '">';
      spans++;
      i++;
    } else if (text.substring(i,i+2) == '&r') {
      res += '</span>'.repeat(spans);
      spans = 0;
      i++;
    } else if (/&#[0-9A-Fa-f]{6}/.test(text.substring(i,i+8))) {
      res += '<span style="color: ' + text.substring(i+1,i+8) + '">';
      spans++;
      i += 7;
    } else if (text[i] == '/') {
      res += '<br>';
    } else {
      res += text[i];
    }
  }
  return res + '</span>'.repeat(spans);
}
function setupPage (active) {
  active.addClass('pageactive');
  var index = active.index();
  var length = active.siblings().length - 2;
  active.siblings('.book_pagenum').text('Page ' + index + ' of ' + length);
  active.siblings('.book_leftarrow, .book_rightarrow').show();
  if (index == 1) {
    active.siblings('.book_leftarrow').hide();
  }
  if (index == length) {
    active.siblings('.book_rightarrow').hide();
  }
}
184

edits

Navigation menu