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:
parent
675f148598
commit
25a6008e6d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user