[embed] extend share buttons

This commit is contained in:
Maxim Kadushkin 2022-04-04 11:23:45 +03:00
parent 3c5fc2e301
commit dbd1055e0a
3 changed files with 24 additions and 27 deletions

View file

@ -57,12 +57,15 @@
$dlgShare.find('#btn-copyshort').on('click', copytext.bind(this, $dlgShare.find('#id-short-url')));
$dlgShare.find('.share-buttons > span').on('click', function(e){
if ( window.config ) {
const key = $(e.target).attr('data-name');
if ( config.btnsShare[key] && config.btnsShare[key].getUrl ) {
window.open(config.btnsShare[key].getUrl(appConfig.shareUrl, encodeURI(appConfig.docTitle)), '',
'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
const btn = config.btnsShare[key];
if ( btn && btn.getUrl ) {
window.open(btn.getUrl(appConfig.shareUrl, appConfig.docTitle), btn.target || '',
btn.features || 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
return;
}
}
var _url;
switch ($(e.target).attr('data-name')) {

View file

@ -53,6 +53,9 @@ common.view.modals = new(function() {
'<input id="id-short-url" class="form-control" type="text" readonly/>' +
'</div>' +
'<div class="share-buttons">' +
'<span class="svg big-facebook" data-name="facebook"></span>' +
'<span class="svg big-twitter" data-name="twitter"></span>' +
'<span class="svg big-email" data-name="email"></span>' +
'<div class="autotest" id="email" style="display: none"></div>' +
'</div>';
@ -70,16 +73,23 @@ common.view.modals = new(function() {
var _$dlg;
if (name == 'share') {
let _btns = '';
if ( config && config.btnsShare ) {
let _btns = [];
for (const key of Object.keys(config.btnsShare))
_btns += `<span class="svg big-${key}" data-name="${key}"></span>`;
_btns.push(`<span class="svg big-${key}" data-name="${key}"></span>`);
if ( _btns ) {
let $sharebox = $(_tplbody_share);
$sharebox.eq(1).prepend(_btns);
$sharebox.find('.autotest').prevAll().remove();
$sharebox.eq(1).prepend(_btns.join(''));
_tplbody_share = $("<div>").append($sharebox).html();
}
}
_$dlg = $(tplDialog
.replace(/\{title}/, this.txtShare)
.replace(/\{body}/, $("<div>").append($sharebox).html())
.replace(/\{body}/, _tplbody_share)
.replace(/\{footer}/, '<button id="btn-copyshort" type="button" class="btn">' + this.txtCopy + '</button>'))
.appendTo(parent)
.attr('id', 'dlg-share');

View file

@ -246,22 +246,6 @@
});
</script>
<script>
window.config = {
btnsShare: {
'facebook': {
getUrl: (shareurl, title) => `https://www.facebook.com/sharer/sharer.php?u=${shareurl}&t=${encodeURI(title)}`
},
'twitter': {
url: ""
},
'email': {
url: ""
}
}
};
</script>
<!--application-->
<script type="text/javascript" src="../../common/locale.js"></script>
<script type="text/javascript" src="../../common/Gateway.js"></script>