-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
191 lines (178 loc) · 5.17 KB
/
scripts.js
File metadata and controls
191 lines (178 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Tracks the Ajax call being most recently requested, used to ignore older results
var AjaxID=0;
var KeyTimer;
$(document).ready(function() {
// Add debounce timer on search code function
$('#searchcode').on('keyup', function(event) {
clearTimeout(KeyTimer);
if ($(this).val().length < 3) {
if (typeof $.ui.fancetree !== 'undefined') {
$.ui.fancetree.getTree('#tree').clearFilter();
return;
}
}
if (event.key === "Enter" || event.which === 13) {
SearchCode($(this).val());
} else {
KeyTimer=setTimeout(() => {
SearchCode($(this).val());
}, 1500);
}
});
function SearchCode(query) {
if (query.length > 2) { // Limit searches to 3 or more searches
document.getElementById('search').value=''; // Clear obj field
document.getElementById('loading').style.display='block'; // Show loading gif
AjaxID++;
var FetchAjaxID=AjaxID;
$.ajax({
url: 'SearchCode.cfm',
method: 'GET',
data: { search: query },
success: function(Keys) {
// Only process the results if AjaxID matches the most recent ID this call was for
if (AjaxID == FetchAjaxID) {
// Hide loading gif
document.getElementById('loading').style.display='none';
// Update tree filter
$.ui.fancytree.getTree("#tree").filterNodes(function(node) {
return Keys.includes(node.key);
})
};
}
});
} else {
$.ui.fancytree.getTree('#tree').clearFilter();
}
};
// Add click events to buttons
document.getElementById('ClearObj').addEventListener('click', function() {
document.getElementById('search').value='';
$.ui.fancytree.getTree('#tree').clearFilter();
});
document.getElementById('ClearSearch').addEventListener('click', function() {
document.getElementById('searchcode').value='';
$.ui.fancytree.getTree('#tree').clearFilter();
});
document.getElementById('SearchList').addEventListener('click', function() {
var search=document.getElementById('searchcode').value;
if (search.length < 3) return;
// Call search
$('#code').html('Loading...');
$.ajax({
url: 'SearchList.cfm',
method: 'GET',
data: {search:search},
success: function(data) {
$('#code').html(data); // Display the code
RunPrism();
}
});
});
// Add OnKeyUp events to search boxes
document.getElementById('search').addEventListener('keyup', function() {
document.getElementById('searchcode').value=''; // Clear code field
$.ui.fancytree.getTree('#tree').filterNodes(this.value);
});
ShowTree();
});
function ShowTree() {
$("#tree").fancytree({
extensions: ["filter"],
// Define filter-extension options:
filter: {
autoExpand: true,
highlight: false,
leavesOnly: true,
mode: "hide",
nodata: true
},
click: function(event, data) {
var ID=data.node.key;
if (ID.substr(0,1) == 'P') ViewCode(ID);
},
activate: function(event, data) {
var ID=data.node.key;
if (ID.substr(0,1) == 'P') ViewCode(ID);
},
source: Code
});
};
var ViewedID=0;
function ViewCode(ViewID) {
ViewedID=ViewID;
var SearchKey=document.getElementById('searchcode').value;
// Update cookie of ID's viewed (LIFO)
var BackIDList=getCookie('BACKID');
if (BackIDList == null || BackIDList == '""') BackIDList='';
// Get last item to check for duplicate
var LastID=BackIDList.split(',').pop();
if (LastID != ViewID) {
if (BackIDList == '') {
BackIDList=ViewID;
} else {
BackIDList=BackIDList + ',' + ViewID;
}
// Limit history to 30 ID's max to keep in cookie max slize
if (BackIDList.split(',').length > 31) BackIDList=BackIDList.split(',').slice(1).join(',');
// Update Cookie
setCookie('BACKID',BackIDList);
}
// Pull object
$('#code').html('Loading...');
$.ajax({
url: 'View.cfm',
method: 'GET',
data: {ID:ViewID,SearchKey:SearchKey},
success: function(data) {
$('#code').html(data); // Display the code
RunPrism();
}
});
};
function ViewRelated() {
$.ajax({
url: 'Related.cfm',
method: 'GET',
data: {ID:ViewedID},
success: function(data) {
$('#PanelSection').html(data); // Display the code
RunPrism();
}
});
}
function GoBack() {
// Fetch Preview ID viewed (LIFO)
var BackIDArray=getCookie('BACKID').split(',');
var ViewID=BackIDArray.pop(); // Remove the current page
var ViewID=BackIDArray.pop(); // Get the prev page
// Update cookie
var BackIDList=BackIDArray.join(',');
setCookie('BACKID',BackIDList);
// Pull object
$('#code').html('Loading...');
$.ajax({
url: 'View.cfm',
method: 'GET',
data: {ID:ViewID},
success: function(data) {
$('#code').html(data); // Display the code
RunPrism();
}
});
}
// Helper to get a cookie by name
function getCookie(name) {
const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
return match ? decodeURIComponent(match[2]) : null;
}
// Helper to set a cookie
function setCookie(name, value) {
document.cookie = `${name}=${encodeURIComponent(value)}; path=/`;
}
var LineArray=[];
var KeywordLine=0;
var KeywordMax=0; // variables reset from View.cfm
function KeywordLine(dir) {
KeywordLine=KeywordLike + dir;
}