mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 22:54:01 +02:00
Support anchor jumps.
This commit is contained in:
parent
51d5b7bab6
commit
5c428ca502
7 changed files with 53 additions and 16 deletions
|
@ -7,7 +7,6 @@ var IV = {
|
||||||
frameClickHandler: function(e) {
|
frameClickHandler: function(e) {
|
||||||
var target = e.target;
|
var target = e.target;
|
||||||
var context = '';
|
var context = '';
|
||||||
console.log('click', target);
|
|
||||||
while (target) {
|
while (target) {
|
||||||
if (target.tagName == 'AUDIO' || target.tagName == 'VIDEO') {
|
if (target.tagName == 'AUDIO' || target.tagName == 'VIDEO') {
|
||||||
return;
|
return;
|
||||||
|
@ -25,16 +24,28 @@ var IV = {
|
||||||
if (!target || !target.hasAttribute('href')) {
|
if (!target || !target.hasAttribute('href')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var base_loc = document.createElement('A');
|
var base = document.createElement('A');
|
||||||
base_loc.href = window.currentUrl;
|
base.href = window.location.href;
|
||||||
if (base_loc.origin != target.origin
|
if (base.origin != target.origin
|
||||||
|| base_loc.pathname != target.pathname
|
|| base.pathname != target.pathname
|
||||||
|| base_loc.search != target.search) {
|
|| base.search != target.search) {
|
||||||
IV.notify({
|
IV.notify({
|
||||||
event: 'link_click',
|
event: 'link_click',
|
||||||
url: target.href,
|
url: target.href,
|
||||||
context: context,
|
context: context,
|
||||||
});
|
});
|
||||||
|
} else if (target.hash.length < 2) {
|
||||||
|
IV.hash = '';
|
||||||
|
IV.scrollTo(0);
|
||||||
|
} else {
|
||||||
|
const name = target.hash.substr(1);
|
||||||
|
IV.hash = name;
|
||||||
|
|
||||||
|
const element = document.getElementsByName(name)[0];
|
||||||
|
if (element) {
|
||||||
|
const y = element.getBoundingClientRect().y;
|
||||||
|
IV.scrollTo(y + document.documentElement.scrollTop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
},
|
},
|
||||||
|
@ -183,6 +194,8 @@ var IV = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
init: function () {
|
init: function () {
|
||||||
|
IV.hash = window.location.hash.substr(1);
|
||||||
|
|
||||||
const buttons = document.getElementsByClassName('fixed_button');
|
const buttons = document.getElementsByClassName('fixed_button');
|
||||||
for (let i = 0; i < buttons.length; ++i) {
|
for (let i = 0; i < buttons.length; ++i) {
|
||||||
const button = buttons[i];
|
const button = buttons[i];
|
||||||
|
@ -210,9 +223,9 @@ var IV = {
|
||||||
document.body.removeChild(toast);
|
document.body.removeChild(toast);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
},
|
},
|
||||||
toTop: function () {
|
scrollTo: function (y) {
|
||||||
document.getElementById('bottom_up').classList.add('hidden');
|
document.getElementById('bottom_up').classList.add('hidden');
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
window.scrollTo({ top: y || 0, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ namespace {
|
||||||
<circle cx="12" cy="6.6" r="1.7"></circle>
|
<circle cx="12" cy="6.6" r="1.7"></circle>
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
<button class="fixed_button hidden" id="bottom_up" onclick="IV.toTop();">
|
<button class="fixed_button hidden" id="bottom_up" onclick="IV.scrollTo(0);">
|
||||||
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M14.9972363,18 L9.13865768,12.1414214 C9.06055283,12.0633165 9.06055283,11.9366835 9.13865768,11.8585786 L14.9972363,6 L14.9972363,6" transform="translate(11.997236, 12.000000) scale(-1, -1) rotate(-90.000000) translate(-11.997236, -12.000000) "></path>
|
<path d="M14.9972363,18 L9.13865768,12.1414214 C9.06055283,12.0633165 9.06055283,11.9366835 9.13865768,11.8585786 L14.9972363,6 L14.9972363,6" transform="translate(11.997236, 12.000000) scale(-1, -1) rotate(-90.000000) translate(-11.997236, -12.000000) "></path>
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -458,7 +458,12 @@ void Controller::showInWindow(
|
||||||
});
|
});
|
||||||
|
|
||||||
raw->init(R"()");
|
raw->init(R"()");
|
||||||
raw->navigateToData("iv/page.html");
|
|
||||||
|
auto id = u"iv/page.html"_q;
|
||||||
|
if (!page.hash.isEmpty()) {
|
||||||
|
id += '#' + page.hash;
|
||||||
|
}
|
||||||
|
raw->navigateToData(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::processKey(const QString &key, const QString &modifier) {
|
void Controller::processKey(const QString &key, const QString &modifier) {
|
||||||
|
@ -487,6 +492,8 @@ void Controller::processLink(const QString &url, const QString &context) {
|
||||||
Event::Type::JoinChannel,
|
Event::Type::JoinChannel,
|
||||||
context.mid(joinPrefix.size()),
|
context.mid(joinPrefix.size()),
|
||||||
});
|
});
|
||||||
|
} else if (context.isEmpty()) {
|
||||||
|
_events.fire({ Event::Type::OpenLink, url });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ public:
|
||||||
Quit,
|
Quit,
|
||||||
OpenChannel,
|
OpenChannel,
|
||||||
JoinChannel,
|
JoinChannel,
|
||||||
|
OpenLink,
|
||||||
};
|
};
|
||||||
Type type = Type::Close;
|
Type type = Type::Close;
|
||||||
QString context;
|
QString context;
|
||||||
|
|
|
@ -18,6 +18,7 @@ struct Options {
|
||||||
struct Prepared {
|
struct Prepared {
|
||||||
QString title;
|
QString title;
|
||||||
QByteArray content;
|
QByteArray content;
|
||||||
|
QString hash;
|
||||||
std::vector<QByteArray> resources;
|
std::vector<QByteArray> resources;
|
||||||
base::flat_map<QByteArray, QByteArray> embeds;
|
base::flat_map<QByteArray, QByteArray> embeds;
|
||||||
base::flat_set<QByteArray> channelIds;
|
base::flat_set<QByteArray> channelIds;
|
||||||
|
|
|
@ -29,6 +29,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "storage/file_download.h"
|
#include "storage/file_download.h"
|
||||||
#include "storage/storage_domain.h"
|
#include "storage/storage_domain.h"
|
||||||
#include "ui/boxes/confirm_box.h"
|
#include "ui/boxes/confirm_box.h"
|
||||||
|
#include "ui/basic_click_handlers.h"
|
||||||
#include "webview/webview_data_stream_memory.h"
|
#include "webview/webview_data_stream_memory.h"
|
||||||
#include "webview/webview_interface.h"
|
#include "webview/webview_interface.h"
|
||||||
#include "window/window_controller.h"
|
#include "window/window_controller.h"
|
||||||
|
@ -65,7 +66,7 @@ public:
|
||||||
Shown(
|
Shown(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Data*> data,
|
not_null<Data*> data,
|
||||||
bool local);
|
QString hash);
|
||||||
|
|
||||||
[[nodiscard]] bool showing(
|
[[nodiscard]] bool showing(
|
||||||
not_null<Main::Session*> session,
|
not_null<Main::Session*> session,
|
||||||
|
@ -163,14 +164,15 @@ private:
|
||||||
Shown::Shown(
|
Shown::Shown(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Data*> data,
|
not_null<Data*> data,
|
||||||
bool local)
|
QString hash)
|
||||||
: _session(&show->session())
|
: _session(&show->session())
|
||||||
, _show(show)
|
, _show(show)
|
||||||
, _id(data->id()) {
|
, _id(data->id()) {
|
||||||
const auto weak = base::make_weak(this);
|
const auto weak = base::make_weak(this);
|
||||||
|
|
||||||
const auto base = local ? LookupLocalPath(show) : QString();
|
const auto base = /*local ? LookupLocalPath(show) : */QString();
|
||||||
data->prepare({ .saveToFolder = base }, [=](Prepared result) {
|
data->prepare({ .saveToFolder = base }, [=](Prepared result) {
|
||||||
|
result.hash = hash;
|
||||||
crl::on_main(weak, [=, result = std::move(result)]() mutable {
|
crl::on_main(weak, [=, result = std::move(result)]() mutable {
|
||||||
_embeds = std::move(result.embeds);
|
_embeds = std::move(result.embeds);
|
||||||
fillChannelJoinedValues(result);
|
fillChannelJoinedValues(result);
|
||||||
|
@ -701,12 +703,12 @@ Instance::~Instance() = default;
|
||||||
void Instance::show(
|
void Instance::show(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Data*> data,
|
not_null<Data*> data,
|
||||||
bool local) {
|
QString hash) {
|
||||||
const auto session = &show->session();
|
const auto session = &show->session();
|
||||||
if (_shown && _shown->showing(session, data)) {
|
if (_shown && _shown->showing(session, data)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_shown = std::make_unique<Shown>(show, data, local);
|
_shown = std::make_unique<Shown>(show, data, hash);
|
||||||
_shownSession = session;
|
_shownSession = session;
|
||||||
_shown->events() | rpl::start_with_next([=](Controller::Event event) {
|
_shown->events() | rpl::start_with_next([=](Controller::Event event) {
|
||||||
using Type = Controller::Event::Type;
|
using Type = Controller::Event::Type;
|
||||||
|
@ -723,6 +725,9 @@ void Instance::show(
|
||||||
case Type::JoinChannel:
|
case Type::JoinChannel:
|
||||||
processJoinChannel(event.context);
|
processJoinChannel(event.context);
|
||||||
break;
|
break;
|
||||||
|
case Type::OpenLink:
|
||||||
|
UrlClickHandler::Open(event.context);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}, _shown->lifetime());
|
}, _shown->lifetime());
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void show(
|
void show(
|
||||||
std::shared_ptr<Main::SessionShow> show,
|
std::shared_ptr<Main::SessionShow> show,
|
||||||
not_null<Data*> data,
|
not_null<Data*> data,
|
||||||
bool local);
|
QString hash);
|
||||||
|
|
||||||
[[nodiscard]] bool hasActiveWindow(
|
[[nodiscard]] bool hasActiveWindow(
|
||||||
not_null<Main::Session*> session) const;
|
not_null<Main::Session*> session) const;
|
||||||
|
|
|
@ -656,9 +656,14 @@ QByteArray Parser::block(const MTPDpageRelatedArticle &data) {
|
||||||
{ "class", "related-link-content" },
|
{ "class", "related-link-content" },
|
||||||
}, inner);
|
}, inner);
|
||||||
}
|
}
|
||||||
|
const auto webpageId = data.vwebpage_id().v;
|
||||||
|
const auto context = webpageId
|
||||||
|
? ("webpage" + QByteArray::number(webpageId))
|
||||||
|
: QByteArray();
|
||||||
return tag("a", {
|
return tag("a", {
|
||||||
{ "class", "related-link" },
|
{ "class", "related-link" },
|
||||||
{ "href", utf(data.vurl()) },
|
{ "href", utf(data.vurl()) },
|
||||||
|
{ "data-context", context },
|
||||||
}, result);
|
}, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -795,8 +800,13 @@ QByteArray Parser::rich(const MTPRichText &text) {
|
||||||
}, [&](const MTPDtextFixed &data) {
|
}, [&](const MTPDtextFixed &data) {
|
||||||
return tag("code", rich(data.vtext()));
|
return tag("code", rich(data.vtext()));
|
||||||
}, [&](const MTPDtextUrl &data) {
|
}, [&](const MTPDtextUrl &data) {
|
||||||
|
const auto webpageId = data.vwebpage_id().v;
|
||||||
|
const auto context = webpageId
|
||||||
|
? ("webpage" + QByteArray::number(webpageId))
|
||||||
|
: QByteArray();
|
||||||
return tag("a", {
|
return tag("a", {
|
||||||
{ "href", utf(data.vurl()) },
|
{ "href", utf(data.vurl()) },
|
||||||
|
{ "data-context", context },
|
||||||
}, rich(data.vtext()));
|
}, rich(data.vtext()));
|
||||||
}, [&](const MTPDtextEmail &data) {
|
}, [&](const MTPDtextEmail &data) {
|
||||||
return tag("a", {
|
return tag("a", {
|
||||||
|
|
Loading…
Add table
Reference in a new issue