User:Lupin/sectionkeys.js

//window.popupShortcutKeys=false;

function getAnchors { var s=[''], anchs=document.getElementsByTagName('A'); for (var i=0; i<anchs.length; ++i) if (anchs[i].name && anchs[i].name!='top') s.push(anchs[i].name); return s; }

window.handleKeys=function(evt){ if (window.handleKeys.disabled) { return true; } var k = window.event ? window.event.keyCode : ( evt.keyCode ? evt.keyCode : evt.which); if (!k) return; var letter=String.fromCharCode(k); switch (letter) { case 'j': changeAnchor(1);      return false; case 'J': changeAnchor('last'); return false; case 'k': changeAnchor(-1);     return false; case 'K': changeAnchor('first'); return false; default: return true; } } window.handleKeys.disabled=false; window.handleKeys.disableFlags=[];

function setupFocusHandlers(elType, startAt) { var inputs=document.getElementsByTagName(elType); var j=startAt || 0; for (var i=0; i<inputs.length; ++i) { if (elType=='input' && inputs[i].type.toLowerCase!='text') { continue; } window.handleKeys.disableFlags[j]=false; inputs[i].onfocus=function{ window.handleKeys.disableFlags[j]=true; updateDisabledFlag; } inputs[i].onblur=function{ window.handleKeys.disableFlags[j]=false; updateDisabledFlag; } ++j; } //alert(j + ' handlers installed'); return j; }

function updateDisabledFlag { for (var i=0; i 0) { var target=loc.slice(1).join('#'); for (var i=0; i=anchs.length) pos=anchs.length-1; } }     else pos = 0; } /* switch */ var newloc=loc[0] + '#' + anchs[pos]; if(document.location!=newloc) document.location=newloc; }

var sectionKeysPage=( ! /^(Editing|Search -|Confirm|Move page|Logs|E-mail user|All pages|Block user)/.test(document.title)			&&			! /([?&]=|wiki\/)[Ss]pecial:/.test(document.location) ); if ( 1 || sectionKeysPage ) { addOnloadHook(function{     var j=setupFocusHandlers('input');      setupFocusHandlers('textarea', j);      document.onkeypress=window.handleKeys;    }); }