Moved scripts out of layout.mjml.hbs

This commit is contained in:
witzig 2017-03-19 16:14:31 +01:00
parent adf4be7836
commit 477aff95d5
5 changed files with 72 additions and 54 deletions

View file

@ -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>

View 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}}