diff --git a/core/server/apps/subscribers/index.js b/core/server/apps/subscribers/index.js index 4199d8c9bc..25752344f0 100644 --- a/core/server/apps/subscribers/index.js +++ b/core/server/apps/subscribers/index.js @@ -11,34 +11,42 @@ var _ = require('lodash'), template = require('../../helpers/template'), 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. + * + * document.querySelector['.location']['value'] = document.querySelector('.location')['value'] || window.location.href; */ - subscribeScript = ''; + subscribeScript = + ''; -function makeHidden(name) { +function makeHidden(name, extras) { return utils.inputTemplate({ type: 'hidden', name: name, className: name, - extras: '' + extras: extras }); } function subscribeFormHelper(options) { - var data = _.merge({}, options.hash, _.pick(options.data.root, params), { - action: path.join('/', config.paths.subdir, config.routeKeywords.subscribe, '/'), - script: new hbs.handlebars.SafeString(subscribeScript), - hidden: new hbs.handlebars.SafeString(makeHidden('confirm') + makeHidden('location') + makeHidden('referrer')) - }); + var root = options.data.root, + data = _.merge({}, options.hash, _.pick(root, params), { + action: path.join('/', config.paths.subdir, config.routeKeywords.subscribe, '/'), + script: new hbs.handlebars.SafeString(subscribeScript), + 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); }