0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

🐛 Fixed missing location/referrer data with multiple {{subscribe_form}} (#9713)

no issue
- replaced `querySelector` with `querySelectorAll` and a loop so that all subscribe form inputs have their values updated rather than only the first form on the page
- made the selector more specific so that it only updates `<input>` elements
- switched to a template string so it's easier to read/write
This commit is contained in:
Kevin Ansfield 2018-07-03 10:16:44 +01:00 committed by GitHub
parent 8c1061cd30
commit 7e105eb5b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,13 +26,19 @@ function makeHidden(name, extras) {
* *
* document.querySelector['.location']['value'] = document.querySelector('.location')['value'] || window.location.href; * document.querySelector['.location']['value'] = document.querySelector('.location')['value'] || window.location.href;
*/ */
subscribeScript = subscribeScript = `
'<script>' + <script>
'(function(g,h,o,s,t){' + (function(g,h,o,s,t){
'h[o](\'.location\')[s]=h[o](\'.location\')[s] || g.location.href;' + var buster = function(b,m) {
'h[o](\'.referrer\')[s]=h[o](\'.referrer\')[s] || h.referrer;' + h[o]('input.'+b).forEach(function (i) {
'})(window,document,\'querySelector\',\'value\');' + i.value=i.value || m;
'</script>'; });
};
buster('location', g.location.href);
buster('referrer', h.referrer);
})(window,document,'querySelectorAll','value');
</script>
`;
// We use the name subscribe_form to match the helper for consistency: // We use the name subscribe_form to match the helper for consistency:
module.exports = function subscribe_form(options) { // eslint-disable-line camelcase module.exports = function subscribe_form(options) { // eslint-disable-line camelcase