How do you tell if dock is open on a page?

How do you tell if dock is open on a page?

It sounds like you’re asking about Perspective, so I’ll chime in.

If you’re asking from a scripting perspective, you can’t. A Page has no idea about what Docked Views or Popups are displayed; when actions or scripts would expand/collapse a Docked View, that all happens without the page even being aware of it.

BUT… depending on your setup, you could track the state using Session properties to a certain degree.

If you configure the Docked View to be visible only onDemand, AND you do not display handles for the Docked View, AND you expand/collapse the Docked View with your own buttons by invoking your own scripts, you could set the state of the Docked View as a Session property in your script:

self.session.custom.dockedViewIsExpanded = True
system.perspective.openDock(id=<dockId>)
self.session.custom.dockedViewIsExpanded = False
system.perspective.closeDock(id=<dockId>)

Even using the Docked View Action with an accompanying script just to set the state value would be unreliable. The avenue I provided would also fall apart and no longer be accurate if you navigate to pages which do not have the dock in question configured because you could open the dock (and set isExpanded to True), but then navigate away and come back at which point your isExpanded value is still True, but the Docked View will actually be collapsed.

Thanks. Yes, I’m talking about Perspective.

What about via page configuration? If the page is configured to open with a “right dock”?

Is there anyway with scripting to look to see if the current page is configured with a dock?

No, you have access to the attributes (pageId, path of primaryView, session) of a Perspective Page (browser tab), but you do not have access to the Page Configuration.

Can dock collapse/expand events be added so that we can set these session parameters on the dock rather than relying on setting them in every script that opens/closes them? I can definitely see this getting stuck!

There is technically another way to identify the current state of the dock, although it may not be the cleanest

A breakpoint container with embedded views will only load the contents of the embedded view for its current breakpoint.

Meaning that if you have a breakpoint container in an always closed footer/header dock, it should always be loading the current embedded view for the current width breakpoint. If you were expecting a resolution of say 1920, and then when the dock was open you could say your resolution would be 1820, then if the breakpoint was met you would load the “smaller” embedded view, and be able to use message handling to see the current state of the dock.

Like I said, not the cleanest solution, but it is 100% doable

This could also work with multiple device sizes, you would just need to nest your breakpoint containers in a way that gives you more clarity at higher and lower resolutions, instead of just the default size.

I mocked this up in a test project and it worked fine, if needed I could clean up my example and provide it here.

Another way that might be cleaner, albeit I am not sure if its possible

If you are able to grab the current html document for the page, you could take a look for the element by class name docked-view-right (or whichever side) and check if its style: right (or whichever side) is 0px or not. The style: right is set between the width of the view and 0 when the view is opened and closed.

Only thing here is that I am not sure if its possible to grab the current page HTML, I tried, but I couldn’t figure out a way.

I know this is a really old question, but in case anyone else is looking to get around this I have a method with some caveats. I think it would still be good if we could get the dock state either as an event or even better as a page property.
My method only works to determine that a dock is open, not which dock or if there are multiple open. For my use, this is ok as I am only worried about the vertical menu dock on the left of screen.
The next limitation is the dock must be set to push, not cover.
I look at the primary view width vs the viewport width. if they match, then my dock is closed. I use this to animate the hamburger menu button in the header. I use an expression binding like below to get a menu state.

if({page.props.dimensions.viewport.width} = {page.props.dimensions.primaryView.width}, 'closed', 'open')

Hope this helps someone, obviously this method could be used to look at top and bottom docks as well by comparing the heights.

I highly advise against string values being used to convey a boolean property/state/value. Consider changing your expression to just this:

{page.props.dimensions.viewport.width} = {page.props.dimensions.primaryView.width}
2 Likes

I agree and in fact, I do, but I thought it would be a more descriptive snippet as written.
Are there any plans to add some mechanism to definitively determine the dock states?

Not at this time, no.