From 508ce715b4c33995f6f7d394f3e6032f7b660b0b Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Mon, 2 Oct 2017 13:43:03 +0530 Subject: [PATCH] create declarative directive for modal triggers. --- src/index.html | 6 +++--- src/script.js | 32 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/index.html b/src/index.html index c002161..ae9cf92 100644 --- a/src/index.html +++ b/src/index.html @@ -49,7 +49,7 @@ Run - + Add library @@ -216,7 +216,7 @@ - + @@ -226,7 +226,7 @@ © Web Maker    - + diff --git a/src/script.js b/src/script.js index ee1b511..54c2bda 100644 --- a/src/script.js +++ b/src/script.js @@ -1,8 +1,8 @@ /* global trackEvent */ /* global layoutBtn1, layoutBtn2, layoutBtn3, helpModal, notificationsModal, addLibraryModal, -onboardModal, layoutBtn1, layoutBtn2, layoutBtn3, layoutBtn4, helpBtn, onboardModal, onboardModal, +onboardModal, layoutBtn1, layoutBtn2, layoutBtn3, layoutBtn4, onboardModal, onboardModal, addLibraryModal, addLibraryModal, notificationsBtn, notificationsModal, notificationsModal, -notificationsModal, notificationsBtn, codepenBtn, saveHtmlBtn, saveBtn, settingsBtn, +notificationsModal, notificationsBtn, codepenBtn, saveHtmlBtn, saveBtn, onboardModal, settingsModal, notificationsBtn, onboardShowInTabOptionBtn, editorThemeLinkTag, onboardDontShowInTabOptionBtn, TextareaAutoComplete, savedItemCountEl, indentationSizeValueEl, runBtn, searchInput, consoleEl, consoleLogEl, logCountEl, fontStyleTag, fontStyleTemplate, @@ -137,7 +137,6 @@ globalConsoleContainerEl jsModelLabel = $('#js-js-mode-label'), titleInput = $('#js-title-input'), addLibrarySelect = $('#js-add-library-select'), - addLibraryBtn = $('#js-add-library-btn'), externalJsTextarea = $('#js-external-js'), externalCssTextarea = $('#js-external-css'); @@ -1295,6 +1294,7 @@ globalConsoleContainerEl gutters: ['CodeMirror-foldgutter'] }); + // DEPRECATED function openSettings() { scope.toggleModal(settingsModal); @@ -1844,6 +1844,18 @@ globalConsoleContainerEl attachListenerForEvent('input'); attachListenerForEvent('keyup'); + // Compile d-open-modal directive + const modalTriggers = $all(`[d-open-modal]`); + modalTriggers.forEach(function(el) { + utils.onButtonClick(el, function() { + scope.toggleModal(window[el.getAttribute('d-open-modal')]); + trackEvent( + el.getAttribute('data-event-category'), + el.getAttribute('data-event-action') + ); + }); + }); + // Compile d-html directive const dHtmlNodes = $all(`[d-html]`); dHtmlNodes.forEach(function(el) { @@ -1919,15 +1931,6 @@ globalConsoleContainerEl layoutBtn3.addEventListener('click', getToggleLayoutButtonListener(3)); layoutBtn4.addEventListener('click', getToggleLayoutButtonListener(4)); - utils.onButtonClick(helpBtn, function() { - scope.toggleModal(helpModal); - trackEvent('ui', 'helpButtonClick'); - }); - utils.onButtonClick(addLibraryBtn, function() { - scope.toggleModal(addLibraryModal); - trackEvent('ui', 'addLibraryButtonClick'); - }); - notificationsBtn.addEventListener('click', function() { scope.toggleModal(notificationsModal); @@ -2157,11 +2160,6 @@ globalConsoleContainerEl } }); - utils.onButtonClick(settingsBtn, function() { - openSettings(); - trackEvent('ui', 'settingsBtnClick'); - }); - // Initialize add library select box var libOptions = window.jsLibs.reduce( (html, lib) =>