MediaWiki:Common.js/sitenotice.js

// ================================================================== // Added SiteNotice Functionality // // Functions: //  * Moves the dismiss link into the SiteNotice table. //  * Saves the show/hide status of the SiteNotice in a cookie. //  * Automatically expands the SiteNotice when the ID is updated. // ==================================================================

var dCookieName = "dismissSiteNotice="; var msgClose = "dismiss";

var hCookieName = "hideSiteNotice="; var hCookiePos = document.cookie.indexOf(hCookieName); var hCookieValue = ""; function editSiteNotice { var snbox = document.getElementById('mw-dismissable-notice'); if (snbox != null){ if (hCookiePos > -1) { hCookiePos = hCookiePos + hCookieName.length; var hideEndPos = document.cookie.indexOf(";", hCookiePos); if (hideEndPos > -1) { hCookieValue = document.cookie.substring(hCookiePos, hideEndPos); } else { hCookieValue = document.cookie.substring(hCookiePos); }       }        var newLink = document.createElement('a'); newLink.setAttribute('href', "javascript:dismissNotice;"); newLink.setAttribute('title', 'Dismiss this notice.'); newLink.innerHTML = msgClose;

var newSpan = document.createElement('span'); newSpan.id = 'siteNoticeDismiss'; newSpan.appendChild(document.createTextNode(' [')); newSpan.appendChild(newLink); newSpan.appendChild(document.createTextNode(']'));

var hideLink = document.getElementById( "collapseButton" + "0" ); hideLink.href = "javascript:hideSiteNotice;" hideLink.parentNode.style.width = "12em"; hideLink.parentNode.appendChild(newSpan);

if (hCookieValue != siteNoticeID && hideLink.innerHTML == "show") { collapseTable(0); }       if (hCookieValue == siteNoticeID && hideLink.innerHTML == "hide") { collapseTable(0); }   } }

function hideSiteNotice { var hideLink = document.getElementById( "collapseButton" + "0" ); var date = new Date; if (hideLink.innerHTML == 'hide'){ date.setTime(date.getTime + 30*86400*1000); } else { date.setTime(date.getTime - 30*86400*1000); }   document.cookie = hCookieName + siteNoticeID + "; expires="+date.toGMTString + "; path=/"; collapseTable(0); }

addOnloadHook(editSiteNotice);

// ================================================================== // End of Added SiteNotice Functionality // ==================================================================