fix hash handling inside widget

This commit is contained in:
igoradamenko
2018-05-26 22:28:24 +03:00
parent 7cc0f41903
commit b5fd095954
2 changed files with 13 additions and 8 deletions
+7 -3
View File
@@ -74,9 +74,13 @@ export default class Root extends Component {
});
}
checkUrlHash() {
if (window.location.hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) {
const comment = document.querySelector(window.location.hash);
checkUrlHash(e) {
const hash = e ? `#${e.newURL.split('#')[1]}` : window.location.hash;
if (hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) {
if (e) e.preventDefault();
const comment = document.querySelector(hash);
if (comment) {
setTimeout(() => {
+6 -5
View File
@@ -75,11 +75,12 @@ function init() {
}
function postHashToIframe(e) {
if (!e && location.hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) {
iframe.contentWindow.postMessage(JSON.stringify({ hash: location.hash }), '*');
} else if (e && e.newURL.includes(`#${COMMENT_NODE_CLASSNAME_PREFIX}`)) {
e.preventDefault();
iframe.contentWindow.postMessage(JSON.stringify({ hash: `#${e.newURL.split('#')[1]}` }), '*');
const hash = e ? `#${e.newURL.split('#')[1]}` : window.location.hash;
if (hash.indexOf(`#${COMMENT_NODE_CLASSNAME_PREFIX}`) === 0) {
if (e) e.preventDefault();
iframe.contentWindow.postMessage(JSON.stringify({ hash }), '*');
}
}
}