1(function ($) { 2 $.fn.share = function ($options) { 3 var $head = $(document.head); 4 5 var $defaults = { 6 url: getSharedUrl(), 7 site_url: location.origin, 8 source: $head.find('[name=site], [name=Site]').attr('content') || document.title, 9 title: $head.find('[name=title], [name=Title]').attr('content') || document.title, 10 description: $head.find('[name=description], [name=Description]').attr('content') || '', 11 image: $('img:first').prop('src') || '', 12 13 imageSelector: undefined, 14 15 weiboKey: '', 16 17 wechatQrcodeDialogId: 'share_weixin_qrcode_dialog_qr', //微信äºç»´ç å¼¹çªçID 18 wechatQrcodeTitle: '微信æ«ä¸æ«ï¼å享', 19 wechatQrcodeHelper: '<p>微信éç¹âåç°âï¼æ«ä¸ä¸</p><p>äºç»´ç 便å¯å°æ¬æåäº«è³æååã</p>', 20 wechatQrcodeSize: 200, 21 22 mobileSites: [], 23 sites: ['weibo', 'qq', 'wechat', 'tencent', 'douban', 'qzone'], 24 disabled: [], 25 initialized: false 26 }; 27 28 var $globals = $.extend({}, $defaults, $options); 29 30 var $templates = { 31 qzone: 32 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url={{URL}}&title={{TITLE}}&desc={{DESCRIPTION}}&summary={{SUMMARY}}&site={{SOURCE}}&pics={{IMAGE}}', 33 qq: 34 'http://connect.qq.com/widget/shareqq/index.html?url={{URL}}&title={{TITLE}}&source={{SOURCE}}&desc={{DESCRIPTION}}&pics={{IMAGE}}', 35 tencent: 'http://share.v.t.qq.com/index.php?c=share&a=index&title={{TITLE}}&url={{URL}}&pic={{IMAGE}}', 36 weibo: 37 'https://service.weibo.com/share/share.php?url={{URL}}&title={{TITLE}}&pic={{IMAGE}}&appkey={{WEIBOKEY}}', 38 //weibo: 'https://service.weibo.com/share/share.php?url={{URL}}&title={{TITLE}}&appkey={{WEIBOKEY}}&searchPic=false', //å¦éè¦å»æå¾®åå享å¾çç请æå¾®å龿¥æ¿æ¢æè¿ä¸ª 39 wechat: 'javascript:;', 40 douban: 41 'http://shuo.douban.com/!service/share?href={{URL}}&name={{TITLE}}&text={{DESCRIPTION}}&image={{IMAGE}}&starid=0&aid=0&style=11' 42 }; 43 44 var $ariaLabels = { 45 qzone: "QQ空é´", 46 qq: "QQ", 47 tencent: "è ¾è®¯å¾®å", 48 weibo: "å¾®å", 49 wechat: "微信", 50 douban: "è±ç£" 51 }; 52 53 this.each(function () { 54 if ($(this).data('initialized')) { 55 return true; 56 } 57 58 var $data = $.extend({}, $globals, $(this).data()); 59 if ($data.imageSelector) { 60 $data.image = $($data.imageSelector).map(function () { 61 return $(this).prop('src'); 62 }).get().join('||'); 63 } 64 var $container = $(this).addClass('share-component social-share'); 65 66 createIcons($container, $data); 67 createWechat($container, $data); 68 69 $(this).data('initialized', true); 70 }); 71 72 function createIcons($container, $data) { 73 var $sites = getSites($data); 74 75 $data.mode == 'prepend' ? $sites.reverse() : $sites; 76 77 if (!$sites.length) { 78 return; 79 } 80 81 $.each($sites, 82 function (i, $name) { 83 var $url = makeUrl($name, $data); 84 var $link = $data.initialized 85 ? $container.find('.icon-' + $name) 86 : $('<a href="javascript:;" class="social-share-icon icon-' + $name + '"></a>'); 87 88 if (!$link.length) { 89 return true; 90 } 91 $link.prop('aria-label', "åäº«å° " + $ariaLabels[$name]); 92 93 $link.prop('href', $url); 94 95 if ($name === 'wechat') { 96 $link.prop('tabindex', -1); 97 } else { 98 $link.prop('target', '_blank'); 99 } 100 101 if (!$data.initialized) { 102 $data.mode == 'prepend' ? $container.prepend($link) : $container.append($link); 103 } 104 }); 105 } 106 107 function createWechat($container, $data) { 108 var $wechat = $container.find('a.icon-wechat'); 109 110 if (!$wechat.length) { 111 return; 112 } 113 114 $("body").append('<div class="wechat-qrcode share-wechat-qrcode" id="' + 115 $data.wechatQrcodeDialogId + 116 '"><div class="close">x</div><h4>' + 117 $data.wechatQrcodeTitle + 118 '</h4><div class="qrcode" data-powertype="qrcode" data-size="' + 119 $data.wechatQrcodeSize + 120 '"></div><div class="help">' + 121 $data.wechatQrcodeHelper + 122 '</div></div>'); 123 124 //å å ¥å¾®ä¿¡å享ç¹å»äºä»¶ 125 $('a.icon-wechat').click(function () { 126 $("#" + $data.wechatQrcodeDialogId).show(); 127 }); 128 $("#" + $data.wechatQrcodeDialogId + " .close").click(function () { 129 $("#" + $data.wechatQrcodeDialogId).hide(); 130 }); 131 132 // if ($wechat.offset().top < 100) { 133 // $wechat.find('.wechat-qrcode').addClass('bottom'); 134 // } 135 } 136 137 function getSites($data) { 138 if ($data['mobileSites'].length === 0 && $data['sites'].length) { 139 $data['mobileSites'] = $data['sites']; 140 }; 141 142 var $sites = 143 (isMobileScreen() ? $data['mobileSites'] : ($data['sites'].length ? $data['sites'] : [])).slice(0); 144 var $disabled = $data['disabled']; 145 146 if (typeof $sites == 'string') { 147 $sites = $sites.split(/\s*,\s*/); 148 } 149 if (typeof $disabled == 'string') { 150 $disabled = $disabled.split(/\s*,\s*/); 151 } 152 153 if (runningInWeChat()) { 154 $disabled.push('wechat'); 155 } 156 // Remove elements 157 $disabled.length && 158 $.each($disabled, 159 function (i, el) { 160 var removeItemIndex = $.inArray(el, $sites); 161 if (removeItemIndex !== -1) { 162 $sites.splice(removeItemIndex, 1); 163 } 164 }); 165 166 return $sites; 167 } 168 169 function makeUrl($name, $data) { 170 var $template = $templates[$name]; 171 $data['summary'] = $data['description']; 172 173 for (var $key in $data) { 174 if ($data.hasOwnProperty($key)) { 175 var $camelCaseKey = $name + 176 $key.replace(/^[a-z]/, 177 function ($str) { 178 return $str.toUpperCase(); 179 }); 180 181 var $value = 182 encodeURIComponent($data[$camelCaseKey] === undefined ? $data[$key] : $data[$camelCaseKey]); 183 $template = $template.replace(new RegExp('{{' + $key.toUpperCase() + '}}', 'g'), $value); 184 } 185 } 186 187 return $template; 188 } 189 190 function runningInWeChat() { 191 return /MicroMessenger/i.test(navigator.userAgent); 192 } 193 194 function isMobileScreen() { 195 return $(window).width() <= 768; 196 } 197 198 function getSharedUrl() { 199 var hrefUrl = location.href; 200 var query = location.search; 201 if (query) { 202 if (query.indexOf('SessionVerify=') > -1) { 203 return location.origin + location.pathname; 204 } 205 } 206 207 return hrefUrl; 208 } 209 }; 210 211 // Domready after initialization 212 $(function () { 213 $('.share-component,.social-share').share(); 214 }); 215 216})(jQuery);
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.