var share = function(){ this.init(); }; var p = share.prototype; p.init = function(){ var cur = this; $("div.tk_sharepic a").each(function(){ $(this).click(function(){ var type = $(this).attr("id"); cur.Share(type); }) }) }; p.HTMLEncode = function(html){ var temp = document.createElement("div"); (temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html); var output = temp.innerHTML; temp = null; return output }; p.HTMLDecode = function(text){ var temp = document.createElement("div"); temp.innerHTML = text; var output = temp.innerText || temp.textContent; temp = null; return output }; p.Share = function(type){ var cur = this; var link = ''; var pics = new Array(); switch (type) { //新浪 case 'sina': link = 'http://v.t.sina.com.cn/share/share.php?&url={url}&title={title}&content=gb2312'; break; //facebook case 'face': link = "http://www.facebook.com/share.php?u={url}&title={title}&pic={pic:|}"; break; case 'lin': link = "http://www.linkedin.com/shareArticle?mini=true&ro=true&url={url}&title={title}"; break; } $('img').each(function(i, n) { pics.push(n.src); }); link = link.replace('{title}', encodeURIComponent(cur.HTMLDecode(document.getElementsByTagName('title')[0].innerHTML))); link = link.replace('{url}', encodeURIComponent(window.location.href)); link = link.replace('{pic:|}', pics.join('|')); window.open(link); }; //微信分享代码 // 中文转换字符 function toUtf8(str) { var out, i, len, c; out = ""; len = str.length; for(i = 0; i < len; i++) { c = str.charCodeAt(i); if ((c >= 0x0001) && (c <= 0x007F)) { out += str.charAt(i); } else if (c > 0x07FF) { out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F)); out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } else { out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F)); out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F)); } } return out; } // 调用生成二维码js function creat(){ $("#qrcodeTable").html(""); var str1=window.location.href; var url=toUtf8(str1); $("#qrcodeTable").qrcode({ render : "table", text : url, width:"300", height:"300" }); } var qrcode = new QRCode($('#qrcodeTable')[0], { width : 200, height : 200 }); function makeCode () { qrcode.makeCode(window.location.href); } //兼容火狐、IE8 弹出层js function showMask(){ $("#mask").css("height",$(document).height()); $("#mask").css("width",$(document).width()); $("#mask").show(); } //让指定的DIV始终显示在屏幕正中间 function letDivCenter(divName){ var top = ($(window).height() - $(divName).height())/2; var left = ($(window).width() - $(divName).width())/2; var scrollTop = $(document).scrollTop(); var scrollLeft = $(document).scrollLeft(); $(divName).css( { position : 'absolute', 'top' : top + scrollTop, left : left + scrollLeft } ).show("slow"); } function showAll(divName){ makeCode(); showMask(); letDivCenter(divName); } function hideAll(){ qrcode.clear(); $("#mask").hide(); $("#model").hide("slow"); } function zappenddiv(){ var zz="
"; zz+="
"; zz+="
×

分享到微信朋友圈

"; zz+="
"; zz+=""; zz+="
"; $("body").append(zz); } $(function(){ if($(".share").length>0){ var ii = new share(); } })