User:Atelaes/InlineBox.js

From Wiktionary, the free dictionary
Jump to navigation Jump to search

Note – after saving, you may have to bypass your browser’s cache to see the changes.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.

// <nowiki>
/** 

  Used in conjunction with {{grc-test}}.  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 );