]> git.saurik.com Git - cydia.git/blob - Cydia.app/package.js
679d1832c42e00e821d76b3b600a1cbb6ebffd77
[cydia.git] / Cydia.app / package.js
1 /*var package = {
2 "name": "MobileTerminal",
3 "latest": "286u-5",
4 "author": {
5 "name": "Allen Porter",
6 "address": "allen.porter@gmail.com"
7 },
8 //"depiction": "http://planet-iphones.com/repository/info/chromium1.3.php",
9 "depiction": "http://cydia.saurik.com/terminal.html",
10 "description": "this is a sample description",
11 "homepage": "http://cydia.saurik.com/terminal.html",
12 "installed": "286u-4",
13 "id": "mobileterminal",
14 "section": "Terminal Support",
15 "size": 552*1024,
16 "maintainer": {
17 "name": "Jay Freeman",
18 "address": "saurik@saurik.com"
19 },
20 "source": {
21 "name": "Telesphoreo Tangelo",
22 "description": "Distribution of Unix Software for the iPhone"
23 }
24 };*/
25
26 function space(selector, html, max) {
27 var node = $(selector);
28 node.html(html);
29 var width = node.width();
30 if (width > max) {
31 var spacing = (max - node.width()) / (html.length - 1) + "px";
32 console.log(width + " " + max + " " + spacing);
33 node.css("letter-spacing", spacing);
34 }
35 }
36
37 var rated = 0;
38
39 var rating = function () {
40 var rating = package.rating;
41 if (rating == null)
42 $(".rating").remove();
43 else {
44 rating = 'fail.html';
45 $.xhr('_' + rating, 'GET', {}, null, {
46 success: function (value) {
47 document.getElementById("rating").contentWindow.document.write(value);
48 },
49
50 failure: function (status) {
51 $(".rating").remove();
52 }
53 });
54 }
55 };
56
57 var rating_ = function() {
58 if (rated == 0)
59 rated = 1;
60 else if (rated == 1) {
61 rating();
62 rated = -1;
63 }
64 };
65
66 $(function () {
67 var id = package.id;
68 var idc = encodeURIComponent(id);
69 var name = package.name;
70 var regarding = encodeURIComponent("Cydia/APT: " + name);
71
72 $("#icon").src("cydia://package-icon/" + idc);
73 $("#reflection").src("cydia://package-icon/" + idc);
74
75 $("#name").html(name);
76 space("#latest", package.latest, 93);
77
78 rating_();
79
80 $("#settings").href("cydia://package-settings/" + idc);
81
82 var warnings = package.warnings;
83 var length = warnings == null ? 0 : warnings.length;
84 if (length == 0)
85 $(".warnings").remove();
86 else {
87 var parent = $("#warnings");
88 var child = $("#warning");
89 child.remove();
90
91 for (var i = 0; i != length; ++i) {
92 var clone = child.clone(true);
93 parent.append(clone);
94 clone.xpath("./div/label").html($.xml(warnings[i]));
95 }
96 }
97
98 var applications = package.applications;
99 var length = applications == null ? 0 : applications.length;
100
101 var child = $("#application");
102 child.remove();
103
104 /*if (length != 0) {
105 var parent = $("#actions");
106
107 for (var i = 0; i != length; ++i) {
108 var application = applications[i];
109 var clone = child.clone(true);
110 parent.append(clone);
111 clone.href("cydia://launch/" + application[0]);
112 clone.xpath("label").html("Run " + $.xml(application[1]));
113 clone.xpath("img").src(application[2]);
114 }
115 }*/
116
117 var purposes = package.purposes;
118 var commercial = false;
119 var _console = false;
120 if (purposes != null)
121 for (var i = 0, e = purposes.length; i != e; ++i) {
122 var purpose = purposes[i];
123 if (purpose == "commercial")
124 commercial = true;
125 else if (purpose == "console")
126 _console = true;
127 }
128 if (!commercial)
129 $(".commercial").remove();
130 if (!_console)
131 $(".console").remove();
132
133 var author = package.author;
134 if (author == null)
135 $(".author").remove();
136 else {
137 space("#author", author.name, 160);
138 if (author.address == null)
139 $("#author-icon").remove();
140 else
141 $("#author-href").href("mailto:" + author.address + "?subject=" + regarding);
142 }
143
144 //$("#notice-src").src("http://saurik.cachefly.net/notice/" + idc + ".html");
145
146 var depiction = package.depiction;
147 if (depiction == null)
148 $(".depiction").remove();
149 else {
150 $(".description").display("none");
151 $("#depiction-src").src(depiction);
152 }
153
154 var description = package.description;
155 if (description == null)
156 description = package.tagline;
157 else
158 description = description.replace(/\n/g, "<br/>");
159 $("#description").html(description);
160
161 var homepage = package.homepage;
162 if (homepage == null)
163 $(".homepage").remove();
164 else
165 $("#homepage-href").href(homepage);
166
167 var installed = package.installed;
168 if (installed == null)
169 $(".installed").remove();
170 else {
171 $("#installed").html(installed);
172 $("#files-href").href("cydia://files/" + idc);
173 }
174
175 space("#id", id, 220);
176
177 var section = package.section;
178 if (section == null)
179 $(".section").remove();
180 else {
181 $("#section-src").src("cydia://section-icon/" + encodeURIComponent(section));
182 $("#section").html(section);
183 }
184
185 var size = package.size;
186 if (size == 0)
187 $(".size").remove();
188 else
189 $("#size").html(size / 1024 + " kB");
190
191 var maintainer = package.maintainer;
192 if (maintainer == null)
193 $(".maintainer").remove();
194 else {
195 space("#maintainer", maintainer.name, 153);
196 if (maintainer.address == null)
197 $("#maintainer-icon").remove();
198 else
199 $("#maintainer-href").href("mailto:" + maintainer.address + "?subject=" + regarding);
200 }
201
202 var sponsor = package.sponsor;
203 if (sponsor == null)
204 $(".sponsor").remove();
205 else {
206 space("#sponsor", sponsor.name, 152);
207 $("#sponsor-href").href(sponsor.address);
208 }
209
210 var source = package.source;
211 if (source == null) {
212 $(".source").remove();
213 $(".trusted").remove();
214 } else {
215 var host = source.host;
216
217 $("#source-src").src("cydia://source-icon/" + encodeURIComponent(host));
218 $("#source-name").html(source.name);
219
220 if (source.trusted)
221 $("#trusted").href("cydia://package-signature/" + idc);
222 else
223 $(".trusted").remove();
224
225 var description = source.description;
226 if (description == null)
227 $(".source-description").remove();
228 else
229 $("#source-description").html(description);
230 }
231 });