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