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