-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyscript.js
113 lines (87 loc) · 4.61 KB
/
myscript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
var imported = document.createElement('script');
imported.src = 'http://np-ec2-nytimes-com.s3.amazonaws.com/dev/test/nyregion.js';
document.head.appendChild(imported);
var NYTD = {
data : {},
render_section_front : function (params){
this.data = params;
this.parseData();
},
parseData : function(){
//container for all
var storyHolder = document.getElementById("storyBits");
//accessing the first batch of content
for(var i=0;i<this.data.page.content[1].collections.length; i++){
var cl1 = this.data.page.content[1].collections[i].assets;
//loop through the first section of content
for (var k=0; k<cl1.length; k++){
var header = document.createElement("div");
var summary = document.createElement("div");
var byline = document.createElement("div");
var aTag = document.createElement("a");
header.className = "header";
summary.className ="summary";
byline.className = "byline";
aTag.setAttribute("href", cl1[k].url);
//place all elements in a var to add to the document fragment
var divs = [header, byline, summary];
var docFrag = document.createDocumentFragment();
//check to see if the data is unusable
if (cl1[k].headline == "Only rank in summary collections" ){
header.innerHTML = ""; byline.innerHTML = ""; summary.innerHTML = "";
}else if (cl1[k].headline == undefined){
header.innerHTML = ""; byline.innerHTML = ""; summary.innerHTML = "";
}
//load up the retrieved data
else {
aTag.innerHTML = cl1[k].headline;
header.appendChild(aTag);
byline.innerHTML = cl1[k].byline;
summary.innerHTML = cl1[k].summary;
for(var l = 0; l < divs.length; l++) {
docFrag.appendChild(divs[l]);
storyHolder.appendChild(docFrag );
}
}
}
}
//accessing the second batch of content
for(var j=0;j<this.data.page.content[2].collections.length; j++){
var cl2 = this.data.page.content[2].collections[j].assets;
//loop through the first section of content
for (var m=0; m<cl2.length; m++){
var header = document.createElement("div");
var summary = document.createElement("div");
var byline = document.createElement("div");
var aTag = document.createElement('a');
header.className = "header";
summary.className ="summary";
byline.className = "byline";
aTag.setAttribute("href", cl2[m].url);
//place all elements in a var to add to the document fragment
var divs = [header, byline, summary];
//check to see if the data is unusable
var docFrag = document.createDocumentFragment();
if (cl2[m].headline == "Only rank in summary collections"){
header.innerHTML = ""; byline.innerHTML = ""; summary.innerHTML = "";
}else if (cl2[m].headline == undefined){
header.innerHTML = ""; byline.innerHTML = ""; summary.innerHTML = "";
}
else if (cl2[m].byline == undefined){
byline.innerHTML = "";
}
//load up the retrieved data
else{
aTag.innerHTML = cl2[m].headline;
header.appendChild(aTag);
byline.innerHTML = cl2[m].byline;
summary.innerHTML = cl2[m].summary;
for(var l = 0; l < divs.length; l++) {
docFrag.appendChild(divs[l]);
storyHolder.appendChild(docFrag );
}
}
}
}
}
}