Skip to content

Commit 93fda80

Browse files
committed
Format License Code for Print and Media
Signed-off-by: Olga Bulat <obulat@gmail.com>
1 parent 6ef753b commit 93fda80

File tree

4 files changed

+209
-10
lines changed

4 files changed

+209
-10
lines changed

src/components/LicenseUseCard.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@
55
<b-tabs>
66
<b-tab-item :label="$t('license-use.web-tab-heading')">
77
{{$t('license-use.web-instructions')}}
8-
<SelectedLicenseCode v-model="value"/>
8+
<SelectedLicenseCode v-model="value" isWeb=true />
99
</b-tab-item>
1010
<b-tab-item :label="$t('license-use.print-media-tab-heading')">
1111
{{$t('license-use.print-media-instructions')}}
12-
<license-code attribution-type="print"/>
12+
<PlaintextLicenseCode v-model="value" isWeb=false />
1313
</b-tab-item>
1414
</b-tabs>
1515
</div>
1616
</template>
1717

1818
<script>
19-
import SelectedLicenseCode from './SelectedLicenseCode'
20-
import LicenseCode from './LicenseCode'
19+
import SelectedLicenseCode from './WebLicenseCode'
20+
import PlaintextLicenseCode from './PrintMediaLicenseCode'
2121
export default {
2222
name: 'LicenseUseCard',
2323
props: ['value'],
2424
components: {
25-
LicenseCode,
26-
SelectedLicenseCode
25+
SelectedLicenseCode,
26+
PlaintextLicenseCode
2727
}
2828
}
2929
</script>
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<template>
2+
<div class="license-code">
3+
<b-tabs
4+
class="attribution-tab"
5+
v-model="activeTab">
6+
<b-tab-item :label="this.$t('license-use.plain-text-label')">
7+
<div id="attribution-plaintext">
8+
<LicenseCode ref="licenseCode" attribution-type="print"/>
9+
</div>
10+
</b-tab-item>
11+
<b-tab-item icon-pack="fas" icon="copy">
12+
<template slot="header">
13+
<a class="copyBtn"
14+
data-clipboard-target="#attribution-plaintext">
15+
<b-icon
16+
icon-pack="fas"
17+
icon="copy"/>
18+
<span class="button-text">{{ copyText }}</span>
19+
</a>
20+
</template>
21+
<div class="dummy" />
22+
</b-tab-item>
23+
</b-tabs>
24+
</div>
25+
</template>
26+
<script>
27+
import Clipboard from 'clipboard'
28+
import { mapGetters } from 'vuex'
29+
import LicenseCode from './LicenseCode'
30+
31+
export default {
32+
name: 'PrintMediaLicenseCode',
33+
components: {
34+
LicenseCode
35+
},
36+
props: {
37+
value: Object
38+
},
39+
data() {
40+
return {
41+
success: false,
42+
clipboard: null,
43+
currentTab: 0,
44+
copyText: this.$t('license-use.copy-label')
45+
}
46+
},
47+
methods: {
48+
onCopySuccess(e) {
49+
this.success = true
50+
if (process.env.NODE_ENV === 'production') {
51+
const fieldsFilled = {}
52+
for (const detail in this.attributionDetails) {
53+
fieldsFilled[detail] = this.attributionDetails[detail] !== ''
54+
}
55+
const copiedLicense = {
56+
license: this.shortName,
57+
// codeType can be either rich-text or html
58+
codeType: 'plaintext',
59+
fieldsFilled: fieldsFilled
60+
}
61+
this.$ga.event({
62+
eventCategory: 'Attribution',
63+
eventAction: 'copied',
64+
eventLabel: JSON.stringify(copiedLicense)
65+
})
66+
}
67+
this.$emit('copied', { content: e.text })
68+
setTimeout(() => {
69+
this.success = false
70+
}, 2000)
71+
e.clearSelection()
72+
},
73+
onCopyError(e) {
74+
this.$emit('copyFailed')
75+
e.clearSelection()
76+
}
77+
},
78+
computed: {
79+
...mapGetters(['shortName', 'fullName', 'iconsList', 'licenseUrl']),
80+
attributionDetails() {
81+
return this.$store.state.attributionDetails
82+
},
83+
activeTab: {
84+
get() { return this.currentTab },
85+
set(val) {
86+
if (val !== 1) {
87+
this.currentTab = val
88+
} else {
89+
this.currentSelection = this.currentTab === 0 ? 'richtext' : 'html'
90+
const tab = this.currentTab
91+
this.currentTab = 1
92+
this.copyText = this.$t('license-use.copied-label')
93+
setTimeout(() => {
94+
this.currentTab = tab
95+
}, 1)
96+
setTimeout(() => {
97+
this.copyText = 'Copy'
98+
}, 2000)
99+
}
100+
}
101+
}
102+
},
103+
mounted() {
104+
this.clipboard = new Clipboard('.copyBtn')
105+
this.clipboard.on('success', this.onCopySuccess)
106+
this.clipboard.on('error', this.onCopyError)
107+
},
108+
destroyed() {
109+
this.clipboard.destroy()
110+
}
111+
}
112+
</script>
113+
<style lang="scss">
114+
.attribution-tab .photo-license-icon {
115+
height: 26px;
116+
}
117+
#attribution-richtext>p>span,
118+
#attribution-richtext .photo-license-icons{
119+
height: 26px;
120+
vertical-align: middle;
121+
}
122+
#attribution-richtext p {
123+
margin-top: 1rem;
124+
margin-bottom: 1rem;
125+
}
126+
.license-use-hint {
127+
text-align: center;
128+
}
129+
.license-use-hint a {
130+
text-decoration: underline;
131+
}
132+
.license-use-hint span {
133+
vertical-align: middle;
134+
}
135+
.license-code .attribution-tab .tabs span {
136+
font-style: normal;
137+
color: #B0B0B0;
138+
font-size: 16px;
139+
line-height: 24px;
140+
}
141+
.license-code .attribution-tab li:last-of-type {
142+
margin-left: auto;
143+
margin-bottom: -1px;
144+
a {
145+
padding:0;
146+
}
147+
& > a {
148+
padding: 0.5em 1em;
149+
a.copyBtn {
150+
border-bottom: none;
151+
span, .button-text {
152+
color: #333333;
153+
}
154+
}
155+
}
156+
}
157+
158+
.license-code {
159+
margin-top: 0.4rem;
160+
.attribution-tab {
161+
margin-bottom: 1rem;
162+
.tabs {
163+
margin-bottom: 0;
164+
}
165+
.tab-content {
166+
margin-top:0;
167+
padding: 0;
168+
.tab-item {
169+
height: 60px;
170+
}
171+
}
172+
}
173+
}
174+
#generated-html-container {
175+
padding-top:10px;
176+
padding-bottom: 10px;
177+
textarea {
178+
word-break: break-all;
179+
-ms-word-break: break-all;
180+
min-height: 60px;
181+
font-family: "Source Sans Pro", "Noto Sans", Arial, "Helvetica Neue", Helvetica, sans-serif;
182+
font-size:0.845rem;
183+
}
184+
}
185+
#generated-richtext-container {
186+
margin-top: 1rem;
187+
display: block;
188+
.attribution-license-icons {
189+
vertical-align: middle;
190+
margin-top: 0;
191+
margin-left: 2px;
192+
}
193+
p {
194+
display: inline
195+
}
196+
}
197+
</style>

