Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / js / 3rdParty / codemirror / addon / hint / xml-hint.js
1 (function() {
2
3 CodeMirror.xmlHints = [];
4
5 CodeMirror.xmlHint = function(cm) {
6
7 var cursor = cm.getCursor();
8
9 if (cursor.ch > 0) {
10
11 var text = cm.getRange(CodeMirror.Pos(0, 0), cursor);
12 var typed = '';
13 var simbol = '';
14 for(var i = text.length - 1; i >= 0; i--) {
15 if(text[i] == ' ' || text[i] == '<') {
16 simbol = text[i];
17 break;
18 }
19 else {
20 typed = text[i] + typed;
21 }
22 }
23
24 text = text.slice(0, text.length - typed.length);
25
26 var path = getActiveElement(text) + simbol;
27 var hints = CodeMirror.xmlHints[path];
28
29 if(typeof hints === 'undefined')
30 hints = [''];
31 else {
32 hints = hints.slice(0);
33 for (var i = hints.length - 1; i >= 0; i--) {
34 if(hints[i].indexOf(typed) != 0)
35 hints.splice(i, 1);
36 }
37 }
38
39 return {
40 list: hints,
41 from: CodeMirror.Pos(cursor.line, cursor.ch - typed.length),
42 to: cursor
43 };
44 }
45 };
46
47 var getActiveElement = function(text) {
48
49 var element = '';
50
51 if(text.length >= 0) {
52
53 var regex = new RegExp('<([^!?][^\\s/>]*)[\\s\\S]*?>', 'g');
54
55 var matches = [];
56 var match;
57 while ((match = regex.exec(text)) != null) {
58 matches.push({
59 tag: match[1],
60 selfclose: (match[0].slice(match[0].length - 2) === '/>')
61 });
62 }
63
64 for (var i = matches.length - 1, skip = 0; i >= 0; i--) {
65
66 var item = matches[i];
67
68 if (item.tag[0] == '/')
69 {
70 skip++;
71 }
72 else if (item.selfclose == false)
73 {
74 if (skip > 0)
75 {
76 skip--;
77 }
78 else
79 {
80 element = '<' + item.tag + '>' + element;
81 }
82 }
83 }
84
85 element += getOpenTag(text);
86 }
87
88 return element;
89 };
90
91 var getOpenTag = function(text) {
92
93 var open = text.lastIndexOf('<');
94 var close = text.lastIndexOf('>');
95
96 if (close < open)
97 {
98 text = text.slice(open);
99
100 if(text != '<') {
101
102 var space = text.indexOf(' ');
103 if(space < 0)
104 space = text.indexOf('\t');
105 if(space < 0)
106 space = text.indexOf('\n');
107
108 if (space < 0)
109 space = text.length;
110
111 return text.slice(0, space);
112 }
113 }
114
115 return '';
116 };
117
118 })();