diff options
author | Jim Fitzpatrick <fitzpatrick.jim@gmail.com> | 2016-06-21 21:45:43 -0400 |
---|---|---|
committer | Jim Fitzpatrick <fitzpatrick.jim@gmail.com> | 2016-06-22 08:39:46 -0400 |
commit | 8c0ff6225c96af2f5f3b7312d7ba7b69f71be575 (patch) | |
tree | 1893639afb3cb78b9275635662f4c0f06d54986e /awesomplete.js | |
parent | ccd4e20ab1adf58bb0be4a121dcdc54c49f1029a (diff) | |
download | awesomplete-8c0ff6225c96af2f5f3b7312d7ba7b69f71be575.zip awesomplete-8c0ff6225c96af2f5f3b7312d7ba7b69f71be575.tar.gz awesomplete-8c0ff6225c96af2f5f3b7312d7ba7b69f71be575.tar.bz2 |
Emit close reason with awesomplete-close events
Emit a reason when firing `awesomplete-close` events to provide
transparency to attached event listeners regarding the circumstance in
which the close was triggered. Reasons include `blur`, `esc`, `submit`,
`select`, and `nomatches`.
Closes #16897
Diffstat (limited to 'awesomplete.js')
-rw-r--r-- | awesomplete.js | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/awesomplete.js b/awesomplete.js index 627f195..48c9e4b 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -55,7 +55,7 @@ var _ = function (input, o) { $.bind(this.input, { "input": this.evaluate.bind(this), - "blur": this.close.bind(this), + "blur": this.close.bind(this, { reason: 'blur' }), "keydown": function(evt) { var c = evt.keyCode; @@ -67,7 +67,7 @@ var _ = function (input, o) { me.select(); } else if (c === 27) { // Esc - me.close(); + me.close({ reason: 'esc' }); } else if (c === 38 || c === 40) { // Down/Up arrow evt.preventDefault(); @@ -77,7 +77,7 @@ var _ = function (input, o) { } }); - $.bind(this.input.form, {"submit": this.close.bind(this)}); + $.bind(this.input.form, {"submit": this.close.bind(this, { reason: 'submit' })}); $.bind(this.ul, {"mousedown": function(evt) { var li = evt.target; @@ -146,7 +146,7 @@ _.prototype = { return !this.ul.hasAttribute("hidden"); }, - close: function () { + close: function (o) { if (!this.opened) { return; } @@ -154,7 +154,7 @@ _.prototype = { this.ul.setAttribute("hidden", ""); this.index = -1; - $.fire(this.input, "awesomplete-close"); + $.fire(this.input, "awesomplete-close", o || {}); }, open: function () { @@ -216,7 +216,7 @@ _.prototype = { if (allowed) { this.replace(suggestion); - this.close(); + this.close({ reason: 'select' }); $.fire(this.input, "awesomplete-selectcomplete", { text: suggestion }); @@ -248,13 +248,13 @@ _.prototype = { }); if (this.ul.children.length === 0) { - this.close(); + this.close({ reason: 'nomatches' }); } else { this.open(); } } else { - this.close(); + this.close({ reason: 'nomatches' }); } } }; |