]> git.saurik.com Git - cydia.git/blob - Cydia.app/package.js
1a78a8bbf914cf94db75b0b78cf943a4d614afd7
[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 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 $(function () {
53 var id = package.id;
54 var idc = encodeURIComponent(id);
55 var name = package.name;
56 var icon = 'cydia://package-icon/' + idc;
57 var api = 'http://cydia.saurik.com/api/';
58
59 var regarding = function (type) {
60 return encodeURIComponent("Cydia/APT(" + type + "): " + name);
61 };
62
63 $("#icon").css("background-image", 'url("' + icon + '")');
64 //$("#reflection").src("cydia://package-icon/" + idc);
65
66 $("#name").html(name);
67 space("#latest", package.latest, 96);
68
69 $.xhr(cache(api + 'package/' + idc), 'GET', {}, null, {
70 success: function (value) {
71 value = eval(value);
72
73 if (typeof value.rating == "undefined")
74 $(".rating").remove();
75 else {
76 $("#rating-load").remove();
77 $("#rating-href").href(value.reviews);
78
79 var none = $("#rating-none");
80 var done = $("#rating-done");
81
82 if (value.rating == null) {
83 done.remove();
84 none.css("display", "block");
85 } else {
86 none.remove();
87 done.css("display", "block");
88
89 $("#rating-value").css('width', 16 * value.rating);
90 }
91 }
92
93 if (typeof value.icon != "undefined" && value.icon != null) {
94 var icon = $("#icon");
95 var thumb = $("#thumb");
96
97 icon[0].className = 'flip-180';
98 thumb[0].className = 'flip-360';
99
100 thumb.css("background-image", 'url("' + value.icon + '")');
101
102 setTimeout(function () {
103 icon.css("display", "none");
104 thumb[0].className = 'flip-0';
105 }, 2000);
106 }
107 },
108
109 failure: function (status) {
110 $(".rating").remove();
111 }
112 });
113
114 $("#settings").href("cydia://package-settings/" + idc);
115
116 var mode = package.mode;
117 if (mode == null)
118 $(".mode").remove();
119 else {
120 $("#mode").html(mode);
121 $("#mode-src").src("Modes/" + mode + ".png");
122 }
123
124 var warnings = package.warnings;
125 var length = warnings == null ? 0 : warnings.length;
126 if (length == 0)
127 $(".warnings").remove();
128 else {
129 var parent = $("#warnings");
130 var child = $("#warning");
131 child.remove();
132
133 for (var i = 0; i != length; ++i) {
134 var clone = child.clone(true);
135 parent.append(clone);
136 clone.xpath("./div/label").html($.xml(warnings[i]));
137 }
138 }
139
140 var applications = package.applications;
141 var length = applications == null ? 0 : applications.length;
142
143 var child = $("#application");
144 child.remove();
145
146 /*if (length != 0) {
147 var parent = $("#actions");
148
149 for (var i = 0; i != length; ++i) {
150 var application = applications[i];
151 var clone = child.clone(true);
152 parent.append(clone);
153 clone.href("cydia://launch/" + application[0]);
154 clone.xpath("label").html("Run " + $.xml(application[1]));
155 clone.xpath("img").src(application[2]);
156 }
157 }*/
158
159 var commercial = package.hasTag('cydia::commercial');
160 if (!commercial)
161 $(".commercial").remove();
162
163 var _console = package.hasTag('purpose::console');
164 if (!_console)
165 $(".console").remove();
166
167 var author = package.author;
168 if (author == null)
169 $(".author").remove();
170 else {
171 space("#author", author.name, 160);
172 if (author.address == null)
173 $("#author-icon").remove();
174 else {
175 var support = package.support;
176 if (support == null)
177 $("#author-href").href("mailto:" + author.address + "?subject=" + regarding("A"));
178 else
179 $("#author-href").href(support);
180 }
181 }
182
183 //$("#notice-src").src("http://saurik.cachefly.net/notice/" + idc + ".html");
184
185 /*var store = commercial;
186 if (!store)
187 $(".activation").remove();
188 else {
189 var activation = api + 'activation/' + idc;
190 $("#activation-src").src(activation);
191 }*/
192
193 var depiction = package.depiction;
194 if (depiction == null)
195 $(".depiction").remove();
196 else {
197 $(".description").css("display", "none");
198 $("#depiction-src").src(depiction);
199 }
200
201 var description = package.description;
202 if (description == null)
203 description = package.tagline;
204 else
205 description = description.replace(/\n/g, "<br/>");
206 $("#description").html(description);
207
208 var homepage = package.homepage;
209 if (homepage == null)
210 $(".homepage").remove();
211 else
212 $("#homepage-href").href(homepage);
213
214 var installed = package.installed;
215 if (installed == null)
216 $(".installed").remove();
217 else {
218 $("#installed").html(installed);
219 $("#files-href").href("cydia://files/" + idc);
220 }
221
222 space("#id", id, 220);
223
224 var section = package.section;
225 if (section == null)
226 $(".section").remove();
227 else {
228 $("#section-src").src("cydia://section-icon/" + encodeURIComponent(section));
229 $("#section").html(section);
230 }
231
232 var size = package.size;
233 if (size == 0)
234 $(".size").remove();
235 else
236 $("#size").html(size / 1024 + " kB");
237
238 var maintainer = package.maintainer;
239 if (maintainer == null)
240 $(".maintainer").remove();
241 else {
242 space("#maintainer", maintainer.name, 153);
243 if (maintainer.address == null)
244 $("#maintainer-icon").remove();
245 else
246 $("#maintainer-href").href("mailto:" + maintainer.address + "?subject=" + regarding("M"));
247 }
248
249 var sponsor = package.sponsor;
250 if (sponsor == null)
251 $(".sponsor").remove();
252 else {
253 space("#sponsor", sponsor.name, 152);
254 $("#sponsor-href").href(sponsor.address);
255 }
256
257 var source = package.source;
258 if (source == null) {
259 $(".source").remove();
260 $(".trusted").remove();
261 } else {
262 var host = source.host;
263
264 $("#source-src").src("cydia://source-icon/" + encodeURIComponent(host));
265 $("#source-name").html(source.name);
266
267 if (source.trusted)
268 $("#trusted").href("cydia://package-signature/" + idc);
269 else
270 $(".trusted").remove();
271
272 var description = source.description;
273 if (description == null)
274 $(".source-description").remove();
275 else
276 $("#source-description").html(description);
277 }
278 });