Skip to content

Commit 1d6952e

Browse files
committed
removed angular dependency
1 parent 1139f61 commit 1d6952e

21 files changed

+904
-682
lines changed

dist/api.min.js

Lines changed: 10 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/article.html

Lines changed: 276 additions & 196 deletions
Large diffs are not rendered by default.

dist/index.html

Lines changed: 230 additions & 154 deletions
Large diffs are not rendered by default.

html/article.ejs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
cur_page["body"] = include("parts/error.html");
44
cur_page["body"] += "\n"+include("parts/blogsingle.html");
55
cur_page["body"] += "\n"+include("parts/commentlist.html");
6-
cur_page["foot"] = include("footerjs/base.js")
6+
cur_page["foot"] = include("footerjs/cacheOrLoad.js")
7+
+ "\n"+include("footerjs/utility.js")
78
+ "\n"+include("footerjs/error.js")
89
+ "\n"+include("footerjs/user.js")
910
+ "\n"+include("footerjs/blogsingle.js")

html/blog.ejs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<%
22
cur_page["head"] = include("parts/head.html");
3-
cur_page["body"] = include("parts/error.html");
4-
cur_page["body"] += "\n"+include("parts/bloglist.html");
5-
cur_page["foot"] = include("footerjs/base.js")
3+
cur_page["body"] = include("parts/error.html")
4+
+ "\n"+include("parts/westoredata.html")
5+
+ "\n"+include("parts/bloglist.html");
6+
cur_page["foot"] = include("footerjs/cacheOrLoad.js")
7+
+ "\n"+include("footerjs/utility.js")
68
+ "\n"+include("footerjs/error.js")
79
+ "\n"+include("footerjs/user.js")
810
+ "\n"+include("footerjs/bloglist.js");

html/footerjs/base.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

html/footerjs/bloglist.js

