# Close a dock when opening another - detect when a dock is open?

**URL:** <https://forum.inductiveautomation.com/t/close-a-dock-when-opening-another-detect-when-a-dock-is-open/96661>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [October 1, 2024, 1:42pm UTC](https://forum.inductiveautomation.com/t/close-a-dock-when-opening-another-detect-when-a-dock-is-open/96661 "2024-10-01T13:42:41Z")\
**Posts on this page:** 1\
**Showing post:** 26

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [October 3, 2024, 1:16pm UTC](https://forum.inductiveautomation.com/t/close-a-dock-when-opening-another-detect-when-a-dock-is-open/96661/26 "2024-10-03T13:16:37Z")

</div>

oke i found a way to get all id's, gimme a sec to write it in a script 🧙

@mazeyrat that should do it, found a way to use perspectives client functions.  
One of these days i'll also find the session settings maybe xd Than we wouldnt need the markdown, but no luck yet, its quite a maze to go through without any docs 😛 ...

> **js**
>
> ```python
> #make the propName the key to write too in the view.custom 
> propName = value
> code = """<img style='display:none' src='/favicon.ico' onload=\"
> const view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == this.closest('[data-component-path]').getAttributeNode('data-component-path').value.split('.')[0]).value; 		
> function getOpenDocks(){
> const openDocks = [];
> for (const side of ['top','right','bottom','left']){										
> const dock = window.__client.mounts?.docks?.get(side);					    
> if(dock?.expanded){
> openDocks.push(dock?.currentViewIndex?.observers?.values()?.next()?.value?.value?.id);                            
> }				   
> }					
> view.custom.write('"""+propName+"""',openDocks);
> };
> const callbackDock = (mutationList, observer) => {
> getOpenDocks();
> };
> const observerDocks = new MutationObserver(callbackDock); 
> const docks = document.querySelectorAll('.docked-view, .docked-view > div >.view');
> docks.forEach(dock => observerDocks.observe(dock, { attributes: true, childList: false, subtree: false }));	
> getOpenDocks();	
> \"></img>""".replace("\n", "").replace("\t", "")
> return code
> 	
> 
> ```

> **markdown**
>
> ```python
> [
> {
> "type": "ia.display.markdown",
> "version": 0,
> "props": {
> "style": {
> "flex": "--neutral-40"
> },
> "markdown": {
> "escapeHtml": false
> }
> },
> "meta": {
> "name": "Markdown_0"
> },
> "position": {
> "x": 88,
> "y": 251,
> "height": 200,
> "width": 200
> },
> "custom": {},
> "propConfig": {
> "props.source": {
> "binding": {
> "type": "expr",
> "config": {
> "expression": "\"openDocks\""
> },
> "transforms": [
> {
> "code": "\t#make the propName the key to write too in the view.custom \n\tpropName = value\n\tcode = \"\"\"<img style='display:none' src='/favicon.ico' onload=\\\"\n\t\t\t\tconst view = [...window.__client.page.views._data.values()].find(view => view.value.mountPath == this.closest('[data-component-path]').getAttributeNode('data-component-path').value.split('.')[0]).value; \t\t\n\t\t\t\tfunction getOpenDocks(){\n\t\t\t\t\tconst openDocks = [];\n\t\t\t\t\tfor (const side of ['top','right','bottom','left']){\t\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t const dock = window.__client.mounts?.docks?.get(side);\t\t\t\t\t \n if(dock?.expanded){\n openDocks.push(dock?.currentViewIndex?.observers?.values()?.next()?.value?.value?.id); \n }\t\t\t\t \n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\tview.custom.write('\"\"\"+propName+\"\"\"',openDocks);\n\t\t\t\t};\n\t\t\t\tconst callbackDock = (mutationList, observer) => {\n\t\t\t\t\tgetOpenDocks();\n\t\t\t\t};\n\t\t\t\tconst observerDocks = new MutationObserver(callbackDock); \n\t\t\t\tconst docks = document.querySelectorAll('.docked-view, .docked-view > div >.view');\n\t\t\t\tdocks.forEach(dock => observerDocks.observe(dock, { attributes: true, childList: false, subtree: false }));\t\n\t\t\t\tgetOpenDocks();\t\n\t\\\"></img>\"\"\".replace(\"\\n\", \"\").replace(\"\\t\", \"\")\n\treturn code\n\t",
> "type": "script"
> }
> ]
> }
> }
> }
> }
> ]
> 
> ```

---

_[View the full topic](https://forum.inductiveautomation.com/t/close-a-dock-when-opening-another-detect-when-a-dock-is-open/96661)._
