From 980e3614e1ff6f51ac23b95202b70645e3b0967f Mon Sep 17 00:00:00 2001 From: Ari Date: Mon, 17 Jun 2019 18:42:03 -0700 Subject: [PATCH 1/4] Add some basic functionality, still very buggy --- src/index.html | 17 +++--- src/index.js | 4 +- src/scripts/choose-a-license.js | 98 +++++++++++++++++++++++++++++++++ src/scripts/scripts.js | 7 +++ 4 files changed, 118 insertions(+), 8 deletions(-) diff --git a/src/index.html b/src/index.html index 5743874bb..caa2cd05f 100644 --- a/src/index.html +++ b/src/index.html @@ -140,7 +140,7 @@


- -->

Changes to the options below will affect the license choice to the right.



@@ -154,13 +154,15 @@

- +

-

- +
+ @@ -185,7 +187,7 @@



-
--> +

Your License!

-

{{chooser.selected_license}}



+ {{chooser.selected_license}}
+

{{chooser.selected_license_short}}

diff --git a/src/index.js b/src/index.js index 5a54b6b5e..64d31c069 100644 --- a/src/index.js +++ b/src/index.js @@ -74,8 +74,10 @@ var app_state = new Vue({ // eslint-disable-line }, chooser: { selected_license: "[License Name]", + selected_license_short: "[License Short]", + selected_license_link: "", inputs: { - share_alike: false, + share_alike: true, allow_adaptations: true, allow_commercial_uses: true, }, diff --git a/src/scripts/choose-a-license.js b/src/scripts/choose-a-license.js index e69de29bb..63b8bc5ae 100644 --- a/src/scripts/choose-a-license.js +++ b/src/scripts/choose-a-license.js @@ -0,0 +1,98 @@ +function set_license() { + set_license_text() +} + +function set_license_text() { + app_state.chooser.selected_license = "{0} ({1})".format( + gen_license_name(), + gen_shortened_name() + ) + set_license_link() +} + +function gen_license_name() { + var state = app_state.chooser + var license_base = "Atribution" + if (state.inputs.allow_commercial_uses) { + license_base += "-NonCommercial" + } + if (state.inputs.share_alike) { + license_base += "-ShareAlike" + } + else { + license_base += "-NoDerivatives" + } + license_base += " 4.0 International" + app_state.chooser.selected_license = license_base + return license_base +} + +/** + * + * @param {boolean} url_version If the shortened name need to be slugified for a URL + */ +function gen_shortened_name(url_version = false) { + const license = app_state.chooser.selected_license + var short = "CC BY" + if (license.includes("NonCommercial")) { + short += "-NC" + } + if (license.includes("NoDerivatives")) { + short += "-ND" + } else if(license.includes("ShareAlike")) { + short += "-SA" + } + return (url_version ? short.slice(3).toLowerCase() : short += " 4.0") +} + +function set_license_link() { + const short_license = gen_shortened_name(true) + var url = "https://creativecommons.org/licenses/{0}/4.0".format(short_license) + app_state.chooser.selected_license_link = url +} + +/** + * + * @param {object} check The HTML SA Checkbox object + */ +function sa_check_callback(check) { + app_state.chooser.inputs.share_alike = check.checked + set_license() +} + +/** + * + * @param {object} cb The HTML switch object + */ +function switch_callback(cb) { + var state = app_state.chooser.inputs + switch (cb.id) { + case "allow-adaptations-switch": + state.allow_adaptations = cb.checked + if (cb.checked) { // If allow adaptations + state.allow_adaptations = true + show_sa_check() + } + else { // If NOT allow adaptations + state.allow_adaptations = false + hide_sa_check() + state.share_alike = false + } + break; + case "allow-commercial-switch": + state.allow_commercial_uses = cb.checked + break; + default: + console.log("Whoops! This function isn't designed to handle that parameter.") + break; + } + set_license() +} + +function hide_sa_check() { + document.getElementById("sa-checkbox").style.display = "none"; +} + +function show_sa_check() { + document.getElementById("sa-checkbox").style.display = "block"; +} \ No newline at end of file diff --git a/src/scripts/scripts.js b/src/scripts/scripts.js index e69de29bb..15219ed3c 100644 --- a/src/scripts/scripts.js +++ b/src/scripts/scripts.js @@ -0,0 +1,7 @@ +String.prototype.format = function() { + a = this; + for (k in arguments) { + a = a.replace("{" + k + "}", arguments[k]) + } + return a +} \ No newline at end of file From 8651768acc3749ea35d0cb61ef868b68cd5207e5 Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 19 Jun 2019 16:26:36 -0700 Subject: [PATCH 2/4] Get chooser working, icon updates still not implemented --- src/index.html | 8 +++++--- src/index.js | 2 +- src/scripts/choose-a-license.js | 11 +++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/index.html b/src/index.html index caa2cd05f..841c85dbb 100644 --- a/src/index.html +++ b/src/index.html @@ -25,7 +25,7 @@

-
+