Aladin CMS accesskeys

By myfonj Last update 5 hours ago — Installed 76 times. Daily Installs: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

There are 8 previous versions of this script.

// ==UserScript==
// @name           cwCMS acesskeye
// @namespace      http://eldar.cz/myf/pub/firefox/
// @description    …
// @include        http://*/cms2ViewWeb/*
// ==/UserScript==

/*
changelog:
2009-11-25 : accesskeye: vícero úprav, zpět pro edity, pryč pro "new"y …
2009-11-24 : § rolldown menu OFF
2009-11-23 : opraven saveNquit
2009-06-19 : opraven link na preview aktuálně editovaného
2009-06-19 : opraven bug s ukládáním divnejch typů stránek
2009-06-16 : titler překopán na triviální komplexitu : )
2009-06-16 : pokud pouštěné v iframe : return (kvůli CK)
2009-05-11 : zničit codepress , pryč save nepřenačte stránku (už tam asi je nativně)
2007-06-27 : save nepřenačte stránku ^_^
2007-06-21 : do tajtlu při editaci jméno souboru
2007-06-08 : do statusbaru délka hodntoty aktuálního inputu

TOC
 § rolldown menu : OFF
 § codepress : OFF
 § accesskeys : ADD
 § document.title : MAKE more INFORMATIVE

*/


