gastor-git
3/21/2017 - 12:19 PM

Кнопки "поделиться" для соц. сетей Social share buttons

Кнопки "поделиться" для соц. сетей Social share buttons

<div class="social-btns">
    <ul class="social-btns__list">
        <li class="social-btns__item">
            <a class="social-btns__vk" rel="nofollow" href="javascript:void(0);" onclick="Share.go(this, 'vkontakte'); return false;">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-vk"></use>
                </svg>
            </a>
        </li>
        <li class="social-btns__item">
            <a class="social-btns__fb" rel="nofollow" href="javascript:void(0);" onclick="Share.go(this, 'facebook'); return false;">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-fb"></use>
                </svg>
            </a>
        </li>
        <?/*<li class="social-btns__item">
            <a class="social-btns__insta" rel="nofollow" href="javascript:void(0);">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-insta"></use>
                </svg>
            </a>
        </li>*/?>
        <li class="social-btns__item">
            <a class="social-btns__twitter" rel="nofollow" href="javascript:void(0);" onclick="Share.go(this, 'twitter'); return false;">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-twitter"></use>
                </svg>
            </a>
        </li>
        <li class="social-btns__item">
            <a class="social-btns__ok" rel="nofollow" href="javascript:void(0);" onclick="Share.go(this, 'odnoklassniki'); return false;">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-odnoklass"></use>
                </svg>
            </a>
        </li>
        <li class="social-btns__item">
            <a class="social-btns__telegram" rel="nofollow" href="javascript:void(0);" onclick="Share.go(this, 'telegram'); return false;">
                <svg class="i-icon i-icon--medium">
                    <use xlink:href="#icon-telegram"></use>
                </svg>
            </a>
        </li>
    </ul>
</div>
<script>
    Share = {
        go: function (a, type, url) {
            type = type || 'facebook';
            url = url || location.href;

            var urlSet = this[type](url);
            var isOpened = this.popup(urlSet);
            if (null === isOpened) {
                a.href = urlSet;
                return true;
            }
            return false;
        },
        telegram: function (purl) {
            url = 'https://telegram.me/share/url?';
            url += 'url=' + encodeURIComponent(purl);
            url += '&text=' + encodeURIComponent('<?=$text?>');
            return url;
        },
        vkontakte: function (purl) {
            url = 'http://vkontakte.ru/share.php?';
            url += 'url=' + encodeURIComponent(purl);
            url += '&title=' + encodeURIComponent('<?=$title?>');
            url += '&description=' + encodeURIComponent('<?=$text?>');
            url += '&image=' + encodeURIComponent('<?=$src?>');
            url += '&noparse=true';
            return url;
        },
        twitter: function (purl) {
            url  = 'http://twitter.com/share?';
            url += 'text='      + encodeURIComponent('<?=$title?>');
            url += '&url='      + encodeURIComponent(purl);
            url += '&counturl=' + encodeURIComponent(purl);
            return url;
        },
        facebook: function (purl) {
            url = 'http://www.facebook.com/sharer.php?s=100';
            url += '&p[title]='     + encodeURIComponent('<?=$title?>');
            url += '&p[summary]='   + encodeURIComponent('<?=$text?>');
            url += '&p[url]='       + encodeURIComponent(purl);
            url += '&p[images][0]=' + encodeURIComponent('<?=$src?>');
            return url;
        },
        odnoklassniki: function(purl) {
            url  = 'http://www.odnoklassniki.ru/dk?st.cmd=addShare&st.s=1';
            url += '&st.comments=' + encodeURIComponent('<?=$text?>');
            url += '&st._surl=' + encodeURIComponent(purl);
            return url;
        },

        popup: function (url) {
            return window.open(url, '', 'toolbar=0,status=0,width=626,height=436');
        }
    };
</script>