src/components/SelectedLicenseCode.vue renamed to src/components/WebLicenseCode.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
v-model="activeTab">
66
<b-tab-item :label="this.$t('license-use.rich-text-label')">
77
<div id="attribution-richtext">
8-
<license-code ref="licenseCode" />
8+
<LicenseCode ref="licenseCode" />
99
</div>
1010
</b-tab-item>
1111
<b-tab-item :label="this.$t('license-use.html-label')">
@@ -43,11 +43,13 @@ import LicenseCode from './LicenseCode'
4343
import { generateHTML } from '../utils/license-utilities'
4444
4545
export default {
46-
name: 'SelectedLicenseCode',
46+
name: 'WebLicenseCode',
4747
components: {
4848
LicenseCode
4949
},
50-
props: ['value'],
50+
props: {
51+
value: Object
52+
},
5153
data() {
5254
return {
5355
success: false,

src/locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
"web-tab-heading": "Website",
113113
"print-media-tab-heading": "Print Work or Media",
114114
"print-media-instructions": "Copy the text below and paste it on the title and/or copyright page of your print work or presentation, or in the credits of your media.",
115-
"media-instructions": "TODO",
116115
"rich-text-label": "Rich Text",
117116
"html-label": "HTML",
117+
"plain-text-label": "Plain Text",
118118
"copy-label": "Copy",
119119
"copied-label": "Copied!",
120120
"richtext": {

0 commit comments

Comments
 (0)