]> git.saurik.com Git - cydia.git/blob - Cydia.app/package.js
Fixed spacing issues.
[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 console.log(width + " " + max + " " + spacing);
33 node.css("letter-spacing", spacing);
34 }
35 }
36
37 $(function () {
38 var id = package.id;
39 var idc = encodeURIComponent(id);
40 var name = package.name;
41 var regarding = encodeURIComponent("Cydia/APT: " + name);
42
43 $("#icon").src("cydia://package-icon/" + idc);
44 $("#reflection").src("cydia://package-icon/" + idc);
45
46 $("#name").html(name);
47 space("#latest", package.latest, 93);
48
49 var rating = package.rating;
50 if (rating == null)
51 $(".rating").remove();
52 else {
53 $.xhr(rating, 'GET', {}, null, {
54 success: function (value) {
55 document.getElementById("rating").contentWindow.document.write(value);
56 }
57 });
58 }
59
60 $("#settings").href("cydia://package-settings/" + idc);
61
62 var warnings = package.warnings;
63 var length = warnings == null ? 0 : warnings.length;
64 if (length == 0)
65 $(".warnings").remove();
66 else {
67 var parent = $("#warnings");
68 var child = $("#warning");
69 child.remove();
70
71 for (var i = 0; i != length; ++i) {
72 var clone = child.clone(true);
73 parent.append(clone);
74 clone.xpath("label").html($.xml(warnings[i]));
75 }
76 }
77
78 var applications = package.applications;
79 var length = applications == null ? 0 : applications.length;
80
81 var child = $("#application");
82 child.remove();
83
84 /*if (length != 0) {
85 var parent = $("#actions");
86
87 for (var i = 0; i != length; ++i) {
88 var application = applications[i];
89 var clone = child.clone(true);
90 parent.append(clone);
91 clone.href("cydia://launch/" + application[0]);
92 clone.xpath("label").html("Run " + $.xml(application[1]));
93 clone.xpath("img").src(application[2]);
94 }
95 }*/
96
97 var purposes = package.purposes;
98 var commercial = false;
99 var _console = false;
100 if (purposes != null)
101 for (var i = 0, e = purposes.length; i != e; ++i) {
102 var purpose = purposes[i];
103 if (purpose == "commercial")
104 commercial = true;
105 else if (purpose == "console")
106 _console = true;
107 }
108 if (!commercial)
109 $(".commercial").remove();
110 if (!_console)
111 $(".console").remove();
112
113 var author = package.author;
114 if (author == null)
115 $(".author").remove();
116 else {
117 space("#author", author.name, 160);
118 if (author.address == null)
119 $("#author-icon").remove();
120 else
121 $("#author-href").href("mailto:" + author.address + "?subject=" + regarding);
122 }
123
124 //$("#notice-src").src("http://saurik.cachefly.net/notice/" + idc + ".html");
125
126 var depiction = package.depiction;
127 if (depiction == null)
128 $(".depiction").remove();
129 else {
130 $(".description").display("none");
131 $("#depiction-src").src(depiction);
132 }
133
134 var description = package.description;
135 if (description == null)
136 description = package.tagline;
137 else
138 description = description.replace(/\n/g, "<br/>");
139 $("#description").html(description);
140
141 var homepage = package.homepage;
142 if (homepage == null)
143 $(".homepage").remove();
144 else
145 $("#homepage-href").href(homepage);
146
147 var installed = package.installed;
148 if (installed == null)
149 $(".installed").remove();
150 else {
151 $("#installed").html(installed);
152 $("#files-href").href("cydia://files/" + idc);
153 }
154
155 space("#id", id, 238);
156
157 var section = package.section;
158 if (section == null)
159 $(".section").remove();
160 else {
161 $("#section-src").src("cydia://section-icon/" + encodeURIComponent(section));
162 $("#section").html(section);
163 }
164
165 var size = package.size;
166 if (size == 0)
167 $(".size").remove();
168 else
169 $("#size").html(size / 1024 + " kB");
170
171 var maintainer = package.maintainer;
172 if (maintainer == null)
173 $(".maintainer").remove();
174 else {
175 space("#maintainer", maintainer.name, 153);
176 if (maintainer.address == null)
177 $("#maintainer-icon").remove();
178 else
179 $("#maintainer-href").href("mailto:" + maintainer.address + "?subject=" + regarding);
180 }
181
182 var sponsor = package.sponsor;
183 if (sponsor == null)
184 $(".sponsor").remove();
185 else {
186 space("#sponsor", sponsor.name, 152);
187 $("#sponsor-href").href(sponsor.address);
188 }
189
190 var source = package.source;
191 if (source == null) {
192 $(".source").remove();
193 $(".trusted").remove();
194 } else {
195 var host = source.host;
196
197 $("#source-src").src("cydia://source-icon/" + encodeURIComponent(host));
198 $("#source-name").html(source.name);
199
200 if (source.trusted)
201 $("#trusted").href("cydia://package-signature/" + idc);
202 else
203 $(".trusted").remove();
204
205 var description = source.description;
206 if (description == null)
207 $(".source-description").remove();
208 else
209 $("#source-description").html(description);
210 }
211 });