Moved scripts out of layout.mjml.hbs
This commit is contained in:
parent
adf4be7836
commit
477aff95d5
5 changed files with 72 additions and 54 deletions
|
@ -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"
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
});
|
||||
})();
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
<mj-title>{{title}}</mj-title>
|
||||
<mj-font name="Lato" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic" />
|
||||
<mj-attributes>
|
||||
<mj-all font-size="15px;" color="#2D3E4F" font-family="Lato, Helvetica, Arial, sans-serif" />
|
||||
<mj-all font-size="15px" color="#2D3E4F" font-family="Lato, Helvetica, Arial, sans-serif" />
|
||||
<mj-class name="h1" font-size="42px" line-height="68px" color="#b4bcc2" />
|
||||
<mj-class name="h3" font-size="24px" line-height="32px" />
|
||||
<mj-class name="p" font-size="15px" line-height="24px" />
|
||||
|
@ -53,9 +53,7 @@
|
|||
<mj-raw>
|
||||
{{#if isWeb}}
|
||||
<!-- fixes https://github.com/mjmlio/mjml/issues/359 -->
|
||||
<script> var btnBgColor = '#2D3E4F'; var btnBgColorHover = '#1A242F'; </script>
|
||||
<script src="/subscription/footer-scripts.js"></script>
|
||||
{{> tracking_scripts}}
|
||||
{{> subscription_footer_scripts btnBgColor='#2D3E4F' btnBgColorHover='#1A242F'}}
|
||||
{{/if}}
|
||||
</mj-raw>
|
||||
|
||||
|
|
56
views/subscription/partials/subscription-footer-scripts.hbs
Normal file
56
views/subscription/partials/subscription-footer-scripts.hbs
Normal file
|
@ -0,0 +1,56 @@
|
|||
<script>
|
||||
var btnBgColor = '{{btnBgColor}}';
|
||||
var btnBgColorHover = '{{btnBgColorHover}}';
|
||||
|
||||
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();
|
||||
};
|
||||
}
|
||||
});
|
||||
})();
|
||||
}
|
||||
</script>
|
||||
|
||||
<!-- custom scripts from config -->
|
||||
{{#each customSubscriptionScripts}}
|
||||
<script src="{{this}}"></script>
|
||||
{{/each}}
|
||||
|
||||
{{> tracking_scripts}}
|
Loading…
Add table
Add a link
Reference in a new issue