Jump to content

User:Dodoïste/vector.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dodoïste (talk | contribs) at 13:22, 6 May 2010. 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.
importScript('User:Cacycle/navbox.js');

/* jQuery section Begin */ jQuery(document).ready(function($){
 
$(':header').each(
  function(){
    $(this)
    .append(' ')
    .append(
      $(this).children('span.editsection')
      .css('display','inline')
      .css('float','none')
      .css('font-size','small')
      .css('margin-left','5px')
      .css('line-height','90%').hide()
    )
    .hover(
      function(){$(this).children('span.editsection').show()},
      function(){$(this).children('span.editsection').hide()}
    )
  }
);
 
/* Auto-hide TOC like that in Baidu Baike */
 
if ($('table#toc.toc').size()>0){
 if ($('table#toc.toc').position().left==0){
  $('li.toclevel-1>ul').hide()
  $('table#toc.toc')
  .css('position','absolute')
  .css('float','left')
  .css('margin-right','1em')
  .hover(
    function(){$('li.toclevel-1>ul').attr('style','display:none').show('slow')},
    function(){$('li.toclevel-1>ul').stop(true,false).hide('slow')}
  )
  .after(
    $('<div/>')
    .css('height',$('table#toc.toc').height())
    .css('padding','8px')
  )
 }
}
 
/* Prototype code to show collapsing left nav options */
/* First draft and will be changing greatly */
 
$( '#panel' ).addClass( 'collapsible-nav' );
 
// Always show the first portal
$( '#panel > div.portal:first' )
.addClass( 'expanded' )
.find( 'div.body' )
.show();
 
// Remember which portals to hide and show
$( '#panel > div.portal:not(:first)' )
.each(
 function() {
  $(this).addClass( 'collapsed' );
 }
);
 
// Toggle the selected menu's class and expand or collapse the menu
$('#panel > div.portal:not(:first) > h5').click(
  function() {
    $('#panel > div.expanded:not(:first)')
    .addClass('collapsed')
    .removeClass('expanded')
    .find('div.body')
    .hide('fast');
    $(this).parent()
    .toggleClass('expanded')
    .toggleClass('collapsed')
    .find('div.body')
    .slideToggle('fast');
    if ($('#panel').css('position')=='absolute'){hide_lang();}
  }
);
 
/* language section collapse */
 
try{
  var langs = prefered_langs
}
catch(err)
{
  var langs = ['en','de','fr','pl','it','ja','nl','es','simple','zh','zh-classical','zh-yue','wuu','la'];
}
var finish = langs.length;
var pan_top = $('#panel').position().top-$(document).scrollTop();
 
var show_lang = function(){
  $('#panel').css('position','absolute').css('top',$(document).scrollTop()+pan_top)
  .animate({top:$(document).scrollTop()},'slow');
  $('#p-lang > div > ul > li').show();
  $('#p-lang-show').hide();
};
 
var hide_lang = function(){
  var top = $('#panel').position().top-$(document).scrollTop();
  $('#panel').css('position','fixed').css('top',top).animate({top:pan_top},'slow');
  $('#p-lang > div > ul > li').hide();
  langs.map(
    function(lang){return $('.interwiki-'+lang).show();}
  );
  $('#p-lang-show').show();
}
 
if ($('#p-lang > div > ul > li').size() > finish){
  $('#p-lang > div > ul > li').hide();
  langs.map(
    function(lang){return $('.interwiki-'+lang).show();}
  );
 
  $('#p-lang > div > ul').append(
    $('<li id="p-lang-show"><span style="color:gray;font-size:90%;">More</span></li>')
    .click(show_lang)
  );
 
  $('#p-lang > div > ul').append(
    $('<li id="p-lang-hide"><span style="color:gray;font-size:90%;">Hide</span></li>')
    .click(hide_lang).hide()
  );
}
 
$('#panel').css('position','fixed')
 
$(window).scroll(function(){
  if ( $('#panel').css('position')=='absolute' &&
       ( $('#panel').offset().top>$(document).scrollTop()+pan_top ||
         $('#p-lang-hide').offset().top<$(document).scrollTop()+pan_top ) )
  {hide_lang()}
})
 
/* jQuery section End */ });