From 78261b738acd3905cc6ee3090b16811c9b4a3567 Mon Sep 17 00:00:00 2001 From: Dominique Da Silva Date: Tue, 12 Nov 2019 19:35:52 +0000 Subject: [PATCH] Prompt and update the title only if empty (mjml) --- views/grapejs/editor.hbs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/views/grapejs/editor.hbs b/views/grapejs/editor.hbs index a16cb07e..64c2ce0b 100644 --- a/views/grapejs/editor.hbs +++ b/views/grapejs/editor.hbs @@ -167,13 +167,11 @@ } var title = head.getElementsByTagName('mj-title')[0]; - if (title) { - title.textContent = resource.name; - } else { + if (!title) { title = document.createElement('mj-title'); - title.textContent = resource.name; head.prepend(title); } + c.needTitle = title.textContent.trim() === ''; c.plugins.push('grapesjs-mjml', 'gjs-preset-mjml'); @@ -503,9 +501,9 @@ history.go(1); }; - // Beautify tooltips $(document).ready(function() { + // Beautify tooltips $('*[title]').each(function() { var el = $(this); var title = el.attr('title').trim(); @@ -514,6 +512,18 @@ el.attr('title', ''); } }); + + // Set title for mjml + if (config.needTitle) { + var titleEl = editor.getWrapper().findType('mj-title')[0]; + if (titleEl) { + var preferSubject = resource.subject ? confirm("Prefer the subject as the landing page title? (default to campaign name)") : false; + var thetitle = preferSubject ? resource.subject : resource.name; + titleEl.set('content', thetitle); + config.needTitle = false; + + } + } });