1
+ function set_license ( ) {
2
+ set_license_text ( )
3
+ set_license_icons ( )
4
+ }
5
+
6
+ function set_license_text ( ) {
7
+ /*
8
+ var state = app_state.chooser
9
+ if (state.inputs.allow_adaptations == null &&
10
+ state.inputs.allow_commercial_uses == null) {
11
+ state.selected_license = "To Choose a License, Please Make Some Selections Using the Controls to the Left."
12
+ } else if (state.inputs.allow_adaptations == null &&
13
+ state.inputs.allow_commercial_uses != null) {
14
+ state.selected_license = "Please Select Whether or not to Allow Adaptations of Your Work."
15
+ }*/
16
+ app_state . chooser . selected_license = gen_license_name ( )
17
+ app_state . chooser . selected_license_short = gen_shortened_name ( )
18
+ set_license_link ( )
19
+ }
20
+
21
+ function set_license_icons ( ) {
22
+ var state = app_state . chooser
23
+ if ( state . inputs . allow_adaptations ) {
24
+ state . icons . nd_shown = false
25
+ state . icons . sa_shown = false
26
+ toggle_license_icon ( "nd-sa" , false )
27
+ if ( state . inputs . share_alike ) {
28
+ state . icons . sa_shown = true
29
+ state . icons . nd_shown = false
30
+ state . icons . nd_sa_src = "cc-sa_icon.svg"
31
+ toggle_license_icon ( "nd-sa" , true )
32
+ }
33
+ }
34
+ else if ( ! state . inputs . allow_adaptations ) {
35
+ state . icons . nd_shown = true
36
+ state . icons . sa_shown = false
37
+ state . icons . nd_sa_src = "cc-nd_icon.svg"
38
+ toggle_license_icon ( "nd-sa" , true )
39
+ }
40
+
41
+ if ( state . inputs . allow_commercial_uses ) {
42
+ state . icons . nc_shown = false
43
+ toggle_license_icon ( "nc" , false )
44
+ } else {
45
+ state . icons . nc_shown = true
46
+ toggle_license_icon ( "nc" , true )
47
+ }
48
+ }
49
+
50
+ function gen_license_name ( ) {
51
+ var state = app_state . chooser
52
+ var license_base = "Atribution"
53
+ if ( ! state . inputs . allow_commercial_uses ) {
54
+ license_base += "-NonCommercial"
55
+ }
56
+ if ( state . inputs . allow_adaptations ) {
57
+ if ( state . inputs . share_alike ) {
58
+ license_base += "-ShareAlike"
59
+ }
60
+ }
61
+ else if ( ! state . inputs . allow_adaptations ) {
62
+ license_base += "-NoDerivatives"
63
+ }
64
+ license_base += " 4.0 International"
65
+ app_state . chooser . selected_license = license_base
66
+ return license_base
67
+ }
68
+
69
+ /**
70
+ *
71
+ * @param {boolean } url_version If the shortened name need to be slugified for a URL
72
+ */
73
+ function gen_shortened_name ( url_version = false ) {
74
+ const license = app_state . chooser . selected_license
75
+ var short = "CC BY"
76
+ if ( license . includes ( "NonCommercial" ) ) {
77
+ short += "-NC"
78
+ }
79
+ if ( license . includes ( "NoDerivatives" ) ) {
80
+ short += "-ND"
81
+ } else if ( license . includes ( "ShareAlike" ) ) {
82
+ short += "-SA"
83
+ }
84
+ return ( url_version ? short . slice ( 3 ) . toLowerCase ( ) : short += " 4.0" )
85
+ }
86
+
87
+ function set_license_link ( ) {
88
+ const short_license = gen_shortened_name ( true )
89
+ var url = "https://creativecommons.org/licenses/{0}/4.0" . format ( short_license )
90
+ app_state . chooser . selected_license_link = url
91
+ }
92
+
93
+ /**
94
+ *
95
+ * @param {object } check The HTML SA Checkbox object
96
+ */
97
+ function sa_check_callback ( check ) {
98
+ console . log ( "Checkbox Toggled" )
99
+ app_state . chooser . inputs . share_alike = check . checked
100
+ set_license ( )
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param {object } cb The HTML switch object
106
+ */
107
+ function switch_callback ( cb ) {
108
+ console . log ( "Switch Toggled - " + cb . id )
109
+ var state = app_state . chooser . inputs
110
+ state . selected_license = ""
111
+ switch ( cb . id ) {
112
+ case "allow-adaptations-switch" :
113
+ state . allow_adaptations = cb . checked
114
+ if ( cb . checked ) { // If allow adaptations
115
+ console . log ( "Is Allow Adaptations - " + cb . checked )
116
+ state . allow_adaptations = true
117
+ show_sa_check ( )
118
+ set_license ( )
119
+ }
120
+ else { // If NOT allow adaptations
121
+ state . allow_adaptations = false
122
+ hide_sa_check ( )
123
+ }
124
+ break ;
125
+ case "allow-commercial-switch" :
126
+ state . allow_commercial_uses = cb . checked
127
+ break ;
128
+ default :
129
+ console . log ( "Whoops! This function isn't designed to handle that parameter." )
130
+ break ;
131
+ }
132
+ set_license ( )
133
+ }
134
+
135
+ function toggle_license_icon ( icon , is_show ) {
136
+ switch ( icon ) {
137
+ case "nd-sa" :
138
+ if ( ! is_show ) document . getElementById ( "adaptations-icon" ) . style . display = "none"
139
+ else document . getElementById ( "adaptations-icon" ) . style . display = "inline"
140
+ break ;
141
+ case "nc" :
142
+ if ( ! is_show ) document . getElementById ( "commercial-icon" ) . style . display = "none"
143
+ else document . getElementById ( "commercial-icon" ) . style . display = "inline"
144
+ break ;
145
+ default :
146
+ console . log ( "Whoops! This function isn't designed to handle that parameter." )
147
+ break ;
148
+ }
149
+ }
150
+
151
+ function hide_sa_check ( ) {
152
+ console . log ( "SA Hidden" )
153
+ document . getElementById ( "sa-checkbox" ) . style . display = "none"
154
+ }
155
+
156
+ function show_sa_check ( ) {
157
+ console . log ( "SA Shown" )
158
+ var element = document . getElementById ( "sa-checkbox" )
159
+ if ( app_state . chooser . inputs . share_alike ) {
160
+ element . checked = "true"
161
+ } else {
162
+ element . checked = "false"
163
+ }
164
+
165
+ element . style . display = "block"
166
+ }
0 commit comments