14
14
</v-tooltip >
15
15
</template >
16
16
<v-list >
17
- <v-list-tile
18
- v-for =" (item, index) in items"
19
- :key =" index"
20
- @click =" onClick(item.action)"
21
- >
22
- <v-list-tile-title >{{ item.title }}</v-list-tile-title >
17
+ <v-list-tile @click =" onCopyUrl()" >
18
+ <v-list-tile-action >
19
+ <v-icon medium >file_copy</v-icon >
20
+ </v-list-tile-action >
21
+ <v-list-tile-content >
22
+ <v-list-tile-title >{{copyUrlText}}</v-list-tile-title >
23
+ </v-list-tile-content >
24
+ </v-list-tile >
25
+ <v-list-tile @click =" onCopyEmbedHTML()" >
26
+ <v-list-tile-action >
27
+ <v-icon medium >code</v-icon >
28
+ </v-list-tile-action >
29
+ <v-list-tile-content >
30
+ <v-list-tile-title >{{copyEmbedHtmlText}}</v-list-tile-title >
31
+ </v-list-tile-content >
32
+ </v-list-tile >
33
+ <v-list-tile >
34
+ <v-list-tile-action >
35
+ <v-icon medium >email</v-icon >
36
+ </v-list-tile-action >
37
+ <v-list-tile-content >
38
+ <v-list-tile-title v-html =" mailToUrl" />
39
+ </v-list-tile-content >
23
40
</v-list-tile >
24
41
</v-list >
25
42
</v-menu >
33
50
{{alertText}}
34
51
</v-alert >
35
52
</div >
36
- <!-- <div>-->
37
- <!-- <div>-->
38
- <!-- <v-btn icon :dark="dark" @click="onClick">-->
39
- <!-- <v-icon medium>{{icon}}</v-icon>-->
40
- <!-- {{text}}-->
41
- <!-- </v-btn>-->
42
- <!-- <textarea id="textstore" ref="textstore" style="display: none; position: relative"></textarea>-->
43
- <!-- </div>-->
44
- <!-- <v-alert-->
45
- <!-- class="wgu-alert"-->
46
- <!-- :value="alert"-->
47
- <!-- :dark="dark"-->
48
- <!-- type="info"-->
49
- <!-- transition="fade-transition"-->
50
- <!-- >-->
51
- <!-- {{alertText}}-->
52
- <!-- </v-alert>-->
53
- <!-- </div>-->
54
53
</template >
55
54
56
55
<script >
57
56
58
57
import { Mapable } from ' ../../mixins/Mapable' ;
58
+ import {WguEventBus } from ' ../../WguEventBus' ;
59
59
60
60
export default {
61
61
name: ' wgu-share-btn' ,
@@ -64,61 +64,95 @@ export default {
64
64
icon: {type: String , required: false , default: ' share' },
65
65
text: {type: String , required: false , default: ' ' },
66
66
hoverText: {type: String , required: false , default: ' Share permalink' },
67
- alertText: {type: String , required: false , default: ' Copied' },
68
67
alertTimeMillis: {type: Number , required: false , default: 1000 },
69
- dark: {type: Boolean , required: false , default: false }
68
+ alertCopiedText: {type: String , required: false , default: ' Copied' },
69
+ alertErrorText: {type: String , required: false , default: ' An error occurred' },
70
+ dark: {type: Boolean , required: false , default: false },
71
+ copyUrlText: {type: String , required: false , default: ' Copy URL' },
72
+ copyEmbedHtmlText: {type: String , required: false , default: ' Copy HTML Embed Code' },
73
+ emailUrlText: {type: String , required: false , default: ' Email URL' },
74
+ emailSubjectText: {type: String , required: false , default: ' NPLH Url Share' }
70
75
},
71
76
data () {
72
77
return {
73
78
alert: false ,
74
- items: [
75
- { title: ' Copy URL' , action: ' copy' },
76
- { title: ' Copy HTML Embed Code' , action: ' embed' }
77
- // { title: 'Email URL', action: 'email' }
78
- ]
79
+ alertText: this .alertCopiedText ,
80
+ mailToUrl: this .emailUrlText
79
81
}
80
82
},
83
+ mounted () {
84
+ // Listen to the ol-map-mounted event and receive the OL map instance
85
+ WguEventBus .$on (' ol-map-mounted' , (olMap ) => {
86
+ // Listen to map state changes (pan, zoom)
87
+ this .map .on (' moveend' , () => {
88
+ this .onMapChange ();
89
+ });
90
+ });
91
+ },
81
92
methods: {
82
- onClick (action ) {
93
+ showAlert (text ) {
94
+ // Show short alert
95
+ this .alertText = text || this .alertCopiedText ;
96
+ this .alert = true ;
97
+ window .setTimeout (() => {
98
+ this .alert = false ;
99
+ }, this .alertTimeMillis );
100
+ },
101
+ copyToClipboard (text ) {
102
+ const textArea = this .$refs .textstore ;
103
+ // Show and select textarea
104
+ textArea .style .display = ' block' ;
105
+ textArea .value = text;
106
+ textArea .select ();
107
+
108
+ // Copy to clipboard
109
+ document .execCommand (' copy' );
110
+
111
+ // Hide textarea
112
+ textArea .value = ' ' ;
113
+ textArea .style .display = ' none' ;
114
+ },
115
+ onCopyUrl () {
83
116
// Get permalink URL and copy to clipboard
84
- const permalinkController = this .map .get (' permalinkcontroller' );
85
- if (! permalinkController) {
86
- console .error (' no permalink controller available!' );
87
- return true ;
88
- }
89
117
try {
90
118
// Copy to clipboard: selected text needs to be visible so
91
119
// toggle textarea short time
92
- let text;
93
-
94
- if (action === ' copy' ) {
95
- text = permalinkController .getShareUrl ();
96
- } else if (action === ' embed' ) {
97
- text = permalinkController .getEmbedHTML ();
98
- } else {
99
- console .error (' no permalink controller available!' );
100
- return true ;
101
- }
102
- const textArea = this .$refs .textstore ;
103
- // Show and select textarea
104
- textArea .style .display = ' block' ;
105
- textArea .value = text;
106
- textArea .select ();
107
-
108
- // Copy to clipboard
109
- document .execCommand (' copy' );
110
- // Hide textarea
111
- textArea .value = ' ' ;
112
- textArea .style .display = ' none' ;
113
-
114
- // Show short alert
115
- this .alert = true ;
116
- window .setTimeout (() => {
117
- this .alert = false ;
118
- }, this .alertTimeMillis );
120
+ const permalinkController = this .map .get (' permalinkcontroller' );
121
+ this .copyToClipboard (permalinkController .getShareUrl ());
122
+ this .showAlert ();
119
123
} catch (error) {
120
- console . error (error );
124
+ this . showAlert ( this . alertErrorText );
121
125
}
126
+ },
127
+ onCopyEmbedHTML () {
128
+ // Get permalink URL and copy to clipboard
129
+ try {
130
+ const permalinkController = this .map .get (' permalinkcontroller' );
131
+ this .copyToClipboard (permalinkController .getEmbedHTML ());
132
+ this .showAlert ();
133
+ } catch (error) {
134
+ this .showAlert (this .alertErrorText );
135
+ }
136
+ },
137
+ setMailtoUrl : function () {
138
+ // if (!this.map) {
139
+ // return 'Waiting for Map...';
140
+ // }
141
+ // https://css-tricks.com/snippets/html/mailto-links/
142
+ // Get permalink URL and add to email Body
143
+ try {
144
+ const permalinkController = this .map .get (' permalinkcontroller' );
145
+ const url = encodeURIComponent (permalinkController .getShareUrl ());
146
+ this .mailToUrl = ` <a href="mailto:?subject=${ this .emailSubjectText } &body=${ url} ">${ this .emailUrlText } </a>`
147
+ } catch (error) {
148
+ this .showAlert (this .alertErrorText );
149
+ }
150
+ },
151
+ /**
152
+ * Callback when Map View has changed, e.g. 'moveend'.
153
+ */
154
+ onMapChange () {
155
+ this .setMailtoUrl ();
122
156
}
123
157
}
124
158
}
@@ -133,5 +167,8 @@ export default {
133
167
right: 4em;
134
168
z-index: 1;
135
169
}
136
-
170
+ a {
171
+ color: inherit;
172
+ text-decoration: none !important;
173
+ }
137
174
</style>
0 commit comments