~jstys-z/helioviewer.org/timeline

« back to all changes in this revision

Viewing changes to timeline/Highstock-1.3.10/exporting-server/java/highcharts-export/highcharts-export-web/src/main/webapp/resources/lib/codemirror/util/xml-hint.js

  • Committer: Jeff Stys
  • Date: 2014-04-21 12:46:26 UTC
  • Revision ID: jstys@sesda3.com-20140421124626-2332pb2dyjc33jxi
Proof-of-concept version of Data Coverage Timeline using Highchart/Highstock javascript library.  Changes to getDataCoverage API in order to feed the necessary data to the Timeline

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
(function() {
 
3
 
 
4
    CodeMirror.xmlHints = [];
 
5
 
 
6
    CodeMirror.xmlHint = function(cm, simbol) {
 
7
 
 
8
        if(simbol.length > 0) {
 
9
            var cursor = cm.getCursor();
 
10
            cm.replaceSelection(simbol);
 
11
            cursor = {line: cursor.line, ch: cursor.ch + 1};
 
12
            cm.setCursor(cursor);
 
13
        }
 
14
 
 
15
        // dirty hack for simple-hint to receive getHint event on space
 
16
        var getTokenAt = editor.getTokenAt;
 
17
 
 
18
        editor.getTokenAt = function() { return 'disabled'; };
 
19
        CodeMirror.simpleHint(cm, getHint);
 
20
 
 
21
        editor.getTokenAt = getTokenAt;
 
22
    };
 
23
 
 
24
    var getHint = function(cm) {
 
25
 
 
26
        var cursor = cm.getCursor();
 
27
 
 
28
        if (cursor.ch > 0) {
 
29
 
 
30
            var text = cm.getRange({line: 0, ch: 0}, cursor);
 
31
            var typed = '';
 
32
            var simbol = '';
 
33
            for(var i = text.length - 1; i >= 0; i--) {
 
34
                if(text[i] == ' ' || text[i] == '<') {
 
35
                    simbol = text[i];
 
36
                    break;
 
37
                }
 
38
                else {
 
39
                    typed = text[i] + typed;
 
40
                }
 
41
            }
 
42
 
 
43
            text = text.slice(0, text.length - typed.length);
 
44
 
 
45
            var path = getActiveElement(cm, text) + simbol;
 
46
            var hints = CodeMirror.xmlHints[path];
 
47
 
 
48
            if(typeof hints === 'undefined')
 
49
                hints = [''];
 
50
            else {
 
51
                hints = hints.slice(0);
 
52
                for (var i = hints.length - 1; i >= 0; i--) {
 
53
                    if(hints[i].indexOf(typed) != 0)
 
54
                        hints.splice(i, 1);
 
55
                }
 
56
            }
 
57
 
 
58
            return {
 
59
                list: hints,
 
60
                from: { line: cursor.line, ch: cursor.ch - typed.length },
 
61
                to: cursor
 
62
            };
 
63
        };
 
64
    };
 
65
 
 
66
    var getActiveElement = function(codeMirror, text) {
 
67
 
 
68
        var element = '';
 
69
 
 
70
        if(text.length >= 0) {
 
71
 
 
72
            var regex = new RegExp('<([^!?][^\\s/>]*).*?>', 'g');
 
73
 
 
74
            var matches = [];
 
75
            var match;
 
76
            while ((match = regex.exec(text)) != null) {
 
77
                matches.push({
 
78
                    tag: match[1],
 
79
                    selfclose: (match[0].slice(match[0].length - 2) === '/>')
 
80
                });
 
81
            }
 
82
 
 
83
            for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
 
84
 
 
85
                var item = matches[i];
 
86
 
 
87
                if (item.tag[0] == '/')
 
88
                {
 
89
                    skip++;
 
90
                }
 
91
                else if (item.selfclose == false)
 
92
                {
 
93
                    if (skip > 0)
 
94
                    {
 
95
                        skip--;
 
96
                    }
 
97
                    else
 
98
                    {
 
99
                        element = '<' + item.tag + '>' + element;
 
100
                    }
 
101
                }
 
102
            }
 
103
 
 
104
            element += getOpenTag(text);
 
105
        }
 
106
 
 
107
        return element;
 
108
    };
 
109
 
 
110
    var getOpenTag = function(text) {
 
111
 
 
112
        var open = text.lastIndexOf('<');
 
113
        var close = text.lastIndexOf('>');
 
114
 
 
115
        if (close < open)
 
116
        {
 
117
            text = text.slice(open);
 
118
 
 
119
            if(text != '<') {
 
120
 
 
121
                var space = text.indexOf(' ');
 
122
                if(space < 0)
 
123
                    space = text.indexOf('\t');
 
124
                if(space < 0)
 
125
                    space = text.indexOf('\n');
 
126
 
 
127
                if (space < 0)
 
128
                    space = text.length;
 
129
 
 
130
                return text.slice(0, space);
 
131
            }
 
132
        }
 
133
 
 
134
        return '';
 
135
    };
 
136
 
 
137
})();