Difference between revisions of "MediaWiki:Common.js"

From Free Software Directory
Jump to: navigation, search
(+dynamic site-wide rt clock)
m (*replace GMT with UTC for clarity)
Line 94: Line 94:
 
     var UTCdate = ts.toUTCString();
 
     var UTCdate = ts.toUTCString();
 
     EDTtimersBlnk = !EDTtimersBlnk;
 
     EDTtimersBlnk = !EDTtimersBlnk;
     if(EDTtimersBlnk == false) cdate = cdate.replace(/[:\.]/gi,' ');
+
     if(EDTtimersBlnk == false) cdate = cdate.replace(/[:\.]/gi, ' ');
 +
    UTCdate = UTCdate.replace('GMT', 'UTC');
 
     timers.html(cdate);
 
     timers.html(cdate);
 
     timers.attr('title', UTCdate);
 
     timers.attr('title', UTCdate);
Line 105: Line 106:
 
   var EDTtimersBlnk = true;
 
   var EDTtimersBlnk = true;
 
   if(EDTtimers.length >= 0) {
 
   if(EDTtimers.length >= 0) {
     window.setInterval(function(){updateTimers(EDTtimers, "en-US", "America/New_York");}, 1000);
+
     window.setInterval(function(){updateTimers(EDTtimers, "UTC", "America/New_York");}, 1000);
 
   } else {
 
   } else {
 
     EDTtimers = null;
 
     EDTtimers = null;

Revision as of 14:22, 10 April 2020

// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
/*    
@licstart  The following is the entire license notice for the 
JavaScript code in this page.

Copyright (C) 2020 Free Software Foundation

The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.  The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.   


@licend  The above is the entire license notice
for the JavaScript code in this page.
*/

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

/* Active Backlog: fix. "Fix search results, so that template data doesn't get dumped..." */
function fixSrTmplBug() {
 function iskSearchCurPage() {
   return window.location.href.match(/\w+\/wiki\?search=\w+/i) !== null;
 }
 function detectSrTmplBug(srcontent) {
   var containsMeta = srcontent.match(/.*\|.*=.*/i);
   var containsRedi = srcontent.match(/#REDIRECT .*/i);
   var containsTmpl = srcontent.match(/.*(\{\{|\}\}).*/i);
   if(containsMeta !== null) return 1;
   else if(containsRedi !== null) return 2;
   else if(containsTmpl !== null) return 3;
   else return 0;
 }
 function correctSrTmplBug(i, el) {
   el = $(el);
   var tres = detectSrTmplBug(el.html());
   switch(tres) {
    case 0: break;
    case 1:
    case 3: el.html('(structured)'); 
     break;
    case 2: el.html('(alias)');
     break;
    default: el.hide();
   }
   el = null;
   tres = null;
   return;
 }

  if(iskSearchCurPage() === false) return false;
  else {
   var sresults = $('.searchresult');
   if(sresults.length > 0) {
     sresults.each(correctSrTmplBug);
     sresults = null;
   }
  }
  return true;
};

/* Active Backlog: fix. ""Preview" button does not work for Template:Entry. It shows the unedited version"... */
function fixEntryPrevBug() {
  function iskEntryRawEditCurPage() {
     var txtArea = $("textarea#wpTextbox1");
     if(txtArea === null || txtArea.length == 0) return false;
    
     return txtArea.html().match(/.*{\{\Entryw*(|w*)+/i) !== null;
   }
  function hidePreviewButton() {$("input#wpPreview").hide();}
  
  if(iskEntryRawEditCurPage() === false) return false;
  else hidePreviewButton();
  
  return true;
};

/* Active Backlog: fix. "Countdown timer / JavaScript enhancement (TOP PRIORITY)" */
function dynTimers() {
  function updateTimers(timers, loc, tz) {
    var ts = new Date();
    var opts = { timeZone:tz, weekday: 'long', hour: '2-digit', minute: '2-digit', second: '2-digit' };

    var cdate = ts.toLocaleTimeString(locales=loc, opts);
    var UTCdate = ts.toUTCString();
    EDTtimersBlnk = !EDTtimersBlnk;
    if(EDTtimersBlnk == false) cdate = cdate.replace(/[:\.]/gi, ' ');
    UTCdate = UTCdate.replace('GMT', 'UTC');
    timers.html(cdate);
    timers.attr('title', UTCdate);
    cdate = null;
    UTCdate = null;
    ts = null;
  }

  var EDTtimers = $('.currentEDT');
  var EDTtimersBlnk = true;
  if(EDTtimers.length >= 0) {
    window.setInterval(function(){updateTimers(EDTtimers, "UTC", "America/New_York");}, 1000);
  } else {
    EDTtimers = null;
    EDTtimersBlnk = null;
  }
}

$(document).ready(function(){fixSrTmplBug();fixEntryPrevBug();dynTimers();});
// @license-end


Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the page “GNU Free Documentation License”.

The copyright and license notices on this page only apply to the text on this page. Any software or copyright-licenses or other similar notices described in this text has its own copyright notice and license, which can usually be found in the distribution or license text itself.