!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).WechatJSSDK=e()}(this,(function(){var t=["updateAppMessageShareData","updateTimelineShareData","onMenuShareTimeline","onMenuShareAppMessage"],e=["wx-open-subscribe","wx-open-audio"];return function(){function i(n){if(this instanceof i){this.sdkUrl="//res.wx.qq.com/open/js/jweixin-1.6.0.js",this.config=n||{},this.config.customUrl&&(this.sdkUrl=this.config.customUrl);var s=this.config.jsApiList,r=this.config.openTagList;return(!s||s.length<=0)&&(this.config.jsApiList=t),(!r||r.length<=0)&&(this.config.openTagList=e),this.debug=!!this.config.debug,this}return new i(n)}var n=i.prototype;return n.initialize=function(){return this.loadScript()},n.signSignature=function(t){var e=this,i=this.config,n=t||i,s={debug:this.debug,appId:i.appId,timestamp:n.timestamp||i.timestamp,nonceStr:n.nonceStr||i.nonceStr,signature:n.signature||i.signature,jsApiList:i.jsApiList.slice(0,i.jsApiList.length),openTagList:i.openTagList.slice(0,i.openTagList.length)},r=this.debug;return new Promise((function(t,i){if(!window.wx)return i(new Error("wx js not defined"));var n=window.wx;e.setOriginWx(),n.config(s),n.ready((function(){console.log("sign signature finished..."),e.setOriginWx(),t(e)})),n.error((function(t){r&&alert("sign error: "+JSON.stringify(t)),e.setOriginWx(),i(t)}))}))},n.loadScript=function(){var t=this;return new Promise((function(e,i){var n=document.createElement("script");n.type="text/javascript",n.async=!0,n.onload=function(){console.log("Wechat script loaded successfully!"),t.signSignature().then((function(t){e(t)})).catch((function(t){i(t)}))},n.onerror=function(e){console.error("Failed to load wechat script!"),console.error(e),t.debug&&alert("Cannot load wechat script!"),i(e)};var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(n,s),n.src=t.sdkUrl}))},n.shareOnMoment=function(t){return t?this.callWechatApi("onMenuShareTimeline",t):this},n.updateAppMessageShareData=function(t){return t?this.callWechatApi("updateAppMessageShareData",t):this},n.shareOnChat=function(t){return t?this.callWechatApi("onMenuShareAppMessage",t):this},n.updateTimelineShareData=function(t){return t?this.callWechatApi("updateTimelineShareData",t):this},n.callWechatApi=function(t,e,i){if(!t)return this;var n=this.debug;if(this.config.jsApiList.indexOf(t)<0)return n&&alert("the wechat api ["+t+"] you call was not registered, \npls add the api into your [jsApiList] config"),this;var s=this.getOriginalWx()[t];return s&&"function"==typeof s?(s(e,i),this):(n&&alert("no such api ["+t+"] found!"),this)},n.getOriginalWx=function(){return this.wx||window.wx},n.setOriginWx=function(){return this.wx||(this.wx=window.wx),this},i}()}));