// hlavní klouzůra ZAČÁTEK:
(function(){


if ( window != window.top ) return;
// ^ jsme pravděpodobně v CK iframu nebo něčem obdobnym, pryč


//
// § rolldown menu : OFF
// !! VYPNI POKUD NEPOUŽÍVÁŠ ALTERNATIVU
// (protože jinak ti budou meníčka viset)
//
unsafeWindow.RollDownMenu = function(){ this.Init = function(){} };


//
// § codepress : OFF
// nyní jenom znovu enablí textareye a ničí CK iframy
// unsafeWindow.CodePress.run se bohužel ve stránkách binduje v na DOMLoaded
// v (asi) anonymní fci, a tenhle userscript to nestíhá unbindout
// unsafeWindow.removeEventListener('DOMContentLoaded',unsafeWindow.CodePress.run,false);
// nepomůže : (
(function()
{ if ( 0 ) return
; var txs = document.getElementsByTagName('textarea')
  , txi = -1 , tx , ifrs
; while ( tx = txs[++txi] ) if ( tx.id.indexOf('cpEditor') === 0 )
  { ifrs = tx.parentNode.getElementsByTagName('iframe')
  ; if ( ifrs.length )
    { tx.parentNode.removeChild(ifrs[0])
    ; tx.removeAttribute('disabled')
    }
  }
})();

//
// § accesskeys : ADD
//
(function(){
 var allKeys = 'yxsaqwedcvfrgbnhtzjmkuilop'
 ,tmpLink,lnki = -1, tmpClass, tmpHref;
while ( tmpLink = document.links[++lnki] ) {
  if ( !allKeys.length || lnki > 500 ) { break } // došly klávesy nebo to už běží "moc dlouho"
  tmpClass = tmpLink.className;
  tmpHref = tmpLink.href;
  if (      tmpClass == 'icoOdejit' )   { setAK('q'); continue }  // quit
  else if ( tmpClass == 'icoUloz' )     { setAK('s');    // save
   /* */
   if
   (  document.location.href.indexOf('edit.do') > -1
   && document.forms[0]
   && document.getElementsByTagName('textarea')[0]
   )
   {
   ; tmpLink.href = 'javascript:document.forms[0].submit()'
   ; tmpLink.setAttribute('onclick','')
   ; var targetName = 'cmsFormTargetAddedByMyfsUserscript'
   ; window.newFrame = document.createElement('iframe')
   ; newFrame.setAttribute('name',targetName)
   ; newFrame.setAttribute('style','display:none;')
   ; document.body.appendChild(newFrame)
   ; tmpLink.addEventListener
     ( 'click'
     , function()
       { document.forms[0].setAttribute('target',targetName);
       }
     , false
     )
   ; tmpLink.addEventListener
     ( 'blur'
     , function()
       { document.forms[0].removeAttribute('target');
       }
     , false
     )
   }
   /* */
   // pravděpodobně by tu mělo být po dokončení submitu vyhození iframu z docu, aby to nemátlo IAT (?)
  ; continue
  }
  else if ( tmpClass == 'icoUlozJdi' )  { setAK('d');
   if ( tmpLink.getAttribute('onclick') == 'saveCP(); return false;' )
   { tmpLink.setAttribute('onclick','')
   ; tmpLink.href = 'javascript:document.forms[0].submit()';
   }
   continue
  }  // saveNquit
  else if ( tmpClass == 'icoUvod' )     { setAK('q'); continue}  // uvod
  else if ( tmpClass == 'icoObsah' )    { setAK('e'); continue}  // content
  else if ( tmpClass == 'icoSablona' )  { setAK('t'); continue}  // templates
  else if ( tmpClass == 'icoTrida' )    { setAK('c'); continue}  // classes
  else if ( tmpClass == 'icoTbl' )      { setAK('p'); continue}  // publikace
  else if ( tmpClass.indexOf('icoNovy') > -1 )
                                        { setAK('w'); continue}  // THE "new button"
  else if ( tmpClass.match('icoAdmin') ){ setAK('a'); continue}  // administrace
  else if ( tmpClass == 'logout' )      { setAK('l'); continue}  // logout
//   else if ( /new\.do/.test(tmpHref) )   { setAK('w'); continue}  // any "new…"
//   else if ( tmpClass == 'edit' )        { setAK(); continue}     // any edit (by class)
//   else if ( /editAtt/.test(tmpHref) )     { setAK(); continue}   // any edit (by URL)
  else if ( tmpLink.innerHTML == '..' ) { setAK('a'); continue}  // go up
  else if ( tmpLink.parentNode.className == 'edit' )
                                        { setAK(); continue}     // any edit (by parents class)
  else if ( /ico/.test(tmpClass) )      { setAK(); continue}     // any ico
  else if ( tmpClass == 'webpreview' )  { setAK('p');
   var ng = document.getElementsByClassName('objectPath');
   var ngngn = ng[0];
   if ( ngngn )
   { var pth = ngngn.innerHTML
   ; var suff = '.html'
   ; var sffRX = /\.([^\.]{2,4})\s*$/
   ; if ( sffRX.test(pth) ) {suff = '' }
   ; tmpLink.href = tmpLink.href.replace
     ( /index\.html$/ , ngngn.innerHTML.match(/\/(.*)/)[1] + suff )
   continue
   }
  }
  else if ( tmpHref.match('allowed') )  { setAK(); continue} // ??
  else if ( tmpClass )                  { setAK(); }     // any class
 }

 // číslíčkový accesskeye prvním deseti použitelnejm inputům
 // + FOCUS do prvního!
 function tellLength(){
  window.status = this.value.length;
 } 
 var focused = false;
 var elm , accki = 0;
 for ( var j = 0, fl = document.forms.length; j < fl; j++ ) {
  for ( var i = 0, fel = document.forms[j].elements.length; i < fel; i++ ) {
   elm = document.forms[j].elements[i];
   if ( elm.getAttribute('maxlength') ) {
    // hotfix, půjde pryč, doufejme
    elm.removeAttribute('maxlength');
    elm.value=elm.getAttribute('value');
   }
   if ( elm.getAttribute('type') == 'text'
     || elm.tagName == 'TEXTAREA')
   {
    elm.addEventListener('keyup',tellLength,false);
    if ( elm.tagName == 'TEXTAREA' )
    {
     elm.setAttribute('wrap','off');
     // tohle je dost strašitedně vypadající hack pro zlozillu
     // : neumí přenastavit wrap takhle snadno : (
     par = elm.parentNode;
     par.removeChild( elm );
     par.appendChild( elm );
    }
   }
   if ( elm.getAttribute('type') != 'hidden'
     && elm.getAttribute('disabled') != 'true' )
   {
    if ( focused == false )
    { if ( elm.getAttribute('type') == 'file' )
      { elm.setAttribute( 'type' , 'text' )
      // další strašidelný hack
      // : mozilla od nějaké trojkové (?) verze z bezpečnostních (?) důvodů
      // ignoruje .focus() zavolaný nad file inputem
      ; elm.focus()
      ; elm.setAttribute( 'type' , 'file' )
      // tohle nechá focus na "textovém" políčku (psát se tam taky nedá, GRRR!)
      // před buttonem "browse", na který se potom dá snadno dotabnout
      // a mezerníkem otevřít fileselectový dialog.
      // Legrační je, že zpět na onen "textový" input se už dotabovat nedá : |
      } else elm.focus()
    ; focused = true
    }
    if ( accki > 9 ) { continue } 
    if ( accki == 9 ) { elm.setAttribute('accesskey',0); ++accki; continue }
    elm.setAttribute('accesskey',++accki);
   }
  }
 }

 // ...
 function setAK( key ) {
  if ( !allKeys.length || !tmpLink  ) { return false }
  if ( tmpLink.getAttribute('accesskey') ) {
   var key = tmpLink.getAttribute('accesskey') ;
   // a pokračujeme, aby se následně vyhodil z allKeys coby použitej
  }
  if ( !key ) {
   var key = allKeys.substring(0,1);
   allKeys = allKeys.substring(1);
  }
   else
  {
   if ( allKeys.indexOf(key) == -1 ) {
    // nojo, co dělat když už bude použitej?
    setAK(); // zavoláme se bez keye
    return false // pro jistotu
   } else {
    allKeys = allKeys.replace(key,'');
   }
  }
  tmpLink.setAttribute('accesskey',key);
  return key // kdyby to bylo někdy potřeba třeba vypisovat
 }

 // to je asi vše
})();


//
// § document.title : MAKE more INFORMATIVE
//
(function ()
{ var t = document.getElementsByTagName('h1')
; var h1 = /* t[0] ? t[0].innerHTML : */ ''
; if( document.getElementsByClassName )
  { var op = document.getElementsByClassName('objectPath')
  ; if ( op && op[0] )
    { document.title = '*) '
      + op[0].innerHTML.match(/[^/]*$/) //  + ' « Edit Content'
    ; var op = document.getElementsByClassName('currentEditLanguage')
    ; if ( op && op[0] ) document.title
      += ' ' + h1 + ' /' + op[0].innerHTML
    ; return
    }
  ; var op = document.getElementsByClassName('crumbNavig')
  ; if ( op && op[0] )
    { var tmptxt = op[0].innerHTML.match(/[^> ]*$/)
    ; if ( /Templates/.test(tmptxt) )
      { document.title = 'T) '
        + 'Templates List'
      ; return
      }
    ; document.title = 'M) '
      + tmptxt  + ' ' + h1 // + ' « Manage'
    ; return
    }
  ; setTimeout
    ( function()
      { var l = document.getElementsByClassName('currentLinkOpen')
      ; if ( l && l[0] ) document.title = 'C) '
        + l[0].innerHTML // + ' « Content List'
      }
    , 1500
    )
  // ^ @todo tohle by bylo lepší udělat přes DOM polling
  // a vůbec se podívat jestli jsme ve výpisu contentu a pak to teprv zkoušet
}
})();

// hlavní klouzůra KONEC:
})();
// EOF