diff --git a/src/Foundation.hs b/src/Foundation.hs index 39fcaf424..f85e69e54 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -1083,7 +1083,6 @@ siteLayout' headingOverride widget = do addScript $ StaticR js_utils_form_js addScript $ StaticR js_utils_inputs_js addScript $ StaticR js_utils_modal_js - addScript $ StaticR js_utils_poc_js addScript $ StaticR js_utils_showHide_js -- addScript $ StaticR js_utils_tabber_js addStylesheet $ StaticR css_utils_alerts_scss diff --git a/static/js/services/utilRegistry.js b/static/js/services/utilRegistry.js index 4ffdada2f..ca12f3d28 100644 --- a/static/js/services/utilRegistry.js +++ b/static/js/services/utilRegistry.js @@ -4,7 +4,7 @@ var registeredUtils = []; var activeUtilInstances = []; - var DEBUG_MODE = /localhost/.test(window.location.href) && 2; + var DEBUG_MODE = /localhost/.test(window.location.href) && 0; // Registry // (revealing module pattern) @@ -46,14 +46,14 @@ } } - function setupAllUtils() { + function setupAllUtils(scope) { if (DEBUG_MODE > 1) { console.info('registered js utilities:'); console.table(registeredUtils); } registeredUtils.forEach(function(util) { - setupUtil(util); + setupUtil(util, scope); }); } diff --git a/static/js/utils/asyncTable.js b/static/js/utils/asyncTable.js index 0c5f30e31..9c731b33e 100644 --- a/static/js/utils/asyncTable.js +++ b/static/js/utils/asyncTable.js @@ -351,7 +351,7 @@ element.innerHTML = newWrapperContents.innerHTML; if (UtilRegistry) { - UtilRegistry.setupAll(); + UtilRegistry.setupAll(element); } } diff --git a/static/js/utils/modal.js b/static/js/utils/modal.js index a0993d802..c29feea69 100644 --- a/static/js/utils/modal.js +++ b/static/js/utils/modal.js @@ -169,7 +169,7 @@ element.insertBefore(modalContent, null); // setup any newly arrived utils - UtilRegistry.setupAll(); + UtilRegistry.setupAll(element); } function withPrefixedInputIDs(modalContent) { diff --git a/static/js/utils/poc.js b/static/js/utils/poc.js deleted file mode 100644 index 5d87a0f82..000000000 --- a/static/js/utils/poc.js +++ /dev/null @@ -1,33 +0,0 @@ -(function() { - - var UTIL_NAME = 'poc'; - var UTIL_SELECTOR = '[uw-poc]'; - - var util = function(element) { - - function _init() { - var color = 'red'; - if (element.dataset.color) { - color = element.dataset.color; - } - element.style.outline = '1px solid ' + color; - } - - _init(); - - return { - name: UTIL_NAME, - element: element, - destroy: function() {}, - }; - }; - - if (UtilRegistry) { - UtilRegistry.register({ - name: UTIL_NAME, - selector: UTIL_SELECTOR, - setup: util, - }); - } - -})(); diff --git a/templates/default-layout.julius b/templates/default-layout.julius index 8c7295843..dffe24834 100644 --- a/templates/default-layout.julius +++ b/templates/default-layout.julius @@ -44,3 +44,30 @@ if (I18n) { document.addEventListener('DOMContentLoaded', function() { setupDatepicker(document.body); }); + +/** + * The following code should be moved to profile.julius as soon as the widget file is actually used. + */ +(function() { + 'use strict'; + + var DEFAULT_THEME = 'theme--default'; + + document.addEventListener('DOMContentLoaded', function() { + + var themeSwitcher = document.querySelector('#theme-select'); + var currentTheme = DEFAULT_THEME; + + if (themeSwitcher) { + currentTheme = 'theme--' + themeSwitcher.value; + themeSwitcher.addEventListener('input', function() { + + var desiredTheme = 'theme--' + themeSwitcher.value; + document.body.classList.remove(currentTheme); + document.body.classList.add(desiredTheme); + currentTheme = desiredTheme; + }); + } + }); + +})(); diff --git a/templates/multiFileField.hamlet b/templates/multiFileField.hamlet index 973cd762e..48af3d786 100644 --- a/templates/multiFileField.hamlet +++ b/templates/multiFileField.hamlet @@ -1,5 +1,5 @@ $newline never - +$if not (null fileInfos)
_{MsgPreviouslyUploadedInfo}
    $forall FileUploadInfo{..} <- fileInfos diff --git a/templates/profile.julius b/templates/profile.julius new file mode 100644 index 000000000..9e125f982 --- /dev/null +++ b/templates/profile.julius @@ -0,0 +1,24 @@ + +(function() { + 'use strict'; + + var DEFAULT_THEME = 'theme--default'; + + document.addEventListener('DOMContentLoaded', function() { + + var themeSwitcher = document.querySelector('#theme-select'); + var currentTheme = DEFAULT_THEME; + + if (themeSwitcher) { + currentTheme = 'theme--' + themeSwitcher.value; + themeSwitcher.addEventListener('input', function() { + + var desiredTheme = 'theme--' + themeSwitcher.value; + document.body.classList.remove(currentTheme); + document.body.classList.add(desiredTheme); + currentTheme = desiredTheme; + }); + } + }); + +})(); diff --git a/templates/widgets/alerts/alerts.julius b/templates/widgets/alerts/alerts.julius deleted file mode 100644 index 659c9d921..000000000 --- a/templates/widgets/alerts/alerts.julius +++ /dev/null @@ -1,4 +0,0 @@ -document.addEventListener('DOMContentLoaded', function() { - var alertsElement = document.querySelector('#' + 'alerts-1'); - window.utils.setup('alerts', alertsElement); -});