From 60769e73f57bf9dd7df0bbe47f9df10ff4862aad Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 8 Apr 2022 11:15:09 +0000 Subject: [PATCH] Update content of files --- data/telegram.org/js/telegram-webview.js | 2 ++ data/webappcontent.telegram.org/demo.html | 33 +++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/data/telegram.org/js/telegram-webview.js b/data/telegram.org/js/telegram-webview.js index 8e05f277bf..7fdea422b0 100644 --- a/data/telegram.org/js/telegram-webview.js +++ b/data/telegram.org/js/telegram-webview.js @@ -450,9 +450,11 @@ mainButton.setParams = setParams; mainButton.setText = function(text) { mainButton.text = text; + return mainButton; }; mainButton.onClick = function(callback) { onClickCallback = callback; + return mainButton; }; mainButton.show = function() { return mainButton.setParams({is_visible: true}); diff --git a/data/webappcontent.telegram.org/demo.html b/data/webappcontent.telegram.org/demo.html index 070fc8a625..e284a724c5 100644 --- a/data/webappcontent.telegram.org/demo.html +++ b/data/webappcontent.telegram.org/demo.html @@ -150,7 +150,7 @@ function sendMessage(msg_id, with_webview) { $('#btn_status').text('Sending...').removeClass('ok err').show(); $.ajax('/demo/sendMessage', { type: 'POST', - data: {query_id: WebAppData.query_id, msg_id: msg_id || '', with_webview: !WebAppData.receiver && with_webview ? 1 : 0}, + data: {_auth: WebAppDataRaw, query_id: WebAppData.query_id, msg_id: msg_id || '', with_webview: !WebAppData.receiver && with_webview ? 1 : 0}, dataType: 'json', success: function(result) { $('button').prop('disabled', false); @@ -173,6 +173,35 @@ function sendMessage(msg_id, with_webview) { } }); } +function changeButton() { + $('button').prop('disabled', true); + $('#btn_status').text('Changing button...').removeClass('ok err').show(); + $.ajax('/demo/changeMenuButton', { + type: 'POST', + data: {_auth: WebAppDataRaw}, + dataType: 'json', + success: function(result) { + $('button').prop('disabled', false); + if (result.response) { + if (result.response.ok) { + $('#btn_status').html('Button changed!').addClass('ok').show(); + Telegram.WebApp.close(); + } else { + $('#btn_status').text(result.response.description).addClass('err').show(); + alert(result.response.description); + } + } else { + $('#btn_status').text('Unknown error').addClass('err').show(); + alert('Unknown error'); + } + }, + error: function(xhr) { + $('button').prop('disabled', false); + $('#btn_status').text('Server error').addClass('err').show(); + alert('Server error'); + } + }); +} function byteLength(str) { if (window.Blob) { try { return new Blob([str]).size; } catch (e) {} @@ -254,7 +283,7 @@ if (WebAppData.query_id && WebAppDataRaw) { $('#webview_data_status').show(); $.ajax('/demo/checkData', { type: 'POST', - data: {data: WebAppDataRaw}, + data: {_auth: WebAppDataRaw}, dataType: 'json', success: function(result) { if (result.ok) {