8
8
*/
9
9
10
10
11
- function Configuration ( file ) {
11
+ function Configuration ( file , showConfigFile ) {
12
12
13
13
// Private Variables
14
14
var that = this ; // generic pointer back to this function
15
15
var fileData ; // configuration file information
16
+ var fileLinesArray ; // Store the contents of the file globally
16
17
18
+ function renderFileContentList ( configurationList , filter ) {
19
+ var li ;
20
+
21
+ // Clear the contents of the list
22
+ $ ( 'li' , configurationList ) . remove ( ) ;
23
+
24
+ for ( var i = 0 ; i < fileLinesArray . length ; i ++ ) {
25
+ if ( ! filter || filter . length < 1 ) { //Everything
26
+ li = $ ( '<li class="configuration-row">' + fileLinesArray [ i ] + '</li>' ) ;
27
+ configurationList . append ( li ) ;
28
+ } else {
29
+ var regFilter = new RegExp ( '(.*)(' + filter + ')(.*)' , 'i' ) ;
30
+ var highLight = fileLinesArray [ i ] . match ( regFilter ) ;
31
+ if ( highLight != null ) { // dont include blank lines
32
+ li = $ ( '<li class="configuration-row">' + highLight [ 1 ] + '<b>' + highLight [ 2 ] + '</b>' + highLight [ 3 ] + '</li>' ) ;
33
+ configurationList . append ( li ) ;
34
+ }
35
+ }
36
+ }
37
+ }
38
+
39
+ function renderFileContents ( filter ) {
40
+
41
+ var
42
+ configurationElem = ( '.configuration-file' ) , // point to the actual element in index.html
43
+ configurationDiv = $ ( '<div class="configuration-file">'
44
+ + '<div class="configuration-header">'
45
+ + '<h3>' + file . name
46
+ + '<span class="configuration-close glyphicon glyphicon-remove"></span>'
47
+ + '</h3>'
48
+ + '<input type="text" class="form-control configuration-filter" placeholder="Enter filter" size="5"/>'
49
+ + '</div>'
50
+ + '<div><ul class="list-unstyled configuration-list"></ul></div>'
51
+ + '</div>' ) ,
52
+ configurationTitle = $ ( 'h3' , configurationDiv ) ,
53
+ li ;
54
+
55
+ // now replace the element in the index.html with the loaded file information
56
+ $ ( configurationElem ) . replaceWith ( configurationDiv ) ;
57
+
58
+ var configurationList = $ ( '.configuration-list' ) ;
59
+ renderFileContentList ( configurationList , null ) ;
60
+
61
+ //configurationTitle.text(file.name);
62
+ $ ( "#status-bar .configuration-file-name" ) . text ( file . name ) ;
63
+
64
+ // now replace the element in the index.html with the loaded file information
65
+ $ ( configurationElem ) . replaceWith ( configurationDiv ) ;
66
+
67
+
68
+ // Add close icon
69
+ $ ( ".configuration-close" ) . click ( function ( ) {
70
+ if ( showConfigFile ) showConfigFile ( false ) ; // hide the config file
71
+ } ) ;
72
+
73
+
74
+ }
75
+
17
76
function loadFile ( file ) {
18
77
19
78
var reader = new FileReader ( ) ;
20
79
fileData = file ; // Store the data locally;
80
+
21
81
22
82
reader . onload = function ( e ) {
23
-
24
- var
25
- configurationElem = ( '.configuration-file' ) , // point to the actual element in index.html
26
- configurationDiv = $ ( '<div class="configuration-file"><h3></h3><ul class="list-unstyled configuration-list"></ul></div>' ) ,
27
- configurationTitle = $ ( 'h3' , configurationDiv ) ,
28
- configurationList = $ ( 'ul' , configurationDiv ) ,
29
- li ;
30
-
31
- var data = e . target . result ; // all the data
32
- var lines = data . split ( '\n' ) ; // separate into lines
33
-
34
- for ( var i = 0 ; i < lines . length ; i ++ ) {
35
- li = $ ( '<li class="configuration-row">' + lines [ i ] + '</li>' ) ;
36
- configurationList . append ( li ) ;
37
- }
38
-
39
- configurationTitle . text ( file . name ) ;
40
- $ ( "#status-bar .configuration-file-name" ) . text ( file . name ) ;
41
-
42
- // now replace the element in the index.html with the loaded file information
43
- $ ( configurationElem ) . replaceWith ( configurationDiv ) ;
44
-
83
+
84
+ var data = e . target . result ; // all the data
85
+
86
+ fileLinesArray = data . split ( '\n' ) ; // separated into lines
87
+
88
+ renderFileContents ( ) ;
89
+
90
+ // Add user configurable file filter
91
+ $ ( ".configuration-filter" ) . keyup ( function ( ) {
92
+
93
+ var newFilter = $ ( ".configuration-filter" ) . val ( ) ;
94
+
95
+ var configurationList = $ ( '.configuration-list' ) ;
96
+ renderFileContentList ( configurationList , newFilter ) ;
97
+
98
+ } ) ;
45
99
46
100
} ;
47
101
@@ -55,4 +109,6 @@ function Configuration(file) {
55
109
56
110
loadFile ( file ) ; // configuration file loaded
57
111
112
+ // Add filter
113
+
58
114
}
0 commit comments