share.js 3.24 KB
/*var $ = require('yoho.jquery');

module.exports = function(options) {
    var openUrl = '';
    var defOption = {
        title: '',
        url: window.location.href,
        weixinUrl: '',
        image: '',
        desc: '',
        channel: ''
    };
    var shareChannels = ['weibo', 'tqq', 'qzone', 'renren', 'qq', 'douban','weixin'];
    var sharebox;
    var shareCon = '<em><i></i></em>';

    defOption = $.extend(defOption, options);
    this.weibo = function() {
        openUrl = 'http://service.weibo.com/share/share.php?url=' +
                defOption.url + '&title=' + defOption.title +
                '&appkey=3739328910&searchPic=true&pic=' + defOption.image;
    };
    this.tqq = function() {
        openUrl = 'http://share.v.t.qq.com/index.php?c=share&a=index&url=' +
        defOption.url + '&title=' + defOption.title +
        '&appkey=c0af9c29e0900813028c2ccb42021792&pic=' + defOption.image;
    };
    this.qzone = function() {
        openUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' +
        defOption.url + '&title=' + defOption.title +
        '&desc=&summary=' + defOption.desc + '&site=YOHO!有货&pics=' + defOption.image;
    };
    this.renren = function() {
        openUrl = 'http://widget.renren.com/dialog/share?resourceUrl=' +
        defOption.url + '&srcUrl=' + defOption.url + '&desc=' + defOption.desc +
        '&title=' + defOption.title + '&description=' +
        defOption.desc + '&pic=' + defOption.image;
    };
    this.qq = function() {
        openUrl = 'http://connect.qq.com/widget/shareqq/index.html?url=' +
        defOption.url + '&desc=' + defOption.desc + '&title=' +
        defOption.title.replace('%', '') + '&desc=&summary=' + defOption.desc +
        '&site=YOHO!有货&pics=' + defOption.image;
    };
    this.weixin = function() {
        openUrl = 'http://s.jiathis.com/qrcode.php?url=' +
        defOption.weixinUrl + '&desc=' + defOption.desc + '&title=' + defOption.title +
        '&description=' + defOption.desc + '&pic=' + defOption.image;
    };
    this.douban = function() {
        openUrl = 'http://www.douban.com/share/service?href=' +
        defOption.url + '&text=' + defOption.desc + '&image=' + defOption.image +
        '&title=' + defOption.title + '&comment=';
    };
    if ($.inArray(defOption.channel, shareChannels) === -1) {
        alert('不存在的分享平台!');
        return false;
    }
    eval(defOption.channel + '();');
    if (defOption.channel === 'weixin') {
        if (defOption.self && defOption.self.closest('.share-to').find('.shareWeixin')) {
            sharebox = defOption.self.closest('.share-to').find('.shareWeixin');
            shareCon += '<div class="con"><h2>分享到微信朋友圈</h2><p class="pic">' +
            '<img src="' + openUrl + '" /></p><p class="w">打开微信,点击底部得“发现”,使用<br/>“扫一扫“即可将网页分享到我的朋友圈。</p>' +
            '<a href="javascript:void(0)" class="close">x</a></div>';
            sharebox.find('div').length > 0 ? sharebox.show() : sharebox.html(shareCon).show();

            sharebox.find('.close').click(function() {
                $(this).closest('.shareWeixin').hide();
            });
        }
    } else {
        window.open(encodeURI(openUrl));
    }
};*/