UNPKG

hpmo

Version:

hybirdApp package manager

1 lines 8.76 kB
!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t():"function"==typeof define&&(define.amd||define.cmd)?define(t):(e.ant=e.Ali=e.Ali||{},t.call(e,e.Ali))}(this,function(e){"use strict";function t(){return/android/i.test(e.ua)}function o(){return/iphone|ipad/i.test(e.ua)}function n(e){return"function"===l(e)}function i(e){return"string"===l(e)}function a(e){return"object"===l(e)}function r(e){return"number"===l(e)}function l(e){return Object.prototype.toString.call(e).replace(/\[object (\w+)\]/,"$1").toLowerCase()}function s(e,t){if(t)for(var o in t)e[o]=t[o];return e}function c(){if(e.debug>0){var t=+new Date,o=[].slice.call(arguments);console.log(t,o),e.debug>1&&e.diagnose(t+"^"+JSON.stringify(o))}}function u(e,t){e=e||{},e.errorCode=e.error||0,e.errorCode>0&&e.errorCode<10?console.error(t+" 发生异常: errorCode: "+e.errorCode+", errorMessage: "+e.errorMessage):c(t+", callback:",e)}function d(t){for(var o,n,i=e.alipayVersion.split("."),t=t.split("."),a=0;a<i.length;a++){if(o=parseInt(t[a],10)||0,n=parseInt(i[a],10)||0,o>n)return-1;if(n>o)return 1}return 0}return e=e||{},e.ua=navigator.userAgent,e.version="1.1.0",e.isAlipay=e.ua.indexOf("AlipayClient")>-1,e.isAlipay?(e.alipayVersion=function(){return e.isAlipay?e.ua.match(/AlipayClient\/(.*)/)[1]:void 0}(),e.appinfo={engine:"alipay",engineVer:e.alipayVersion,name:"alipay",ver:e.alipayVersion},e.on=function(e,t){e.split(/\s+/g).forEach(function(e){document.addEventListener(e,t,!1)})},e.call=function(){var t=[].slice.call(arguments);if(window.AlipayJSBridge){var o=t[0],r=t[1]||{},l=t[2];if(!i(o))return void console.error("接口名非法:",o);if(void 0===l&&n(r)&&(l=r,r={}),!a(r))return void console.error(o+": 入参必须为object类型");var s=l;l=function(e){u(e,o),s&&s(e)},"remoteLog"!==o&&c("AlipayJSBridge.call:",o,r,s),window.AlipayJSBridge.call(o,r,l)}else e._apiQueue=e._apiQueue||[],e._apiQueue.push(t)},e._ready=function(t){window.AlipayJSBridge?t&&t():e.on("AlipayJSBridgeReady",t)},e.ready=e.ready||e._ready,e.toast=function(o,n){(i(o)||r(o))&&(o={text:o+""}),o=o||{},o.content=o.text,o.duration=o.duration||2e3,n&&r(o.duration)&&t()?(o.duration=o.duration<2500?2e3:3e3,e.call("toast",o),setTimeout(n,o.duration)):e.call("toast",o,n)},e.setTitle=function(t,o){var n={type:"title"};return i(t)&&(t={title:t}),t.title=t.title||t.text,s(n,t),null==n.title?(console.error("setTitle: title 参数必填!"),!1):void e.call("setTitle",n,o)},e.showTitle=function(t){e.call("showTitlebar",t)},e.hideTitle=function(t){e.call("hideTitlebar",t)},e.showLoading=function(t,n){if((i(t)||r(t))&&(t={text:t+""}),t=t||{},t.delay=t.delay||300,r(t.delay)&&o()){var a=t.delay;delete t.delay;var l=setTimeout(function(){e.call("showLoading",t,n)},a);return e._stLoadingQueue=e._stLoadingQueue||[],e._stLoadingQueue.push(l),l}e.call("showLoading",t,n)},e.hideLoading=function(t){if("array"===l(e._stLoadingQueue)&&e._stLoadingQueue.length)for(c("clearLoadingCount: "+e._stLoadingQueue.length);e._stLoadingQueue.length;)clearTimeout(e._stLoadingQueue.shift());e.call("hideLoading",t)},e.pushWindow=function(o,n){return i(o)&&(o={url:o}),o=o||{},o.url?(o.param&&t()&&d("8.3")<0&&console.warn("Ali.pushWindow: android 版 param 参数请在 8.3 及以上版本使用"),void e.call("pushWindow",o,n)):(console.error("Ali.pushWindow: url不能为空!"),!1)},e.popWindow=function(t,o){e.call("popWindow",t,o)},e.popTo=function(t,o){r(t)?t={step:t}:i(t)&&(t={urlPattern:t}),void 0!=t.step&&(t.index=t.step),e.call("popTo",t,o)},e.login=function(t){e.call("login",t)},e.tradePay=function(t,o){e.call("tradePay",t,o)},e.h5TradePay=function(e,t){console.error("支付宝不支持 Ali.h5TradePay,支付宝请使用 Ali.tradePay"),t&&t({errorCode:1,errorMessage:"接口不存在"})},e.geolocation={},e.geolocation.getCurrentPosition=function(t,o){void 0===o&&n(t)&&(o=t,t=null),t=t||{timeout:15e3};var i=setTimeout(function(){i=null,console.error("geolocation.getCurrentPosition: timeout");var e={errorCode:5,errorMessage:"调用超时"};o&&o(e)},t.timeout);e.call("getLocation",function(e){i&&(clearTimeout(i),e.coords={},e.coords.latitude=+e.latitude,e.coords.longitude=+e.longitude,e.city=e.city?e.city:e.province,e.cityCode=e.citycode,e.address=e.pois,o&&o(e))})},e.shake={},e.shake.watch=function(t,o){e.call("watchShake",t,o)},e.vibration={},e.vibration.vibrate=function(t,o){r(t)&&(t={duration:t}),e.call("vibrate",t,o)},e.network={},e.network.getType=function(t,o){void 0===o&&n(t)&&(o=t,t=null),t=t||{timeout:15e3};var i=setTimeout(function(){i=null,console.error("network.getType: timeout");var e={errorCode:5,errorMessage:"调用超时"};o&&o(e)},t.timeout);e.call("getNetworkType",function(e){i&&(clearTimeout(i),e.networkAvailable="fail"!==e.networkType,e.is3G=e.is2G=e.isE=e.isG=e.isH=!1,e.isWifi="wifi"===e.networkType,e.isOnline=e.networkAvailable,e.type=e.networkType,o&&o(e,e.networkAvailable))})},e.calendar={},e.calendar.add=function(t,o){d("8.3")<0?(console.error("Ali.calendar.add: 在 8.3 及以上版本使用"),o&&o({errorCode:1,errorMessage:"接口不存在"})):e.call("addEventCal",t,o)},e.photo=function(t,o){void 0===o&&n(t)&&(o=t,t={});var i={format:"jpg",dataType:"dataurl",quality:50,allowEdit:!1,src:void 0,cameraType:void 0,maskImg:void 0,maskWidth:void 0,maskHeight:void 0};s(i,t),i.imageFormat=i.format,"remoteurl"==i.dataType&&(i.dataType="dataurl"),i.dataType=i.dataType.slice(0,-3)+i.dataType.slice(-3).toUpperCase(),e.call("photo",i,function(e){e.dataURL&&(e.dataURL="data:image/"+i.imageFormat+";base64,"+e.dataURL),e.photo=e.dataURL||e.fileURL,e.errorMessage=10==e.error?"用户取消":e.errorMessage,o&&o(e)})},e.contacts={},e.contacts.get=function(t,o){void 0==o&&n(t)&&(o=t,t=null),t=t||{},t.multiple&&console.error("仅支持单选"),e.call("contact",t,function(e){switch(e.results=[],e.results[0]={phoneNumber:e.mobile,email:void 0,name:e.name},e.errorCode){case 10:e.errorMessage="没有权限";break;case 11:e.errorMessage="用户取消操作"}o&&o(e)})},e.share=function(t,o){var n={1:"Weixin",2:"Weibo",4:"SMS",8:"LaiwangContacts",16:"LaiwangTimeline",32:"WeixinTimeLine",64:"CopyLink"};t=t||{};var i=t;if(!t.channels||0===t.channels.length){t.title=t.title||"",t.content=t.text,t.imageUrl=t.image,t.captureScreen=!!t.captureScreen,t.url=t.url||"",i={channels:[]},"undefined"==typeof t.shareType&&(t.shareType=-1);for(var a in n)Number(a)&t.shareType&&i.channels.push({name:n[a],param:t})}e.call("share",i,o)},e.debugEnabled=function(t){e.debug=t===!0?2:1},e.setOptionMenu=function(t,o){i(t)&&(t=/^http/i.test(t)?{icon:t}:{title:t}),e.call("setOptionMenu",t,o)},e.alert=function(t,o){(i(t)||r(t))&&(t={message:t+""}),e.call("alert",t,o)},e.confirm=function(t,o){(i(t)||r(t))&&(t={message:t+""}),e.call("confirm",t,o)},e.openInBrowser=function(t,o){i(t)&&(t={url:t}),e.call("openInBrowser",t,o)},e.diagnose=function(t){if(!o())return console.warn("diagnose only in iOS"),!1;if(a(t)||"array"===l(t))t=JSON.stringify(t);else if(!i(t)&&!r(t))return console.error("diagnose必须为string或json对象"),!1;t=location.href+": "+t,t={type:"diagnose",seedId:"H5_DIAGNOSED_JSLOG",param1:t};var n=["remoteLog",t];window.AlipayJSBridge?window.AlipayJSBridge.call("remoteLog",t):(e._apiQueue=e._apiQueue||[],e._apiQueue.push(n))},e.requestAnimationFrame=function(e){var t=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame;return t?t(e):void console.error("Not support requestAnimationFrame!")},e.on("AlipayJSBridgeReady",function(){function t(){e.requestAnimationFrame(function(){var n=o.shift();e.call.apply(null,n),o.length&&t()})}c("AlipayJSBridgeReady");var o=e._apiQueue||[];!!o.length&&t()}),["startApp","showOptionMenu","hideOptionMenu","showToolbar","hideToolbar","closeWebview","sendSMS","scan","getSessionData","setSessionData","checkJSAPI","checkApp","isInstalledApp","deposit","chooseContact","alipayContact","getConfig","getCities","rsa","getWifiList","connectWifi","notifyWifiShared","thirdPartyAuth","getThirdPartyAuthcode","setToolbarMenu","exitApp","actionSheet","hideBackButton","startApp","startPackage","getSharedData","setSharedData","removeSharedData","setClipboard","startDownload","stopDownload","getDownloadInfo","detectBeacons","startBeaconsBeep","stopBeaconsBeep","startIndoorLocation","stopIndoorLocation","addEventCal","startSpeech","stopSpeech","getWifiInfo","clearAllCookie","getMtopToken","getClientInfo","sinasso","getClipboard","checkBLEAvalability","scanBeacons","isSpeechAvailable","speechRecognizer","contactSync","setGestureBack","httpRequest","rpc","networkAnalysis"].forEach(function(t){e[t]=function(){var o=[].slice.call(arguments);e.call.apply(null,[t].concat(o))}}),e):void console.error("请在支付宝钱包内使用antBridge!")});