From ff96925633403dbaba4b5725ac98a99d5b690509 Mon Sep 17 00:00:00 2001 From: Reorx Date: Sat, 11 Feb 2023 23:46:14 +0800 Subject: [PATCH] toggle preview/json in one button --- src/editor/index.html | 3 +-- src/editor/main.js | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/editor/index.html b/src/editor/index.html index a35c01e..3fcfee7 100644 --- a/src/editor/index.html +++ b/src/editor/index.html @@ -16,8 +16,7 @@
- - + diff --git a/src/editor/main.js b/src/editor/main.js index 9ae237b..041f0cf 100644 --- a/src/editor/main.js +++ b/src/editor/main.js @@ -152,8 +152,7 @@ editor.on('change', () => { }) // actions -const $btnShowPreview = $('#fn-show-preview') -const $btnShowJSON = $('#fn-show-json') +const $btnTogglePreview = $('#fn-toggle-preview') const $btnNewData = $('#fn-new-data') const $btnUploadData = $('#fn-upload-data') const $inputUploadData = $('input[name=upload-data]') @@ -162,14 +161,16 @@ const $btnDownloadHTML = $('#fn-download-html') const $btnLoadSample = $('#fn-load-sample') const $btnPrintPreview = $('#fn-print-preview') -$btnShowPreview.on('click', () => { - $outputJSON.hide() - $outputHTML.show() -}) - -$btnShowJSON.on('click', () => { - $outputHTML.hide() - $outputJSON.show() +const isElementHidden = elt => + ! (elt.offsetWidth || elt.offsetHeight || elt.getClientRects().length); +$btnTogglePreview.on('click', () => { + if (isElementHidden($outputHTML.get(0))) { + $outputJSON.hide() + $outputHTML.show() + } else { + $outputHTML.hide() + $outputJSON.show() + } }) $btnNewData.on('click', () => {