Skip to content

Commit 1c82dca

Browse files
committed
modal refactor and some style fixes
1 parent d7bfe24 commit 1c82dca

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</svg>Run
2424
</a>
2525

26-
<a id="js-add-library-btn" class="fleex-v-center hint--rounded hint--bottom-left" aria-label="Add a JS/CSS library">
26+
<a id="js-add-library-btn" class="flex-v-center hint--rounded hint--bottom-left" aria-label="Add a JS/CSS library">
2727
Add library <span id="js-external-lib-count" style="display:none;" class="count-label"></span>
2828
</a>
2929

src/script.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ runBtn, searchInput, consoleEl, consoleLogEl
985985
});
986986

987987
function openSettings() {
988-
settingsModal.classList.toggle('is-modal-visible');
988+
scope.toggleModal(settingsModal);
989989

990990
/* if (chrome.runtime.openOptionsPage) {
991991
// New way to open options pages, if supported (Chrome 42+).
@@ -1289,6 +1289,14 @@ runBtn, searchInput, consoleEl, consoleLogEl
12891289
trackEvent('ui', 'saveBtnClick', currentItem.id ? 'saved' : 'new');
12901290
saveItem();
12911291
};
1292+
/**
1293+
* Toggles a modal and logs an event.
1294+
* @param {Node} modal modal to be toggled
1295+
*/
1296+
scope.toggleModal = function (modal) {
1297+
modal.classList.toggle('is-modal-visible');
1298+
document.body.classList[modal.classList.contains('is-modal-visible') ? 'add' : 'remove']('overlay-visible');
1299+
};
12921300
scope.onSearchInputChange = function (e) {
12931301
const text = e.target.value;
12941302
let el;
@@ -1363,19 +1371,17 @@ runBtn, searchInput, consoleEl, consoleLogEl
13631371
layoutBtn4.addEventListener('click', getToggleLayoutButtonListener(4));
13641372

13651373
utils.onButtonClick(helpBtn, function () {
1366-
helpModal.classList.toggle('is-modal-visible');
1367-
document.body.classList[helpModal.classList.contains('is-modal-visible') ? 'add' : 'remove']('overlay-visible');
1374+
scope.toggleModal(helpModal);
13681375
trackEvent('ui', 'helpButtonClick');
13691376
});
13701377
utils.onButtonClick(addLibraryBtn, function () {
1371-
addLibraryModal.classList.toggle('is-modal-visible');
1372-
document.body.classList[addLibraryModal.classList.contains('is-modal-visible') ? 'add' : 'remove']('overlay-visible');
1378+
scope.toggleModal(addLibraryModal);
13731379
trackEvent('ui', 'addLibraryButtonClick');
13741380
});
13751381

13761382
notificationsBtn.addEventListener('click', function () {
1377-
notificationsModal.classList.toggle('is-modal-visible');
1378-
document.body.classList[notificationsModal.classList.contains('is-modal-visible') ? 'add' : 'remove']('overlay-visible');
1383+
scope.toggleModal(notificationsModal);
1384+
13791385
if (notificationsModal.classList.contains('is-modal-visible') && !hasSeenNotifications) {
13801386
hasSeenNotifications = true;
13811387
notificationsBtn.classList.remove('has-new');

0 commit comments

Comments
 (0)