forked from hminaya/DevDomWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.htm
executable file
·147 lines (119 loc) · 4.88 KB
/
test.htm
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<html>
<head>
<script type="text/javascript">
<!--
/**
* http://code.google.com/apis/gdata/samples/spreadsheet_sample.html
* Lists the entries from the specified JSON feed
* by creating a new 'dl' element in the DOM.
* Each 'dt' is the title of the row, and each 'dd'
* is the content of the row.
*/
function listEntries(json) {
removeOldResults();
var dl = document.createElement('dl');
dl.setAttribute('id', 'output');
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
var dt = document.createElement('dt');
var title = document.createTextNode(entry.title.$t);
dt.appendChild(title);
var dd = document.createElement('dd');
var content = document.createTextNode(entry.content.$t);
dd.appendChild(content);
dl.appendChild(dt);
dl.appendChild(dd);
}
document.getElementById('data').appendChild(dl);
}
/**
* Lists the entries from the specified JSON feed
* by inserting the cells into a new 'table'
* element in the DOM. Each 'tr' represents a
* row in the spreadsheet, and each 'td' is a cell
* within that row.
*/
function cellEntries(json) {
removeOldResults();
var table = document.createElement('table');
table.setAttribute('id', 'output');
var tbody = document.createElement('tbody');
var tr;
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
var columna = entry.gs$cell.col;
if ((columna == 2) || (columna == 3) || (columna == 6) || (columna == 7)) {
if (entry.gs$cell.col == '2') {
if (tr != null) {
tbody.appendChild(tr);
}
tr = document.createElement('tr');
}
var td = document.createElement('td');
td.appendChild(document.createTextNode(entry.content.$t));
tr.appendChild(td);
}
}
tbody.appendChild(tr);
table.appendChild(tbody);
document.getElementById('data').appendChild(table);
}
/**
* Called when the user clicks the 'OK' button to
* retrieve a spreadsheet's JSON feed. Creates a new
* script element in the DOM whose source is the JSON feed,
* and specifies that the callback function is
* 'listEntries' for a list feed and 'cellEntries' for a
* cells feed (above).
*/
function displayResults() {
removeOldJSONScriptNodes();
removeOldResults();
// Show a "Loading..." indicator.
var div = document.getElementById('data');
var p = document.createElement('p');
p.appendChild(document.createTextNode('Loading...'));
div.appendChild(p);
// Retrieve the JSON feed.
var script = document.createElement('script');
script.setAttribute('src', 'http://spreadsheets.google.com/feeds/cells'
+ '/' + '0Amb0BYy0MWESdHd6Uy04QVR1bnJYWkxqcV9xNE5TaGc'
+ '/' + 'oD6' + '/public/values' +
'?alt=json-in-script&callback=cellEntries');
script.setAttribute('id', 'jsonScript');
script.setAttribute('type', 'text/javascript');
document.documentElement.firstChild.appendChild(script); ;
}
/**
* Removes the script element from the previous result.
*/
function removeOldJSONScriptNodes() {
var jsonScript = document.getElementById('jsonScript');
if (jsonScript) {
jsonScript.parentNode.removeChild(jsonScript);
}
}
/**
* Removes the output generated from the previous result.
*/
function removeOldResults() {
var div = document.getElementById('data');
if (div.firstChild) {
div.removeChild(div.firstChild);
}
}
//-->
</script>
<link rel="stylesheet" type="text/css" href="http://code.google.com/css/dev_docs.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
$(function (data) {
displayResults();
});
</script>
</head>
<body>
<div id="data">
</div>
</body>
</html>