123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- function WX_share(b,c,d,e){var f=navigator.userAgent,g=-1<f.indexOf("Android")||-1<f.indexOf("Adr");f.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)&&(function(a){window.WebViewJavascriptBridge?a(WebViewJavascriptBridge):document.addEventListener("WebViewJavascriptBridgeReady",function(){a(WebViewJavascriptBridge)},!1)}(function(a){a.init(function(a,b){alert("Received message: "+a);b&&b("Right back atcha")});a.send({url:b,typeid:8,depict:c,title:d,picture:e});a.send("Please respond to this",function(a){alert("Javascript got its response",
- a)})}),window.webkit.messageHandlers.JS_Call_OC_login.postMessage({url:b,typeid:8,depict:c,title:d,picture:e}));g&&Android.share(b,c,d,e)};
- ;(function($, window, document, undefined) {
- function regist(mName, module) {
- if (typeof window.brickjs === "undefined") {
- window.brickjs = {};
- }
- brickjs[mName] = module;
- }
- ;
- var isWeixin = navigator.userAgent.toLowerCase().indexOf("micromessenger") > -1;
- function MShare(cfgs, selector) {
- this._cfgs = {
- site: "",
- catalog: "",
- sUrl: window.location.href,
- title: document.title,
- imgUrl: "",
- desc: "",
- appKey: "",
- ralateUid: "",
- source_id:"",
- source_table :"",
- timelineCallback: function() {},
- sendMessageCallback: function() {},
- shareQQCallback: function() {},
- wxGuide: {
- tpl: '',
- imgUrl: 'http://css.selfimg.com.cn/vogue/mdiscovery/images/weixin-guide.png',
- width: 295,
- height: 273,
- style: {
- right: 0,
- top: 0
- }
- }
- };
- this.weixinSigned = 0;
- this.trigger = $(selector);
- this._baseUrl = "/collect.";
- this._tsinaParam = "get?platform=tsina&title={title}&url={url}&pic={pic}&site={site}&source_id={source_id}&source_table={source_table}&ralateUid={ralateUid}&appkey={appkey}&hash={hash}";
- this._init(cfgs, selector);
- this._reflux();
- }
- MShare.prototype = {
- _init: function(cfgs, selector) {
- var self = this;
- $.extend(true, this._cfgs, cfgs)
- if (selector) {
- $(selector).on('click', function() {
- if (isWeixin) {
- self._weixinGuide();
- } else {
- self._weiboShare($(this));
- }
- })
- }
- if (isWeixin) {
- this.weixinInit();
- }
- },
- _weixinGuide: function() {
- var cfg = this._cfgs,
- weixinCfg = cfg.wxGuide,
- defImg = weixinCfg.imgUrl,
- tpl = weixinCfg.tpl || '<div id="weixin_guide" style="position: fixed;background:url(http://css.selfimg.com.cn/cnt/mobile/images/blk80.png) repeat;left:0;top:0;right:0;bottom:0;z-index:1000;"><img src="' + defImg + '" style="position: absolute;z-index:100;" width="' + weixinCfg.width + '" height="' + weixinCfg.height + '"/></div>';
- $('#weixin_guide').remove();
- $(tpl).attr('id', 'weixin_guide').appendTo($('body'));
- $('#weixin_guide img').css(weixinCfg.style || {})
- setTimeout(function() {
- $('#weixin_guide').click(function() {
- $(this).remove();
- })
- }, 300)
- },
-
- weixinInit: function(cfgs) {
- var self = this,
- wxCfgs;
- cfgs && $.extend(true, this._cfgs, cfgs);
- wxCfgs = {
- "site": this._cfgs.website,
- "img_url": this._cfgs.imgUrl || "",
- "link": this._cfgs.sUrl || location.href,
- "desc": this._cfgs.desc || "",
- "title": this._cfgs.title || document.title,
- timelineCallback: this._cfgs.timelineCallback,
- sendMessageCallback: this._cfgs.sendMessageCallback,
- shareQQCallback: this._cfgs.shareQQCallback
- }
-
- var url = VG.conf.root_domain + '?c=WeixinJsSDK&a=AjaxConfigData&thisPageUrl=' + location.href.split('#')[0];
- var state = false;
- if (location.href.indexOf('test') > -1) {
- var state = true;
- }
-
- $.ajax({
- type:'post',
- dataType:'jsonp',
- jsonp: 'jsonp_cb',
- url: url,
-
- success:function(data){
- var d = data.msg;
-
- wx.config({
-
- appId: d.appId,
- timestamp: d.timestamp,
- nonceStr: d.nonceStr,
- signature: d.signature,
- jsApiList: [
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage',
- 'onMenuShareQQ'
- ]
- });
-
- wx.ready(function() {
-
- if (state) {
-
- }
- wx.onMenuShareAppMessage({
- title: wxCfgs.title,
- desc: wxCfgs.desc,
- link: wxCfgs.link,
- imgUrl: wxCfgs.img_url,
- success: function(res) {
- if (state) {
- alert(1);
- }
- wxCfgs.sendMessageCallback('success', res)
- self._shareLog(0, 1);
- },
- cancel: function(res) {
- if (state) {
- alert(2);
- }
- wxCfgs.sendMessageCallback('cancel', res)
- self._shareLog(0, 2);
- },
- fail: function(res) {
- if (state) {
- alert(3);
- }
- wxCfgs.sendMessageCallback('fail', res)
- self._shareLog(0, 0);
- }
- });
- wx.onMenuShareTimeline({
- title: wxCfgs.title,
- link: wxCfgs.link,
- imgUrl: wxCfgs.img_url,
- success: function(res) {
- if (state) {
- alert(1);
- }
- wxCfgs.timelineCallback('success', res)
- self._shareLog(1, 1);
- },
- cancel: function(res) {
- if (state) {
- alert(2);
- }
- wxCfgs.timelineCallback('cancel', res)
- self._shareLog(1, 2);
- },
- fail: function(res) {
- if (state) {
- alert(3);
- }
- wxCfgs.timelineCallback('fail', res)
- self._shareLog(1, 0);
- }
- });
- wx.onMenuShareQQ({
- title: wxCfgs.title,
- link: wxCfgs.link,
- imgUrl: wxCfgs.img_url,
- success: function(res) {
- wxCfgs.shareQQCallback('success', res)
- self._shareLog(2, 1);
- },
- cancel: function(res) {
- wxCfgs.shareQQCallback('cancel', res)
- self._shareLog(2, 2);
- },
- fail: function(res) {
- wxCfgs.shareQQCallback('fail', res)
- self._shareLog(2, 0);
- }
- });
- });
- },
- async:'true',
- timeout: 3000
- });
-
-
- },
-
- reset: function(cfg) {
- var self = this;
- if (!isWeixin) {
- cfg.sUrl && self.trigger.data('sUrl', cfg.sUrl);
- cfg.desc && self.trigger.data('desc', cfg.desc);
- cfg.imgUrl && self.trigger.data("imgUrl", cfg.imgUrl);
- } else {
- this.weixinInit({
- sUrl: cfg.sUrl || self._cfgs.sUrl,
- desc: cfg.desc || self._cfgs.desc,
- imgUrl: cfg.imgUrl || self._cfgs.imgUrl,
- title: cfg.title || self._cfgs.title
- });
- }
- },
- _reflux: function() {
- var refer = document.referrer,
- url = document.location.href,
- param = location.search.substr(1),
- ua = navigator.userAgent;
- if (param.indexOf("tsina-") > -1 || param.indexOf("timeline") > -1 || param.indexOf("singlemessage") > -1 || param.indexOf("groupmessage") > -1) {
- $.getJSON(this._baseUrl + "reflux?" + "callback=?" + "&url=" + encodeURIComponent(url) + '&ua=' + ua + '¶m=' + encodeURIComponent(param));
- }
- },
- _shareLog: function(actType, actResult) {
- var site = this._cfgs.website;
-
- },
- _weiboShare: function(trigger) {
- var self = this;
- var cfg = this._cfgs,
- params = {
- title: cfg.desc,
- url: cfg.sUrl,
- pic: cfg.imgUrl,
- site: cfg.site,
- cat: cfg.catalog,
- source_id: cfg.source_id,
- source_table: cfg.source_table,
- ralateUid: cfg.ralateUid,
- appkey: cfg.appKey.tsina
- },
- tgUrl = trigger.data('sUrl'),
- tgTitle = trigger.data('desc'),
- tgPic = trigger.data("imgUrl");
- params.title = encodeURIComponent(tgTitle ? tgTitle : params.title);
- params.url = encodeURIComponent(tgUrl ? tgUrl : params.url);
- params.pic = encodeURIComponent(tgPic ? tgPic : params.pic);
- var cmdUrl = this._baseUrl + self._formatUri(this._tsinaParam, params);
- window.open(cmdUrl);
- },
- _formatUri: function(uri, params) {
- var reg, uri = uri;
- for (var k in params) {
- reg = new RegExp("{" + k + "}", "g");
- uri = uri.replace(reg, params[k]);
- }
- return uri;
- }
- }
- ;regist("MShare",MShare);
- })((typeof Zepto !== 'undefined' ? Zepto : jQuery), window, document)
|