Created
June 26, 2015 00:56
-
-
Save Jamedjo/c07433cc08e473be7e2a to your computer and use it in GitHub Desktop.
Strikingly enter submit fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addEvent(element, eventName, fn) { | |
if (element.addEventListener) | |
element.addEventListener(eventName, fn, false); | |
else if (element.attachEvent) | |
element.attachEvent('on' + eventName, fn); | |
} | |
var wasEnterPressed = function(e){ | |
return e.which == 13 || e.keyCode == 13; | |
}; | |
var onFormSubmit = function(){ | |
var email_submit = document.querySelectorAll('.signup-form input.submit-button[type="button"]')[0]; | |
email_submit.click(); | |
}; | |
var onEmailKeyPress = function(e){ | |
if(wasEnterPressed(e)) { | |
onFormSubmit(); | |
} | |
}; | |
var onLoadOrNow = function(f){ | |
if (document.readyState === 'complete'){ | |
f(); | |
} else { | |
addEvent(window, 'load', f); | |
} | |
}; | |
onLoadOrNow(function(){ | |
var email_input = document.querySelectorAll('.signup-form input[name="collected_email[email]"]')[0]; | |
addEvent(email_input, 'keypress', onEmailKeyPress); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment