From 37127f182886af07278e3905ceccf7d021f8723f Mon Sep 17 00:00:00 2001 From: Aliaksei Tsitovich Date: Thu, 30 Nov 2017 09:26:35 +0100 Subject: [PATCH 1/2] Initial implementation with explicit href-clicktracking attribute --- lib/componentFactory.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/componentFactory.js b/lib/componentFactory.js index 858d506..0e577dd 100644 --- a/lib/componentFactory.js +++ b/lib/componentFactory.js @@ -45,7 +45,12 @@ module.exports = function(element) { // If we have the href attribute we can create an anchor for the inner of the button; if (element.attr('href')) { - inner = format('%s', attrs, element.attr('href'), target, inner); + // support for Sendgrid's clicktracking="off" attribute + var hrefAttrs = ''; + if (element.attr('href-clicktracking')) { + hrefAttrs = format('clicktracking="%s"', element.attr('href-clicktracking')); + } + inner = format('%s', hrefAttrs, element.attr('href'), target, inner); } // If the button is expanded, it needs a
tag around the content @@ -102,7 +107,12 @@ module.exports = function(element) { if (element.attr('class')) { classes = classes.concat(element.attr('class').split(' ')); } - return format('%s', attrs, classes.join(' '), element.attr('href'), target, inner); + // support for Sendgrid's clicktracking="off" attribute + var hrefAttrs = ''; + if (element.attr('href-clicktracking')) { + hrefAttrs = format('clicktracking="%s"', element.attr('href-clicktracking')); + } + return format('%s', attrs, classes.join(' '), hrefAttrs, element.attr('href'), target, inner); //
case this.components.center: From 480b44043cc8a051fa8a8d593baa6597576c4da9 Mon Sep 17 00:00:00 2001 From: Aliaksei Tsitovich Date: Thu, 30 Nov 2017 10:12:25 +0100 Subject: [PATCH 2/2] generalized support for inner link attributes, all href- attributes are considered --- lib/componentFactory.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/componentFactory.js b/lib/componentFactory.js index 0e577dd..40c46de 100644 --- a/lib/componentFactory.js +++ b/lib/componentFactory.js @@ -45,11 +45,11 @@ module.exports = function(element) { // If we have the href attribute we can create an anchor for the inner of the button; if (element.attr('href')) { - // support for Sendgrid's clicktracking="off" attribute - var hrefAttrs = ''; - if (element.attr('href-clicktracking')) { - hrefAttrs = format('clicktracking="%s"', element.attr('href-clicktracking')); - } + // support for all types of href- attributes for inner link (e.g. Sendgrid's clicktracking="off") + var hrefAttrs = attrs.split(' ') + .filter(attr => attr.startsWith('href-')) + .map(attr => ' '+attr.replace('href-','')) + .join(); inner = format('%s', hrefAttrs, element.attr('href'), target, inner); } @@ -107,11 +107,11 @@ module.exports = function(element) { if (element.attr('class')) { classes = classes.concat(element.attr('class').split(' ')); } - // support for Sendgrid's clicktracking="off" attribute - var hrefAttrs = ''; - if (element.attr('href-clicktracking')) { - hrefAttrs = format('clicktracking="%s"', element.attr('href-clicktracking')); - } + // support for all types of href- attributes for inner link (e.g. Sendgrid's clicktracking="off") + var hrefAttrs = attrs.split(' ') + .filter(attr => attr.startsWith('href-')) + .map(attr => ' '+attr.replace('href-','')) + .join(); return format('%s', attrs, classes.join(' '), hrefAttrs, element.attr('href'), target, inner); //