MediaWiki:MenuChanges.js

/* ============== MENU CHANGES ======================================== author:       Petr Kajzar User:Slepi description:  personal menu and sidebar changes ====================================================================

/* ============== Personal menu ==================================== */

// FUNCTION ADDING SANDBOX $(function { if (mw.config.get("wgUserName") != null)    mw.util.addPortletLink('p-personal', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php?title=User:' + mw.config.get("wgUserName") + '/Sandbox', 'My sandbox', 'pt-piskoviste', 'Place, where I can experiment', 'a', document.getElementById('pt-preferences')); });

/* ================== Sidebar ====================================== */ // add links "User rights", "Check IP address" and "Patrol rights" to toolbox menu // only for head editors and administrators on user pages and discussion pages $(function { if($.inArray(mw.config.get("wgNamespaceNumber"), [2,3]) == -1) return;

wgTitleAa = new Array; wgTitleAa = mw.config.get("wgTitle").split('/'); urPath = mw.config.get("wgServer") + mw.config.get("wgScript") + '/';

if(mwGetUserRight("sysop")) { mw.util.addPortletLink('p-tb', urPath + "Special:Userrights/" + wgTitleAa[0], 'User rights', 't-userrights', 'Set user rights for this user'); }

if(mwGetUserRight("bureaucrat")) { mw.util.addPortletLink('p-tb', urPath + "Special:CheckUser?user=" + wgTitle, 'Check IP address', 't-ipcheckuser', 'Check IP address of this user'); }

});

// FUNCTION ADDING LINKS TO SIDEBAR $(function { // Category History  if (mw.config.get("wgUserName") != null && mw.config.get("wgCanonicalNamespace") == "Category" && mw.config.get("wgTitle")) {    mw.util.addPortletLink('p-tb', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php/Special:CategoryHistory/'+mw.config.get("wgTitle"), 'Category history', 't-cathistory', 'History of changes of the articles in this category');  }

// recent changes mw.util.addPortletLink('p-tb', mw.config.get("wgServer") + mw.config.get("wgScriptPath") + '/index.php?title=Special:RecentChanges', 'Recent changes', 'pt-recent', 'The list of recent changes at WikiLectures', '', document.getElementById("t-specialpages"));

});

// FUNCTION ADDING LIST OF RELATED PORTALS AND EXAM QUESTIONS if (mw.config.get("wgNamespaceNumber") == 0 && mw.config.get("wgTitle") != mw.config.get("wgMainPageTitle") && mw.config.get("wgAction") != "markpatrolled") { jsonapi = mw.config.get("wgServer") + "/api.php?action=query&list=backlinks&bltitle=" + wgPageName + "&blnamespace=100&format=json"; $.getJSON(jsonapi).done(function(data){     // response      var pocetOtazek = 0; // exam questins      var pocetSkutPortalu = 0; // number of portals without exam questions      pocetPortalu = data.query.backlinks.length;      if(pocetPortalu == 0) return; // do not continue without portals      for(i=0;i<pocetPortalu;i++) {        // portal name        aktPortal = data.query.backlinks[i].title;        aktPortalNazev = aktPortal.replace("Portal:", "");        // test to         var zjisteniOtazek = new RegExp("(exam|Exam|questions|Questions)");        if(zjisteniOtazek.test(aktPortalNazev)) {          idPortalu = "p-rel-exam";          pocetOtazek++;        } else {          idPortalu = "p-rel-portals";          pocetSkutPortalu++;        }        // intert portal to menu        $(function{ mw.util.addPortletLink(idPortalu, wgServer + wgScript + '/' + aktPortal, aktPortalNazev, , aktPortalNazev, ); });     }      // portal section      if(pocetSkutPortalu > 0) {        $j(document).ready(function { $j("#p-rel-portals").slideDown; });     }      // unfold portal section      $j(document).ready(function { if(document.getElementById("p-rel-portals").className.indexOf("collapsed") != -1) { $j('#mw-panel > div#p-rel-portals').toggleClass('collapsed').toggleClass('expanded').find('div.body').slideToggle('fast'); }     });      // exam quiestions section      if(pocetOtazek>0) {        $j(document).ready(function { $j("#p-rel-exam").slideDown; });     }    }  ); }

// show editorial links to editors $(function{ if(mwGetUserRight("editor")) $("#p-editorial-links").css("display", "block"); });

// FUNCTION FIXES THE SIDEBAR WHEN SCROLLING $j(function { // some variables  var $wind = $j(window),        $element = $j('#mw-panel'),        timer,        highEnough,  // if the window is high enough to show whole sidebar        topPosition = $element.position.top,        headMargin = 0;

// when scrolling, start this $wind.scroll(function {   if (timer) {      clearTimeout(timer);    }

timer = setTimeout(function {     timer = null;      highEnough = (($wind.height - headMargin) > $element.height); // if the window is high enough to show whole sidebar

// when scrolling up and down, fix the sidebar if (($wind.scrollTop >= topPosition) && highEnough && ($wind.scrollLeft == 0)) { $element.css({          position: 'fixed',           top: headMargin        });

// when scrolling left and right, keep the position on the left } else if(($wind.scrollTop >= topPosition) && highEnough && ($wind.scrollLeft != 0)) { $element.css({         position: 'absolute',          top: $wind.scrollTop,          left: 0        });

// normal position under logo } else { $element.css({          position: ,           top:          }); }    }, 15);  }); });

/* ============================== Footer ============================================== */

// FUNCTION ADDING "Share Button" FROM FACEBOOK // to the end of an article // and links to stimulate editors $(function {

// check NS // only main NS, portal or studium guide if (mw.config.get("wgNamespaceNumber") != 0 && mw.config.get("wgNamespaceNumber") != 100 && mw.config.get("wgTitle").indexOf("guide") == -1) return false;

// check main page if (mw.config.get("wgTitle") == mw.config.get("wgMainPageTitle")) return false;

// check action if (mw.config.get("wgAction") != "view") return false;

// create button fbShareButton = document.createElement("div"); fbShareButton.className = "fb_sharebutton"; fbShareButton.id = "fb_likebutton"; document.getElementById("content").appendChild(fbShareButton);

if (document.getElementById("catlinks")) { fbShareButton.parentNode.insertBefore(document.getElementById("catlinks"), fbShareButton.nextSibling); }

fbShareButton.innerHTML = " ";

// script for addthis.com mw.loader.load("http://s7.addthis.com/js/300/addthis_widget.js#pubid=xa-4f3a743e135889bd"); // link to fb and others (AddThis.com) fbShareButton.innerHTML += '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + ' \n' + '';

// link to editations if(mw.config.get("wgNamespaceNumber") == 0) { fbShareButton.innerHTML += ' Join us! If you find this article incomplete, inaccurate or false, correct it! Or tell us about the shortcomings. '; } });

// FOOTER $(function { links = document.createElement("div");  links.id = "myLfFooter";  document.getElementById("footer").appendChild(links);  links.innerHTML = 'WikiLectures, project of the medical faculties network MEFANET</a> • ISSN 1804-9885 • e-mail: info&#64;wikilectures.eu</a>'; });