Monday, August 31, 2020

How to automatically expand the Navigator in the Fluid NavBar

Whilst looking for a solution to do this I came across Sasank's page documenting how he achieved this, via injecting JavaScript and using JQuery. 

The downside, at least for me, was implementing all of the other JavaScript to actually trigger the click event. What I really wanted was a native JavaScript solution, i.e. without any frameworks.

With Fluid pages it is now possible to inject JavaScript (and CSS) through Fluid specific PeopleCode events. There are quite a few different functions, which are documented here.

So we know that we can inject JavaScript into a Fluid component, and we also know that the NavBar is a Fluid component. So, can we use Event Mapping to inject the PeopleCode? The answer is yes we can.

Like any Related Content Framework PeopleCode, you need to:

  • Create an Application Package PeopleCode class.
  • Create a Service Definition with a URL Type of Application Class, and reference the class created above.
  • And then map the PeopleCode to the Content Reference (Event Mapping).

import PT_RCF:ServiceInterface;

class OpenNavigator implements PT_RCF:ServiceInterface;
   method execute();
end-class;


method execute
   /+ Extends/implements PT_RCF:ServiceInterface.execute +/
   AddJavaScript(HTML.OPEN_NAV_MENU);
end-method;

The HTML referenced is as follows:

var callback = function () {
    // Handler when the DOM is fully loaded
    if (document.querySelector("[page='PTNUI_NAVBAR']") !== null) {
        let navButton = document.getElementById('PTNB$PTNUI_NB_MENU');
        navButton.click();
    }
};


document.addEventListener("DOMContentLoaded"callback);

The component you map this your Service Definition to is found here (hidden by default so remember to check the 'Include Hidden CREFs' checkbox):

Root > Fluid Structure Content > Fluid PeopleTools > Fluid PeopleTools Framework > NavBar

Given that this solution does the same thing as Sasank's solution, I did not add any extra screenshots showing the before and after. And whilst there probably are better ways of doing this, this is what I found working for me.

Credit for the JavaScript idea belongs to the post here


    No comments:

    Post a Comment