Lines changed: 39 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,44 @@
1-
NodeOsBlog.controller('BlogListCtrl', function ($scope, $http) {
2-
$scope.uriPath = "/NodeOS/NodeOS/issues";
3-
$scope.user = user;
4-
$scope.blog = [];
5-
$scope.last = void(0);
6-
$scope.parseMarkdown = parseMarkdown;
7-
$scope.loadMore = function(since){
8-
if($scope.last && $scope.last < page) return;
9-
var i=0;
10-
var l=-1;
11-
$scope.user.asAuthority(
12-
'https://api.github.com/repos'+$scope.uriPath+'?labels=blog&sort=updated'+(since?'&since='+since:""),
13-
function(uri){
14-
$http.get(uri).success(function(data,status,headers) {
15-
console.log(headers);
16-
console.log(headers.link);
17-
if(!$scope.last) $scope.last = headers.link?headers.link.split("=").pop():1;
18-
l = data.length;
19-
console.log(data.length);
20-
if(i === l) return; //No more
21-
var iterator = function(item){
22-
$scope.blog.push(item);
23-
$scope.$apply();
24-
i++;
25-
if(i === l){
26-
try{
27-
localStorage.setItem("issue-list-"+num, JSON.stringify($scope.blog));
28-
}catch(e){
29-
errors.push({name:"LocalStorage", message:"Cannot Store Anymore"});
30-
}
31-
return;
32-
}
33-
$scope.parseMarkdown(data[i],iterator);
34-
};
35-
$scope.parseMarkdown(data[0],iterator);
36-
}).error(function(data, status, headers, config) {
37-
if(status === 403){
1+
2+
var listHandler;
3+
4+
jQuery(function($){
5+
listHandler = new Template(
6+
"script.template.bloglist",
7+
"div.container.bloglist"
8+
);
9+
listHandler._x = {
10+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues?labels=blog&sort=updated",
11+
last: void(0)
12+
};
13+
cacheOrUriIterator(
14+
"issue-list",
15+
{
16+
timestamp2URI: function(timestamp,next){
17+
var uri = listHandler._x.uri;
18+
if(timestamp) {
19+
var temp = new Date(timestamp+1000);
20+
uri += "&since="+(new Date(timestamp+1000)).toISOString();
21+
}
22+
user.asAuthority(uri,next);
23+
},
24+
prep: function(item, next){
25+
item.timestamp = (new Date(item.updated_at)).getTime();
26+
parseMarkdown(item,next);
27+
},
28+
ready: function(item,next){
29+
listHandler.add(item);
30+
setTimeout(next,1);
31+
},
32+
done: function(date){
33+
listHandler._x.last = date;
34+
},
35+
error: function(error){
36+
if(error.status && error.status === 403){
3837
add403();
3938
}else{
40-
errors.push({name:"Bad issues list request: "+status, message: data.message});
39+
addError(error);
4140
}
42-
});
43-
});
44-
};
45-
var lastdate;
46-
var cached = localStorage.getItem("issue-list");
47-
if(cached){
48-
cached = JSON.parse(cached);
49-
var i = 0;
50-
var l = cached.length;
51-
var iterator = function(item){
52-
$scope.blog.push(item);
53-
i++;
54-
if(i === l){
55-
var d = new Date(cached[i-1].updated_at);
56-
d.setSeconds(d.getSeconds() + 1);
57-
d = d.toISOString();
58-
return $scope.loadMore(d);
5941
}
60-
setTimeout(iterator.bind(void(0),cached[i]),1);
61-
};
62-
iterator(cached[0]);
63-
}else{
64-
$scope.loadMore();
65-
}
42+
}
43+
);
6644
});

html/footerjs/blogsingle.js

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,57 @@ var num = (function(){
1212
}
1313
return temp._escaped_fragment_;
1414
})();
15-
NodeOsBlog.controller('BlogSingleCtrl', function ($scope, $http) {
16-
if(!num) return;
17-
$scope.uriPath = "/NodeOS/NodeOS/issues/"+num;
18-
$scope.user = user;
19-
$scope.blog = [];
20-
$scope.parseMarkdown = parseMarkdown;
2115

22-
var cached = localStorage.getItem("issue-"+num);
23-
if(cached){
24-
cached = JSON.parse(cached);
25-
var d = new Date(cached.updated_at);
26-
if(Date.now() - d.getTime() < 1000*60*60*24){
27-
console.log("cached");
28-
$scope.blog.push(cached);
29-
return;
30-
}
31-
}
16+
var singleHandler;
3217

33-
var markdown = require("markdown").markdown;
34-
$scope.user.asAuthority('https://api.github.com/repos'+$scope.uriPath,function(uri){
35-
$http.get(uri).success(function(data,status,headers) {
36-
var l = data.labels.length;
37-
while(l--){
38-
if(data.labels[l].name === "blog"){
39-
break;
18+
jQuery(function($){
19+
if(!num) return;
20+
singleHandler = new Template(
21+
"script.template.blogsingle",
22+
"div.container.blogsingle"
23+
);
24+
singleHandler._x = {
25+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues/"+num,
26+
last: void(0)
27+
};
28+
cacheOrUriIterator(
29+
"issue-"+num,
30+
{
31+
timestamp2URI: function(timestamp,next){
32+
if(Date.now() - timestamp < 1000*60*60*24) return;
33+
user.asAuthority(singleHandler._x.uri,next);
34+
},
35+
prep: function(item, next){
36+
item.timestamp = Date.now();
37+
var l = item.labels.length;
38+
while(l--){
39+
if(item.labels[l].name === "blog"){
40+
break;
41+
}
4042
}
41-
}
42-
if(l < 0){
43-
return errors.push({
44-
name:"Trying to load a non-blog?",
45-
message: "I technically can't stop you since this is clientside."+
46-
" Hopefully my code feels clean enough to hack"
47-
});
48-
}
49-
$scope.parseMarkdown(data,function(item){
50-
item.date = Date.now();
51-
try{
52-
localStorage.setItem("issue-"+num,JSON.stringify(item));
53-
}catch(e){
54-
errors.push({name:"LocalStorage", message:"Cannot Store Anymore"});
43+
if(l < 0){
44+
return addError({
45+
name:"Trying to load a non-blog?",
46+
message: "I technically can't stop you since this is clientside."+
47+
" Hopefully my code feels clean enough to hack"
48+
});
49+
}
50+
parseMarkdown(item,next);
51+
},
52+
ready: function(item,next){
53+
singleHandler.add(item);
54+
next();
55+
},
56+
done: function(date){
57+
singleHandler._x.last = date;
58+
},
59+
error: function(error){
60+
if(error.status && error.status === 403){
61+
add403();
62+
}else{
63+
addError(error);
5564
}
56-
$scope.blog.push(item);
57-
$scope.$apply();
58-
});
59-
}).error(function(data, status, headers, config) {
60-
if(status === 403){
61-
add403();
62-
}else{
63-
errors.push({name:"Bad issues list request: "+status, message: data.message});
6465
}
65-
});
66-
});
66+
}
67+
);
6768
});

html/footerjs/cacheOrLoad.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
var async = require("async");
2+
3+
var in_memory = {};
4+
5+
function cacheOrUriIterator(cachename, itemCBs){
6+
var cached = localStorage.getItem(cachename);
7+
if(!cached || cached === "undefined" || cached === "[]" ){
8+
in_memory[cachename] = [];
9+
return UriIterator(cachename, void(0), itemCBs);
10+
}
11+
console.log("cached");
12+
cached = JSON.parse(cached);
13+
if(!Array.isArray(cached)){
14+
cached = [cached];
15+
}
16+
async.eachSeries(cached,
17+
itemCBs.ready,
18+
function(e,results){
19+
in_memory[cachename] = cached;
20+
UriIterator(cachename, cached[cached.length - 1].timestamp, itemCBs);
21+
});
22+
}
23+
24+
function UriIterator(cachename, timestamp, itemCBs){
25+
itemCBs.timestamp2URI(timestamp,function(uri){
26+
jQuery.get(uri).done(function(data){
27+
if(!Array.isArray(data)){
28+
data = [data];
29+
}
30+
async.eachSeries(data, function(item,next){
31+
itemCBs.prep(item,function(item){
32+
itemCBs.ready(item, next);
33+
});
34+
},function(err,results){
35+
if(err) return itemCBs.error(err);
36+
in_memory[cachename] = in_memory[cachename].concat(data);
37+
try{
38+
localStorage.setItem( cachename,JSON.stringify(in_memory[cachename]) );
39+
}catch(e){
40+
return itemCBs.error(e);
41+
}
42+
if(data.length === 0){
43+
itemCBs.done(timestamp);
44+
}else{
45+
itemCBs.done(data[data.length -1].timestamp);
46+
}
47+
});
48+
}).fail(itemCBs.error);
49+
});
50+
}

html/footerjs/commentlist.js

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,44 @@
1-
NodeOsBlog.controller('CommentListCtrl', function ($scope, $http) {
2-
if(!num) return;
3-
$scope.uriPath = "/NodeOS/NodeOS/issues/"+num+"/comments";
4-
$scope.user = user;
5-
$scope.blog = [];
6-
$scope.last = void(0);
7-
$scope.parseMarkdown = parseMarkdown;
81

9-
$scope.loadMore = function(since){
10-
var i=0;
11-
var l=-1;
12-
$scope.user.asAuthority(
13-
'https://api.github.com/repos'+$scope.uriPath+(since?'?since='+since:""),
14-
function(uri){
15-
$http.get(uri).success(function(data,status,headers) {
16-
if(!$scope.last) $scope.last = headers.link?headers.link.split("=").pop():1;
17-
l = data.length;
18-
if(i === l) return; //No more
19-
var iterator = function(item){
20-
$scope.blog.push(item);
21-
$scope.$apply();
22-
i++;
23-
if(i === l){
24-
try{
25-
localStorage.setItem("issue-comments-"+num, JSON.stringify($scope.blog));
26-
}catch(e){
27-
errors.push({name:"LocalStorage", message:"Cannot Store Anymore"});
28-
}
29-
return;
30-
}
31-
$scope.parseMarkdown(data[i],iterator);
32-
};
33-
$scope.parseMarkdown(data[0],iterator);
34-
}).error(function(data, status, headers, config) {
35-
if(status === 403){
2+
var commentHandler;
3+
4+
jQuery(function($){
5+
if(!num) return;
6+
commentHandler = new Template(
7+
"script.template.comments",
8+
"div.container.comments"
9+
);
10+
commentHandler._x = {
11+
uri: "https://api.github.com/repos/NodeOS/NodeOS/issues/"+num+"/comments",
12+
last: void(0)
13+
};
14+
cacheOrUriIterator(
15+
"issue-comments-"+num,
16+
{
17+
timestamp2URI: function(timestamp,next){
18+
var uri = commentHandler._x.uri;
19+
if(timestamp) {
20+
uri += "?since="+(new Date(timestamp+1000)).toISOString();
21+
}
22+
user.asAuthority(uri,next);
23+
},
24+
prep: function(item, next){
25+
item.timestamp = (new Date(item.created_at)).getTime();
26+
parseMarkdown(item,next);
27+
},
28+
ready: function(item,next){
29+
commentHandler.add(item);
30+
setTimeout(next,1);
31+
},
32+
done: function(date){
33+
commentHandler._x.last = date;
34+
},
35+
error: function(error){
36+
if(error.status && error.status === 403){
3637
add403();
3738
}else{
38-
errors.push({name:"Bad issues list request: "+status, message: data.message});
39+
addError(error);
3940
}
40-
});
41-
});
42-
};
43-
var lastdate;
44-
var cached = localStorage.getItem("issue-comments-"+num);
45-
if(cached){
46-
console.log("cached");
47-
cached = JSON.parse(cached);
48-
var i = 0;
49-
var l = cached.length;
50-
var iterator = function(item){
51-
$scope.blog.push(item);
52-
i++;
53-
if(i === l){
54-
var d = new Date(cached[i-1].created_at);
55-
d.setSeconds(d.getSeconds() + 1);
56-
d = d.toISOString();
57-
return $scope.loadMore(d);
5841
}
59-
setTimeout(iterator.bind(void(0),cached[i]),1);
60-
};
61-
iterator(cached[0]);
62-
}else{
63-
$scope.loadMore();
64-
}
42+
}
43+
);
6544
});

0 commit comments

Comments
 (0)