diff --git a/resources/js/headerAnchor.js b/resources/js/headerAnchor.js index aec9ce910..ede8d1ff0 100644 --- a/resources/js/headerAnchor.js +++ b/resources/js/headerAnchor.js @@ -31,7 +31,7 @@ function anchorHeaderElements(headers) }); } -function getHeaders() +function getHeadersJSON() { const headerInfo = { url: window.location.href.replace(location.hash,""), headers: [] }; @@ -40,12 +40,12 @@ function getHeaders() const headers = getDOMElementsPreorderDFS(document.body, isHeaderElement); headerInfo.headers = anchorHeaderElements(headers); } - return headerInfo; + return JSON.stringify(headerInfo); } new QWebChannel(qt.webChannelTransport, function(channel) { var kiwixObj = channel.objects.kiwixChannelObj; - kiwixObj.sendHeaders(getHeaders()); + kiwixObj.sendHeadersJSON(getHeadersJSON()); kiwixObj.navigationRequested.connect(function(url, anchor) { if (window.location.href.replace(location.hash,"") == url) document.getElementById(anchor).scrollIntoView(); diff --git a/src/kiwixwebchannelobject.h b/src/kiwixwebchannelobject.h index 538c0da63..a4afaf223 100644 --- a/src/kiwixwebchannelobject.h +++ b/src/kiwixwebchannelobject.h @@ -10,10 +10,10 @@ class KiwixWebChannelObject : public QObject public: explicit KiwixWebChannelObject(QObject *parent = nullptr) : QObject(parent) {}; - Q_INVOKABLE void sendHeaders(const QJsonObject& headers) { emit headersChanged(headers); }; + Q_INVOKABLE void sendHeadersJSON(const QString& headersJSON) { emit headersChanged(headersJSON); }; signals: - void headersChanged(const QJsonObject& headers); + void headersChanged(const QString& headersJSON); void navigationRequested(const QString& url, const QString& anchor); }; diff --git a/src/tableofcontentbar.cpp b/src/tableofcontentbar.cpp index 97c2f8819..78531db34 100644 --- a/src/tableofcontentbar.cpp +++ b/src/tableofcontentbar.cpp @@ -85,8 +85,11 @@ void createSubTree(QTreeWidgetItem* parent, QString parentNo, QJsonArray& header void TableOfContentBar::setupTree(const QJsonObject& headers) { - const auto headerUrl = headers["url"].toString(); const auto webView = KiwixApp::instance()->getTabWidget()->currentWebView(); + if (!webView) + return; + + const auto headerUrl = headers["url"].toString(); const auto currentUrl = webView->url().url(QUrl::RemoveFragment); if (headerUrl != currentUrl) return; diff --git a/src/webview.cpp b/src/webview.cpp index 006ce7330..4b44faa4d 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -221,10 +221,10 @@ void WebView::onCurrentTitleChanged() emit headersChanged(m_headers); } -void WebView::onHeadersReceived(const QJsonObject& headers) +void WebView::onHeadersReceived(const QString& headersJSON) { const auto tabbar = KiwixApp::instance()->getTabWidget(); - m_headers = QJsonObject(headers); + m_headers = QJsonDocument::fromJson(headersJSON.toUtf8()).object(); if (tabbar->currentWebView() == this) emit headersChanged(m_headers); diff --git a/src/webview.h b/src/webview.h index 6ec8b5bf0..793136b4d 100644 --- a/src/webview.h +++ b/src/webview.h @@ -71,7 +71,7 @@ public slots: private slots: void gotoTriggeredHistoryItemAction(); void onCurrentTitleChanged(); - void onHeadersReceived(const QJsonObject& headers); + void onHeadersReceived(const QString& headersJSON); void onNavigationRequested(const QString& url, const QString& anchor); private: