1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

WebPage: Fix scroll to anchor workaround to also look for element ids

BUG: 402836
FIXED-IN: 3.1.0
This commit is contained in:
David Rosca 2019-01-24 15:36:02 +01:00
parent 675f148598
commit 25a6008e6d
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 19 additions and 2 deletions

View File

@ -332,3 +332,19 @@ QString Scripts::getFormData(const QPointF &pos)
return source.arg(pos.x()).arg(pos.y());
}
QString Scripts::scrollToAnchor(const QString &anchor)
{
QString source = QL1S("(function() {"
"var e = document.getElementById(\"%1\");"
"if (!e) {"
" var els = document.querySelectorAll(\"[name='%1']\");"
" if (els.length)"
" e = els[0];"
"}"
"if (e)"
" e.scrollIntoView();"
"})()");
return source.arg(anchor);
}

View File

@ -40,6 +40,7 @@ public:
static QString getAllImages();
static QString getAllMetaAttributes();
static QString getFormData(const QPointF &pos);
static QString scrollToAnchor(const QString &anchor);
};
#endif // SCRIPTS_H

View File

@ -41,6 +41,7 @@
#include "ui_jsalert.h"
#include "ui_jsprompt.h"
#include "passwordmanager.h"
#include "scripts.h"
#include <iostream>
@ -98,8 +99,7 @@ WebPage::WebPage(QObject* parent)
m_contentsResizedConnection = connect(this, &QWebEnginePage::contentsSizeChanged, this, [this]() {
const QString fragment = url().fragment();
if (!fragment.isEmpty()) {
const QString src = QSL("var els = document.querySelectorAll(\"[name='%1']\"); if (els.length) els[0].scrollIntoView();");
runJavaScript(src.arg(fragment));
runJavaScript(Scripts::scrollToAnchor(fragment));
}
disconnect(m_contentsResizedConnection);
});