Skip to main content
Legend
May 12, 2014
Answered

Is it possible to create/ assign shortcut keys for TOC navigation?

  • May 12, 2014
  • 2 replies
  • 824 views

Hi

I am using RH10 as part of TCS4.

Is it possible to assign PgUp and PgDn keys as shortcuts to navigate between topics in the TOC? I have created the browse sequence.

Sreekanth

This topic has been closed for replies.
Correct answer Willam van Weelden

Ah, it was for WebHelp. Didn't see that...

For WebHelp, it is easy. Paste the code below in whutils.js. Note that it will not work on local Chrome. This script will work for RH8+ WebHelp

var nextBRS = 102;/* Key code of next page key */

var prevBRS = 100;/* Key code of prev page key */

var nextBRS = 102;/* Key code of next page key */
var prevBRS = 100;/* Key code of prev page key */

if(window.addEventListener){
     window.addEventListener("keyup", brsListener, false);
} else if(window.attachEvent) {
     window.attachEvent("onkeyup", brsListener);
}

function brsListener(event) {
     var GetTopicPaneBRS = function () {//Get the topic pane
          var topicPane;
          if (top.frames[0].name == "ContentFrame")
               topicPane = top.frames[0].frames[1].frames[1];
          else
               topicPane = top.frames[1].frames[1];
          topicPane.focus();
          return topicPane;
     }
     var topic = GetTopicPaneBRS();
     if(event.which == nextBRS) {
          if(topic.canGo(true)) {
               topic.goAvenue(true);
          }
     } else if(event.which == prevBRS) {
          if(topic.canGo(false)) {
               topic.goAvenue(false);
          }
     }
}

Kind regards,

Willam

2 replies

Willam van Weelden
Inspiring
May 31, 2014

Apart from the precise key bindings, this can be done. (Page up and Page down are not registered by the browser as key press events.) This is actually simple in WebHelp, but less so in HTML5 outputs. This post includes instruction for both Multiscreen and Responsive HTML5.

What you need to do (Multiscreen HTML5 only):

  1. Get jQuery. (The 1.x version.)  (jQuery is already available in the Responsive layout from RH11.) -- I was too lazy to make it in pure JS ;-)
  2. Add the jQuery file in your layout as a baggage file.
  3. On the topic page, include a link to the jQuery file. (<script type="text/javascript" src="jquery.min.js"></script> or something similar.
  4. Save the file.

Then do the following:

  1. Copy the following code into a JS file:

//-- Start of script, do not copy

/* Enable PgUp/PgDwn shortcut for browse sequences */
$(function(){
     var nextBRS = 54;/* Key code of next page key */
     var prevBRS = 52;/* Key code of prev page key */
     
     $backElem = $("#browseSeqBack");
     $forwElem = $("#browseSeqNext");
     
     var custCanGo = function(forward) {
          var canGo = false;
          if(forward) {
               if($forwElem.length != 0) {
                    canGo = true;
               }
          } else {
               if($backElem.length != 0) {
                    canGo = true;
               }
          }
          return canGo;
     };
     var custGoAvenue = function (forward) {
          if(forward) {
               if(custCanGo(true)) {
                    $forwElem[0].click();
               }
          } else {
               if(custCanGo(false)) {
                    $backElem[0].click();
               }
          }
     }
     
     $(window).keypress(function(event){
          if(event.which == nextBRS) {
               custGoAvenue(true);
          } else if(event.which == prevBRS) {
               custGoAvenue(false);
          }
     });
     
});

//--End of script, do not copy

  1. Add the JavaScript file in your layout as a baggage file.
  2. On the topic page, include a link to the JavaScript file. (<script type="text/javascript" src="myscriptfile.js"></script> or something similar.
  3. Save the file.

Alternatively, you can paste it in the file Layout.js if you are using Responsive HTML5.

Last, you need to map the keys you want to use. You can find the codes for the keyboard keys on; http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

In the script, replace the following keys with the keys you want to use:

   var nextBRS = 54;/* Key code of next page key */

   var prevBRS = 52;/* Key code of prev page key */

By default, this is mapped to the numpad 4 and 6 keys. Note that keys like page up/down, home and the arrow keys don't work.

I have tested this in RH11 Responsive HTML5 output and it will work with Multiscreen HTML5 as well. I haven't tested this with topics that occur in multiple browse sequences, so you may want to test that first is you use that.

Greet,

Willam

Willam van Weelden
Willam van WeeldenCorrect answer
Inspiring
May 31, 2014

Ah, it was for WebHelp. Didn't see that...

For WebHelp, it is easy. Paste the code below in whutils.js. Note that it will not work on local Chrome. This script will work for RH8+ WebHelp

var nextBRS = 102;/* Key code of next page key */

var prevBRS = 100;/* Key code of prev page key */

var nextBRS = 102;/* Key code of next page key */
var prevBRS = 100;/* Key code of prev page key */

if(window.addEventListener){
     window.addEventListener("keyup", brsListener, false);
} else if(window.attachEvent) {
     window.attachEvent("onkeyup", brsListener);
}

function brsListener(event) {
     var GetTopicPaneBRS = function () {//Get the topic pane
          var topicPane;
          if (top.frames[0].name == "ContentFrame")
               topicPane = top.frames[0].frames[1].frames[1];
          else
               topicPane = top.frames[1].frames[1];
          topicPane.focus();
          return topicPane;
     }
     var topic = GetTopicPaneBRS();
     if(event.which == nextBRS) {
          if(topic.canGo(true)) {
               topic.goAvenue(true);
          }
     } else if(event.which == prevBRS) {
          if(topic.canGo(false)) {
               topic.goAvenue(false);
          }
     }
}

Kind regards,

Willam

Captiv8r
Legend
May 31, 2014

Thanks Willam!

Captiv8r
Legend
May 12, 2014

Hi there

Hmmm, I'm thinking it might be possible to achieve with some scripting modification. Hopefully Willam will pop in here to advise.

Earth to Willam... Earth to Willam... are we reaching you Willam?

Cheers... Rick