summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-28 17:21:33 +0200
committerAlon Levy <alon@pobox.com>2014-10-28 17:21:33 +0200
commite299a57a72ee786818cad4f9b8e3aea3b6fb8544 (patch)
treeeca344168fd6bc0f86ba13859e214600586bfca2
parenta005563b0d7b6636d79d268cfcf6582071644d36 (diff)
textanalysis.ui: use input event if it exists, fallback to polling of 50ms (not 5ms) otherwise
-rw-r--r--scripts/textanalysis.ui.js27
1 files changed, 17 insertions, 10 deletions
diff --git a/scripts/textanalysis.ui.js b/scripts/textanalysis.ui.js
index 75eae67e..2eadff0b 100644
--- a/scripts/textanalysis.ui.js
+++ b/scripts/textanalysis.ui.js
@@ -129,18 +129,25 @@ return {
}
});
- /* TODO: don't use interval by default but only if keys are comming to fast (but still - 5 ms??) */
- window.setInterval(function() {
- if (element.val() != text) {
-
- if (text.length * 8 > 500) {
- element.css('width', text.length * 8 + 20);
- }
- // text changed
+ if ('oninput' in document.documentElement) {
+ element.on('input', function(e) {
text = element.val();
analyzeSentence(text, false);
- }
- }, 5);
+ });
+ } else {
+ console.log('textanalysis.ui: fallback to polling');
+ window.setInterval(function() {
+ if (element.val() != text) {
+ if (text.length * 8 > 500) {
+ element.css('width', text.length * 8 + 20);
+ }
+ // text changed
+ text = element.val();
+ analyzeSentence(text, false);
+ suggestionChange = false;
+ }
+ }, 50);
+ }
}
};
}); // define