Index: ../xwiki-platform-skins/albatross/src/main/resources/albatross/xwiki.js =================================================================== --- ../xwiki-platform-skins/albatross/src/main/resources/albatross/xwiki.js (revision 7911) +++ ../xwiki-platform-skins/albatross/src/main/resources/albatross/xwiki.js Mon Feb 18 18:05:42 CET 2008 @@ -1,3 +1,45 @@ +/* +** Key press observer, allow to launch js functions on key press +** This simple implementation allow to add callbacks on modifier + keypress with a humane syntax +** examples : +** observedKeys['Alt+e'] = function(){ alert("Alt+e"); }; +** observedKeys['Ctrl+Alt+Shift+b'] = function(){ alert("Ctrl+Alt+Shift+b"); }; +*/ +var observedKeys = new Array(); +Event.observe(window, 'load', function() { + Event.observe(document, 'keypress', function(e){ + if (!e) + var e = window.event; + if (e.ctrlKey || e.altKey || e.shiftKey) { + var ctrl = e.ctrlKey ? 'Ctrl' : ''; + var alt = e.altKey ? 'Alt' : ''; + var shift = e.shiftKey ? 'Shift' : ''; + var code; + if (e.keyCode) + code = e.keyCode; + else if (e.which) + code = e.which; + var shortcut = ctrl; + if (shortcut != '' && e.altKey) + shortcut += '+'; + shortcut += alt; + if (shortcut != '' && e.shiftKey) + shortcut += '+'; + shortcut += shift; + if (shortcut != '') + shortcut += '+'; + var character = String.fromCharCode(code); + shortcut += character; + if (observedKeys[shortcut]) { + observedKeys[shortcut](); + document.defaultAction = false; + } else { + document.defaultAction = true; + } + } + }); +}); + function hideForm(form){ form.getElementsByTagName("fieldset").item(0).className = "collapsed"; } @@ -69,7 +111,7 @@ i = fname.lastIndexOf('/'); } - fname = fname.substring(i + 1); + fname = fname.substring(i + 1); if (form.filename.value == fname){ return true; }