Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 1 | /* |
| 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 Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 18 | var licenseButtons = false; |
| 19 | var licenseDetails = false; |
| 20 | |
Felix Meschberger | 7b9f751 | 2010-02-23 09:26:00 +0000 | [diff] [blame] | 21 | /* |
| 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 | */ |
| 29 | function insertLicenseData( /* String */ data ) |
| 30 | { |
| 31 | licenseDetails.html( "<pre>" + data + "</pre>" ); |
| 32 | } |
| 33 | |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 34 | function displayBundle(/* String */ bundleIndex) |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 35 | { |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 36 | var theBundleData = bundleData[bundleIndex]; |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 37 | if (!theBundleData) |
| 38 | { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | var title = theBundleData.title; |
| 43 | |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 44 | if (licenseButtons) { |
| 45 | |
| 46 | var innerHTML = ""; |
| 47 | for (var name in theBundleData.files) |
| 48 | { |
| 49 | var entry = theBundleData.files[name]; |
| 50 | var buttons = ""; |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 51 | var firstPage = null; |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 52 | for (var idx in entry) |
| 53 | { |
| 54 | var descr = entry[idx]; |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 55 | |
| 56 | var link = pluginRoot + "/" + theBundleData.bid; |
| 57 | if (descr.jar) |
| 58 | { |
| 59 | link += descr.jar + "!/"; // inner jar attribute |
| 60 | } |
| 61 | link += descr.path; |
| 62 | |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 63 | buttons += '<a href="' + link + '">' + descr.url + '</a> '; |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 64 | |
| 65 | if (!firstPage) |
| 66 | { |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 67 | firstPage = link; |
| 68 | } |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 69 | } |
| 70 | if (buttons) |
| 71 | { |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 72 | // apply i18n |
| 73 | name = '__res__' == name ? i18n.resources : i18n.resources_emb.msgFormat( name ); |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 74 | innerHTML += name + ": " + buttons + "<br />"; |
| 75 | } |
| 76 | } |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 77 | |
| 78 | licenseButtons.html("<h1>" + title + "</h1>" + innerHTML); |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 81 | if (firstPage) { |
Felix Meschberger | 7b9f751 | 2010-02-23 09:26:00 +0000 | [diff] [blame] | 82 | $.get(firstPage, insertLicenseData); |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 83 | } else { |
| 84 | licenseDetails.html(""); |
| 85 | } |
| 86 | |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 87 | $("#licenseLeft a").removeClass('ui-state-default ui-corner-all'); |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 88 | $("#licenseLeft #" +bundleIndex).addClass('ui-state-default ui-corner-all'); |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 89 | |
| 90 | $('#licenseButtons a').click(function() { |
Felix Meschberger | 7b9f751 | 2010-02-23 09:26:00 +0000 | [diff] [blame] | 91 | $.get(this.href, insertLicenseData); |
Felix Meschberger | 9efe9ae | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 92 | return false; |
| 93 | }); |
Felix Meschberger | ab2b4f0 | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 96 | |
| 97 | $(document).ready(function() { |
| 98 | // init elements cache |
| 99 | licenseButtons = $("#licenseButtons"); |
| 100 | licenseDetails = $("#licenseDetails") |
| 101 | |
| 102 | // render list of bundles |
| 103 | var txt = ""; |
| 104 | for(id in bundleData) { |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 105 | txt += '<a id="' + id + '" href="javascript:displayBundle(\'' + id + '\')">' + bundleData[id].title + '</a>'; |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 106 | } |
| 107 | if (txt) { |
| 108 | $("#licenseLeft").html(txt); |
| 109 | } else { |
| 110 | $(".statline").html(i18n.status_none); |
| 111 | } |
| 112 | |
| 113 | // display first element |
Felix Meschberger | 321618f | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 114 | displayBundle(0); |
Felix Meschberger | d219cc7 | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 115 | }); |