2021-11-22 17:51:50 +00:00
|
|
|
import { Controller } from "stimulus";
|
2021-09-17 23:28:39 +00:00
|
|
|
|
|
|
|
export default class extends Controller {
|
|
|
|
static values = {
|
|
|
|
title: String,
|
|
|
|
text: String,
|
2021-11-22 17:51:50 +00:00
|
|
|
url: String,
|
|
|
|
};
|
2021-09-17 23:28:39 +00:00
|
|
|
|
2021-11-22 17:51:50 +00:00
|
|
|
async share(event = undefined) {
|
|
|
|
event?.preventDefault();
|
|
|
|
event?.stopPropagation();
|
2021-09-17 23:28:39 +00:00
|
|
|
|
2021-11-22 17:51:50 +00:00
|
|
|
const title = this.titleValue;
|
|
|
|
const text = this.textValue;
|
|
|
|
const url = this.urlValue;
|
|
|
|
const data = { title, text, url };
|
2021-09-17 23:28:39 +00:00
|
|
|
|
2021-11-22 17:51:50 +00:00
|
|
|
if ("share" in navigator) {
|
2021-09-17 23:28:39 +00:00
|
|
|
if (navigator.canShare(data)) {
|
2021-11-22 17:51:50 +00:00
|
|
|
navigator.share(data);
|
2021-09-17 23:28:39 +00:00
|
|
|
} else {
|
2021-11-22 17:51:50 +00:00
|
|
|
console.error("No se puede compartir", data);
|
2021-09-17 23:28:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|