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