PageSourceSearch

http://www.498.net/Home/Tpl/default/js/share.js

js 498.net collected 2026-10-02 15:22:38 UTC 7,042 bytes, 179 lines download raw bytes

1/*
2 * @Description: 分享插件
3 */
4;
5(function($, window, document, undefined) {
6    //插件初始化
7    function init(target, options) {
8        var settings = $.extend({}, $.fn.socialShare.defaults, options);
9        //初始化各个组件
10        var $social_group = "<div class='social_group share_icons'>"
11        + "<a target='_blank' class='msb_network_button weixin a-icon weixin-icon'></a>"
12        + "<a target='_blank' class='msb_network_button sina a-icon sina-icon'></a>"
13        + "<a target='_blank' class='msb_network_button tQQ a-icon qq-icon'></a>"
14        + "</div>"
15        + "<div class='fr'>分享到:</div>";
16        $(target).append($social_group);
17        $(target).addClass("socialShare");
18
19        //添加腾讯微博分享事件
20        $(document).on("click", ".msb_network_button.tQQ", function() {
21            tQQ(this, settings);
22        });
23        //添加QQ空间分享事件
24        $(document).on("click", ".msb_network_button.qZone", function() {
25            qZone(this, settings);
26        });
27        //添加新浪微博分享事件
28        $(document).on("click", ".msb_network_button.sina", function() {
29            sinaWeibo(this, settings);
30        });
31        //添加豆瓣分享事件
32        $(document).on("click", ".msb_network_button.douban", function() {
33            doubanShare(this, settings);
34        });
35        //添加微信分享事件
36        $(document).on("click", ".msb_network_button.weixin", function() {
37            weixinShare(this, settings);
38        });
39    }
40
41    function replaceAPI(api, options) {
42        api = api.replace('{url}', options.url);
43        api = api.replace('{title}', options.title);
44        api = api.replace('{content}', options.content);
45        api = api.replace('{pic}', options.pic);
46        return api;
47    }
48
49    function OPenWindow(URL) {
50        var openUrl = URL; //弹出窗口的url
51        var iWidth = 630; //弹出窗口的宽度;
52        var iHeight = 580; //弹出窗口的高度;
53        var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
54        var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
55        window.open(openUrl, "", "height=" + iHeight + ", width=" + iWidth + ", top=" + iTop + ", left=" + iLeft + "" + ",toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no");
56        //window.open('page.html', 'newwindow', 'height=580, width=650, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
57    }
58
59    function tQQ(target, options) {
60        var options = $.extend({}, $.fn.socialShare.defaults, options);
61        OPenWindow(replaceAPI(tqq, options));
62        //      window.open(replaceAPI(tqq, options));
63    }
64
65    function qZone(target, options) {
66        var options = $.extend({}, $.fn.socialShare.defaults, options);
67        OPenWindow(replaceAPI(qzone, options));
68        //  window.open(replaceAPI(qzone, options));
69    }
70
71    function sinaWeibo(target, options) {
72        var options = $.extend({}, $.fn.socialShare.defaults, options);
73        OPenWindow(replaceAPI(sina, options));
74        //  window.open(replaceAPI(sina, options));
75    }
76
77    function doubanShare(target, options) {
78        var options = $.extend({}, $.fn.socialShare.defaults, options);
79        OPenWindow(replaceAPI(douban, options));
80        //  window.open(replaceAPI(douban, ));
81    }
82
83    function weixinShare(target, options) {
84        var options = $.extend({}, $.fn.socialShare.defaults, options);
85        console.log(options);
86        showWX(replaceAPI(weixin, options));
87
88        //  window.open(replaceAPI(weixin, ));
89    }
90
91    function autocenter() {
92        var bodyW = parseInt(document.documentElement.clientWidth);
93        var bodyH = parseInt(document.documentElement.clientHeight);
94        var elW = $("#weixin").width();
95        var elH = $("#weixin").height();
96        console.log((bodyW - elW) / 2);
97        $("#weixin").css("left", (bodyW - elW) / 2);
98        $("#weixin").css("top", (bodyH - elH) / 2);
99    }
100
101    function showWX(url) {
102        var weixing = '<div id="weixin">' +
103            '<div class="bd_weixin_popup_head">' +
104            '<span>分享到微信朋友圈</span>' +
105            '<a id="close" class="bd_weixin_popup_close">×</a>' +
106            '</div>' +
107            '<div class="erweima">' +
108            '<img class="erweimas" src="" />' +
109            '</div>' +
110            '<p class="msgs">打开微信,点击右上角的  + ,<br/> 使用“扫一扫”即可将网页分享至朋友圈。</p>' +
111            '</div>';
112        $("body").append(weixing);
113        $(".erweimas").attr('src', url);
114        autocenter();
115        $("#weixin").show();
116    }
117    $(document).on('click', "#close", function() {
118        $("#weixin").hide();
119    });
120    $.fn.socialShare = function(options, param) {
121        if(typeof options == 'string') {
122            var method = $.fn.socialShare.methods[options];
123            if(method)
124                return method(this, param);
125        } else
126            init(this, options);
127    }
128
129    //插件默认参数
130    $.fn.socialShare.defaults = {
131        url: window.location.href,
132        title: document.title,
133        content: '',
134        pic: ''
135    }
136
137    //插件方法
138    $.fn.socialShare.methods = {
139        //初始化方法
140        init: function(jq, options) {
141            return jq.each(function() {
142                init(this, options);
143            });
144        },
145        tQQ: function(jq, options) {
146            return jq.each(function() {
147                tQQ(this, options);
148            })
149        },
150        qZone: function(jq, options) {
151            return jq.each(function() {
152                qZone(this, options);
153            })
154        },
155        sinaWeibo: function(jq, options) {
156            return jq.each(function() {
157                sinaWeibo(this, options);
158            });
159        },
160        doubanShare: function(jq, options) {
161            return jq.each(function() {
162                doubanShare(this, options);
163            });
164        },
165        weixinShare: function(jq, options) {
166            return jq.each(function() {
167                weixinShare(this, options);
168            });
169        }
170    }
171
172    //分享地址
173    var qzone = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={url}&title={title}&pics={pic}&summary={content}';
174    var sina = 'http://service.weibo.com/share/share.php?url={url}&title={title}&pic={pic}&searchPic=false';
175    var tqq = 'http://share.v.t.qq.com/index.php?c=share&a=index&url={url}&title={title}&appkey=801cf76d3cfc44ada52ec13114e84a96';
176    var douban = 'http://www.douban.com/share/service?href={url}&name={title}&text={content}&image={pic}';
177    var weixin = 'http://qr.liantu.com/api.php?text={url}'; //接受URL返回图片
178
179})(jQuery, window, document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.