MediaWiki:Common.js: Difference between revisions

From DM Live - the Depeche Mode live encyclopedia for the masses
Jump to navigationJump to search
No edit summary
(Undo revision 52871 by Majora101 (talk))
Tag: Undo
 
(29 intermediate revisions by the same user not shown)
Line 2: Line 2:
/* 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. */


if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
    // Start of custom navbar js
{
(function($) { // Begin jQuery
  var script  = document.createElement( 'script' );
  $(function() { // DOM ready
  script.src  = '/w/index.php?title=User:Poke/CollapsibleTables.js&action=raw&ctype=text/javascript&smaxage=18000&action=raw&maxage=18000';
    // If a link has a dropdown, add sub menu toggle.
   script.type = 'text/javascript';
    $('nav ul li a:not(:only-child)').click(function(e) {
   document.getElementsByTagName( 'head' )[0].appendChild( script );
      $(this).siblings('.nav-dropdown').toggle();
      // Close one dropdown when selecting another
      $('.nav-dropdown').not($(this).siblings()).hide();
      e.stopPropagation();
    });
    // Clicking away from dropdown will remove the dropdown class
    $('html').click(function() {
      $('.nav-dropdown').hide();
    });
    // Toggle open and close nav styles on click
    $('#nav-toggle').click(function() {
      $('nav ul').slideToggle();
    });
    // Hamburger to X toggle
    $('#nav-toggle').on('click', function() {
      this.classList.toggle('active');
    });
   }); // end DOM ready
})(jQuery); // end jQuery
    // End of custom navbar
 
// Collapsible menus...
$(function() {
  var b = $("#toggle-button");
   var w = $("#toggle");
  var l = $("#toggle-content");
    
    
   addOnloadHook(function () { new CollapsibleTables(); });
   w.height(l.outerHeight(true));
}
 
function formatDate(t)
{
var month = new Array();
month[0] = 'January';
month[1] = 'February';
month[2] = 'March';
month[3] = 'April';
month[4] = 'May';
month[5] = 'June';
month[6] = 'July';
month[7] = 'August';
month[8] = 'September';
month[9] = 'October';
month[10] = 'November';
month[11] = 'December';
y = t.getUTCFullYear();
M = t.getUTCMonth();
D = t.getUTCDate();
h = t.getUTCHours();
m = t.getUTCMinutes();
s = t.getUTCSeconds();
if (h > 0 || m > 0 || s > 0)
{
hms = '';
if (s > 10)
hms = ':' + s;
else if (s > 0)
hms = ':0' + s;
if (m > 10)
hms = ':' + m + hms;
else if (m > 0)
hms = ':0' + m + hms;
if (h > 12)
hms = (h - 12) + hms + ' PM';
else if (h > 0)
hms = h + hms + ' AM';
else
hms = '12' + hms + ' AM';
return hms + ', ' + month[M] + ' ' + D + ', ' + y;
} else {
return month[M] + ' ' + D + ', ' + y;
}
}
 
function formatTime(h, m, s)
{
var o = '';
if (h != 1)
{
o = h + ' hours ';
} else {
o = '1 hour ';
}
if (m != 1)
{
o += m + ' minutes ';
} else {
o += '1 minute ';
}
if (s != 1)
{
o += s + ' seconds';
} else {
o += '1 second';
}
return o;
}
 
function updateClocks()
{
var t = new Date();
 
setTimeout(updateClocks, 1000);
D = t.getUTCDate();
M = t.getUTCMonth();
y = t.getUTCFullYear();
h = t.getUTCHours();
m = t.getUTCMinutes();
s = t.getUTCSeconds();
 
t = Date.UTC(y, M, D, h, m, s);
 
t = (T - t) / 1000;
if (t < 0 && t > -86400 && (h > 0 || m > 0 || s > 0))
{
document.getElementById('countdown-big').innerHTML = 'Today';
document.getElementById('countdown-small').innerHTML = '';
document.getElementById('countdown-target').innerHTML = 'is ' + formatDate(new Date(T + tzOffset)) + ' ' + tz;
return;
} else if (t < 0) {
document.getElementById('countdown-big').innerHTML = 'Past';
document.getElementById('countdown-target').innerHTML = formatDate(new Date(T + tzOffset)) + ' ' + tz;
return;
}
D = Math.floor(t / 86400.0);
h = Math.floor(t % 86400.0 / 3600.0);
m = Math.floor(t % 3600.0 / 60.0);
s = Math.floor(t % 60.0)
 
if (D == 1)
{
document.getElementById('countdown-big').innerHTML = '1 day';
} else if (D == 0) {
document.getElementById('countdown-big').innerHTML = '';
} else {
document.getElementById('countdown-big').innerHTML = D + ' days';
}
document.getElementById('countdown-small').innerHTML = formatTime(h, m, s);
}
 
function startCountdown()
{
document.getElementById('countdown-target').innerHTML = 'to ' + formatDate(new Date(T + tzOffset)) + ' ' + tz;
document.getElementById('countdown').style.display = 'block';
updateClocks();
}
 
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
 
});
 
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}


  b.click(function() {
 
    if(w.hasClass('open')) {
      w.removeClass('open');
      w.height(0);
    } else {
      w.addClass('open');
      w.height(l.outerHeight(true));
    }
 
  });
});
});
// This will add an [edit] link at the top of all pages except preview pages and the main page
// by User:Pile0nades (blatantly stolen from Wikipedia by User:The dark lord trombonator; "Sampled" by Majora101 for use with DM Live
// Add an [edit] link to pages
addOnloadHook(function () {
// if this is preview page or generated page, stop
if(
document.getElementById("wikiPreview") ||
document.getElementById("histlegend‎") ||
document.getElementById("difference‎") ||
document.getElementById("watchdetails") ||
document.getElementById("ca-viewsource") ||
window.location.href.indexOf("/wiki/Special:") != -1
) {
if(window.location.href.indexOf("&action=edit&section=0") != -1) {
document.getElementById("wpSummary").value = "/* Intro */ ";
}
return;
};
// get the page title
var pageTitle = wgPageName;
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsection">[<a href="/w/index.php?title='+encodeURIComponent(pageTitle)+'&action=edit&section=0" title="Edit first section: '+pageTitle+'">edit top of page</a>]</div>';
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
});
// This will add an [+] (new section) link at the top of all pages except preview pages and the main page... because some people are having trouble finding it or something
// Roughly edited from the above section by User:The dark lord trombonator; "Sampled" by Majora101 for use with DM Live
// Add an [+] link to pages
addOnloadHook(function () {
// if this is preview page or generated page, stop
if(
document.getElementById("wikiPreview") ||
document.getElementById("histlegend‎") ||
document.getElementById("difference‎") ||
document.getElementById("watchdetails") ||
document.getElementById("ca-viewsource") ||
document.getElementById("article") ||
window.location.href.indexOf("/wiki/Special:") != -1
) {
if(window.location.href.indexOf("&action=edit&section=0") != -1) {
document.getElementById("wpSummary").value = "/* Intro */ ";
}
return;
};
// get the page title
var pageTitle = wgPageName;
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '<div class="editsectionnew">[<a href="/w/index.php?title='+encodeURIComponent(pageTitle)+'&action=edit&section=new" title="Start new section: '+pageTitle+'">+</a>]</div>';
// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
});
// Checks if page has the parts of a countdown, then starts it if it does
if(document.getElementById('countdown') && document.getElementById('countdown-big') && document.getElementById('countdown-small') && document.getElementById('countdown-target')) {
    startCountdown();
}
/* </pre> */

