From d5a0be02adac636593b3c5af2d1863d21cd24d73 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 19 Mar 2022 00:59:40 +0300 Subject: main.js: refactor overlay buttons --- assets/js/main.js | 133 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 58 deletions(-) diff --git a/assets/js/main.js b/assets/js/main.js index 7cb8d43..21b5d62 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -465,46 +465,19 @@ Data.prototype.hide_advanced = function() { }); } -function edit_btn_init(btn) { - btn.empty(); - btn.append(''); -} - -function edit_btn_save(btn) { - btn.empty(); - btn.append(''); -} - -function edit_btn_on_click(btn, pre) { - var editable = pre.prop('isContentEditable'); - pre.prop('contentEditable', !editable); - if (editable) { - edit_btn_init(btn); - btn.blur(); // a.k.a. unfocus - } else { - edit_btn_save(btn); - pre.focus(); - } -} - -function dload_btn_init(btn) { - btn.empty(); - btn.append(''); -} - function basename(path) { return path.substring(path.lastIndexOf('/') + 1); } -function dload_btn_on_click(btn, path, pre) { +function download(file_name, text) { // The type must be application/octet-stream; if it's text/plain, the // Android Chrome appends the .txt suffix to the downloaded file names. - var blob = new Blob([pre.text()], {type: 'application/octet-stream'}); + var blob = new Blob([text], {type: 'application/octet-stream'}); var url = URL.createObjectURL(blob); var link = $(''); link.prop('href', url); - link.prop('download', basename(path)); + link.prop('download', file_name); // Whoever thought of this [0] is fucking crazy: // https://stackoverflow.com/a/36483380/514684 @@ -557,44 +530,75 @@ function copy_to_clipboard(elem) { return succeed; } -function copy_btn_init(btn) { - btn.empty(); - btn.append(''); +var OverlayButton = function(title, icon, click_handler) { + this.btn = $('