Skip to content

Commit

Permalink
Showing 2 changed files with 41 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cosmos/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -163,6 +163,26 @@ def open_file(path: str, conn_id: Optional[str] = None) -> str:
)
}
}
// Prevent parent hash changes from sending a message back to the parent.
// This is necessary for making sure the browser back button works properly.
let hashChangeLock = true;
window.addEventListener('hashchange', function () {
if (!hashChangeLock) {
window.parent.postMessage(window.location.hash);
}
hashChangeLock = false;
});
window.addEventListener('message', function (event) {
let msgData = event.data;
if (typeof msgData === 'string' && msgData.startsWith('#!')) {
let updateUrl = new URL(window.location);
updateUrl.hash = msgData;
hashChangeLock = true;
history.replaceState(null, null, updateUrl);
}
});
</script>
"""

22 changes: 21 additions & 1 deletion cosmos/plugin/templates/dbt_docs.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% extends base_template %}
{% block page_title %}dbt docs - {{ appbuilder.app_name }}{% endblock %}
{% block content %}
<script src="{{ url_for('.static', filename='iframeResizer.min.js') }}"></script>
<iframe id="dbtIframe" src="{{ url_for('.dbt_docs_index') }}" style="min-width: 100%; border: 0;"></iframe>
@@ -10,6 +11,25 @@
minHeight: 500
},
'#dbtIframe'
)
);

window.addEventListener('message', function (event) {
let msgData = event.data;
if (msgData.startsWith('#!')) {
let updateUrl = new URL(window.location);
updateUrl.hash = msgData;
history.replaceState(null, null, updateUrl);
}
});

window.addEventListener('popstate', function () {
dbtIframe.contentWindow.postMessage(window.location.hash);
});

let dbtIframe = document.getElementById('dbtIframe');
let iframeUrl = new URL(dbtIframe.src);
iframeUrl.hash = window.location.hash;
dbtIframe.src = iframeUrl.href;

</script>
{% endblock %}

0 comments on commit 3c9cf6f

Please sign in to comment.