$(function() { if (!$('#HTMLDATA').length) { //处理结构 var share_ele = ['sqq', 'weixin', 'tsina', 'qzone', 'tieba'] var followtop = $(window).height() * 0.5; $(".wqd-share ").each(function() { $(this).addClass("share-list").attr({ 'data-url': window.location.href, "data-text": $(this).closest("[sharetext]").attr("sharetext"), "data-desc": $(this).closest("[sharetext]").attr("sharetext"), 'data-pic': $(this).closest("[qqerweima]").attr("qqerweima"), 'data-summary': $(this).closest("[sharetext]").attr("sharetext") }); $(this).children().each(function() { $(this).addClass("btn-share").attr({ "data-type": share_ele[$(this).index()] }) }) }); $("body").append($('')); $("body").click(function() { $("#J_qr_code_share").hide(200); }) $("head").prepend(''); $(' ').appendTo("body"); //关注设置 // $('.wqd-follow li').on('click', function() { // window.open($(this).attr("url")) // }); $("body").append("") $(".follow_box").css({ "margin-top": -135 + "px", "margin-left": -120 + "px" }); $('.wqd-follow li').each(function() { var index = $(this).index(); var that = $(this); $(this).click(function() { if (index > 1) { window.open($(this).attr("url")); } if (index <= 1) { if (index == 0 && $("[qqerweima]")) { var qqbgurl = "url(" + that.parents(".wqdelementEdit").attr("qqerweima") + ")"; $(".follow_box").show(200).css({ background: "#fff" }).find("p").css({ "background-image": qqbgurl }).end().find(".follow_txt").text("关注QQ帐号"); } if (index == 1 && $("[wxerweima]")) { var wxbgurl = "url(" + that.parents(".wqdelementEdit").attr("wxerweima") + ")"; $(".follow_box").show(200).css({ background: "#fff" }).find("p").css({ "background-image": wxbgurl }).end().find(".follow_txt").text("关注微信帐号"); } } }) }) $(".follow_close").click(function() { $(".follow_box").hide(200); }); } }) //分享组件 ; (function($) { $(function() { var uid = +new Date; Share(uid); }); function Share(uid, options) { /** * 初始化分享 * @param {String} uid 用户的百度分享AK * @return this; * */ if (!(this instanceof Share)) { return new Share(); } this.uid = uid; this.url = 'http://s.share.baidu.com/'; this.title = document.title; this.size = 'height=500,width=700,left=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no'; this.render = 'table'; this.options = $.extend({}, { render: this.render, width: 120, height: 120, background: "#fff", foreground: "#000", text: '' }, options); this.isLoad = false; this.init(); } Share.prototype = { constructor: 'Share', init: function() { var that = this; $('body').css("position", "relative").off('click.share', '.btn-share').on('click.share', '.btn-share', function(event) { var _self = $(this), type = _self.data('type'), data = _self.parent('.share-list').data(); if ($(this).attr("data-type") == "weixin") { $("#J_qr_code_share").css({ top: $(window).width() > 1200 ? ($(window).height() * 0.5) : ("280px!important"), left: $(window).width() * 0.5 }).show(); } that.fire(type, data, _self); event.stopPropagation(); }) }, setwin: function(w, d) { var iWidth = w; //弹出窗口的宽度; var iHeight = d; //弹出窗口的高度; var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置; var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置; return { iTop: iTop, iLeft: iLeft } }, fire: function(t, d, self) { var that = this, query = that.set(t, d); this.load(query); if (t === 'weixin') { if (!that.isLoad) { var qrcode = document.createElement('script'); qrcode.src = 'javascripts/jquery.qrcode.min.js'; document.head.appendChild(qrcode); that.isLoad = true; qrcode.onload = function() { that.renderQrCode(self); }; } that.renderQrCode(self); return; } else if (t === "qzone") { (function() { var p = { url: location.href, showcount: '1', desc: d.desc, summary: d.summary, title:/\/template/g.test(location.href)==true?document.title.replace(/微企点/g,"本公司"):document.title, site: document.domain, pics: d.pic, style: '203', width: 98, height: 22 }; var s = []; for (var i in p) { s.push(i + '=' + encodeURIComponent(p[i] || '')); } window.open("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?" + s.join('&'), "newwindow", "width=601,height=590, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no" + ",top=" + that.setwin(601, 590).iTop + ",left=" + that.setwin(601, 590).iLeft) })(); return; } else if (t === "sqq") { var p = { url: d.url, desc: d.desc, title:/\/template/g.test(location.href)==true?document.title.replace(/微企点/g,"本公司"):document.title, summary: d.summary, pics: d.pic, flash: '', site: document.domain, style: '201', width: 32, height: 32 }; var s = []; for (var i in p) { s.push(i + '=' + encodeURIComponent(p[i] || '')); } window.open("http://connect.qq.com/widget/shareqq/index.html?" + s.join('&'), "newwindow", "width=721,height=572, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no" + ",top=" + that.setwin(721, 567).iTop + ",left=" + that.setwin(721, 567).iLeft); return; } this.open(query); }, /** * 设置分享内容 * @param {String} type 分享到的社交媒体,如tsina,qqzone,以data-type的形式存储在 .btn-share 标签上 * @param {Object} data 需要分享的hash表,以data-***的形式存储在 .share-list 标签上 * @return {String} queryString 序列化的分享内容url字符串; * */ set: function(type, data) { var query = {}; query.click = 1; query.url = (data.url || ""); query.uid = this.uid; query.to = type; query.type = "text"; query.relateUid = data.wbuid || ""; query.pic = (data.pic || ""); query.title =/\/template/g.test(location.href)==true?document.title.replace(/微企点/g,"本公司"):this._formatTitle(data.text); query.key = ""; query.sign = "on"; query.desc = (data.desc || ""); query.summary = (data.summary || ""); query.comment = encodeURIComponent(data.comment || ""); query.searchPic = 0; query.l = this.time(); query.linkid = this.string(); query.sloc = ""; query.apiType = 0; query.buttonType = 0; query.site = "bshare"; this.options.text = query.url; return '?' + $.param(query); }, load: function(query) { var img = new Image(); img.onload = function() { img = img.onload = null; }; img.src = this.url + "commit" + query + "&t=" + Math.random(); }, open: function(query) { var that = this; window.open(that.url + query, "_blank", "width=721,height=572, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no" + ",top=" + that.setwin(721, 567).iTop + ",left=" + that.setwin(721, 567).iLeft); }, time: function() { var t = +new Date, e = t + 1000, n = t + 3000; return t.toString(32) + e.toString(32) + n.toString(32) }, string: function() { var t = (new Date).toString(36), e = Math.random().toString(36).substr(3); return t + e }, _formatTitle: function(text) { return text ? (text.substr(0, 120)) : this.title; }, renderQrCode: function(self) { var that = this; var followtop = $(window).height() * 0.5; $('#J_qr_code_share').empty().append('扫码查看').qrcode({ text: window.location.href, width: 210, height: 210, }).css({ top: followtop, left: self.offset().left - that.options.width / 2 + 30 }).show(200); }, _randomString: function(str, e) { var n = str.length, o = "", i = 1; while (i < n) { var a = Math.floor(n * Math.random()); o += str.charAt(a); i++; } return o } }; window.Share = function() { return Share(); } }(window.jQuery)); //微信分享 var wxShare = function() { //引入 $("body").append("