blob: 8fc2891cfc203f0c2cb7a9fae748d2affe2c39a7 [file] [log] [blame]
Felix Meschberger407b3eb2008-06-13 05:28:27 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +000018var licenseButtons = false;
19var licenseDetails = false;
20
Felix Meschberger895bf002010-02-23 09:26:00 +000021/*
22 * Fuction called after receiving the license data from the server to insert
23 * it into the licenseDetails div
24 * Because IE does not properly support the white-space:pre CSS setting when
25 * DOM-loading data into a <pre> element, the licenseDetails element is a
26 * <div> into which we insert the data surrounded by <pre>-</pre> tags as
27 * innerHtml. This also works in IE.
28 */
29function insertLicenseData( /* String */ data )
30{
31 licenseDetails.html( "<pre>" + data + "</pre>" );
32}
33
Felix Meschberger1b886172010-02-21 15:43:43 +000034function displayBundle(/* String */ bundleIndex)
Felix Meschberger407b3eb2008-06-13 05:28:27 +000035{
Felix Meschberger1b886172010-02-21 15:43:43 +000036 var theBundleData = bundleData[bundleIndex];
Felix Meschberger407b3eb2008-06-13 05:28:27 +000037 if (!theBundleData)
38 {
39 return;
40 }
41
42 var title = theBundleData.title;
43
Felix Meschberger407b3eb2008-06-13 05:28:27 +000044 if (licenseButtons) {
45
46 var innerHTML = "";
47 for (var name in theBundleData.files)
48 {
49 var entry = theBundleData.files[name];
50 var buttons = "";
Felix Meschbergercf2b6772010-02-20 18:42:55 +000051 var firstPage = null;
Felix Meschberger407b3eb2008-06-13 05:28:27 +000052 for (var idx in entry)
53 {
54 var descr = entry[idx];
Felix Meschberger1b886172010-02-21 15:43:43 +000055
56 var link = pluginRoot + "/" + theBundleData.bid;
57 if (descr.jar)
58 {
59 link += descr.jar + "!/"; // inner jar attribute
60 }
61 link += descr.path;
Valentin Pavlov Valcheva62b4a42010-04-15 13:32:59 +000062 if (descr.path.indexOf('http:') == 0 || descr.path.indexOf('ftp:') == 0) link = descr.path;
Felix Meschberger1b886172010-02-21 15:43:43 +000063
Felix Meschbergercf2b6772010-02-20 18:42:55 +000064 buttons += '<a href="' + link + '">' + descr.url + '</a> ';
Felix Meschberger1b886172010-02-21 15:43:43 +000065
66 if (!firstPage)
67 {
Felix Meschbergercf2b6772010-02-20 18:42:55 +000068 firstPage = link;
69 }
Felix Meschberger407b3eb2008-06-13 05:28:27 +000070 }
71 if (buttons)
72 {
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +000073 // apply i18n
74 name = '__res__' == name ? i18n.resources : i18n.resources_emb.msgFormat( name );
Felix Meschberger407b3eb2008-06-13 05:28:27 +000075 innerHTML += name + ": " + buttons + "<br />";
76 }
77 }
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +000078
79 licenseButtons.html("<h1>" + title + "</h1>" + innerHTML);
Felix Meschberger407b3eb2008-06-13 05:28:27 +000080 }
81
Felix Meschbergercf2b6772010-02-20 18:42:55 +000082 if (firstPage) {
Valentin Pavlov Valcheva62b4a42010-04-15 13:32:59 +000083 openLicenseLink(firstPage);
Felix Meschbergercf2b6772010-02-20 18:42:55 +000084 } else {
85 licenseDetails.html("");
86 }
87
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +000088 $("#licenseLeft a").removeClass('ui-state-default ui-corner-all');
Felix Meschberger1b886172010-02-21 15:43:43 +000089 $("#licenseLeft #" +bundleIndex).addClass('ui-state-default ui-corner-all');
Felix Meschbergercf2b6772010-02-20 18:42:55 +000090
91 $('#licenseButtons a').click(function() {
Valentin Pavlov Valcheva62b4a42010-04-15 13:32:59 +000092 openLicenseLink(this.href);
93 return false;
Felix Meschbergercf2b6772010-02-20 18:42:55 +000094 });
Felix Meschberger407b3eb2008-06-13 05:28:27 +000095}
96
Valentin Pavlov Valcheva62b4a42010-04-15 13:32:59 +000097function openLicenseLink(uri) {
98 if (uri.indexOf(window.location.href) == 0 || uri.indexOf(pluginRoot) == 0) { // local URI
99 $.get(uri, insertLicenseData);
100 } else {
101 licenseDetails.html( '<iframe frameborder="0" src="' + uri+ '"></iframe>' );
102 }
103}
104
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +0000105
106$(document).ready(function() {
107 // init elements cache
108 licenseButtons = $("#licenseButtons");
109 licenseDetails = $("#licenseDetails")
110
111 // render list of bundles
112 var txt = "";
113 for(id in bundleData) {
Felix Meschberger1b886172010-02-21 15:43:43 +0000114 txt += '<a id="' + id + '" href="javascript:displayBundle(\'' + id + '\')">' + bundleData[id].title + '</a>';
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +0000115 }
116 if (txt) {
117 $("#licenseLeft").html(txt);
118 } else {
119 $(".statline").html(i18n.status_none);
120 }
121
122 // display first element
Felix Meschberger1b886172010-02-21 15:43:43 +0000123 displayBundle(0);
Felix Meschbergerd39ce9a2010-02-19 10:09:34 +0000124});