MediaWiki:Common.js/Main Page

From Wikinews, the free news source you can write!
Jump to navigation Jump to search

//

 1 // This is the javascript that is executed only when viewing the [[Main Page]].
 2 
 3 /* add class for autoconfirmed users, so [edit lead] only appears to those who can edit them */ 
 4 $(function() {
 5 if (!mw.config.get('wgUserGroups', []).join('').indexOf('autoconfirmed') === -1) {
 6     try {
 7     document.body.className += " notAutoconfirmed";
 8     } catch (e) {}
 9 }
10 });
11 
12 /*
13 function dieWhitespaceDie () {
14  try {
15  //this is for us low res folks
16  //hides some of the members of the dpl list on main page, if list too long.
17  //this is not cross browser (yet). IE uses different method names for height
18  if (mw.config.get('wgPageName') !== "Main_Page" || mw.config.get('wgAction') !== "view") {return;}
19  var firstLead = document.getElementById('mf-l_table_numb4'); //switch to last after height:100% hack.
20  var excessWS = (firstLead.parentNode.clientHeight - firstLead.clientHeight);
21  var DPLList = document.getElementById('MainPage_latest_news_text').getElementsByTagName('ul')[0];
22  var DPL = DPLList.getElementsByTagName('li');
23  var DPLlength = DPL.length;
24  //10 is just emergancy cut off. should stop way before that.
25  if (DPLlength < 10) {throw new Error("Latest news should have more items...");}
26  var curItem, prev = -1;
27  for (var i = 1; i < 10;i++) { //note, start at 1.
28   curItem = DPL[DPLlength - i];
29   prev = excessWS;
30   excessWS -= curItem.clientHeight;
31   if (excessWS < 5 || prev === excessWS)  { break;}
32   DPLList.removeChild(curItem); //this should perhaps use a range, so only a single re-draw.
33   if (prev === (firstLead.parentNode.clientHeight - firstLead.clientHeight)) {break;}
34  }
35  } catch (e) {}
36  
37 }
38 $(dieWhitespaceDie);
39 */
40 //