User:Atelaes/InlineBox.js

// /**

Used in conjunction with. Adds a button which can show and hide example quotations, similar to the translation bars.



mw.util.addCSS('ul.hidden{display:none;}'); var InlineShow = 'show quotations'; var InlineHide = 'hide quotations';

function setupInlineBox {  var indexInlineBox = 0; for(           var i=0;            InlineBox = document.getElementsByTagName("span")[i];            i++        ) { if (InlineBox.className == "InlineBox") { if (InlineBox.parentNode.nodeName == "LI") { InlineParentDef = InlineBox.parentNode; for(                   var j=0;                    j < InlineParentDef.childNodes.length;                    j++                   )  { if (InlineParentDef.childNodes[j].nodeName == "UL") { var SubordinateQuote = InlineParentDef.childNodes[j]; SubordinateQuote.setAttribute('id', 'SubordinateQuote' + indexInlineBox); InlineBox.setAttribute('id', 'InlineBox' + indexInlineBox); InlineBox.setAttribute('style', 'font-size:0.65em'); InlineBox.innerHTML = '['; InlineBox.appendChild(document.createElement("a")); if (true) {  //Just an empty condition, to add user prefs or perhaps a preview setting. SubordinateQuote.className = 'hidden'; SubordinateQuote.isHidden = true; var InlineToggleText = document.createTextNode(InlineShow); InlineBox.childNodes[1].appendChild(InlineToggleText); }                      else if (false) {   //See above. SubordinateQuote.className = 'revealed'; SubordinateQuote.isHidden = false; var InlineToggleText = document.createTextNode(InlineHide); InlineBox.childNodes[1].appendChild(InlineToggleText); }                      InlineBox.childNodes[1].setAttribute('href', 'javascript:toggleInlineBox(' + indexInlineBox + ')'); InlineBox.appendChild(document.createTextNode(']')); indexInlineBox++; }                   }                     }              }           } }

function toggleInlineBox(Id) {  var InlineBox = document.getElementById('InlineBox' + Id); var SubordinateQuote = document.getElementById('SubordinateQuote' + Id); if (SubordinateQuote.isHidden == true) { SubordinateQuote.className = 'revealed'; InlineBox.childNodes[1].innerHTML = InlineHide; SubordinateQuote.isHidden = false; }  else if (SubordinateQuote.isHidden == false) { SubordinateQuote.className = 'hidden'; InlineBox.childNodes[1].innerHTML = InlineShow; SubordinateQuote.isHidden = true; } }

$( setupInlineBox );