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