mirror of
https://github.com/MarshalX/telegram-crawler.git
synced 2025-01-11 12:41:37 +01:00
Update content of files
This commit is contained in:
parent
5dea094c25
commit
8ae0692fa3
3 changed files with 27 additions and 10 deletions
|
@ -50,11 +50,23 @@
|
|||
window.Telegram.WebApp.MainButton.setParams({});
|
||||
}
|
||||
}
|
||||
|
||||
var lastWindowHeight = window.innerHeight, skipOnViewportChanged = false;
|
||||
function onViewportChanged(eventType, eventData) {
|
||||
if (eventData.height) {
|
||||
if (!skipOnViewportChanged &&
|
||||
eventData.height) {
|
||||
window.removeEventListener('resize', onWindowResize);
|
||||
setViewportHeight(eventData.height);
|
||||
}
|
||||
}
|
||||
function onWindowResize(e) {
|
||||
if (lastWindowHeight != window.innerHeight) {
|
||||
lastWindowHeight = window.innerHeight;
|
||||
skipOnViewportChanged = true;
|
||||
receiveEvent('viewport_changed', {height: lastWindowHeight});
|
||||
skipOnViewportChanged = false;
|
||||
}
|
||||
}
|
||||
|
||||
function urlSafeDecode(urlencoded) {
|
||||
try {
|
||||
|
@ -127,12 +139,10 @@
|
|||
|
||||
if (window.TelegramWebviewProxy !== undefined) {
|
||||
TelegramWebviewProxy.postEvent(eventType, JSON.stringify(eventData));
|
||||
console.log('[Telegram.WebView] postEvent via TelegramWebviewProxy', eventType, eventData);
|
||||
callback();
|
||||
}
|
||||
else if (window.external && 'notify' in window.external) {
|
||||
window.external.notify(JSON.stringify({eventType: eventType, eventData: eventData}));
|
||||
console.log('[Telegram.WebView] postEvent via external.notify', eventType, eventData);
|
||||
callback();
|
||||
}
|
||||
else if (isIframe) {
|
||||
|
@ -141,20 +151,26 @@
|
|||
// For now we don't restrict target, for testing purposes
|
||||
trustedTarget = '*';
|
||||
window.parent.postMessage(JSON.stringify({eventType: eventType, eventData: eventData}), trustedTarget);
|
||||
console.log('[Telegram.WebView] postEvent via postMessage', eventType, eventData);
|
||||
if (initParams.tgWebAppDebug) {
|
||||
console.log('[Telegram.WebView] postEvent via postMessage', eventType, eventData);
|
||||
}
|
||||
callback();
|
||||
} catch (e) {
|
||||
callback(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
console.log('[Telegram.WebView] postEvent', eventType, eventData);
|
||||
if (initParams.tgWebAppDebug) {
|
||||
console.log('[Telegram.WebView] postEvent', eventType, eventData);
|
||||
}
|
||||
callback({notAvailable: true});
|
||||
}
|
||||
};
|
||||
|
||||
function receiveEvent(eventType, eventData) {
|
||||
console.log('[Telegram.WebView] receiveEvent', eventType, eventData);
|
||||
if (initParams.tgWebAppDebug) {
|
||||
console.log('[Telegram.WebView] receiveEvent', eventType, eventData);
|
||||
}
|
||||
var curEventHandlers = eventHandlers[eventType];
|
||||
if (curEventHandlers === undefined ||
|
||||
!curEventHandlers.length) {
|
||||
|
@ -613,6 +629,8 @@
|
|||
onEvent('viewport_changed', onViewportChanged);
|
||||
postEvent('web_app_request_viewport');
|
||||
|
||||
window.addEventListener('resize', onWindowResize);
|
||||
|
||||
// For Windows Phone app
|
||||
window.TelegramGameProxy_receiveEvent = receiveEvent;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<meta name="MobileOptimized" content="176" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="robots" content="noindex, nofollow" />
|
||||
<script src="https://tg.dev/js/telegram-webview.js?9"></script>
|
||||
<script src="https://tg.dev/js/telegram-webview.js?10"></script>
|
||||
<script>
|
||||
function setThemeClass() {
|
||||
document.documentElement.className = document.documentElement.style.getPropertyValue('--tg-theme-color-scheme');
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<meta name="MobileOptimized" content="176" />
|
||||
<meta name="HandheldFriendly" content="True" />
|
||||
<meta name="robots" content="noindex,nofollow" />
|
||||
<script src="https://telegram.org/js/telegram-webview.js?9"></script>
|
||||
<script src="https://telegram.org/js/telegram-webview.js?10"></script>
|
||||
<script>
|
||||
function setThemeClass() {
|
||||
document.documentElement.className = document.documentElement.style.getPropertyValue('--tg-theme-color-scheme');
|
||||
|
@ -338,8 +338,7 @@ Telegram.WebApp.MainButton
|
|||
.onClick(function(){ webviewClose(); });
|
||||
|
||||
function setViewportHeight() {
|
||||
var h = document.documentElement.style.getPropertyValue('--tg-viewport-height');
|
||||
$('.viewport_border').attr('text', h);
|
||||
$('.viewport_border').attr('text', window.innerWidth + ' x ' + Telegram.WebApp.viewportHeight);
|
||||
}
|
||||
Telegram.WebApp.onEvent('viewport_changed', setViewportHeight);
|
||||
setViewportHeight();
|
||||
|
|
Loading…
Reference in a new issue