// 重写分享js
$.cxfx = { 
	shareTimelineSuccess: function(){
		console.log('share timeline success.')
	},
	shareTimelineCancel: function(){
		console.log('share timeline cancel.')
	},
	shareAppMessageSuccess: function(){
		console.log('share app message success.')
	},
	shareAppMessageCancel: function(){
		console.log('share app message cancel.')
	},
	error: function(err){
		console.error(err);
	}
};
$(function() {
	var title = $('#share').attr('title');
	var desc = $('#share').attr('desc');
	var shareurl = $('#share').attr('link');
	var imgurl = $('#share').attr('imgurl');
	var appid = $('#share').attr('appid') || "wx1be04c15feb25455";
	if (title || desc || shareurl || imgurl) {
		$.ajax({
			type : "post",
			url : "http://wx.cc-lotus.info/api/jssign?appid=" + appid,
			dataType : 'json',
			success : function(result) {
				if (result.errcode == 0) {
					wx.config({
						debug : false,
						appId : appid,
						timestamp : result.timestamp,
						nonceStr : result.noncestr,
						signature : result.sign,
						jsApiList : [ 'onMenuShareTimeline',
								'onMenuShareAppMessage', 'hideMenuItems' ]
					});
					wx.ready(function() {
						if (shareurl == "disable") {
							wx.hideMenuItems({
								menuList : [ 'menuItem:share:appMessage',
										'menuItem:share:timeline',
										'menuItem:share:qq',
										'menuItem:share:weiboApp',
										'menuItem:share:QZone',
										'menuItem:copyUrl',
										'menuItem:openWithQQBrowser',
										'menuItem:openWithSafari',
										'menuItem:share:facebook' ]
							})
						} else {
							wx.onMenuShareAppMessage({
								title : title,
								desc : desc,
								link : shareurl,
								imgUrl : imgurl,
								success : function() {
									if($.cxfx.shareAppMessageSuccess){
										$.cxfx.shareAppMessageSuccess();
									}
								},
								cancel : function() {
									if($.cxfx.shareAppMessageCancel){
										$.cxfx.shareAppMessageCancel();
									}
								}
							});
							wx.onMenuShareTimeline({
								title : title,
								desc : desc,
								link : shareurl,
								imgUrl : imgurl,
								success : function() {
									if($.cxfx.shareTimelineSuccess){
										$.cxfx.shareTimelineSuccess();
									}
								},
								cancel : function() {
									if($.cxfx.shareTimelineCancel){
										$.cxfx.shareTimelineCancel();
									}
								}
							})
						}
					});
					wx.error(function(err) {
						if($.cxfx.error){
							$.cxfx.error(err);
						}
					})
				} else {
				}
			}
		})
	}
});