summaryrefslogtreecommitdiff
path: root/scripts/textanalysis-ui.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-10-20 13:25:32 +0300
committerAlon Levy <alon@pobox.com>2014-10-20 21:36:37 +0300
commitc919c4bfef4ad9e2dc25d040c0727dd29ad541ae (patch)
treedd6394603680976c48801b53321e8085b0db1505 /scripts/textanalysis-ui.js
parentf1f4e937932f52c630831d0d501f8f8756b37531 (diff)
introduce require.js and rewrite tests
Yes, I'm being lazy. The purpose of require.js is to allow writing modules, i.e. individual smaller then the whole files with clear dependencies. This is achieved by using a new api provided by require.js: define, require, requirejs Read more at [requirejs] (http://requirejs.org) Tests have been rewritten to work correctly with require.js; they still use jsdom. Test output is now stored in the repository, all tests are run via run_tests.js; This is a hack - once a good harness (with assertions, suites - unittest like) presents itself it will be used. Hidden here is also using FileSaver for history saving, so history is saved to history.json instead to a random name. Plus dropping some dead code.
Diffstat (limited to 'scripts/textanalysis-ui.js')
-rw-r--r--scripts/textanalysis-ui.js142
1 files changed, 0 insertions, 142 deletions
diff --git a/scripts/textanalysis-ui.js b/scripts/textanalysis-ui.js
deleted file mode 100644
index d3f0f723..00000000
--- a/scripts/textanalysis-ui.js
+++ /dev/null
@@ -1,142 +0,0 @@
-var text = ""; // Last text of sentence
-var element_name = '#textanalyser';
-var element = $(element_name);
-
-element.autocompleteTrigger({
- triggerStart: '#',
- triggerEnd: '',
- source: autocompleteCallback
-});
-
-// TODO - hide this in a scope
-function analyzeSentence(sentence, finalize)
-{
- var ret = textAnalyser2(sentence, finalize);
- switch (ret.state) {
- case ANALYSIS_NODE_START:
- $('.typeselection').css({top:window.innerHeight/2-115,left:window.innerWidth/2-325});
- $('.typeselection').html('<table><tr><td style="height:28px"></td></tr><tr><td>Use [TAB] key to pick a type</td></tr></table>');
- break;
- case ANALYSIS_LINK:
- $('.typeselection').css('top', -300);
- $('.typeselection').css('left', 0);
- break;
- }
- ret.applyToGraph(graph);
- if (finalize || sentence.length == 0) {
- $('.typeselection').css('top', -300);
- $('.typeselection').css('left', 0);
- }
-}
-
-
-element.keypress(function(e) {
- if (graph.history !== undefined) {
- graph.history.record_keystrokes(KEYSTROKE_WHERE_TEXTANALYSIS, [e.which]);
- }
- if (e.which == 13) {
- if(!suggestionChange) {
- text = element.val();
- element.val("");
- analyzeSentence(text, true);
- typeStack = [];
- } else {
- suggestionChange = false;
- }
- return false;
- }
-
- if (e.which == 37) {//RIGHT
- $('body').scrollLeft(0);
- e.stopPropagation();
- return false;
- }
- if (e.which == 39) { //LEFT
- $('body').scrollLeft(0);
- e.stopPropagation();
- return false;
- }
-
-});
-
-$(document).keydown(function(e) {
-
- if (graph.history !== undefined) {
- graph.history.record_keystrokes(KEYSTROKE_WHERE_DOCUMENT, [e.KeyCode]);
- }
- if (e.keyCode == 9) {//TAB
- e.preventDefault();
- changeType("down", lastnode);
- return false;
- }
-
- if (e.keyCode == 37) {//UP
- $('html, body').scrollLeft(0);
- }
- if (e.keyCode == 39) {//DOWN
- $('html, body').scrollLeft(0);
- }
-
- if (e.keyCode == 38) {//UP
- suggestionChange = true;
- }
- if (e.keyCode == 40) {//DOWN
- suggestionChange = true;
- }
-
- if (e.keyCode == 9) {//TAB
- return false;
- }
-
-});
-
-function textSelect(inp, s, e) {
- e = e || s;
- if (inp.createTextRange) {
- var r = inp.createTextRange();
- r.collapse(true);
- r.moveEnd('character', e);
- r.moveStart('character', s);
- r.select();
- }else if(inp.setSelectionRange) {
- inp.focus();
- inp.setSelectionRange(s, e);
- }
-}
-
-function changeType(arg, id) {
- if(!id) {
- id = "new node";
- }
- if (arg === 'up') {
- if (typeindex < 4) typeindex++;
- else typeindex = 0;
- graph.editType(id, null, nodetypes[typeindex]);
- $('.typeselection').html('<table><tr><td style="height:28px"></td></tr><tr><td>' + "Chosen Type: " + nodetypes[typeindex] + '</td></tr></table>');
- graph.findCoordinates(lastnode,null);
- } else {
- if (typeindex > 0) typeindex--;
- else typeindex = 4;
-
- graph.editType(id, null, nodetypes[typeindex]);
- $('.typeselection').html('<table><tr><td style="height:28px"></td></tr><tr><td>' + "Chosen Type: " + nodetypes[typeindex] + '</td></tr></table>');
- graph.findCoordinates(lastnode,null);
- }
- graph.update(true);
-}
-
-if (element.length == 1) {
- /* 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
- text = element.val();
- analyzeSentence(text, false);
- suggestionChange = false;
- }
- }, 5);
-}