Jump to content

User:Ch1902/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Ch1902 (talk | contribs) at 12:36, 5 January 2011. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* disable */
ls_enable = false;

function addCustomLink (href, title)
{
   var ca = document.getElementById('p-cactions');
   var ul = ca.getElementsByTagName('UL')[0];

   var li = document.createElement('LI');
   var lk = document.createElement('A');
       lk.setAttribute('href', href);

   lk.appendChild(document.createTextNode(title));
   li.appendChild(lk);

   ul.appendChild(li);

   return;
}

addOnloadHook(function () {
   addCustomLink('http://commons.wikimedia.org/wiki/User:Ch1902', 'COM:Ch1902');
   addCustomLink('http://commons.wikimedia.org/wiki/Special:Watchlist', 'COM:Watch');
   addCustomLink('http://commons.wikimedia.org/w/index.php?title=Special:Upload&uploadformstyle=basic', 'COM:Upload');
});

/* testing */
function initCollapseSections (tag)
{
   var content = $('#bodyContent');
   
   $j('#bodyContent > ' + tag).each(function (i, el) {

      if ($(el).data('collapser'))
         return;
      
      var holder = $('<div/>').attr('id', 'collapser-' + tag + '-' + i);
      var curLevel = parseInt(el.nodeName.replace(/h/i, ''));
      var node = el;
      var kids = [];
      
      while (node = node.nextSibling)
      {
         if (node.nodeType == 1 && node.nodeName.match(/h[1-6]/i))
         {
            var thisLevel = parseInt(node.nodeName.replace(/h/i, ''));
            if (thisLevel <= curLevel)
               break;
         }

         kids.push(node);         
      }

      holder.insertAfter(el).append(kids);

      $(el).data('collapser', holder).append($('<span/>').text('[hide]').click(function (e) {
         $(el).data('collapser').toggle();
         if ($(e.target).text() == '[hide]')
            $(e.target).text('[show]');
         else
            $(e.target).text('[hide]');
      }).addClass('editsection').css('cursor', 'pointer'));
   });
}

$(document).ready(function () {
   initCollapseSections('h4');
   initCollapseSections('h3');
   initCollapseSections('h2');
});