Latest revision as of 03:44, 30 March 2024

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

    // Start of custom navbar js
(function($) { // Begin jQuery
  $(function() { // DOM ready
    // If a link has a dropdown, add sub menu toggle.
    $('nav ul li a:not(:only-child)').click(function(e) {
      $(this).siblings('.nav-dropdown').toggle();
      // Close one dropdown when selecting another
      $('.nav-dropdown').not($(this).siblings()).hide();
      e.stopPropagation();
    });
    // Clicking away from dropdown will remove the dropdown class
    $('html').click(function() {
      $('.nav-dropdown').hide();
    });
    // Toggle open and close nav styles on click
    $('#nav-toggle').click(function() {
      $('nav ul').slideToggle();
    });
    // Hamburger to X toggle
    $('#nav-toggle').on('click', function() {
      this.classList.toggle('active');
    });
  }); // end DOM ready
})(jQuery); // end jQuery
    // End of custom navbar

// Collapsible menus...
$(function() {
  var b = $("#toggle-button");
  var w = $("#toggle");
  var l = $("#toggle-content");
  
  w.height(l.outerHeight(true));

  b.click(function() {
  
    if(w.hasClass('open')) {
      w.removeClass('open');
      w.height(0);
    } else {
      w.addClass('open');
      w.height(l.outerHeight(true));
    }
  
  });
});