User:Jeremyb/geonotice.js

(function { var notices = {

DCLuceLunder: { begin: '11 July 2013 00:00 UTC', end: '20 July 2013 12:00 UTC', corners : [ [39.8, -76], [37.5, -78.3] ], text: "The Smithsonian American Art Museum invites you to an American art-themed edit-a-thon—with a special tour of the Luce Foundation Center for American Art and the Lunder Conservation Center—on Friday, July 19. Please RSVP today!" },

NewEngland2013update: {  begin: '9 July 2013 00:00 UTC', end: '21 July 2013 00:00 UTC', corners: [ [45,-67], [35,-78.62] ], text: "You are invited to the 2nd Annual Wikimedia New England General Meeting, on 20 July 2013 in Boston! We will be talking about the future of the chapter, including GLAM, Wiki Loves Monuments, and where we want to take our chapter in the future." },

LondonICEJuly13: {  begin: '28 June 2013 00:00 UTC', end: '19 July 2013 12:00 UTC', corners:[ [54,-2], [50, 2] ], text: "You are invited to an editathon at the Institution of Civil Engineers, in London, on 19 July 2013. See GLAM/ICE." },

UK130708: /* last 6 chars of ID is date of last amendment in YYMMDD format - change this if making major amendment or adding a meetup; leave alone if minor amendment or removing a meetup */ {  begin: '07 July 2013 12:00 UTC', end: '28 July 2013 16:00 UTC', /* set this to date of last meetup shown */ corners:[ [60,-9], [50, 2] ], text: "Interested in having a chat with fellow Wikipedians? There are forthcoming meetups in: Oxford, 14 July; London, 14 July; Chester, 21 July; and Bristol, 28 July!" /* try to limit this to four meetups, no more than one per town/city, and no more than four weeks in advance; shorten month names to three letters if four meetups are shown */ }

// DO NOT COPY THIS PART...

// COPY STARTING HERE!

/******************************************* *            End of list. *          Edit only above! * * Format is: * * ID: * { begin: 'date', *  end: 'date', *  corners: [ [lat,lon], [lat,lon] ], *  text: 'message' * } * * There also is an option to use country instead of corners. For example: * ID: * { begin: 'date', *  end: 'date', *  country: 'US', *  text: 'message' * } * * See http://dev.maxmind.com/geoip/legacy/codes/iso3166 for full list of country codes * * * There should be commas between the notices, but not after the last one. BE SURE TO ESCAPE YOUR APOSTROPHES (put a backslash in front of it, like this: \')! * Use link format for internal links, so that they work properly on the other projects where the geonotice is displayed. * *******************************************/ };

function geoWikiLinker (str, page, text) { text = text || page; return mw.html.element(   'a', {      href: mw.util.getUrl( page ),      title: page    }, text  ); }

function addGeonoticeCss { mw.util.addCSS( [   '#watchlist-message .geonotice {',      'width:98%;',      'background:transparent;',      'text-align:left;',      'line-height:1.8em;',    '}',    '#watchlist-message .geonotice span {',      'font-size:144.5%;',    '}',    '#watchlist-message .geonotice small {',      'font-style:italic;',      'margin-left:.5em;',    '}',    '#watchlist-message .geonotice small a::before {',      'content: "[";',    '}',    '#watchlist-message .geonotice small a::after {',      'content: "]";',    '}'  ].join( ' ' ) ); }

function hideGeonotice(e) { e.preventDefault;

var parentId = $(this).closest('li').attr('id'); var date = new Date;

date.setTime(date.getTime+8640000000);

var expireDate = date.toGMTString;

document.cookie = 'hide' + parentId + '=1; expires=' + expireDate + ';path=/'; $( '#' + parentId ).hide; $( '#geonotice-hr' ).hide;

return false; }

var firstnotice = true; var regexForInternalLinks = /\[\[([^{|}\[\]\n]+)(?:\|(.*?))?\]\]/g;

function displayGeonotice(notice) { var geonoticeText = notice.text.replace( regexForInternalLinks, geoWikiLinker );

if (firstnotice) { firstnotice = false; $('#watchlist-message').prepend(     $( ' ' ).attr({ 'id' : 'geonotice-hr' })    ); addGeonoticeCss; }

$('#watchlist-message').prepend(   $('')      .attr({ 'class' : 'geonotice plainlinks', 'id' : 'geonotice' + notice.id     })      .append( $( ' ' )         .html( geonoticeText ) )     .append( $( ' ' ) .append(         $('')            .text( 'hide' )            .click( hideGeonotice )            .attr({ 'href' : '#' })         ) ) ); }

if ( Geo !== undefined && notices ) { var now = new Date, id, notice, minlat, maxlat, minlon, maxlon, startNotice, endNotice;

for (id in notices) { if (!document.cookie.match('hidegeonotice'+id+'=1')) {

notice = notices[id]; notice.id = id;

if (!notice || !notice.begin || !notice.end) { continue; }

startNotice = Date.parse(notice.begin); endNotice = Date.parse(notice.end);

if ( now.getTime > startNotice &&       now.getTime < endNotice ) { if (notice.country && Geo.country === notice.country) { displayGeonotice(notice); } else { if (notice.corners) { minlat = Math.min(notice.corners[0][0], notice.corners[1][0]); maxlat = Math.max(notice.corners[0][0], notice.corners[1][0]); minlon = Math.min(notice.corners[0][1], notice.corners[1][1]); maxlon = Math.max(notice.corners[0][1], notice.corners[1][1]);

if ( minlat < Geo.lat && Geo.lat < maxlat && minlon < Geo.lon && Geo.lon < maxlon ) { displayGeonotice(notice); }           }          }      }    }  } } });