From 477aff95d5103f20a537df2418141c9ac0671498 Mon Sep 17 00:00:00 2001 From: witzig Date: Sun, 19 Mar 2017 16:14:31 +0100 Subject: [PATCH] Moved scripts out of layout.mjml.hbs --- config/default.toml | 3 + lib/helpers.js | 13 ++++- public/subscription/footer-scripts.js | 48 ---------------- views/subscription/layout.mjml.hbs | 6 +- .../partials/subscription-footer-scripts.hbs | 56 +++++++++++++++++++ 5 files changed, 72 insertions(+), 54 deletions(-) delete mode 100644 public/subscription/footer-scripts.js create mode 100644 views/subscription/partials/subscription-footer-scripts.hbs diff --git a/config/default.toml b/config/default.toml index 93fbab01..2d8849ab 100644 --- a/config/default.toml +++ b/config/default.toml @@ -38,6 +38,9 @@ language="en" # Inject custom scripts in layout.hbs # customscripts=["/custom/hello-world.js"] +# Inject custom scripts in subscription/layout.mjml.hbs +# customsubscriptionscripts=["/custom/hello-world.js"] + # If you start out as a root user (eg. if you want to use ports lower than 1000) # then you can downgrade the user once all services are up and running #user="nobody" diff --git a/lib/helpers.js b/lib/helpers.js index 62545670..2cac3dbb 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -1,8 +1,10 @@ 'use strict'; +let config = require('config'); let path = require('path'); let fs = require('fs'); let tools = require('./tools'); +let settings = require('./models/settings'); let lists = require('./models/lists'); let fields = require('./models/fields'); let forms = require('./models/forms'); @@ -156,10 +158,17 @@ function injectCustomFormData(customFormId, viewPath, data, callback) { let key = tools.fromDbKey(view); data.template.template = form[key] || data.template.template; data.template.layout = form.layout || data.template.layout; - data.formInputStyle = form.formInputStyle || '@import url(/subscription/form-input-style.css);'; - callback(null, data); + settings.list(['ua_code'], (err, configItems) => { + if (err) { + return callback(err); + } + + data.uaCode = configItems.uaCode; + data.customSubscriptionScripts = config.customsubscriptionscripts || []; + callback(null, data); + }); }); } diff --git a/public/subscription/footer-scripts.js b/public/subscription/footer-scripts.js deleted file mode 100644 index af5e3137..00000000 --- a/public/subscription/footer-scripts.js +++ /dev/null @@ -1,48 +0,0 @@ -/* eslint-env browser */ -/* eslint no-invalid-this: 0, no-var: 0, prefer-arrow-callback: 0 */ -/* globals $: false, ace: false */ - -if (typeof moment !== 'undefined' && moment.tz) { - (function () { - var tz = moment.tz.guess(); - if (tz) { - document.querySelectorAll('.tz-detect').forEach(function(el) { - el.value = tz; - }); - } - })(); -} - -document.querySelectorAll('a[href="#submit"]').forEach(function(a) { - a.onclick = function() { - var form = document.getElementById('main-form'); - form && form.submit(); - return false; - }; -}); - -// Fixes MJML Button until they do ... -// https://github.com/mjmlio/mjml/issues/359 - -if (window.btnBgColor) { - (function() { - var s = document.createElement('style'); - var c = document.createTextNode( - '.td-btn:hover { background-color: ' + window.btnBgColorHover + '; }' + - '.td-btn { cursor: pointer !important; }' + - '.a-btn { background-color: transparent !important; }' - ); - s.appendChild(c); - document.getElementsByTagName('head')[0].appendChild(s); - document.querySelectorAll('a').forEach(function(a) { - if (a.parentNode.getAttribute('bgcolor') === window.btnBgColor) { - a.target = '_self'; - a.className += 'a-btn'; - a.parentNode.className += 'td-btn'; - a.parentNode.onclick = function() { - a.click(); - }; - } - }); - })(); -} diff --git a/views/subscription/layout.mjml.hbs b/views/subscription/layout.mjml.hbs index 3166da50..80932bc4 100644 --- a/views/subscription/layout.mjml.hbs +++ b/views/subscription/layout.mjml.hbs @@ -3,7 +3,7 @@ {{title}} - + @@ -53,9 +53,7 @@ {{#if isWeb}} - - - {{> tracking_scripts}} + {{> subscription_footer_scripts btnBgColor='#2D3E4F' btnBgColorHover='#1A242F'}} {{/if}} diff --git a/views/subscription/partials/subscription-footer-scripts.hbs b/views/subscription/partials/subscription-footer-scripts.hbs new file mode 100644 index 00000000..f173a6cf --- /dev/null +++ b/views/subscription/partials/subscription-footer-scripts.hbs @@ -0,0 +1,56 @@ + + + +{{#each customSubscriptionScripts}} + +{{/each}} + +{{> tracking_scripts}}