Skip to content

[WIP] Add chooser functionality #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Icons setting in chooser now working, code still messy
  • Loading branch information
Ari committed Jun 20, 2019
commit b1e13929a586d5e848a7cef33f384195f208d6bd
17 changes: 10 additions & 7 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</style>
</noscript>
</head>
<body>
<body onload="set_license()">
<header style="padding-bottom: 1%">
<br>
<img src="assets/cc-logo_white.png" style="width: 20%; margin-left: 5%">
Expand Down Expand Up @@ -237,13 +237,16 @@ <h4 class="title is-4">
</div>
</div> <br><br>
</div>-->
<div class="column">
<h3 class="title is-3">Your License!</h3>
<div class="column" align="center">
<h3 class="title is-3">Your License!</h3> <br><br>
<a v-bind:href="chooser.selected_license_link" align="center">{{chooser.selected_license}}</a> <br>
<p>{{chooser.selected_license_short}}</p>
<div id="license-chooser-icons" align="center">
<img src="assets/cc.svg" class="chooser-license-icon">
</div>
<p>{{chooser.selected_license_short}}</p> <br>
<span id="license-chooser-icons">
<img src="assets/cc.svg" class="chooser-license-icon" id="cc-logo-icon">
<img src="assets/license-icons/cc-by_icon.svg" class="chooser-license-icon" id="attribution-icon">
<img src="assets/license-icons/cc-nc_icon.svg" class="chooser-license-icon" id="commercial-icon">
<img v-bind:src="'assets/license-icons/' + chooser.icons.nd_sa_src" class="chooser-license-icon" id="adaptations-icon">
</span>
</div>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ var app_state = new Vue({ // eslint-disable-line
selected_license: "[License Name]",
selected_license_short: "[License Short]",
selected_license_link: "",
icons: {
nc_shown: false,
sa_shown: false,
nd_shown: false,
nd_sa_src: "cc-sa_icon.svg",
},
inputs: {
share_alike: false,
allow_adaptations: true,
Expand Down
79 changes: 70 additions & 9 deletions src/scripts/choose-a-license.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
function set_license() {
set_license_text()
set_license_icons()
}

function set_license_text() {
app_state.chooser.selected_license = "{0} ({1})".format(
gen_license_name(),
gen_shortened_name()
)
/*
var state = app_state.chooser
if (state.inputs.allow_adaptations == null &&
state.inputs.allow_commercial_uses == null) {
state.selected_license = "To Choose a License, Please Make Some Selections Using the Controls to the Left."
} else if (state.inputs.allow_adaptations == null &&
state.inputs.allow_commercial_uses != null) {
state.selected_license = "Please Select Whether or not to Allow Adaptations of Your Work."
}*/
app_state.chooser.selected_license = gen_license_name()
app_state.chooser.selected_license_short = gen_shortened_name()
set_license_link()
}

function set_license_icons() {
var state = app_state.chooser
if (state.inputs.allow_adaptations) {
state.icons.nd_shown = false
state.icons.sa_shown = false
toggle_license_icon("nd-sa", false)
if (state.inputs.share_alike) {
state.icons.sa_shown = true
state.icons.nd_shown = false
state.icons.nd_sa_src = "cc-sa_icon.svg"
toggle_license_icon("nd-sa", true)
}
}
else if (!state.inputs.allow_adaptations) {
state.icons.nd_shown = true
state.icons.sa_shown = false
state.icons.nd_sa_src = "cc-nd_icon.svg"
toggle_license_icon("nd-sa", true)
}

if (state.inputs.allow_commercial_uses) {
state.icons.nc_shown = false
toggle_license_icon("nc", false)
} else {
state.icons.nc_shown = true
toggle_license_icon("nc", true)
}
}

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"
if (state.inputs.allow_adaptations) {
if (state.inputs.share_alike) {
license_base += "-ShareAlike"
}
}
else if (!state.inputs.allow_adaptations) {
license_base += "-NoDerivatives"
Expand Down Expand Up @@ -81,7 +120,6 @@ function switch_callback(cb) {
else { // If NOT allow adaptations
state.allow_adaptations = false
hide_sa_check()
state.share_alike = false
}
break;
case "allow-commercial-switch":
Expand All @@ -94,12 +132,35 @@ function switch_callback(cb) {
set_license()
}

function toggle_license_icon(icon, is_show) {
switch (icon) {
case "nd-sa":
if (!is_show) document.getElementById("adaptations-icon").style.display = "none"
else document.getElementById("adaptations-icon").style.display = "inline"
break;
case "nc":
if (!is_show) document.getElementById("commercial-icon").style.display = "none"
else document.getElementById("commercial-icon").style.display = "inline"
break;
default:
console.log("Whoops! This function isn't designed to handle that parameter.")
break;
}
}

function hide_sa_check() {
console.log("SA Hidden")
document.getElementById("sa-checkbox").style.display = "none";
document.getElementById("sa-checkbox").style.display = "none"
}

function show_sa_check() {
console.log("SA Shown")
document.getElementById("sa-checkbox").style.display = "block";
var element = document.getElementById("sa-checkbox")
if (app_state.chooser.inputs.share_alike) {
element.checked = "true"
} else {
element.checked = "false"
}

element.style.display = "block"
}
7 changes: 7 additions & 0 deletions src/scripts/page-controls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import set_license from "../scripts/choose-a-license.js"

function spawn_modal(modal_id) {
app_state.modals.modal_content = app_state.modals.modal_packs[modal_id].content // Update modal content
app_state.modals.modal_title = app_state.modals.modal_packs[modal_id].title // Update modal title
Expand All @@ -18,6 +20,11 @@ function destroy_modal() {
app_state.modals.modal_toggle = "modal"
}

function on_page_load() {
set_license()
document.getElementById('sa-checkbox').checked = app_state.chooser.inputs.share_alike
}

function copy_text_to_clipboard() {

}
29 changes: 2 additions & 27 deletions src/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,15 @@
display: inline;
}

/* The next three classes were copied from w3schools */
/* Style the button that is used to open and close the collapsible content */
.collapsible {
background-color: #eee;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}

/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */
.active, .collapsible:hover {
background-color: #ccc;
}

/* Style the collapsible content. Note: hidden by default */
.content {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #f1f1f1;
}

a.modal-icon {
vertical-align: middle;
display: inline;
}

img.chooser-license-icon {
width: 15%;
margin-right: 1.4%;
display: inline;
}

a.generator-copy-button {
Expand Down