0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Subscribers: keep original referrer & location if set

This commit is contained in:
kirrg001 2016-04-28 12:40:08 +02:00 committed by Hannah Wolfe
parent 6ef79534e4
commit a836081f54

View file

@ -11,34 +11,42 @@ var _ = require('lodash'),
template = require('../../helpers/template'), template = require('../../helpers/template'),
utils = require('../../helpers/utils'), utils = require('../../helpers/utils'),
params = ['error', 'success', 'email', 'referrer', 'location'], params = ['error', 'success', 'email'],
/** /**
* Dirrrrrty script * This helper script sets the referrer and current location if not existent.
* <script type="text/javascript"> *
* document.querySelector('.location').setAttribute('value', window.location.href); * document.querySelector['.location']['value'] = document.querySelector('.location')['value'] || window.location.href;
* document.querySelector('.referrer').setAttribute('value', document.referrer);
* </script>
*/ */
subscribeScript = '<script type="text/javascript">(function(g,h,o,s,t){' + subscribeScript =
'h[o](\'.location\')[s]=g.location.href;h[o](\'.referrer\')[s]=h.referrer;' + '<script type="text/javascript">' +
'})(window,document,\'querySelector\',\'value\');</script>'; '(function(g,h,o,s,t){' +
'h[o](\'.location\')[s]=h[o](\'.location\')[s] || g.location.href;' +
'h[o](\'.referrer\')[s]=h[o](\'.referrer\')[s] || h.referrer;' +
'})(window,document,\'querySelector\',\'value\');' +
'</script>';
function makeHidden(name) { function makeHidden(name, extras) {
return utils.inputTemplate({ return utils.inputTemplate({
type: 'hidden', type: 'hidden',
name: name, name: name,
className: name, className: name,
extras: '' extras: extras
}); });
} }
function subscribeFormHelper(options) { function subscribeFormHelper(options) {
var data = _.merge({}, options.hash, _.pick(options.data.root, params), { var root = options.data.root,
data = _.merge({}, options.hash, _.pick(root, params), {
action: path.join('/', config.paths.subdir, config.routeKeywords.subscribe, '/'), action: path.join('/', config.paths.subdir, config.routeKeywords.subscribe, '/'),
script: new hbs.handlebars.SafeString(subscribeScript), script: new hbs.handlebars.SafeString(subscribeScript),
hidden: new hbs.handlebars.SafeString(makeHidden('confirm') + makeHidden('location') + makeHidden('referrer')) hidden: new hbs.handlebars.SafeString(
makeHidden('confirm') +
makeHidden('location', root.subscribed_url ? 'value=' + root.subscribed_url : '') +
makeHidden('referrer', root.subscribed_referrer ? 'value=' + root.subscribed_referrer : '')
)
}); });
return template.execute('subscribe_form', data, options); return template.execute('subscribe_form', data, options);
} }