MediaWiki:Common.js/watchlist.js: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
Undid revision 331956218 by Fran Rogers (talk)
Moving the geonotice code up to its own section, it doesn't seem to really be a part of the regular watchlist-message code. And adding a comment what it is.
Line 1: Line 1:
//<source lang="JavaScript">
//<source lang="JavaScript">
/* Load the geonotices. See [[Wikipedia:Geonotice]]. */
importScriptURI('http://toolserver.org/~para/geoip.fcgi');
addOnloadHook(function() {
  importScriptURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Geonotice.js&action=raw&ctype=text/javascript&maxage=3600');
});


/** Add dismiss buttons to watchlist-message *************************************
/** Add dismiss buttons to watchlist-message *************************************
Line 7: Line 15:
  *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]]
  *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]]
  */
  */
importScriptURI('http://toolserver.org/~para/geoip.fcgi');
addOnloadHook(function() { importScriptURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Geonotice.js&action=raw&ctype=text/javascript&maxage=3600'); });


function addDismissButton() {
function addDismissButton() {
Line 48: Line 53:
}
}
addOnloadHook(addDismissButton);
addOnloadHook(addDismissButton);


//</source>
//</source>

Revision as of 01:24, 5 February 2010

//<source lang="JavaScript">


/* Load the geonotices. See [[Wikipedia:Geonotice]]. */
importScriptURI('http://toolserver.org/~para/geoip.fcgi');
addOnloadHook(function() {
  importScriptURI('http://en.wikipedia.org/w/index.php?title=MediaWiki:Geonotice.js&action=raw&ctype=text/javascript&maxage=3600');
});


/** Add dismiss buttons to watchlist-message *************************************
 *
 *  Description: Allows multiple dismiss buttons on [[MediaWiki:Watchlist-details]] with bump-able cookie IDs.
 *  Note: HTML is backwards compatible with old version, new version ignores old syntax, except for dismissed IDs.
 *  Maintainers: [[User:Ruud Koot|Ruud Koot]], [[User:MZMcBride|MZMcBride]]
 */

function addDismissButton() {
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document
  var watchItems = getElementsByClassName(docobj, 'div', 'watchlist-message');
  if(watchItems.length == 0) return
  for(var i=0;i<watchItems.length;i++) {
    var watchlistCookieID = parseInt(watchItems[i].className.replace(/.*cookie\-ID\_(\d*).*/ig,'$1'));
    if(isNaN(watchlistCookieID)) continue
    if(document.cookie.indexOf('hidewatchlistmessage-' + watchlistCookieID + '=yes') != -1) {
      watchItems[i].style.display = 'none';
      continue;
    }
    var Button     = document.createElement('span');
    var ButtonLink = document.createElement('a');
    var ButtonText = document.createTextNode('dismiss');

    ButtonLink.setAttribute('id','dismissButton');
    ButtonLink.setAttribute('href','javascript:dismissWatchlistMessage(' + i + ',' + watchlistCookieID + ')');
    ButtonLink.setAttribute('title','Hide this message');
    ButtonLink.appendChild(ButtonText);

    Button.appendChild(document.createTextNode('['));
    Button.appendChild(ButtonLink);
    Button.appendChild(document.createTextNode(']'));
    watchItems[i].appendChild(Button);
  }
}

function dismissWatchlistMessage(num,cid) {
  var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document
  var watchItems = getElementsByClassName(docobj, 'div', 'watchlist-message');
  watchItems[num].style.display = 'none';

  var e = new Date();
  e.setTime( e.getTime() + (4*7*24*60*60*1000) );
  document.cookie = 'hidewatchlistmessage-' + cid + '=yes; expires=' + e.toGMTString() + '; path=/';
}
addOnloadHook(addDismissButton);


//</source>