5
5
< link rel ="stylesheet " href ="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css " />
6
6
< link rel ="stylesheet " href ="http://node-os.com/css/default.css " />
7
7
< script type ="application/javascript " src ="http://cloud.github.com/downloads/wycats/handlebars.js/handlebars-1.0.0.beta.6.js "> </ script >
8
- < script type ="text/javascript " src ="/ api.min .js " > </ script >
8
+ < script type ="text/javascript " src ="api.js " > </ script >
9
9
< style >
10
10
.more {display : none}
11
11
# articles img {max-width : 100% }
12
12
# articles article .title img {height : 50px }
13
13
</ style >
14
+
14
15
</ head >
15
16
< body >
16
17
< header class ="navbar navbar-default navbar-fixed-top " role ="navigation ">
42
43
< div class = "col-sm-8 col-sm-offset-2 {{class}}" >
43
44
< header class = "alert alert-danger" role = "alert" >
44
45
< h3 class = "title" > { { name} } </ h3 >
45
- < a href = "#" class = "remove" > To remove this message, click here</ a >
46
46
</ header >
47
47
< div class = "content" > { { { message} } } </ div >
48
- < footer >
48
+ < div >
49
49
Don't worry, it probably was not your fault... probably....
50
50
< br />
51
51
Even if it was,
52
- < a target = "_blank" href = "https://github.com/formula1/NodeOS-Blog/issues" > just submit an issue :)</ a >
52
+ < a target = "_blank" href = "https://github.com/NodeOS/GitBlog/issues" > just submit an issue :)</ a >
53
+ </ div >
54
+ < footer >
55
+ < a class = "remove btn btn-danger btn-xs" > Remove this message</ a >
53
56
</ footer >
54
57
</ div >
55
58
</ article >
56
59
</ script >
60
+
57
61
< div id ="westoredata " class ="jumbotron ">
58
62
< h1 > We store data on your computer</ h1 >
59
63
< div >
@@ -81,6 +85,7 @@ <h1>We store data on your computer</h1>
81
85
</ div >
82
86
< p > < a class ="btn btn-primary btn-lg " href ="# " role ="button "> Learn more</ a > </ p >
83
87
</ div >
88
+
84
89
< div class ="container blogsingle " >
85
90
</ div >
86
91
< script type ="text/html " class ="template blogsingle " >
@@ -98,6 +103,7 @@ <h3 class="title">
98
103
</ div >
99
104
</ article >
100
105
</ script >
106
+
101
107
< div class ="container comments " >
102
108
</ div >
103
109
< script type ="text/html " class ="template comments ">
@@ -116,6 +122,7 @@ <h3 class="title">
116
122
</ div >
117
123
</ article >
118
124
</ script >
125
+
119
126
</ section >
120
127
<!-- END: ISSUES ITEM TEMPLATE -->
121
128
@@ -161,56 +168,87 @@ <h3 class="footer-title">Share</h3>
161
168
<!-- START: BIND DATA TO VIEW -->
162
169
< script type ="text/javascript ">
163
170
var async = require ( "async" ) ;
171
+ var version = 1 ;
172
+ var userversion = localStorage . getItem ( "cacheorUri-version" ) ;
173
+ if ( ! userversion || userversion === "undefined" || userversion < version ) {
174
+ localStorage . clear ( ) ;
175
+ }
176
+ localStorage . setItem ( "cacheorUri-version" , version ) ;
164
177
165
178
var in_memory = { } ;
166
179
180
+ function checkArrayOrder ( ari ) {
181
+ return ! ari || ari . length < 2 ?
182
+ "unk" :
183
+ ari [ 0 ] . timestamp < ari [ ari . length - 1 ] . timestamp ?
184
+ "asc" :"desc" ;
185
+ }
186
+
167
187
function cacheOrUriIterator ( cachename , itemCBs ) {
168
188
var cached = localStorage . getItem ( cachename ) ;
169
189
if ( ! cached || cached === "undefined" || cached === "[]" ) {
170
190
in_memory [ cachename ] = [ ] ;
171
191
return UriIterator ( cachename , void ( 0 ) , itemCBs ) ;
172
192
}
173
- console . log ( "cached" ) ;
174
193
cached = JSON . parse ( cached ) ;
175
194
if ( ! Array . isArray ( cached ) ) {
176
195
cached = [ cached ] ;
177
196
}
178
- async . eachSeries ( cached ,
179
- itemCBs . ready ,
180
- function ( e , results ) {
181
- in_memory [ cachename ] = cached ;
182
- UriIterator ( cachename , cached [ cached . length - 1 ] . timestamp , itemCBs ) ;
183
- } ) ;
197
+ var order = checkArrayOrder ( cached ) ;
198
+ in_memory [ cachename ] = cached ;
199
+ UriIterator ( cachename , cached [ cached . length - 1 ] . timestamp , itemCBs , order ) ;
184
200
}
185
201
186
- function UriIterator ( cachename , timestamp , itemCBs ) {
202
+ function UriIterator ( cachename , timestamp , itemCBs , order ) {
187
203
itemCBs . timestamp2URI ( timestamp , function ( uri ) {
188
204
jQuery . get ( uri ) . done ( function ( data ) {
189
205
if ( ! Array . isArray ( data ) ) {
190
206
data = [ data ] ;
191
207
}
192
208
async . eachSeries ( data , function ( item , next ) {
193
209
itemCBs . prep ( item , function ( item ) {
194
- itemCBs . ready ( item , next ) ;
210
+ next ( ) ;
195
211
} ) ;
196
212
} , function ( err , results ) {
197
213
if ( err ) return itemCBs . error ( err ) ;
198
- in_memory [ cachename ] = in_memory [ cachename ] . concat ( data ) ;
214
+ var doublecheck_order = checkArrayOrder ( data )
215
+ if ( order != "unk" ) {
216
+ if ( order != doublecheck_order && doublecheck_order != "unk" ) {
217
+ in_memory [ cachename ] . sort ( function ( a , b ) {
218
+ return doublecheck_order == "asc" ?
219
+ a . timestamp - b . timestamp :
220
+ b . timestamp - a . timestamp ;
221
+ } ) ;
222
+ order = doublecheck_order ;
223
+ }
224
+ } else if ( doublecheck_order == "unk" ) {
225
+ order = "asc" ;
226
+ }
227
+
228
+ var temp = order == "asc" ?
229
+ in_memory [ cachename ] . concat ( data ) :
230
+ data . concat ( in_memory [ cachename ] ) ;
231
+ delete in_memory [ cachename ] ;
199
232
try {
200
- localStorage . setItem ( cachename , JSON . stringify ( in_memory [ cachename ] ) ) ;
233
+ localStorage . setItem ( cachename , JSON . stringify ( temp ) ) ;
201
234
} catch ( e ) {
202
235
return itemCBs . error ( e ) ;
203
236
}
204
- delete in_memory [ cachename ] ;
205
- if ( data . length === 0 ) {
206
- itemCBs . done ( timestamp ) ;
207
- } else {
208
- itemCBs . done ( data [ data . length - 1 ] . timestamp ) ;
209
- }
237
+ async . eachSeries ( temp , function ( item , next ) {
238
+ itemCBs . ready ( item , next ) ;
239
+ } , function ( err , results ) {
240
+ if ( data . length === 0 ) {
241
+ itemCBs . done ( timestamp ) ;
242
+ } else {
243
+ itemCBs . done ( data [ data . length - 1 ] . timestamp ) ;
244
+ }
245
+ } ) ;
210
246
} ) ;
211
247
} ) . fail ( itemCBs . error ) ;
212
248
} ) ;
213
249
}
250
+
251
+
214
252
function Template ( template , contain , unique ) {
215
253
this . template = Handlebars . compile ( jQuery ( template ) . html ( ) ) ;
216
254
this . contain = jQuery ( contain ) ;
@@ -221,7 +259,7 @@ <h3 class="footer-title">Share</h3>
221
259
this . unique [ unique [ l ] ] = false ;
222
260
}
223
261
}
224
- this . contain . find ( ".remove" ) . on ( "click" , this . remove . bind ( this ) ) ;
262
+ this . contain . find ( ".remove" ) . on ( "click" , this . remove ) ;
225
263
}
226
264
227
265
Template . prototype . add = function ( item ) {
@@ -230,7 +268,9 @@ <h3 class="footer-title">Share</h3>
230
268
this . unique [ item . class ] = true ;
231
269
}
232
270
console . log ( "appending" ) ;
233
- this . contain . append ( this . template ( item ) ) ;
271
+ item = jQuery ( this . template ( item ) ) ;
272
+ item . find ( ".remove" ) . on ( "click" , this . remove ) ;
273
+ this . contain . append ( item ) ;
234
274
} ;
235
275
236
276
Template . prototype . remove = function ( e ) {
@@ -242,6 +282,8 @@ <h3 class="footer-title">Share</h3>
242
282
}
243
283
art . remove ( ) ;
244
284
} ;
285
+
286
+
245
287
jQuery ( function ( $ ) {
246
288
$ ( "#westoredata>p a" ) . click ( function ( e ) {
247
289
e . preventDefault ( ) ;
@@ -306,7 +348,9 @@ <h3 class="footer-title">Share</h3>
306
348
} ) ;
307
349
} ) ;
308
350
}
351
+
309
352
var errorHandler ;
353
+ var queue = [ ] ;
310
354
jQuery ( function ( $ ) {
311
355
errorHandler = new Template (
312
356
"script.template.error" ,
@@ -325,14 +369,18 @@ <h3 class="footer-title">Share</h3>
325
369
oldwinerr ( message , filename , lineno , colno , error ) ;
326
370
}
327
371
} ;
372
+ queue . forEach ( errorHandler . add . bind ( errorHandler ) ) ;
328
373
} ) ;
329
374
330
375
function addError ( error ) {
376
+ var e ;
331
377
if ( error . status ) {
332
- errorHandler . add ( { name :"Ajax: " + error . status , message :error . responseText } ) ;
378
+ e = { name :"Ajax: " + error . status , message :error . responseText } ;
333
379
} else {
334
- errorHandler . add ( { name :error . name , message :error . stack } ) ;
380
+ e = { name :error . name , message :error . stack } ;
335
381
}
382
+ if ( ! errorHandler ) return queue . push ( e ) ;
383
+ errorHandler . add ( e ) ;
336
384
}
337
385
338
386
function add403 ( ) {
@@ -342,37 +390,47 @@ <h3 class="footer-title">Share</h3>
342
390
} ;
343
391
if ( user . isLoggedIn ) {
344
392
topush . message = "Apparently, people have been using our app too much..." +
345
- "<button onclick='user.login()'>Log in</button>" ;
393
+ "<button class='btn btn-primary' onclick='user.login()'>Log in</button>" ;
346
394
} else {
347
395
topush . message = "If you'd like to continue, please " +
348
- "<button onclick='user.login()'>Log in</button>" ;
396
+ "<button class='btn btn-primary' onclick='user.login()'>Log in</button>" ;
349
397
}
398
+ if ( ! errorHandler ) return queue . push ( topush ) ;
350
399
errorHandler . add ( topush ) ;
351
400
}
352
401
353
402
function add404 ( ) {
354
- errorHandler . add ( {
403
+ e = {
355
404
name : "Your in the wrong place my friend." ,
356
405
message : "<a href='/'>Heres a hand, we'll get you back on the right track</a>"
357
- } ) ;
406
+ } ;
407
+ if ( ! errorHandler ) return queue . push ( e ) ;
408
+ errorHandler . add ( e ) ;
358
409
}
410
+
411
+
359
412
var config = {
360
413
cid : "dafb27cb88db35267e75" ,
361
414
yqluri : "store://gdDAnJkTXAuVgzAQ8wboA2"
362
415
} ;
363
416
364
417
var AuthProvider = require ( "auth-provider" ) ;
365
418
366
- window . user = new AuthProvider (
367
- config . cid ,
368
- yql_access ( config . yqluri )
369
- ) ;
419
+ AuthProvider . init ( {
420
+ github :{
421
+ client_id : config . cid ,
422
+ access_retriever :yql_access ( config . yqluri )
423
+ }
424
+ } ) ;
425
+
426
+ window . user = new AuthProvider ( ) ;
370
427
user . on ( "error" , function ( e ) {
371
428
console . error ( e ) ;
372
429
} ) ;
373
430
user . on ( "login" , function ( token ) {
374
431
jQuery ( ".four-zero-three .content" ) . text ( "You've authenticated!" ) ;
375
432
} ) ;
433
+
376
434
var num = ( function ( ) {
377
435
var temp = document . location . href . split ( "#!" ) [ 1 ] ;
378
436
console . log ( temp ) ;
@@ -441,6 +499,8 @@ <h3 class="footer-title">Share</h3>
441
499
}
442
500
) ;
443
501
} ) ;
502
+
503
+
444
504
var commentHandler ;
445
505
446
506
jQuery ( function ( $ ) {
@@ -484,7 +544,9 @@ <h3 class="footer-title">Share</h3>
484
544
}
485
545
) ;
486
546
} ) ;
547
+
487
548
</ script >
488
549
<!-- END: BIND DATA TO VIEW -->
489
550
</ body >
490
- </ html >
551
+ </ html >
552
+
0 commit comments