XWiki Standard 9.8.1 Documentation » Programming Overview » Customize the Keyboard Shortcuts

Customize the Keyboard Shortcuts

Customize Keyboard Shortcuts

To define custom keyboard shortcuts for your wiki, create a new page, for example XWiki.KeyboardShortcuts, edit it in "Wiki" mode and paste the following content inside:

core.shortcuts.view.edit=e
core.shortcuts.view.wiki=k
core.shortcuts.view.wysiwyg=g
core.shortcuts.view.inline=f
core.shortcuts.view.rights=r
core.shortcuts.view.objects=o
core.shortcuts.view.class=s
core.shortcuts.view.comments=c
core.shortcuts.view.attachments=a
core.shortcuts.view.history=h
core.shortcuts.view.information=i
core.shortcuts.view.code=d
core.shortcuts.view.delete=Delete
core.shortcuts.view.rename=F2
core.shortcuts.edit.cancel=Alt+C
core.shortcuts.edit.backtoedit=Alt+B
core.shortcuts.edit.preview=Alt+P
core.shortcuts.edit.saveandcontinue=Alt+Shift+S
core.shortcuts.edit.saveandview=Alt+S

These are the default keyboard shortcuts but you can modify then as you please. Next, to to the wiki preferences page and click on the "Localization" from the vertical menu to the left. 

AdministrationLocalization.png

Finally, add XWiki.KeyboardShortcuts to the "Internationalization Document Bundles" text-box and save the changes.

LanguageAdministration.png

Add New Customized Shortcuts

You can add your own keyboard shortcuts in a few JavaScript lines:

<script type="text/javascript">
//<![CDATA[
 shortcut.add("Ctrl+Alt+n", function() { alert("Hey there! Congratulations on typing this one ;)"); });
//]]>
</script>

{{html clean="false"}}
<script type="text/javascript">
  shortcut.add("Ctrl+Alt+n", function() { alert("Hey there! Congratulations on typing this one ;)"); }, {'propagate':false} );
</script>
{{/html}}

The above snippet displays an alert after pressing Ctrl+Alt+n.

Remove Shortcuts

To remove a keyboard shortcut you could adapt the following snippet:

<script type="text/javascript">
//<![CDATA[
 shortcut.remove("Ctrl+Alt+n");
//]]>
</script>

{{html clean="false"}}
<script type="text/javascript">
function removeCtrlAltN() {
  shortcut.remove("Ctrl+Alt+n");
}
</script>
<a onclick="removeCtrlAltN(); return false;" href="#">Click here to try the snippet, it will remove the Ctrl+Alt+n shortcut</a>.
{{/html}} 

You could also remove all shortcuts at once using the below code:

<script type="text/javascript">
//<![CDATA[
 for (binding in shortcut.all_shortcuts) {
    shortcut.remove(binding);
  }
//]]>
</script>

{{velocity}}
#if (!$isGuest && $isAdvancedUser)
{{html clean="false"}}
<script type="text/javascript">
//<![CDATA[
function removeAll() {
 for (binding in shortcut.all_shortcuts) {
    shortcut.remove(binding);
  }
}
//]]>
</script>
<a onclick="removeAll(); return false;" href="#">Click here to try the snippet, it will disable all keyboard shortcuts</a>.
{{/html}}
#end
{{/velocity}}

 

Related Pages

Search this space

 

Most popular tags

Failed to execute the [groovy] macro
  1. access rights
  2. activity stream
  3. annotation
  4. attachment
  5. comment
  6. Document Tree Macro
  7. export
  8. Extension Manager
  9. Flamingo skin
  10. global user
  11. Groovy event listener
  12. group
  13. nested page
  14. search
  15. skin
  16. syntax
  17. user
  18. user profile
  19. velocity macros
  20. wiki
  21. wysiwyg
  22. XWiki Applications
  23. xwikiattachment_archive table
  24. xwikiattachment table
  25. xwikiattrecyclebin table
  26. xwikiproperties table

[Display all tags from this space]