Update content of files

This commit is contained in:
GitHub Action 2022-05-24 12:50:44 +00:00
parent 72d18f2db6
commit 41351769be
5 changed files with 84 additions and 30 deletions

View file

@ -395,12 +395,19 @@
function parseColorToHex(color) { function parseColorToHex(color) {
color += ''; color += '';
var match; var match;
if (/^#([0-9a-f]){6}$/i.test(color)) { if (match = /^\s*#([0-9a-f]{6})\s*$/i.exec(color)) {
return color.toLowerCase(); return '#' + match[1].toLowerCase();
} }
else if (match = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(color)) { else if (match = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(color)) {
return ('#' + match[1] + match[1] + match[2] + match[2] + match[3] + match[3]).toLowerCase(); return ('#' + match[1] + match[1] + match[2] + match[2] + match[3] + match[3]).toLowerCase();
} }
else if (match = /^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(color)) {
var r = parseInt(match[1]), g = parseInt(match[2]), b = parseInt(match[3]);
r = (r < 16 ? '0' : '') + r.toString(16);
g = (g < 16 ? '0' : '') + g.toString(16);
b = (b < 16 ? '0' : '') + b.toString(16);
return '#' + r + g + b;
}
return false; return false;
} }
@ -450,11 +457,6 @@
return s; return s;
} }
var windowOpen = window.open;
window.open = function(url) {
WebApp.openLink(url);
};
var BackButton = (function() { var BackButton = (function() {
var isVisible = false; var isVisible = false;
@ -487,7 +489,9 @@
function buttonCheckVersion() { function buttonCheckVersion() {
if (!versionAtLeast('6.1')) { if (!versionAtLeast('6.1')) {
console.warn('[Telegram.WebApp] BackButton is not supported in version ' + webAppVersion); console.warn('[Telegram.WebApp] BackButton is not supported in version ' + webAppVersion);
return false;
} }
return true;
} }
function updateButton() { function updateButton() {
@ -501,6 +505,9 @@
} }
function setParams(params) { function setParams(params) {
if (!buttonCheckVersion()) {
return backButton;
}
if (typeof params.is_visible !== 'undefined') { if (typeof params.is_visible !== 'undefined') {
isVisible = !!params.is_visible; isVisible = !!params.is_visible;
} }
@ -509,21 +516,21 @@
} }
backButton.onClick = function(callback) { backButton.onClick = function(callback) {
buttonCheckVersion(); if (buttonCheckVersion()) {
onWebViewEvent('backButtonClicked', callback); onWebViewEvent('backButtonClicked', callback);
}
return backButton; return backButton;
}; };
backButton.offClick = function(callback) { backButton.offClick = function(callback) {
buttonCheckVersion(); if (buttonCheckVersion()) {
offWebViewEvent('backButtonClicked', callback); offWebViewEvent('backButtonClicked', callback);
}
return backButton; return backButton;
}; };
backButton.show = function() { backButton.show = function() {
buttonCheckVersion();
return setParams({is_visible: true}); return setParams({is_visible: true});
}; };
backButton.hide = function() { backButton.hide = function() {
buttonCheckVersion();
return setParams({is_visible: false}); return setParams({is_visible: false});
}; };
return backButton; return backButton;
@ -685,7 +692,7 @@
} else { } else {
var color = parseColorToHex(params.color); var color = parseColorToHex(params.color);
if (!color) { if (!color) {
console.error('[Telegram.WebApp] Main button color format is invalid', color); console.error('[Telegram.WebApp] Main button color format is invalid', params.color);
throw Error('WebAppMainButtonParamInvalid'); throw Error('WebAppMainButtonParamInvalid');
} }
buttonColor = color; buttonColor = color;
@ -698,7 +705,7 @@
} else { } else {
var text_color = parseColorToHex(params.text_color); var text_color = parseColorToHex(params.text_color);
if (!text_color) { if (!text_color) {
console.error('[Telegram.WebApp] Main button text color format is invalid', text_color); console.error('[Telegram.WebApp] Main button text color format is invalid', params.text_color);
throw Error('WebAppMainButtonParamInvalid'); throw Error('WebAppMainButtonParamInvalid');
} }
buttonTextColor = text_color; buttonTextColor = text_color;
@ -764,6 +771,10 @@
var hapticFeedback = {}; var hapticFeedback = {};
function triggerFeedback(params) { function triggerFeedback(params) {
if (!versionAtLeast('6.1')) {
console.warn('[Telegram.WebApp] HapticFeedback is not supported in version ' + webAppVersion);
return hapticFeedback;
}
if (params.type == 'impact') { if (params.type == 'impact') {
if (params.impact_style != 'light' && if (params.impact_style != 'light' &&
params.impact_style != 'medium' && params.impact_style != 'medium' &&
@ -786,14 +797,11 @@
console.error('[Telegram.WebApp] Haptic feedback type is invalid', params.type); console.error('[Telegram.WebApp] Haptic feedback type is invalid', params.type);
throw Error('WebAppHapticFeedbackTypeInvalid'); throw Error('WebAppHapticFeedbackTypeInvalid');
} }
if (!versionAtLeast('6.1')) {
console.warn('[Telegram.WebApp] HapticFeedback is not supported in version ' + webAppVersion);
}
WebView.postEvent('web_app_trigger_haptic_feedback', false, params); WebView.postEvent('web_app_trigger_haptic_feedback', false, params);
return hapticFeedback; return hapticFeedback;
} }
hapticFeedback.impactOccupped = function(style) { hapticFeedback.impactOccurred = function(style) {
return triggerFeedback({type: 'impact', impact_style: style}); return triggerFeedback({type: 'impact', impact_style: style});
}; };
hapticFeedback.notificationOccurred = function(type) { hapticFeedback.notificationOccurred = function(type) {
@ -868,6 +876,22 @@
value: HapticFeedback, value: HapticFeedback,
enumerable: true enumerable: true
}); });
WebApp.setHeaderColor = function(color_key) {
if (color_key != 'bg_color' &&
color_key != 'secondary_bg_color') {
console.error('[Telegram.WebApp] Header color key should be one of \'bg_color\', \'secondary_bg_color\'', color_key);
throw Error('WebAppHeaderColorKeyInvalid');
}
WebView.postEvent('web_app_set_header_color', false, {color_key: color_key});
};
WebApp.setBackgroundColor = function(color) {
var bg_color = parseColorToHex(color);
if (!bg_color) {
console.error('[Telegram.WebApp] Background color format is invalid', color);
throw Error('WebAppBackgroundColorInvalid');
}
WebView.postEvent('web_app_set_background_color', false, {color: color});
};
WebApp.isVersionAtLeast = function(ver) { WebApp.isVersionAtLeast = function(ver) {
return versionAtLeast(ver); return versionAtLeast(ver);
}; };
@ -899,7 +923,7 @@
if (versionAtLeast('6.1')) { if (versionAtLeast('6.1')) {
WebView.postEvent('web_app_open_link', false, {url: url}); WebView.postEvent('web_app_open_link', false, {url: url});
} else { } else {
windowOpen(url, '_blank'); window.open(url, '_blank');
} }
}; };
WebApp.openTelegramLink = function (url) { WebApp.openTelegramLink = function (url) {

View file

@ -9,7 +9,7 @@
<meta name="MobileOptimized" content="176" /> <meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" /> <meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex, nofollow" /> <meta name="robots" content="noindex, nofollow" />
<script src="https://tg.dev/js/telegram-web-app.js?11"></script> <script src="https://tg.dev/js/telegram-web-app.js?13"></script>
<script> <script>
function setThemeClass() { function setThemeClass() {
document.documentElement.className = Telegram.WebApp.colorScheme; document.documentElement.className = Telegram.WebApp.colorScheme;
@ -17,7 +17,7 @@
Telegram.WebApp.onEvent('themeChanged', setThemeClass); Telegram.WebApp.onEvent('themeChanged', setThemeClass);
setThemeClass(); setThemeClass();
</script> </script>
<link href="/css/cafe.css?17" rel="stylesheet"> <link href="/css/cafe.css?18" rel="stylesheet">
</head> </head>
<body style="display:none"> <body style="display:none">
<section class="cafe-page cafe-items"> <section class="cafe-page cafe-items">
@ -441,7 +441,7 @@
</div> </div>
<script src="https://tg.dev/js/jquery.min.js"></script> <script src="https://tg.dev/js/jquery.min.js"></script>
<script src="https://tg.dev/js/tgsticker.js?27"></script> <script src="https://tg.dev/js/tgsticker.js?27"></script>
<script src="/js/cafe.js?21"></script> <script src="/js/cafe.js?22"></script>
<script>Cafe.init({"apiUrl":"\/cafe\/api","userId":0,"userHash":null});</script> <script>Cafe.init({"apiUrl":"\/cafe\/api","userId":0,"userHash":null});</script>
</body> </body>
</html> </html>

View file

@ -38,7 +38,10 @@ html.dark body {
--hint-color: #64666d; --hint-color: #64666d;
--placeholder-color: #5d6163; --placeholder-color: #5d6163;
} }
body.order-mode { html.order-mode {
background-color: var(--bg-color);
}
html.order-mode body {
background-color: var(--bg-color); background-color: var(--bg-color);
} }
@ -69,7 +72,7 @@ body.closed .cafe-page {
transition: max-height var(--page-animation), opacity var(--page-animation); transition: max-height var(--page-animation), opacity var(--page-animation);
background-color: var(--block-bg-color); background-color: var(--block-bg-color);
} }
body.order-mode .cafe-items { html.order-mode .cafe-items {
max-height: 0 !important; max-height: 0 !important;
opacity: 0 !important; opacity: 0 !important;
} }
@ -290,7 +293,7 @@ button,
transition: opacity var(--page-animation); transition: opacity var(--page-animation);
opacity: 0; opacity: 0;
} }
body.order-mode .cafe-order-overview { html.order-mode .cafe-order-overview {
opacity: 1; opacity: 1;
} }
.cafe-order-header-wrap { .cafe-order-header-wrap {

View file

@ -8,7 +8,7 @@
<meta name="MobileOptimized" content="176" /> <meta name="MobileOptimized" content="176" />
<meta name="HandheldFriendly" content="True" /> <meta name="HandheldFriendly" content="True" />
<meta name="robots" content="noindex,nofollow" /> <meta name="robots" content="noindex,nofollow" />
<script src="https://telegram.org/js/telegram-web-app.js?11"></script> <script src="https://telegram.org/js/telegram-web-app.js?13"></script>
<script> <script>
function setThemeClass() { function setThemeClass() {
document.documentElement.className = Telegram.WebApp.colorScheme; document.documentElement.className = Telegram.WebApp.colorScheme;
@ -400,6 +400,7 @@ function setViewportData() {
$('.viewport_border').attr('text', window.innerWidth + ' x ' + round(Telegram.WebApp.viewportHeight, 2)); $('.viewport_border').attr('text', window.innerWidth + ' x ' + round(Telegram.WebApp.viewportHeight, 2));
$('.viewport_stable_border').attr('text', window.innerWidth + ' x ' + round(Telegram.WebApp.viewportStableHeight, 2) + ' | is_expanded: ' + (Telegram.WebApp.isExpanded ? 'true' : 'false')); $('.viewport_stable_border').attr('text', window.innerWidth + ' x ' + round(Telegram.WebApp.viewportStableHeight, 2) + ' | is_expanded: ' + (Telegram.WebApp.isExpanded ? 'true' : 'false'));
} }
Telegram.WebApp.setHeaderColor('bg_color');
Telegram.WebApp.onEvent('viewportChanged', setViewportData); Telegram.WebApp.onEvent('viewportChanged', setViewportData);
setViewportData(); setViewportData();

View file

@ -35,6 +35,7 @@ var Cafe = {
text_color: '#fff' text_color: '#fff'
}).onClick(Cafe.mainBtnClicked); }).onClick(Cafe.mainBtnClicked);
Telegram.WebApp.BackButton.onClick(Cafe.backBtnClicked); Telegram.WebApp.BackButton.onClick(Cafe.backBtnClicked);
Telegram.WebApp.setHeaderColor('bg_color');
initRipple(); initRipple();
}, },
initLotties: function() { initLotties: function() {
@ -150,6 +151,11 @@ var Cafe = {
} }
return s.join(dec) return s.join(dec)
}, },
updateBackgroundColor: function() {
var style = window.getComputedStyle(document.body);
var bg_color = parseColorToHex(style.backgroundColor || '#fff');
Telegram.WebApp.setBackgroundColor(bg_color);
},
updateMainButton: function() { updateMainButton: function() {
var mainButton = Telegram.WebApp.MainButton; var mainButton = Telegram.WebApp.MainButton;
if (Cafe.modeOrder) { if (Cafe.modeOrder) {
@ -220,7 +226,7 @@ var Cafe = {
}); });
$('.cafe-order-overview').show(); $('.cafe-order-overview').show();
$('.cafe-items').css('maxHeight', height).redraw(); $('.cafe-items').css('maxHeight', height).redraw();
$('body').addClass('order-mode'); $('html').addClass('order-mode');
$('.js-order-comment-field').each(function() { $('.js-order-comment-field').each(function() {
autosize.update(this); autosize.update(this);
}); });
@ -235,7 +241,7 @@ var Cafe = {
$('.js-item-lottie').each(function() { $('.js-item-lottie').each(function() {
RLottie.setVisible(this, false); RLottie.setVisible(this, false);
}); });
$('body').removeClass('order-mode'); $('html').removeClass('order-mode');
setTimeout(function() { setTimeout(function() {
$('.cafe-items').css('maxHeight', ''); $('.cafe-items').css('maxHeight', '');
$('.cafe-order-overview').hide(); $('.cafe-order-overview').hide();
@ -245,6 +251,7 @@ var Cafe = {
}, anim_duration); }, anim_duration);
Telegram.WebApp.BackButton.hide(); Telegram.WebApp.BackButton.hide();
} }
Cafe.updateBackgroundColor();
Cafe.updateMainButton(); Cafe.updateMainButton();
}, },
toggleLoading: function(loading) { toggleLoading: function(loading) {
@ -333,6 +340,25 @@ var Cafe = {
} }
}; };
function parseColorToHex(color) {
color += '';
var match;
if (match = /^\s*#([0-9a-f]{6})\s*$/i.exec(color)) {
return '#' + match[1].toLowerCase();
}
else if (match = /^\s*#([0-9a-f])([0-9a-f])([0-9a-f])\s*$/i.exec(color)) {
return ('#' + match[1] + match[1] + match[2] + match[2] + match[3] + match[3]).toLowerCase();
}
else if (match = /^\s*rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+\.{0,1}\d*))?\)\s*$/.exec(color)) {
var r = parseInt(match[1]), g = parseInt(match[2]), b = parseInt(match[3]);
r = (r < 16 ? '0' : '') + r.toString(16);
g = (g < 16 ? '0' : '') + g.toString(16);
b = (b < 16 ? '0' : '') + b.toString(16);
return '#' + r + g + b;
}
return false;
}
/*! /*!
Autosize 3.0.20 Autosize 3.0.20
license: MIT license: MIT