|
| 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> |
0 commit comments