diff options
author | cnuessgens <christian@nuessgens.com> | 2018-03-22 17:48:58 +0100 |
---|---|---|
committer | cnuessgens <christian@nuessgens.com> | 2018-03-22 17:48:58 +0100 |
commit | 06da0854e93df222603fcc2e51c9594c16899087 (patch) | |
tree | 66fb28a407cf3322801f241cc419767a25417e03 /website/resources | |
parent | 1b6de01bf187def687cb0e757da4295b0790f0ac (diff) | |
parent | 5a5d75a931e66b03212081e35bdfdc7b6be98783 (diff) | |
download | lombok-06da0854e93df222603fcc2e51c9594c16899087.tar.gz lombok-06da0854e93df222603fcc2e51c9594c16899087.tar.bz2 lombok-06da0854e93df222603fcc2e51c9594c16899087.zip |
Merge remote-tracking branch 'remotes/upstream/master'
Diffstat (limited to 'website/resources')
-rw-r--r-- | website/resources/W8BEN_lombok.pdf | bin | 0 -> 60743 bytes | |||
-rw-r--r-- | website/resources/css/custom.css | 100 | ||||
-rw-r--r-- | website/resources/files/supporters.json | 13 | ||||
-rw-r--r-- | website/resources/img/spinner.gif | bin | 0 -> 828 bytes | |||
-rw-r--r-- | website/resources/js/main.js | 2 | ||||
-rw-r--r-- | website/resources/js/order-license.js | 231 | ||||
-rw-r--r-- | website/resources/js/supporters.js | 221 |
7 files changed, 561 insertions, 6 deletions
diff --git a/website/resources/W8BEN_lombok.pdf b/website/resources/W8BEN_lombok.pdf Binary files differnew file mode 100644 index 00000000..b87bded8 --- /dev/null +++ b/website/resources/W8BEN_lombok.pdf diff --git a/website/resources/css/custom.css b/website/resources/css/custom.css index 795b155c..f81a3dd9 100644 --- a/website/resources/css/custom.css +++ b/website/resources/css/custom.css @@ -7,6 +7,101 @@ margin-bottom: 40px; } +.buttonLike { + cursor: pointer; + background: -webkit-linear-gradient(top, #FFFEF7, #CFCEC7); + background: -moz-linear-gradient(top, #FFFEF7, #CFCEC7); + background: -o-linear-gradient(#FFFEF7, #CFCEC7); + background: -ms-linear-gradient(#FFFEF7, #CFCEC7); + background: linear-gradient(top, #FFFEF7, #CFCEC7); + line-height: 1; + padding: 3px 10px; + border: 1px solid black; + position: relative; + overflow: visible; + color: black; + margin: 2px; + border-radius: 5px; + display: inline-block; + text-align: center; +} + +.orderButton { + width: 280px; +} + +.orderDetails { + font-style: italic; + font-size: 10px; + margin-top: 20px; +} + +.formErr { + color: #FF7777; +} + +.order-license #deleteCompanyLogo { + margin-top: 12px; +} + +.formSubmitFail { + color: #FF6666; + font-size: 1.2em; + font-style: italic; +} + +.order-license .btn-primary { + float: left; + margin-right: 20px; + background: -webkit-linear-gradient(#1725e0, #0923df 6%, #0b21ce); + background: -o-linear-gradient(#1725e0, #0923df 6%, #0b21ce); + background: -webkit-gradient(linear, left top, left bottom, from(#1725e0), color-stop(6%, #0923df), to(#0b21ce)); + background: linear-gradient(#1725e0, #0923df 6%, #0b21ce); + background-repeat: no-repeat; + filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff1725e0', endColorstr='#ff0b21ce', GradientType=0); + -webkit-filter: none; + filter: none; + border: 1px solid #091bac; +} + +#onlyYearlyWarning { + font-size: 0.8em; + padding-left: 16px; +} + +.deemphasize { + color: #AAAAAA; + font-size: 0.8em; + font-style: italic; +} + +.supporterBar .introText { + margin-top: 16px; +} + +.barItem { + margin: 16px; + max-width: 168px; +} + +.barItem img { + width: 100%; +} + +.supportItem, .barItem { + display: inline-block; +} + +.supporters .supportItem { + margin: 6px 10px; +} + +.supporterBar { + width: 100%; + margin-left: auto; + margin-right: auto; +} + .errorBox { border: 1px dashed #F44; font-size: 1.2em; @@ -30,11 +125,6 @@ height: 16px; } -.legalese { - font-style: italic; - font-size: 0.8em; -} - #companyLogo { margin-right: 8px; } diff --git a/website/resources/files/supporters.json b/website/resources/files/supporters.json new file mode 100644 index 00000000..a895f95b --- /dev/null +++ b/website/resources/files/supporters.json @@ -0,0 +1,13 @@ +{ + "modWeight": { + "professional": 2.0, + "enterprise": 4.0, + "patron": 1.0 + }, + "professional": [ + ], + "enterprise": [ + ], + "patron": [ + ] +} diff --git a/website/resources/img/spinner.gif b/website/resources/img/spinner.gif Binary files differnew file mode 100644 index 00000000..f627b993 --- /dev/null +++ b/website/resources/img/spinner.gif diff --git a/website/resources/js/main.js b/website/resources/js/main.js index 3ad77958..f07da70d 100644 --- a/website/resources/js/main.js +++ b/website/resources/js/main.js @@ -37,7 +37,7 @@ if (self.data("clc")) return; var href = self.attr("href"); self.data("clc", true); - if (!href || href.substr(0, 4) === "http" || href === "/api/") return; + if (!href || href.substr(0, 4) === "http" || href === "/api/" || href === "/" || href === "/supporters" || href === "/order-license") return; var ext = href.substr(href.length - 4, 4); if (ext === ".xml" || ext === ".jar") return; self.on("click", function(evt) { diff --git a/website/resources/js/order-license.js b/website/resources/js/order-license.js new file mode 100644 index 00000000..b2842456 --- /dev/null +++ b/website/resources/js/order-license.js @@ -0,0 +1,231 @@ +"use strict"; + +(function() { + if (!String.prototype.trim) { + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; + } + + var imgDataUrl = null; + + function updateLocationInfo() { + var locationType = $("input:radio[name='locationType']:checked").val(); + $("#locationType_usa").toggle(locationType === "usa"); + $("#locationType_eu").toggle(locationType === "eu"); + $("#locationType_other").toggle(locationType === "other"); + $("#paymentMethod_iban").toggle(locationType === "eu"); + if ($("#paymentMethod_iban input").is(":checked") && locationType !== "eu") $("#paymentMethod_payoneer input").prop("checked", true); + if ($("#paymentMethod_intl input").is(":checked") && locationType === "eu") $("#paymentMethod_iban input").prop("checked", true); + $("#paymentMethod_intl").toggle(locationType !== "eu"); + } + + function updatePriceIndication() { + $("#onlyYearlyWarning").hide(); + var x = getPriceIndication(); + if (x === "") { + $("#costIndicator").text("").hide(); + } else { + $("#costIndicator").text(x).show(); + } + } + + function getPriceIndication() { + try { + var seats = parseInt($("#seats").val()); + if (isNaN(seats) || seats < 1) return ""; + var licenseType = $("input:radio[name='licenseType']:checked").val(); + var costPer; + if (licenseType === "enterprise") costPer = 5; + else if (licenseType === "professional") costPer = 2; + else return ""; + var periodRaw = $("input:radio[name='paymentType']:checked").val(); + if (periodRaw === "monthly") { + if (costPer*seats < 50) { + $("#onlyYearlyWarning").show(); + return "Your license will cost €" + (costPer*seats*12) + ",- per year."; + } + return "Your license will cost €" + (costPer*seats) + ",- per month."; + } + return "Your license will cost €" + (costPer*seats*12) + ",- per year."; + } catch (e) { + return ""; + } + } + + function showError(elemName) { + var elem = $("#" + elemName + "Err"); + elem.fadeIn(); + $("#" + elemName).on("change keyup", function() { + elem.hide(); + }); + } + + function applyLicense() { + var submitButton = $("#submit"); + var spinner = $("<img>").attr("src", "/img/spinner.gif").attr("alt", "submitting").css("float", "left").css("margin-right", "20px"); + + submitButton.on("click", function(evt) { + evt.preventDefault(); + + var onSuccess = function() { + $("#orderHelp").hide(); + var okMsg = $("<div>").addClass("formSubmitOk").html("Thank you for ordering a Project Lombok license! We'll send your bill via email. If you have any further questions please contact us at <a href=\"mailto:orders@projectlombok.org\"><code>orders@projectlombok.org</code></a>."); + spinner.replaceWith(okMsg); + }; + + var onFailure = function() { + $("#orderHelp").hide(); + var errMsg = $("<div>").addClass("formSubmitFail").html("Our order form appears to be broken. Could you do us a favour and contact us at <a href=\"mailto:orders@projectlombok.org\"><code>orders@projectlombok.org</code></a>? Thank you!"); + spinner.replaceWith(errMsg); + }; + + var data = {}; + data.name = $("#companyName").val(); + data.email = $("#email").val(); + data.licenseType = $("input:radio[name='licenseType']:checked").val(); + data.seats = parseInt($("#seats").val()); + data.paymentType = $("input:radio[name='paymentType']:checked").val(); + data.mentionMe = $("#mentionMe").prop("checked"); + data.companyUrl = $("#companyUrl").val(); + data.locationType = $("input:radio[name='locationType']:checked").val(); + data.euVat = $("#euVat").val(); + data.paymentMethod = $("input:radio[name='paymentMethod']:checked").val(); + + var formFail = false; + + if (!data.paymentMethod) { + showError("paymentMethod"); + formFail = true; + } + + if (!data.euVat && data.locationType === 'eu') { + $("#euVat").focus(); + showError("euVat"); + formFail = true; + } + + if (!data.locationType) { + showError("locationType"); + formFail = true; + } + + if (!data.seats || isNaN(data.seats) || data.seats < 1) { + $("#seats").focus(); + showError("seats"); + formFail = true; + } + + if (!data.paymentType) { + showError("paymentType"); + formFail = true; + } + + if (data.email.indexOf('@') === -1) { + $("#email").focus(); + showError("email"); + formFail = true; + } + + if (data.name.trim().length < 1) { + $("#companyName").focus(); + showError("companyName"); + formFail = true; + } + + if (formFail) return; + + var rnd = generateRandom(); + var err = processImageUpload(); + if (err) { + alert(err); + $("#logo")[0].value = null; + return; + } + if (imgDataUrl) data.logo = imgDataUrl; + + submitButton.replaceWith(spinner); + + $.ajax({ + url: "/license-submit/" + rnd, + method: "PUT", + contentType: "application/json", + data: JSON.stringify(data), + processData: false, + success: onSuccess, + error: onFailure + }); + }); + + $("#companyLogo").on("click", function(evt) { + evt.preventDefault(); + $("#logo").click(); + }); + + $("#deleteCompanyLogo").on("click", function(evt) { + evt.preventDefault(); + $("#logo")[0].value = null; + $("#logoCnt").empty().hide(); + $("#companyLogo").show(); + $("#deleteCompanyLogo").hide(); + }); + + $("#logo").on("change", function() { + var err = showImage(); + if (err) { + alert(err); + $("#logo")[0].value = null; + } else { + $("#companyLogo").hide(); + $("#deleteCompanyLogo").show(); + } + }); + + $("#seats,.paymentType,.licenseType").on("change keyup", function() { + updatePriceIndication(); + }); + $(".locationType").on("change", function() { + updateLocationInfo(); + }); + } + + function generateRandom() { + var buf = new Uint8Array(40); + window.crypto.getRandomValues(buf); + return btoa(String.fromCharCode.apply(null, buf)).replace(/\+/g, '_').replace(/\//gi, '-'); + } + + function showImage() { + $("#logoCnt").empty().hide(); + try { + return processImageUpload(function(dataUrl) { + var img = $("<img />"); + img.css({ + "max-width": "500px", + "max-height": "300px" + }); + $("#logoCnt").append(img).show(); + img.attr("src", dataUrl); + }); + } catch (e) { + if (console && console.log) console.log(e); + } + } + + function processImageUpload(fnc) { + var f = $("#logo")[0].files[0]; + if (!f) return; + if (f.size > 10000000) return "Logo too large; please give us a logo below 10MiB in size."; + var imageType = /^image\//; + if (!imageType.test(f.type)) return "Please upload an image, for example in PNG format."; + var reader = new FileReader(); + reader.onload = function(e) { + imgDataUrl = e.target.result; + if (fnc) fnc(e.target.result); + }; + reader.readAsDataURL(f); + return null; + } + + $(applyLicense); +})(); diff --git a/website/resources/js/supporters.js b/website/resources/js/supporters.js new file mode 100644 index 00000000..11f77640 --- /dev/null +++ b/website/resources/js/supporters.js @@ -0,0 +1,221 @@ +"use strict"; + +(function($) { + var supporters = {}; + var weights = {}; + var types = ["enterprise", "professional", "patron"]; + + function shuffle(array) { + var i = 0, j = 0, temp = null; + for (i = array.length - 1; i > 0; i -= 1) { + j = Math.floor(Math.random() * (i + 1)); + temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + } + + function pad(number) { + return number < 10 ? '0' + number : number; + } + + function fromDate(d) { + return d.getUTCFullYear() + '-' + pad(d.getUTCMonth() + 1) + '-' + pad(d.getUTCDate()); + + } + + function toDate(s) { + var x = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s); + if (x) return new Date(parseInt(x[1]), parseInt(x[2]), parseInt(x[3])); + return null; + } + + function Supporter(type, json) { + this.type = type; + this.name = json.name; + this.logo = json.logo; + this.url = json.url; + this.showName = json.showName; + this.start = json.range ? toDate(json.range[0]) : null; + this.end = json.range ? toDate(json.range[1]) : null; + this.weight = (!json.weight && json.weight !== 0.0) ? 1.0 : json.weight; + } + + Supporter.prototype.inRange = function(d) { + return (!this.start || this.start <= d) && (!this.end || this.end > d); + }; + + Supporter.prototype.render = function() { + var d = $("<div />").addClass("supportItem").addClass(this.type); + var a = d; + if (this.url) { + a = $("<a />").attr("href", this.url).attr("rel", "noopener").attr("target", "_blank"); + d.append(a); + } + var n = $("<span />").text(this.name); + a.append(n); + + if (this.logo) { + a.addClass("logo"); + var i = new Image(); + var showName = this.showName; + i.onload = function() { + var w = i.width; + var h = i.height; + var wf = w / 162; + var hf = h / 80; + var f = hf > wf ? hf : wf; + var wt = Math.round(w / f); + var ht = Math.round(h / f); + i.width = wt; + i.height = ht; + var ji = $(i); + if (!showName) a.empty(); + ji.css("width", wt + "px"); + ji.css("height", ht + "px"); + ji.attr("alt", n.text()); + ji.attr("title", n.text()); + a.prepend(ji); + }; + i.src = 'files/' + this.logo; + } + return d; + } + + function errorHandler(xhr, statusText, err) { + var errMsg = "Can't connect to projectlombok.org to fetch the list of licensees and supporters."; + if (console && console.log) { + console.log("AJAX error for loading list of supporters:"); + console.log(err); + } + var errBox = $("<div />").addClass("errorBox").text(errMsg); + $(".supporters").text("").append(errBox); + } + + function successHandler(data) { + $.each(types, function() { + var t = this; + supporters[t] = []; + if (data && data[t]) $.each(data[t], function() { + supporters[t].push(new Supporter(t, this)); + }); + }); + weights = data.modWeight; + if (typeof weights !== 'object') weights = {}; + updatePage(); + } + + function build() { + var spinner = $("<img />").attr("title", "loading").attr("src", "/img/spinner.gif").addClass("spinner"); + $(".supporters").append(spinner); + $.ajax({ + url: "/files/supporters.json", + dataType: "json", + cache: true, + error: errorHandler, + success: function(data) { + spinner.remove(); + successHandler(data); + } + }); + } + + function applySupporters() { + build(); + } + + function updatePage() { + updateSupporters(); + updateSupporterBar(); + } + + var supPerBar = 4; + function updateSupporterBar() { + var s = $(".supporterBar"); + s.find(".introText").show(); + s.append($("<div />").addClass("sbCnt")); + var sf = s.find(".supporterFooter").show(); + s.append(sf); + s = s.find(".sbCnt"); + var now = new Date(); + var list = []; + $.each(types, function() { + var t = this; + $.each(supporters[t], function() { + if (this.inRange(now)) { + var w = weights[t] ? weights[t] : 1.0; + if (this.weight) w = w * this.weight; + for (var i = 0; i < w; i++) list.push(this); + } + }); + }); + + shuffle(list); + + var len = list.length; + var pos = 0; + var c = [], cd = []; + for (var i = 0; i < supPerBar; i++) { + c[i] = null; + cd[i] = $("<div />").addClass("barItem"); + } + + var upd = function() { + var nw = [], a = [], fo = $(), fi = $(); + var sPos = pos; + for (var i = 0; i < supPerBar; i++) { + if (++pos === len) pos = 0; + var z = false; + for (var j = 0; j < i; j++) if (nw[j] === list[pos]) z = true; + if (z) i--; + else nw[i] = list[pos]; + if (pos === sPos) break; + } + for (var i = 0; i < supPerBar; i++) a[i] = (nw[i] === c[i] || !nw[i]) ? null : nw[i].render(i + 1).hide(); + for (var i = 0; i < supPerBar; i++) { + if (a[i]) { + fi = fi.add(a[i]); + fo = fo.add(cd[i].children()); + if (cd[i].parent().length === 0) s.append(cd[i]); + cd[i].append(a[i]); + c[i] = nw[i]; + } + } + + if (fo.length === 0) fi.fadeIn(); + else { + fo.fadeOut("normal", function() { + fi.fadeIn(); + fo.remove(); + }); + } + }; + + setInterval(upd, 10000); + upd(); + } + + function updateSupporters() { + var s = $(".supporters"); + s.empty(); + var now = new Date(); + $.each(types, function() { + var t = this; + var d = $("<div />").addClass("row"); + var h = $("<h2 />").text(t); + d.append(h); + $.each(supporters[t], function() { + if (this.inRange(now)) d.append(this.render()); + }); + if (d.children().length > 1) s.append(d); + }); + if (s.children().length < 1) { + var x = $("<div />").addClass("noSupportersBox").html( + "We don't have any supporters yet this month.<br /><a href=\"https://patreon.com/lombok\" rel=\"noopener\">Become a patron</a> " + + "or <a href=\"/order-license-info\">order a professional or enterprise license</a> today!"); + s.append(x); + } + } + + $(applySupporters); +})($);
\ No newline at end of file |