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 ="text/javascript " src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.min.js "> </ script >
8
- < script type ="text/javascript " src ="api.min.js " > </ script >
8
+ < script type ="text/javascript " src ="https://gist.githubusercontent.com/formula1/749db638e5b5ac630caf/raw/2e07d087e9991213d40183f270d15f6d54244d39/ api.min.js " > </ script >
9
9
< style >
10
10
# articles img {max-width : 100% }
11
+ # articles article .title img {width : 100px }
11
12
</ style >
12
13
</ head >
13
14
< body >
35
36
< section ng-app ="NodeOsBlog " id ="articles " class ="section ">
36
37
< div class ="container " ng-controller ="ErrorListCtrl " >
37
38
< article ng-repeat ="(index, error) in errors " class ="row ">
38
- < div class ="col-sm-8 col-sm-offset-2 {{error.class}} " ng-mousedown =" removeError(error) " >
39
+ < div class ="col-sm-8 col-sm-offset-2 {{error.class}} " >
39
40
< header class ="alert alert-danger " role ="alert ">
40
41
< h3 class ="title "> {{error.name}}</ h3 >
42
+ < p ng-mousedown ="removeError(error) " > To remove this message, click here</ p >
41
43
</ header >
42
- < div class ="content "> {{ error.message}} </ div >
44
+ < div class ="content " ng-bind-html =" error.message | to_trusted " > </ div >
43
45
< footer >
44
46
Don't worry, it probably was not your fault... probably....
45
47
< br /> < br />
46
48
Even if it was,
47
49
< a target ="_blank " href ="https://github.com/formula1/NodeOS-Blog/issues " > just submit an issue :)</ a >
48
- < br /> < br />
49
- To remove this message, click it.
50
50
</ footer >
51
51
</ div >
52
52
</ article >
@@ -134,7 +134,7 @@ <h3 class="footer-title">Share</h3>
134
134
} ;
135
135
} ] ) ;
136
136
var errors = [ ] ;
137
- var is_authed = false ;
137
+
138
138
function add403 ( ) {
139
139
var topush = {
140
140
class :"four-zero-three" ,
@@ -144,10 +144,11 @@ <h3 class="footer-title">Share</h3>
144
144
topush . message = "Apparently, people have been using our app too much..." ;
145
145
} else {
146
146
topush . message = "If you'd like to continue, please " +
147
- "<button onclick='hello(\"github\"). login()'>Log in</button>" ;
147
+ "<button onclick='login()'>Log in</button>" ;
148
148
}
149
149
errors . push ( topush ) ;
150
150
}
151
+
151
152
NodeOsBlog . controller ( 'ErrorListCtrl' , function ( $scope ) {
152
153
$scope . removeError = function ( error ) {
153
154
var l = errors . length ;
@@ -163,89 +164,206 @@ <h3 class="footer-title">Share</h3>
163
164
}
164
165
} ;
165
166
} ) ;
166
- var hello = require ( "hello" ) ;
167
- hello . on ( "auth.login" , function ( auth ) {
168
- hello ( auth . network ) . api ( "/me" ) . then ( function ( r ) {
169
- document . querySelector ( ".four-zero-three .content" ) . innerHTML ( "You've authenticated!" ) ;
167
+ function parseMarkdown ( item , next ) {
168
+ jQuery . post ( "https://api.github.com/markdown" , { text :item . body } )
169
+ . done ( function ( data ) {
170
+ item . bodyHTML = data ;
171
+ next ( item ) ;
172
+ } ) . fail ( function ( data , status , headers , config ) {
173
+ errors . push ( { name :"Bad markdown call: " + status , message : data . message } ) ;
174
+ item . bodyHTML = "<pre>" + item . body + "</pre>" ;
175
+ next ( item ) ;
170
176
} ) ;
171
- } ) ;
177
+ }
178
+ /*
179
+ var markdown = require("markdown").markdown;
180
+ function parseMarkdown(item,next){
181
+ console.log("parsing");
182
+
183
+ try{
184
+ item.bodyHTML = markdown.toHTML(item.body);
185
+ console.log(item.bodyHTML);
186
+ }catch(e){
187
+ console.log(e);
188
+ item.bodyHTML = "<pre>"+item.body+"</pre>";
189
+ }
190
+ setTimeout(next.bind(next,item),1);
191
+ }
192
+ */
193
+ function CookieStore ( id ) {
194
+ this . id = id ;
195
+ var cook = document . cookie . split ( ";" ) ;
196
+ var current ;
197
+ var i ;
198
+ for ( i = 0 ; i < cook . length ; i ++ ) {
199
+ if ( cook [ i ] . indexOf ( "=" ) != - 1 ) {
200
+ current = cook [ i ] . split ( "=" ) ;
201
+ if ( current [ 0 ] . replace ( / s / , "" ) == id ) {
202
+ this . cookie = JSON . parse ( decodeURIComponent ( current [ 1 ] ) ) ;
203
+ return ;
204
+ }
205
+ }
206
+ }
207
+ this . cookie = { } ;
208
+ this . save ( ) ;
209
+ }
210
+
211
+ CookieStore . prototype . get = function ( key ) {
212
+ return this . cookie [ key ] ;
213
+ } ;
214
+ CookieStore . prototype . set = function ( key , value ) {
215
+ this . cookie [ key ] = value ;
216
+ this . save ( ) ;
217
+ return this ;
218
+ } ;
219
+ CookieStore . prototype . delete = function ( key ) {
220
+ delete this . cookie [ key ] ;
221
+ this . save ( ) ;
222
+ return this ;
223
+ } ;
224
+
225
+ CookieStore . prototype . save = function ( ) {
226
+ document . cookie = this . id + "=" + encodeURIComponent ( JSON . stringify ( this . cookie ) ) + ";" ;
227
+ } ;
228
+
229
+ //==========Auth Start===================
230
+
231
+
232
+ var auth = new CookieStore ( "auth" ) ;
233
+ var is_authed = - 1 ;
234
+ var auth_queueu = [ ] ;
235
+ var url = require ( "url" ) ;
236
+ var docuri = url . parse ( window . location . href ) ;
237
+ if ( docuri . query && docuri . query . code ) {
238
+ if ( url . query . state != auth . get ( "state" ) ) {
239
+ errors . push ( new Error ( "Improper State" ) ) ;
240
+ } else {
241
+ getAccess ( docuri . query . code ) ;
242
+ }
243
+ } else if ( auth . get ( "access_token" ) ) {
244
+ is_authed = 1 ;
245
+ }
246
+
247
+ var config = {
248
+ cid : "dafb27cb88db35267e75" ,
249
+ yqluri : "store://gdDAnJkTXAuVgzAQ8wboA2"
250
+ } ;
251
+
252
+ function login ( ) {
253
+ var state = Date . now ( ) + "_" + Math . random ( ) ;
254
+ auth . set ( "state" , state ) ;
255
+ window . location . href = "https://github.com/login/oauth/authorize" +
256
+ "?client_id=" + config . cid +
257
+ "&state=" + state ;
258
+ }
259
+ function getAccess ( code ) {
260
+ is_authed = 0 ;
261
+ auth . delete ( "state" ) ;
262
+ jQuery . get ( compileYQL ( [
263
+ "env \"" + config . yqlur + "\"" ,
264
+ "select * from github where CODE=\"" + code + "\""
265
+ ] ) ) . done ( function ( results ) {
266
+ auth . set ( "access_token" , results . query . results . OAuth . access_token ) ;
267
+ is_authed = 1 ;
268
+ jQuery ( ".four-zero-three .content" ) . text ( "You've authenticated!" ) ;
269
+ } ) . error ( function ( e ) {
270
+ is_authed = - 1 ;
271
+ errors . push ( e ) ;
272
+ } ) . finally ( function ( ) {
273
+ while ( auth_queue . length ) {
274
+ uriAsAuthority . apply ( void ( 0 ) , auth_queue . pop ( ) ) ;
275
+ }
276
+ } ) ;
277
+ }
278
+
279
+ function compileYQL ( query ) {
280
+ if ( Array . isArray ( query ) ) {
281
+ query = query . join ( ";" ) ;
282
+ }
283
+ if ( typeof query != "string" ) {
284
+ throw new Error ( "A yql query must be a string" ) ;
285
+ }
286
+ return "https://query.yahooapis.com/v1/public/yql?q=" +
287
+ encodeURIComponent ( query ) +
288
+ "&diagnostics=true&format=json" ;
289
+ }
290
+
291
+ function uriAsAuthority ( uri , next ) {
292
+ switch ( is_authed ) {
293
+ case - 1 : return next ( uri ) ;
294
+ case 0 : return auth_queueu . push ( [ uri , next ] ) ;
295
+ case 1 : uri = url . parse ( uri ) ;
296
+ uri . query . access_token = auth . get ( "access_token" ) ;
297
+ return next ( url . format ( uri ) ) ;
298
+ }
299
+ }
300
+
301
+ function logout ( ) {
302
+ auth . delete ( "access_token" ) ;
303
+ is_authed = - 1 ;
304
+ }
172
305
var hash = document . location . toString ( ) . split ( "#" ) [ 1 ] ;
173
306
NodeOsBlog . controller ( 'BlogSingleCtrl' , function ( $scope , $http ) {
174
307
$scope . uriPath = "/NodeOS/NodeOS/issues/" + hash ;
175
308
$scope . blog = [ ] ;
176
309
177
310
var markdown = require ( "markdown" ) . markdown ;
178
- $scope . parseMarkdown = function ( item , next ) {
179
- try {
180
- item . bodyHTML = markdown . toHTML ( item . body ) ;
181
- } catch ( e ) {
182
- item . bodyHTML = "<pre>" + item . body + "</pre>" ;
183
- }
184
- next ( item ) ;
185
- } ;
186
- $http . get ( 'https://api.github.com/repos' + $scope . uriPath )
187
- . success ( function ( data , status , headers ) {
188
- var l = data . labels . length ;
189
- while ( l -- ) {
190
- if ( data . labels [ l ] . name === "blog" ) {
191
- break ;
311
+ uriAsAuthority ( 'https://api.github.com/repos' + $scope . uriPath , function ( uri ) {
312
+ $http . get ( uri ) . success ( function ( data , status , headers ) {
313
+ var l = data . labels . length ;
314
+ while ( l -- ) {
315
+ if ( data . labels [ l ] . name === "blog" ) {
316
+ break ;
317
+ }
192
318
}
193
- }
194
- if ( l < 0 ) {
195
- return errors . push ( {
196
- name :"Trying to load a non-blog?" ,
197
- message : "I technically can't stop you since this is clientside." +
198
- " Hopefully my code feels clean enough to hack"
319
+ if ( l < 0 ) {
320
+ return errors . push ( {
321
+ name :"Trying to load a non-blog?" ,
322
+ message : "I technically can't stop you since this is clientside." +
323
+ " Hopefully my code feels clean enough to hack"
324
+ } ) ;
325
+ }
326
+ parseMarkdown ( data , function ( item ) {
327
+ $scope . blog . push ( item ) ;
199
328
} ) ;
200
- }
201
- $scope . parseMarkdown ( data , function ( item ) {
202
- $scope . blog . push ( item ) ;
329
+ } ) . error ( function ( data , status , headers , config ) {
330
+ if ( status === 403 ) {
331
+ add403 ( ) ;
332
+ } else {
333
+ errors . push ( { name :"Bad issues list request: " + status , message : data . message } ) ;
334
+ }
203
335
} ) ;
204
- } ) . error ( function ( data , status , headers , config ) {
205
- if ( status === 403 ) {
206
- add403 ( ) ;
207
- } else {
208
- errors . push ( { name :"Bad issues list request: " + status , message : data . message } ) ;
209
- }
210
336
} ) ;
211
337
} ) ;
212
338
NodeOsBlog . controller ( 'CommentListCtrl' , function ( $scope , $http ) {
213
339
$scope . uriPath = "/NodeOS/NodeOS/issues/" + hash + "/comments" ;
214
340
$scope . blog = [ ] ;
215
- $scope . parseMarkdown = function ( item , next ) {
216
- $http . post ( "https://api.github.com/markdown" , { text :item . body } )
217
- . success ( function ( data ) {
218
- item . bodyHTML = data ;
219
- next ( item ) ;
220
- } ) . error ( function ( data , status , headers , config ) {
221
- errors . push ( { name :"Bad markdown call: " + status , message : data . message } ) ;
222
- item . bodyHTML = "<pre>" + item . body + "</pre>" ;
223
- next ( item ) ;
224
- } ) ;
225
- } ;
226
341
$scope . last = void ( 0 ) ;
227
342
$scope . loadMore = function ( page ) {
228
343
if ( $scope . last && $scope . last < page ) return ;
229
344
var i = 0 ;
230
345
var l = - 1 ;
231
- $http . get ( 'https://api.github.com/repos' + $scope . uriPath + '?labels=blog&sort=created&page=' + page )
232
- . success ( function ( data , status , headers ) {
233
- if ( ! $scope . last ) $scope . last = headers . link ?headers . link . split ( "=" ) . pop ( ) :1 ;
234
- l = data . length ;
235
- if ( i === l ) return ; //No more
236
- var iterator = function ( item ) {
237
- $scope . blog . push ( item ) ;
238
- i ++ ;
239
- if ( i === l ) return ;
240
- $scope . parseMarkdown ( data [ i ] , iterator ) ;
241
- } ;
242
- $scope . parseMarkdown ( data [ 0 ] , iterator ) ;
243
- } ) . error ( function ( data , status , headers , config ) {
244
- if ( status === 403 ) {
245
- add403 ( ) ;
246
- } else {
247
- errors . push ( { name :"Bad issues list request: " + status , message : data . message } ) ;
248
- }
346
+ uriAsAuthority (
347
+ 'https://api.github.com/repos' + $scope . uriPath + '?labels=blog&sort=created&page=' + page ,
348
+ function ( uri ) {
349
+ $http . get ( is_authed ) . success ( function ( data , status , headers ) {
350
+ if ( ! $scope . last ) $scope . last = headers . link ?headers . link . split ( "=" ) . pop ( ) :1 ;
351
+ l = data . length ;
352
+ if ( i === l ) return ; //No more
353
+ var iterator = function ( item ) {
354
+ $scope . blog . push ( item ) ;
355
+ i ++ ;
356
+ if ( i === l ) return ;
357
+ parseMarkdown ( data [ i ] , iterator ) ;
358
+ } ;
359
+ parseMarkdown ( data [ 0 ] , iterator ) ;
360
+ } ) . error ( function ( data , status , headers , config ) {
361
+ if ( status === 403 ) {
362
+ add403 ( ) ;
363
+ } else {
364
+ errors . push ( { name :"Bad issues list request: " + status , message : data . message } ) ;
365
+ }
366
+ } ) ;
249
367
} ) ;
250
368
} ;
251
369
$scope . loadMore ( 1 ) ;
0 commit comments