Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active December 4, 2018 04:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshliaer/10ea6ecf35f17f9340906714a9f7f714 to your computer and use it in GitHub Desktop.
Save oshliaer/10ea6ecf35f17f9340906714a9f7f714 to your computer and use it in GitHub Desktop.
function onOpen(){
SpreadsheetApp.getUi()
.createMenu("Примеры закрывашек")
.addItem("Закрыть диалог на клиенте после паузы (колбэк)", "showClientCloser")
.addItem("Закрыть диалог после расчетов на сервере", "showServerCloser")
.addToUi();
}
function showClientCloser(){
showDialog("js_clientCloser");
}
function showServerCloser(){
showDialog("js_serverCloser");
}
function getCloser(filename){
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}
function setServerTimeout(milliseconds){
Utilities.sleep(milliseconds);
}
function showDialog(closerName) {
var htmlTemplate = HtmlService.createTemplateFromFile("html_index");
htmlTemplate.closer = getCloser(closerName);
var userInterface = htmlTemplate.evaluate()
.setWidth(4).setHeight(3);
SpreadsheetApp.getUi().showModalDialog(userInterface, 'Победа');
}
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<audio id="player" autoplay>
<source src="http://pesochnica.tk/cut.mp3" type="audio/mpeg">
Ваш браузер не поддерживает аудио элементы.
</audio>
<?!= closer ?>
</body>
</html>
<script type="text/javascript">
window.onload = function() {
setTimeout(function() {
google.script.host.close();
}, 5000);
};
</script>
<script type="text/javascript">
window.onload = function() {
google.script.run
.withSuccessHandler(function() {
google.script.host.close();
})
.setServerTimeout(5000);
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment