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:
parent
8c1061cd30
commit
7e105eb5b6
1 changed files with 13 additions and 7 deletions
|
@ -26,13 +26,19 @@ function makeHidden(name, extras) {
|
|||
*
|
||||
* document.querySelector['.location']['value'] = document.querySelector('.location')['value'] || window.location.href;
|
||||
*/
|
||||
subscribeScript =
|
||||
'<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>';
|
||||
subscribeScript = `
|
||||
<script>
|
||||
(function(g,h,o,s,t){
|
||||
var buster = function(b,m) {
|
||||
h[o]('input.'+b).forEach(function (i) {
|
||||
i.value=i.value || m;
|
||||
});
|
||||
};
|
||||
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:
|
||||
module.exports = function subscribe_form(options) { // eslint-disable-line camelcase
|
||||
|
|
Loading…
Add table
Reference in a new issue