123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- /* ================================================================================
- * dever.js v1.0
- * http://git.shemic.com/dever/script
- * ================================================================================
- * Copyright 2017-2018 Dever(dever.cc)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ================================================================================
- */
- //<filter><script src="../js/lib/jquery.min.js"></script><script src="../js/dever.js"></script></filter>
- //分享 暂时只支持手机版微信分享 请同时安装wechat组件
- var Dever_Share =
- {
- wechat : false,
- url : '',
- project : '',
- uid : '-1',
- param : {
- title : '',
- img : '',
- desc : '',
- url : '',
- timelineCallback: function() {},
- sendMessageCallback: function() {},
- shareQQCallback: function() {}
- },
- Init : function(uid, project, url, param, button)
- {
- var self = this;
- self.wechat = self.CheckWechat();
- self.project = project;
- self.url = url;
- self.uid = uid;
- //self.param = param;
- $.extend(true, self.param, param)
- if (button) {
- $(button).on('click', function() {
- if (self.wechat == 1) {
- self.WechatGuide();
- } else {
- self.WeiboShare($(this));
- }
- })
- }
- if (self.wechat == 1) {
- self.WechatInit();
- }
- self.Reflux();
- }
- ,CheckWechat : function()
- {
- var state = navigator.userAgent.toLowerCase().indexOf("micromessenger") > -1;
- if (state) {
- return 1;
- } else {
- return 2;
- }
- }
- ,WechatGuide : function()
- {
- var param = this.param;
- var tpl = '<div id="weixin_guide" style="position: fixed;background:url(../img/background.png) repeat;left:0;top:0;right:0;bottom:0;z-index:1000;"><img src="../img/weixin-guide.png" style="position: absolute;z-index:100;" width="295" height="273"/></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)
- }
- ,WechatInit: function()
- {
- var self = this;
- var url = this.url + 'init?callback=?';
- var param = this.param;
- var project = this.project;
- $.ajax({
- type:'post',
- dataType:'jsonp',
- jsonp: 'jsonp_cb',
- url: url,
- data: {
- 'project' : project,
- 'url' : location.href.split('#')[0]
- },
- success:function(result) {
- var data = result.data;
- wx.config({
- //debug:true,
- appId: data.appId,
- timestamp: data.timestamp,
- nonceStr: data.nonceStr,
- signature: data.signature,
- jsApiList: [
- 'updateTimelineShareData',//'onMenuShareTimeline',
- 'updateAppMessageShareData',//'onMenuShareAppMessage',
- //'onMenuShareQQ'
- ]
- });
- wx.ready(function() {
- wx.updateAppMessageShareData({
- title: param.title,
- desc: param.desc,
- link: param.url,
- imgUrl: param.img,
- success: function(res) {
- //param.sendMessageCallback('success', res)
- //self.ShareLog(1, 1);
- },
- });
- wx.updateTimelineShareData({
- title: param.title,
- link: param.url,
- imgUrl: param.img,
- success: function(res) {
- //param.timelineCallback('success', res)
- //self.ShareLog(2, 1);
- },
- });
- /*
- wx.onMenuShareQQ({
- title: param.title,
- link: param.url,
- imgUrl: param.img,
- success: function(res) {
- param.shareQQCallback('success', res)
- self.ShareLog(3, 1);
- },
- cancel: function(res) {
- param.shareQQCallback('cancel', res)
- self.ShareLog(3, 2);
- },
- fail: function(res) {
- param.shareQQCallback('fail', res)
- self.ShareLog(3, 3);
- }
- });*/
- });
- },
- async:'true',
- timeout: 3000
- });
- }
- ,Reflux: function() {
- var refer = document.referrer,
- url = encodeURIComponent(document.location.href),
- param = location.search.substr(1),
- ua = encodeURIComponent(navigator.userAgent),
- project = this.project,
- uid = this.uid,
- wechat = this.wechat;
- if (param.indexOf("tsina-") > -1 || param.indexOf("timeline") > -1 || param.indexOf("singlemessage") > -1 || param.indexOf("groupmessage") > -1) {
- $.getJSON(this.url + 'reflux?callback=?' + '&project='+project+'&url=' + url + '&ua=' + ua + '¶m=' + encodeURIComponent(param) + '&uid=' + uid + '&type=' + wechat);
- }
- }
- ,ShareLog: function(actType, actResult) {
- var project = this.project;
- var uid = this.uid;
- var wechat = this.wechat;
- var ua = encodeURIComponent(navigator.userAgent);
- var url = encodeURIComponent(document.location.href);
- $.getJSON(this.url + 'collect?callback=?' + '&project='+project+'&url=' + url + '&actType=' + actType + '&actResult=' + actResult + '&ua=' + ua + '&uid=' + uid + '&type=' + wechat);
- }
- }
|