summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2014-08-19 19:32:16 +0300
committerAlon Levy <alon@pobox.com>2014-08-19 19:32:16 +0300
commitcca5a2dbc2e0a92bee72b56d9a708a641d4153a9 (patch)
tree1e3af554bc33fca54a2b00bd3a1c74cbbebf4d61 /scripts
parente893cf18cd13d7ceaf6d601faf476b50a20cae8f (diff)
start breaking textanalysis to logic and ui
Diffstat (limited to 'scripts')
-rw-r--r--scripts/textanalysis-ui.js124
-rw-r--r--scripts/textanalysis.js117
2 files changed, 125 insertions, 116 deletions
diff --git a/scripts/textanalysis-ui.js b/scripts/textanalysis-ui.js
new file mode 100644
index 00000000..de163056
--- /dev/null
+++ b/scripts/textanalysis-ui.js
@@ -0,0 +1,124 @@
+var text = ""; // Last text of sentence
+var sugg = []; // suggestions for autocompletion of node names
+
+$('#textanalyser').autocompleteTrigger({
+ triggerStart: '#',
+ triggerEnd: '',
+ source: sugg
+});
+
+function analyzeSentence(sentence, finalize)
+{
+ var d = TextAnalyser2(graph, sentence, finalize);
+ for (var k in d.suggestions) {
+ sugg[k] = k;
+ }
+}
+
+
+$("#textanalyser").keypress(function(e) {
+ if (graph.history !== undefined) {
+ graph.history.record_keystrokes(KEYSTROKE_WHERE_TEXTANALYSIS, [e.which]);
+ }
+ if (e.which == 13) {
+ if(!suggestionChange){
+ text = $('#textanalyser').val();
+ $('#textanalyser').val("");
+ TextAnalyser2(graph, 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.updateGraph();
+}
+
+window.setInterval(function() {
+ if ($('#textanalyser').val() != text) {
+
+ if(text.length*8>500)$('#textanalyser').css('width',text.length*8+20);
+ // text changed
+ text = $('#textanalyser').val();
+ TextAnalyser2(graph, text, false);
+ suggestionChange=false;
+ }
+}, 5);
+
+
diff --git a/scripts/textanalysis.js b/scripts/textanalysis.js
index e055d860..3f50387a 100644
--- a/scripts/textanalysis.js
+++ b/scripts/textanalysis.js
@@ -1,7 +1,5 @@
"use strict"
-var text = "";
-var sugg = [];
var typeindex = 0;
var nodetypes = ["person", "project", "skill", "deliverable", "objective"];
var suggestionChange=false;
@@ -12,121 +10,8 @@ var ExecutionStack = [];
var lastnode;
-$('#textanalyser').autocompleteTrigger({
- triggerStart: '#',
- triggerEnd: '',
- source: sugg
-});
-
-$("#textanalyser").keypress(function(e) {
- if (graph.history !== undefined) {
- graph.history.record_keystrokes(KEYSTROKE_WHERE_TEXTANALYSIS, [e.which]);
- }
- if (e.which == 13) {
- if(!suggestionChange){
- text = $('#textanalyser').val();
- $('#textanalyser').val("");
- TextAnalyser2(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.updateGraph();
-}
-
-window.setInterval(function() {
- if ($('#textanalyser').val() != text) {
-
- if(text.length*8>500)$('#textanalyser').css('width',text.length*8+20);
- // text changed
- text = $('#textanalyser').val();
- TextAnalyser2(text, false);
- suggestionChange=false;
- }
-}, 5);
-
-
-function TextAnalyser2(newtext, finalize) {
+function TextAnalyser2(graph, newtext, finalize) {
var segment = [],
subsegment = [],
sentence = [];