Felix Meschberger | 407b3eb | 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 | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 18 | var licenseButtons = false; |
| 19 | var licenseDetails = false; |
| 20 | |
Felix Meschberger | 895bf00 | 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 | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 34 | function displayBundle(/* String */ bundleIndex) |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 35 | { |
Felix Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 36 | var theBundleData = bundleData[bundleIndex]; |
Felix Meschberger | 407b3eb | 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 | 407b3eb | 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 | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 51 | var firstPage = null; |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 52 | for (var idx in entry) |
| 53 | { |
| 54 | var descr = entry[idx]; |
Felix Meschberger | 1b88617 | 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; |
Valentin Pavlov Valchev | a62b4a4 | 2010-04-15 13:32:59 +0000 | [diff] [blame^] | 62 | if (descr.path.indexOf('http:') == 0 || descr.path.indexOf('ftp:') == 0) link = descr.path; |
Felix Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 63 | |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 64 | buttons += '<a href="' + link + '">' + descr.url + '</a> '; |
Felix Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 65 | |
| 66 | if (!firstPage) |
| 67 | { |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 68 | firstPage = link; |
| 69 | } |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 70 | } |
| 71 | if (buttons) |
| 72 | { |
Felix Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 73 | // apply i18n |
| 74 | name = '__res__' == name ? i18n.resources : i18n.resources_emb.msgFormat( name ); |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 75 | innerHTML += name + ": " + buttons + "<br />"; |
| 76 | } |
| 77 | } |
Felix Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 78 | |
| 79 | licenseButtons.html("<h1>" + title + "</h1>" + innerHTML); |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 82 | if (firstPage) { |
Valentin Pavlov Valchev | a62b4a4 | 2010-04-15 13:32:59 +0000 | [diff] [blame^] | 83 | openLicenseLink(firstPage); |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 84 | } else { |
| 85 | licenseDetails.html(""); |
| 86 | } |
| 87 | |
Felix Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 88 | $("#licenseLeft a").removeClass('ui-state-default ui-corner-all'); |
Felix Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 89 | $("#licenseLeft #" +bundleIndex).addClass('ui-state-default ui-corner-all'); |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 90 | |
| 91 | $('#licenseButtons a').click(function() { |
Valentin Pavlov Valchev | a62b4a4 | 2010-04-15 13:32:59 +0000 | [diff] [blame^] | 92 | openLicenseLink(this.href); |
| 93 | return false; |
Felix Meschberger | cf2b677 | 2010-02-20 18:42:55 +0000 | [diff] [blame] | 94 | }); |
Felix Meschberger | 407b3eb | 2008-06-13 05:28:27 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Valentin Pavlov Valchev | a62b4a4 | 2010-04-15 13:32:59 +0000 | [diff] [blame^] | 97 | function 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 Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 105 | |
| 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 Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 114 | txt += '<a id="' + id + '" href="javascript:displayBundle(\'' + id + '\')">' + bundleData[id].title + '</a>'; |
Felix Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 115 | } |
| 116 | if (txt) { |
| 117 | $("#licenseLeft").html(txt); |
| 118 | } else { |
| 119 | $(".statline").html(i18n.status_none); |
| 120 | } |
| 121 | |
| 122 | // display first element |
Felix Meschberger | 1b88617 | 2010-02-21 15:43:43 +0000 | [diff] [blame] | 123 | displayBundle(0); |
Felix Meschberger | d39ce9a | 2010-02-19 10:09:34 +0000 | [diff] [blame] | 124 | }); |