Skip to content

Commit

Permalink
feat: make copy driver to consider share link if exists
Browse files Browse the repository at this point in the history
Close #8
  • Loading branch information
paodb authored and javier-godoy committed Feb 16, 2024
1 parent 83e95d2 commit 9423b11
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ window.fcShareeConnector = {

create: function (container, optionsJson) {
this._updateSocialShareLinks();
this._updateCopyDriverOnClick();
let parsedOptions = JSON.parse(optionsJson);
const sharee = new Sharee(container, parsedOptions);
},

createWithCustomDrivers: function (container, optionsJson) {
this._updateSocialShareLinks();
this._updateCopyDriverOnClick();
let parsedOptions = JSON.parse(optionsJson);
// add the custom drivers to the list of drivers
let drivers = parsedOptions.drivers.concat(container.customDrivers);
Expand Down Expand Up @@ -105,4 +107,32 @@ window.fcShareeConnector = {
}
},

/**
* Replaces onClick function on CopyDriver to take in consideration shareLink option
* if exists. (Fixes https://github.com/FlowingCode/ShareEasy/issues/8)
*/
_updateCopyDriverOnClick() {
Sharee.drivers['copy'].prototype.onClick = function(e) {
const successText = this.lang['CopiedSuccessfully']
const el = e.currentTarget;
const textEl = el.querySelector('div:nth-child(2)')
if (textEl.innerHTML === successText) {
textEl.innerHTML = this.getButtonText()
return
}
let copyText = this.options?.shareLink || window.location.href
navigator.clipboard.writeText(copyText).then(() => {
textEl.innerHTML = successText
textEl.style.transition = '300ms all'
textEl.style.transform = 'scale(1)'
textEl.style.transform = `scale(1.07) translateX(${this.lang.Direction === 'rtl' ? '-' : ''}4px)`
clearTimeout(this.timeout)
this.timeout = setTimeout(() => {
textEl.innerHTML = this.getButtonText()
textEl.style.transition = 'none'
textEl.style.transform = 'scale(1)'
}, 5000)
});
}
}
}

0 comments on commit 9423b11

Please sign in to comment.