1
- // requirejs.config({waitSeconds:0});
1
+ requirejs . config ( { waitSeconds :0 } ) ;
2
2
require ( [
3
3
'./jquery.js' ,
4
4
'./handlebars.min.js' ,
@@ -9,39 +9,41 @@ require([
9
9
'text!data.json'
10
10
] , function ( _ , Mustache , elasticlunr , questionView , questionList , wordList , data , indexDump ) {
11
11
12
+ //, 'text!example_index.json', 'text!example_data.json',
13
+
12
14
var WLtemplate = Mustache . compile ( wordList ) ;
13
15
var QLtemplate = Mustache . compile ( questionList ) ;
14
16
var QVtemplate = Mustache . compile ( questionView ) ;
15
17
16
- var seeder = 999999 ;
18
+ var seeder = 11091974 ;
17
19
18
20
var BodyRef = document . getElementById ( "body" ) ;
19
21
var clearButton = $ ( '#clearButton' ) ;
20
22
21
-
22
23
var renderQuestionList = function ( qs ) {
23
24
$ ( "#question-list-container" )
24
25
. empty ( )
25
- . append ( QLtemplate ( { questions : qs } ) )
26
+ . append ( QLtemplate ( { questions : qs } ) ) ;
26
27
}
27
28
28
29
var renderWordList = function ( qs ) {
30
+
29
31
$ ( "#question-list-container" )
30
32
. empty ( )
31
- . append ( WLtemplate ( { list : qs } ) )
33
+ . append ( PRERENDERED_LIST_HTML ) ;
32
34
}
33
35
34
36
var renderQuestionView = function ( question ) {
35
37
$ ( "#question-view-container" )
36
38
. empty ( )
37
- . append ( QVtemplate ( question ) )
39
+ . append ( QVtemplate ( question ) ) ;
38
40
39
41
}
40
-
42
+
41
43
window . profile = function ( term ) {
42
- console . profile ( 'search' )
43
- window . idx . search ( term )
44
- console . profileEnd ( 'search' )
44
+ console . profile ( 'search' ) ;
45
+ window . idx . search ( term ) ;
46
+ console . profileEnd ( 'search' ) ;
45
47
}
46
48
47
49
window . search = function ( term ) {
@@ -59,23 +61,69 @@ var clearButton = $('#clearButton');
59
61
this . saveDocument ( false ) ;
60
62
} ) ;
61
63
62
- var fulllist = new Array ( ) ;
64
+ Mustache . registerHelper ( 'everyOther' , function ( index , options ) {
65
+ if ( index % 2 == 0 ) {
66
+ return options . fn ( this ) ;
67
+ } else {
68
+ return options . inverse ( this ) ;
69
+ }
70
+
71
+ } ) ;
72
+
73
+ // Modified to
74
+ Array . prototype . byCount = function ( ) {
75
+ //var lenHolder = [];
76
+ var itm , a = [ ] , L = this . length , o = { } ;
77
+ for ( var i = 0 ; i < L ; i ++ ) {
78
+ itm = this [ i ] ;
79
+ if ( ! itm ) continue ;
80
+ if ( o [ itm ] == undefined ) o [ itm ] = 1 ;
81
+ else ++ o [ itm ] ;
82
+ }
83
+ countHolder = [ ] ;
84
+ for ( var p in o ) { a [ a . length ] = p ;
85
+ countHolder [ countHolder . length ] = { name : a . slice ( - 1 ) . toString ( ) , amount : o [ p ] } ;
86
+ }
87
+ var returnWithCounts =
88
+ a . sort ( function ( a , b ) {
89
+ return o [ b ] - o [ a ] ;
90
+ } )
91
+ countHolder . sort ( function ( a , b ) {
92
+ return a . amount > b . amount ;
93
+ } )
94
+ return returnWithCounts } ;
95
+
96
+ // prep the questions
97
+ var fulllist = [ ] ;
98
+ var rawQuestions = JSON . parse ( data ) . questions ;
99
+
100
+ rawQuestions . map ( function ( raw ) {
101
+ for ( thing in raw . question . content )
102
+ {
103
+ fulllist [ fulllist . length ] = thing ; //{'x': thing};
104
+ }
105
+ } )
106
+
107
+ var shortlist = fulllist . byCount ( ) ;
108
+ dict = { }
109
+ countHolder . forEach ( function ( x ) {
110
+ dict [ x . name ] = x . amount
111
+ } )
112
+
63
113
64
- var questions = JSON . parse ( data ) . questions . map ( function ( raw ) {
65
- var holder = ""
114
+ var questions = rawQuestions . map ( function ( raw ) {
115
+ rawQuestion = raw ;
116
+
117
+ var holder = ""
66
118
for ( i in raw . question . content ) {
67
119
holder += i + ' : ' + raw . question . content [ i ] + '\n' ;
68
120
}
69
121
var make_id = murmurhash3_32_gc ( raw . img . filename , seeder ) ;
122
+ //console.log(make_id);
70
123
71
- for ( thing in raw . question . content )
72
- {
73
- fulllist [ fulllist . length ] = thing ; //{'x': thing};
74
- }
75
-
76
124
var clickableTags = Object . keys ( raw . question . content ) . map ( function ( k ) {
77
125
78
- var result = '<a style="cursor:pointer" onclick="searchTerm(\'' + k + '\')">' + k + '</a>' ;
126
+ var result = '<a title="' + dict [ k ] + ' results for ' + k + '" style="cursor:pointer" onclick="searchTerm(\''+ k + '\')">' + k + '</a>' ;
79
127
80
128
return result ;
81
129
} )
@@ -87,7 +135,7 @@ var clearButton = $('#clearButton');
87
135
title : raw . img . filename . replace ( '.JPG' , '' ) ,
88
136
body : holder ,
89
137
searchTerms : Object . keys ( raw . question . content ) . join ( ' ' ) ,
90
- tags : clickableTags ,
138
+ tags : clickableTags , // Object.keys(raw.question.content).join(' '),
91
139
img : raw . img . filename ,
92
140
thumb : raw . thumb . filename
93
141
}
@@ -107,17 +155,14 @@ window.idx = idx;
107
155
document . getElementById ( "loader" ) . style . display = "none" ;
108
156
document . getElementById ( "hiding_title" ) . style . display = "none" ;
109
157
110
-
111
- // this is how one might expose the complete engine for saving in a NON Node.js scenario.
112
- // var code = JSON.stringify(idx);
113
- // $('#codehere').text(code);
114
-
115
158
renderQuestionView ( questions [ 0 ] )
116
-
159
+
117
160
118
- var shortlist = fulllist . filter ( ( v , i , a ) => a . indexOf ( v ) === i ) . map ( function ( raw ) {
119
- return { x : raw }
120
- } ) ;
161
+
162
+ shortlist = countHolder . map ( function ( raw ) { return { x : raw . name , count : raw . amount } } ) ;
163
+
164
+ var PRERENDERED_LIST_HTML = WLtemplate ( { list : shortlist } ) ;
165
+
121
166
122
167
var emptyFunction = function emptyMe ( ) {
123
168
@@ -152,23 +197,27 @@ window.emptyFunction = emptyFunction;
152
197
153
198
function doHeavyWork ( results , start , totalResultsToRender , term ) {
154
199
var total = totalResultsToRender ;
155
- var fragment = 50 ;
200
+ var fragment = 20 ;
156
201
var end = start + fragment ;
157
202
var left = totalResultsToRender - end ;
158
203
204
+
205
+ // console.log( left + ' results of '+ totalResultsToRender +' total left to render');
159
206
160
207
// partially render list
161
208
// the thing to render, the start record and the end record
162
209
renderPartialQuestionList ( results , end - fragment , end )
163
- clearButton . text ( end + fragment + ' of ' + results . length + ' for ' + term ) ;
210
+ clearButton . text ( end + ' of ' + results . length + ' for ' + term ) ;
164
211
212
+ //clearButton.addClass('blink');
165
213
166
214
if ( end >= total ) {
167
215
168
216
// If we reached the end, stop and change status
169
217
clearButton . removeClass ( 'blink' ) ;
170
218
clearButton . text ( results . length + ' for ' + term ) ;
171
- BodyRef . style . cursor = '' ;
219
+ $ ( 'body' ) . removeClass ( 'custom' ) ;
220
+ //BodyRef.style.cursor = '';
172
221
173
222
} else {
174
223
// Otherwise, process next fragment
@@ -180,10 +229,10 @@ window.emptyFunction = emptyFunction;
180
229
181
230
function dowork ( results , totalResultsToRender , term ) {
182
231
// Set "working" status
183
- document . body . style . cursor = "wait" ;
232
+
184
233
document . getElementById ( "clearButton" ) . innerHTML = "working" ;
185
234
// render the single view and set term in search bar
186
-
235
+ $ ( 'body' ) . addClass ( 'custom' ) ; //document.body.style.cursor = "progress";
187
236
renderQuestionView ( results [ 0 ] ) ;
188
237
189
238
// render big view in chunks
0 commit comments