Created
April 10, 2014 00:58
-
-
Save esprehn/10334499 to your computer and use it in GitHub Desktop.
This file contains 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() { | |
var requestAutocomplete = HTMLFormElement.prototype.requestAutocomplete; | |
HTMLFormElement.prototype.requestAutocomplete = function() { | |
var form = this; | |
return new Promise(function(resolve, reject) { | |
requestAutocomplete.call(form); | |
function cleanup() { | |
form.removeEventListener(onSuccess); | |
form.removeEventListener(onError); | |
} | |
function onSuccess() { | |
resolve(); | |
cleanup(); | |
} | |
function onError(event) { | |
reject(event.reason); | |
cleanup(); | |
} | |
form.addEventListener("autocomplete", onSuccess); | |
form.addEventListener("autocompleteerror", onError); | |
}); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rejection reasons should always be
Error
instances.