-
Notifications
You must be signed in to change notification settings - Fork 66
/
app.js
116 lines (96 loc) · 3.3 KB
/
app.js
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
/* ----------------------------------------------------------------------------
* Log Search Server JS
* by John Tajima
* requires jQuery 1.3.2
* ----------------------------------------------------------------------------
*/
var Search = {
search_form : 'search', // domId of the form
resultsId : 'results',
search_fields: [ 'term1', 'term2', 'term3' ], // domIds of search term fields
file_list : 'file-list', // domId of select for logfiles
past_params : null, // recent request
url : '/perform',
scroll_fnId : null,
// initialize Search form
init: function(params) {
this.past_params = params;
this.bind_options();
if (!this.past_params) return; // return if no prev settings, nothing to set
// init tool selector
(this.past_params['tool'] == 'grep') ? $('#grep-tool').attr('checked', 'checked') : $('#tail-tool').attr('checked', 'checked');
// init log file selector
$('#'+this.file_list).val(this.past_params['file']);
// init search fields
jQuery.each(this.search_fields, function(){
$('#'+this).val(Search.past_params[this]);
});
// advanced options usd?
// time was set - so show advanced options
if ((this.past_params['sh']) || (this.past_params['eh'])) {
this.showAdvanced();
if (this.past_params['sh']) {
jQuery.each(['sh', 'sm', 'ss'], function(){ $('#'+this).val(Search.past_params[this]) });
}
if (this.past_params['eh']) {
jQuery.each(['eh', 'em', 'es'], function(){ $('#'+this).val(Search.past_params[this]) });
}
}
},
// bind option selectors
bind_options: function() {
$('#auto-scroll').bind('change', function(){
Search.autoScroll(this.checked);
});
$('#auto-scroll').attr('checked', true).trigger('change'); // by default, turn on
},
// clears the terms fields
clear: function() {
jQuery.each(this.search_fields, function(){
$('#'+this).val("");
});
},
showAdvanced: function() {
$('#enable-advanced').hide();
$('#disable-advanced').show();
$('.advanced-options').show();
},
hideAdvanced: function() {
this.clearAdvanced();
$('#enable-advanced').show();
$('#disable-advanced').hide();
$('.advanced-options').hide();
},
clearAdvanced: function() {
$('#advanced-options input').val("");
},
// gathers form elements and submits to proper url
submit: function() {
$('#'+this.search_form).submit();
$('#'+this.resultsId).html("Sending new query...");
},
//
// Misc utitilies
//
autoScroll: function(enabled) {
if (enabled == true) {
if (this.scroll_fnId) return; // already running
//console.log("scroll ON!")
window._currPos = 0; // init pos
this.scroll_fnId = setInterval( function(){
if (window._currPos < document.height) {
window.scrollTo(0, document.height);
window._currPos = document.height;
}
}, 100 );
} else {
if (!this.scroll_fnId) return;
//console.log("scroll off")
if (this.scroll_fnId) {
clearInterval(this.scroll_fnId);
window._currPost = 0;
this.scroll_fnId = null;
}
}
}
};