]> git.saurik.com Git - cydia.git/blob - Cydia.app/package.js
ForRelease, !ForSaurik
[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 "longDescription": "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 node.css("letter-spacing", spacing);
33 }
34 }
35
36 function cache(url) {
37 return url.replace('://', '://ne.edgecastcdn.net/8003A4/');
38 }
39
40 var swap_, swap = function (on, off, time) {
41 setTimeout(swap_(on, off, time), time);
42 };
43
44 swap_ = function (on, off, time) {
45 return function () {
46 on.className = 'fade-out';
47 off.className = 'fade-in';
48 swap(off, on, time);
49 };
50 };
51
52 var special_ = function () {
53 if (package == null)
54 return;
55
56 var id = package.id;
57 var idc = encodeURIComponent(id);
58 var name = package.name;
59 var icon = 'cydia://package-icon/' + idc;
60 var api = 'http://cydia.saurik.com/api/';
61
62 var support = package.support;
63
64 var regarding = function (type) {
65 return encodeURIComponent("Cydia/APT(" + type + "): " + name);
66 };
67
68 $("#icon").css("background-image", 'url("' + icon + '")');
69 //$("#reflection").src("cydia://package-icon/" + idc);
70
71 $("#name").html(name);
72 space("#latest", package.latest, 96);
73
74 $.xhr(cache(api + 'package/' + idc), 'GET', {}, null, {
75 success: function (value) {
76 value = eval(value);
77
78 if (typeof value.notice == "undefined")
79 $(".notice").addClass("deleted");
80 else
81 $("#notice-src").src(value.notice);
82
83 if (typeof value.rating == "undefined")
84 $(".rating").addClass("deleted");
85 else {
86 $("#rating-load").addClass("deleted");
87 $("#rating-href").href(value.reviews);
88
89 var none = $("#rating-none");
90 var done = $("#rating-done");
91
92 if (value.rating == null) {
93 none.css("display", "block");
94 } else {
95 done.css("display", "block");
96
97 $("#rating-value").css('width', 16 * value.rating);
98 }
99 }
100
101 if (typeof value.icon != "undefined" && value.icon != null) {
102 var icon = $("#icon");
103 var thumb = $("#thumb");
104
105 icon[0].className = 'flip-180';
106 thumb[0].className = 'flip-360';
107
108 thumb.css("background-image", 'url("' + value.icon + '")');
109
110 setTimeout(function () {
111 icon.addClass("deleted");
112 thumb[0].className = 'flip-0';
113 }, 2000);
114 }
115 },
116
117 failure: function (status) {
118 $(".rating").addClass("deleted");
119 }
120 });
121
122 $("#settings").href("cydia://package-settings/" + idc);
123
124 var mode = package.mode;
125 if (mode == null)
126 $(".mode").addClass("deleted");
127 else {
128 $("#mode").html(cydia.localize(mode));
129 $("#mode-src").src("Modes/" + mode + ".png");
130 }
131
132 var warnings = package.warnings;
133 var length = warnings == null ? 0 : warnings.length;
134 if (length == 0)
135 $(".warnings").addClass("deleted");
136 else {
137 var parent = $("#warnings");
138 var child = $("#warning");
139
140 for (var i = 0; i != length; ++i) {
141 var clone = child.clone(true);
142 clone.addClass("inserted");
143 parent.append(clone);
144 clone.xpath("./div/label").html($.xml(warnings[i]));
145 }
146
147 child.addClass("deleted");
148 }
149
150 var applications = package.applications;
151 var length = applications == null ? 0 : applications.length;
152
153 var child = $("#application");
154
155 /*if (length != 0) {
156 var parent = $("#actions");
157
158 for (var i = 0; i != length; ++i) {
159 var application = applications[i];
160 var clone = child.clone(true);
161 parent.append(clone);
162 clone.href("cydia://launch/" + application[0]);
163 clone.xpath("label").html("Run " + $.xml(application[1]));
164 clone.xpath("img").src(application[2]);
165 }
166 }*/
167
168 child.addClass("deleted");
169
170 var commercial = package.hasTag('cydia::commercial');
171 if (!commercial)
172 $(".commercial").addClass("deleted");
173
174 var _console = package.hasTag('purpose::console');
175 if (!_console)
176 $(".console").addClass("deleted");
177
178 var author = package.author;
179 if (author == null)
180 $(".author").addClass("deleted");
181 else {
182 space("#author", author.name, 160);
183 if (author.address == null)
184 $("#author-icon").addClass("deleted");
185 else if (support == null)
186 $("#author-href").href("mailto:" + author.address + "?subject=" + regarding("A"));
187 else
188 $("#author-href").href(support);
189 }
190
191 /*var store = commercial;
192 if (!store)
193 $(".activation").addClass("deleted");
194 else {
195 var activation = api + 'activation/' + idc;
196 $("#activation-src").src(activation);
197 }*/
198
199 var depiction = package.depiction;
200 if (depiction == null)
201 $(".depiction").addClass("deleted");
202 else {
203 $(".description").addClass("deleted");
204 $("#depiction-src").src(depiction);
205 }
206
207 var description = package.longDescription;
208 if (description == null)
209 description = package.shortDescription;
210 else
211 description = description.replace(/\n/g, "<br/>");
212 $("#description").html(description);
213
214 var homepage = package.homepage;
215 if (homepage == null)
216 $(".homepage").addClass("deleted");
217 else
218 $("#homepage-href").href(homepage);
219
220 var installed = package.installed;
221 if (installed == null)
222 $(".installed").addClass("deleted");
223 else {
224 $("#installed").html(installed);
225 $("#files-href").href("cydia://files/" + idc);
226 }
227
228 space("#id", id, 220);
229
230 var section = package.longSection;
231 if (section == null)
232 $(".section").addClass("deleted");
233 else {
234 $("#section-src").src("cydia://section-icon/" + encodeURIComponent(section));
235 $("#section").html(section);
236 }
237
238 var size = package.size;
239 if (size == 0)
240 $(".size").addClass("deleted");
241 else
242 $("#size").html(size / 1024 + " kB");
243
244 var maintainer = package.maintainer;
245 if (maintainer == null)
246 $(".maintainer").addClass("deleted");
247 else {
248 space("#maintainer", maintainer.name, 153);
249 if (maintainer.address == null)
250 $("#maintainer-icon").addClass("deleted");
251 else if (support == null)
252 $("#maintainer-href").href("mailto:" + maintainer.address + "?subject=" + regarding("M"));
253 else
254 $("#maintainer-href").href(support);
255 }
256
257 var sponsor = package.sponsor;
258 if (sponsor == null)
259 $(".sponsor").addClass("deleted");
260 else {
261 space("#sponsor", sponsor.name, 152);
262 $("#sponsor-href").href(sponsor.address);
263 }
264
265 var source = package.source;
266 if (source == null) {
267 $(".source").addClass("deleted");
268 $(".trusted").addClass("deleted");
269 } else {
270 var host = source.host;
271
272 $("#source-src").src("cydia://source-icon/" + encodeURIComponent(host));
273 $("#source-name").html(source.name);
274
275 if (source.trusted)
276 $("#trusted").href("cydia://package-signature/" + idc);
277 else
278 $(".trusted").addClass("deleted");
279
280 var description = source.description;
281 if (description == null)
282 $(".source-description").addClass("deleted");
283 else
284 $("#source-description").html(description);
285 }
286 };
287
288 $(special_);
289
290 var special = function () {
291 $(".deleted").removeClass("deleted");
292 $(".inserted").remove();
293
294 $("#icon")[0].className = 'flip-0';
295 $("#thumb")[0].className = 'flip-180';
296
297 /* XXX: this could be better */
298 $("#rating-href").href(null);
299 $("#rating-none").css("display", "none");
300 $("#rating-done").css("display", "none");
301
302 var notice = $("#notice-src");
303
304 notice[0].outerHTML = '<iframe' +
305 ' class="notice"' +
306 ' id="notice-src"' +
307 ' frameborder="0"' +
308 ' width="320"' +
309 ' height="0"' +
310 ' target="_top"' +
311 '></iframe>';
312
313 var depiction = $("#depiction-src");
314
315 depiction[0].outerHTML = '<iframe' +
316 ' class="depiction"' +
317 ' id="depiction-src"' +
318 ' frameborder="0"' +
319 ' width="320"' +
320 ' height="0"' +
321 ' target="_top"' +
322 ' onload_="loaded()"' +
323 '></iframe>';
324
325 special_();
326 };
327
328 cydia.setSpecial(special);