$(function () { // 分享插件功能 $.fn.globalShare = function () { // 获取对象 var _this = this; var win_w = $(window).width(); var headObj = $(document.head); // 初始化 var defaults = { url: location.href, site_url: location.origin, title: headObj.find('[name=title], [name=Title]').attr('content') || document.title, description: headObj.find('[name=description], [name=Description]').attr('content') || '', image: $('img:first').prop('src') || '', wechatQrcodeTitle: $("html").hasClass("LANG-cn") ? '使用微信扫描二维码' : "Use Wechat scan QR code", sites: ['favorite', 'weibo', 'qq', 'wechat', 'tencent', 'douban', 'qzone', 'linkedin', 'diandian', 'facebook', 'twitter', 'google'], isInit: false, email: "information@huawei.com", } // 定义模块 var templates = { wechat: 'javascript:;', weibo: 'https://service.weibo.com/share/share.php?url={{URL}}&title={{TITLE}}&pic={{IMAGE}}', linkedin: 'https://www.linkedin.com/shareArticle?mini=true&ro=true&title={{TITLE}}&url={{URL}}&summary={{DESCRIPTION}}&source={{TITLE}}&armin=armin', facebook: 'https://www.facebook.com/sharer/sharer.php?u={{URL}}', twitter: 'https://twitter.com/intent/tweet?text={{TITLE}}&url={{URL}}&via={{SITE_URL}}', google: 'https://plus.google.com/share?url={{URL}}', email: 'mailto:{{EMAIL}}?subject={{TITLE}}&body={{URL}}' + encodeURIComponent('\n') + '{{DESCRIPTION}}', print: 'javascript:window.print();void(0)' } // 初始化 init(); function init() { _this.each(function () { var _this = $(this); // 是否需要初始化 if (_this.data('isInit')) { return true; } // 合并最新的配置参数 var newDefaults = $.extend({}, defaults, _this.data()); // 获取html结构 var getHtml = createHtml(_this, newDefaults); // 把结构放进social-share dom里 _this.html('') _this.append(getHtml) // 创建微信二维码 createWechat(_this, newDefaults); }); } // 创建微信 function createWechat(conObj, newDefaults) { var wechatObj = conObj.find('a.icon-wechat'); wechatObj.append('
' + newDefaults.wechatQrcodeTitle + '