summaryrefslogtreecommitdiffstats
path: root/client/lib
diff options
context:
space:
mode:
authorMaxime Quandalle <maxime@quandalle.com>2015-10-13 18:36:58 +0200
committerMaxime Quandalle <maxime@quandalle.com>2015-10-13 18:36:58 +0200
commit8bbc69616f91e9d09302d8a00f845b74e37d535f (patch)
tree50519e1012c6aaa06a502aca48ed7f6b4fa5398f /client/lib
parente504ac28940f614652f8e414aa0a67f60985bb89 (diff)
downloadwekan-8bbc69616f91e9d09302d8a00f845b74e37d535f.tar.gz
wekan-8bbc69616f91e9d09302d8a00f845b74e37d535f.tar.bz2
wekan-8bbc69616f91e9d09302d8a00f845b74e37d535f.zip
Abstract the jquery-textcomplete integration with EscapeActions
We now can re-use this integration in multiple places, this will be useful for #342 for instance.
Diffstat (limited to 'client/lib')
-rw-r--r--client/lib/textComplete.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/client/lib/textComplete.js b/client/lib/textComplete.js
new file mode 100644
index 00000000..e50d7cbc
--- /dev/null
+++ b/client/lib/textComplete.js
@@ -0,0 +1,30 @@
+// We “inherit” the jquery-textcomplete plugin to integrate with our
+// EscapeActions system. You should always use `escapeableTextComplete` instead
+// of the vanilla `textcomplete`.
+let dropdownMenuIsOpened = false;
+
+$.fn.escapeableTextComplete = function(...args) {
+ this.textcomplete(...args);
+
+ // Since commit d474017 jquery-textComplete automatically closes a potential
+ // opened dropdown menu when the user press Escape. This behavior conflicts
+ // with our EscapeActions system, but it's too complicated and hacky to
+ // monkey-pach textComplete to disable it -- I tried. Instead we listen to
+ // 'open' and 'hide' events, and create a ghost escapeAction when the dropdown
+ // is opened (and rely on textComplete to execute the actual action).
+ this.on({
+ 'textComplete:show'() {
+ dropdownMenuIsOpened = true;
+ },
+ 'textComplete:hide'() {
+ Tracker.afterFlush(() => {
+ dropdownMenuIsOpened = false;
+ });
+ },
+ });
+};
+
+EscapeActions.register('textcomplete',
+ () => {},
+ () => dropdownMenuIsOpened
+);