mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 06:07:06 +02:00
Fix navigation on macOS.
This commit is contained in:
parent
8b62c37c34
commit
5f3c380d56
2 changed files with 34 additions and 10 deletions
|
@ -93,13 +93,16 @@ var IV = {
|
|||
},
|
||||
lastScrollTop: 0,
|
||||
frameScrolled: function (e) {
|
||||
const now = document.documentElement.scrollTop;
|
||||
if (now < 100) {
|
||||
const was = IV.lastScrollTop;
|
||||
IV.lastScrollTop = IV.findPageScroll().scrollTop;
|
||||
IV.updateJumpToTop(was < IV.lastScrollTop);
|
||||
},
|
||||
updateJumpToTop: function (scrolledDown) {
|
||||
if (IV.lastScrollTop < 100) {
|
||||
document.getElementById('bottom_up').classList.add('hidden');
|
||||
} else if (now > IV.lastScrollTop && now > 200) {
|
||||
} else if (scrolledDown && IV.lastScrollTop > 200) {
|
||||
document.getElementById('bottom_up').classList.remove('hidden');
|
||||
}
|
||||
IV.lastScrollTop = now;
|
||||
},
|
||||
updateStyles: function (styles) {
|
||||
if (IV.styles !== styles) {
|
||||
|
@ -221,7 +224,13 @@ var IV = {
|
|||
}
|
||||
},
|
||||
init: function () {
|
||||
IV.platform = window.navigator.platform.toLowerCase();
|
||||
IV.mac = IV.platform.startsWith('mac');
|
||||
IV.win = IV.platform.startsWith('win');
|
||||
|
||||
window.history.replaceState(IV.computeCurrentState(), '');
|
||||
IV.lastScrollTop = window.history.state.scroll;
|
||||
IV.findPageScroll().onscroll = IV.frameScrolled;
|
||||
|
||||
const buttons = document.getElementsByClassName('fixed_button');
|
||||
for (let i = 0; i < buttons.length; ++i) {
|
||||
|
@ -287,7 +296,9 @@ var IV = {
|
|||
}, 3000);
|
||||
},
|
||||
scrollTo: function (y, instant) {
|
||||
document.getElementById('bottom_up').classList.add('hidden');
|
||||
if (y < 200) {
|
||||
document.getElementById('bottom_up').classList.add('hidden');
|
||||
}
|
||||
IV.findPageScroll().scrollTo({
|
||||
top: y || 0,
|
||||
behavior: instant ? 'instant' : 'smooth'
|
||||
|
@ -348,6 +359,7 @@ var IV = {
|
|||
el.innerHTML = '<div class="page-slide"><article>'
|
||||
+ data.html
|
||||
+ '</article></div>';
|
||||
el.onscroll = IV.frameScrolled;
|
||||
IV.cache[index].dom = el;
|
||||
|
||||
IV.navigateToDOM(index, hash);
|
||||
|
@ -357,7 +369,7 @@ var IV = {
|
|||
navigateToDOM: function (index, hash) {
|
||||
IV.pending = null;
|
||||
if (IV.index == index) {
|
||||
IV.jumpToHash(hash);
|
||||
IV.jumpToHash(hash, IV.mac);
|
||||
return;
|
||||
}
|
||||
window.history.replaceState(IV.computeCurrentState(), '');
|
||||
|
@ -429,11 +441,16 @@ var IV = {
|
|||
IV.initMedia();
|
||||
if (scroll === undefined) {
|
||||
IV.jumpToHash(hash, true);
|
||||
} else {
|
||||
IV.lastScrollTop = scroll;
|
||||
IV.updateJumpToTop(true);
|
||||
}
|
||||
} else if (scroll !== undefined) {
|
||||
IV.scrollTo(scroll);
|
||||
IV.scrollTo(scroll, IV.mac);
|
||||
IV.lastScrollTop = scroll;
|
||||
IV.updateJumpToTop(true);
|
||||
} else {
|
||||
IV.jumpToHash(hash);
|
||||
IV.jumpToHash(hash, IV.mac);
|
||||
}
|
||||
},
|
||||
back: function () {
|
||||
|
@ -449,7 +466,6 @@ document.onclick = IV.frameClickHandler;
|
|||
document.onkeydown = IV.frameKeyDown;
|
||||
document.onmouseenter = IV.frameMouseEnter;
|
||||
document.onmouseup = IV.frameMouseUp;
|
||||
document.onscroll = IV.frameScrolled;
|
||||
window.onmessage = IV.postMessageHandler;
|
||||
|
||||
window.addEventListener('popstate', function (e) {
|
||||
|
|
|
@ -204,7 +204,9 @@ Controller::Controller()
|
|||
}
|
||||
|
||||
Controller::~Controller() {
|
||||
_window->hide();
|
||||
if (_window) {
|
||||
_window->hide();
|
||||
}
|
||||
_ready = false;
|
||||
_webview = nullptr;
|
||||
_title = nullptr;
|
||||
|
@ -424,6 +426,10 @@ void Controller::createWebview(const QString &dataPath) {
|
|||
});
|
||||
});
|
||||
raw->setDataRequestHandler([=](Webview::DataRequest request) {
|
||||
const auto pos = request.id.find('#');
|
||||
if (pos != request.id.npos) {
|
||||
request.id = request.id.substr(0, pos);
|
||||
}
|
||||
if (!request.id.starts_with("iv/")) {
|
||||
_dataRequests.fire(std::move(request));
|
||||
return Webview::DataResult::Pending;
|
||||
|
@ -520,11 +526,13 @@ void Controller::showInWindow(const QString &dataPath, Prepared page) {
|
|||
}
|
||||
} else if (_ready) {
|
||||
_webview->eval(navigateScript(index, hash));
|
||||
_window->raise();
|
||||
_window->activateWindow();
|
||||
_window->setFocus();
|
||||
} else {
|
||||
_navigateToIndexWhenReady = index;
|
||||
_navigateToHashWhenReady = hash;
|
||||
_window->raise();
|
||||
_window->activateWindow();
|
||||
_window->setFocus();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue