weixinapi.min.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var WeixinApi = function() {
  2. "use strict";
  3. function e(e, t) {
  4. t = t || {};
  5. var n = function(e) {
  6. WeixinJSBridge.invoke("shareTimeline", {
  7. appid: e.appId ? e.appId: "",
  8. img_url: e.imgUrl,
  9. link: e.link,
  10. desc: e.title,
  11. title: e.desc,
  12. img_width: "120",
  13. img_height: "120"
  14. },
  15. function(e) {
  16. switch (e.err_msg) {
  17. case "share_timeline:cancel":
  18. t.cancel && t.cancel(e);
  19. break;
  20. case "share_timeline:fail":
  21. t.fail && t.fail(e);
  22. break;
  23. case "share_timeline:confirm":
  24. case "share_timeline:ok":
  25. t.confirm && t.confirm(e)
  26. }
  27. t.all && t.all(e)
  28. })
  29. };
  30. WeixinJSBridge.on("menu:share:timeline",
  31. function(r) {
  32. t.async && t.ready ? (window._wx_loadedCb_ = t.dataLoaded || new Function, window._wx_loadedCb_.toString().indexOf("_wx_loadedCb_") > 0 && (window._wx_loadedCb_ = new Function), t.dataLoaded = function(e) {
  33. window._wx_loadedCb_(e),
  34. n(e)
  35. },
  36. t.ready && t.ready(r)) : (t.ready && t.ready(r), n(e))
  37. })
  38. }
  39. function t(e, t) {
  40. t = t || {};
  41. var n = function(e) {
  42. WeixinJSBridge.invoke("sendAppMessage", {
  43. appid: e.appId ? e.appId: "",
  44. img_url: e.imgUrl,
  45. link: e.link,
  46. desc: e.desc,
  47. title: e.title,
  48. img_width: "120",
  49. img_height: "120"
  50. },
  51. function(e) {
  52. switch (e.err_msg) {
  53. case "send_app_msg:cancel":
  54. t.cancel && t.cancel(e);
  55. break;
  56. case "send_app_msg:fail":
  57. t.fail && t.fail(e);
  58. break;
  59. case "send_app_msg:confirm":
  60. case "send_app_msg:ok":
  61. t.confirm && t.confirm(e)
  62. }
  63. t.all && t.all(e)
  64. })
  65. };
  66. WeixinJSBridge.on("menu:share:appmessage",
  67. function(r) {
  68. t.async && t.ready ? (window._wx_loadedCb_ = t.dataLoaded || new Function, window._wx_loadedCb_.toString().indexOf("_wx_loadedCb_") > 0 && (window._wx_loadedCb_ = new Function), t.dataLoaded = function(e) {
  69. window._wx_loadedCb_(e),
  70. n(e)
  71. },
  72. t.ready && t.ready(r)) : (t.ready && t.ready(r), n(e))
  73. })
  74. }
  75. function n(e, t) {
  76. t = t || {};
  77. var n = function(e) {
  78. WeixinJSBridge.invoke("shareWeibo", {
  79. content: e.desc,
  80. url: e.link
  81. },
  82. function(e) {
  83. switch (e.err_msg) {
  84. case "share_weibo:cancel":
  85. t.cancel && t.cancel(e);
  86. break;
  87. case "share_weibo:fail":
  88. t.fail && t.fail(e);
  89. break;
  90. case "share_weibo:confirm":
  91. case "share_weibo:ok":
  92. t.confirm && t.confirm(e)
  93. }
  94. t.all && t.all(e)
  95. })
  96. };
  97. WeixinJSBridge.on("menu:share:weibo",
  98. function(r) {
  99. t.async && t.ready ? (window._wx_loadedCb_ = t.dataLoaded || new Function, window._wx_loadedCb_.toString().indexOf("_wx_loadedCb_") > 0 && (window._wx_loadedCb_ = new Function), t.dataLoaded = function(e) {
  100. window._wx_loadedCb_(e),
  101. n(e)
  102. },
  103. t.ready && t.ready(r)) : (t.ready && t.ready(r), n(e))
  104. })
  105. }
  106. function r(e, t) {
  107. if (!e || !t || t.length == 0) return;
  108. WeixinJSBridge.invoke("imagePreview", {
  109. current: e,
  110. urls: t
  111. })
  112. }
  113. function i() {
  114. WeixinJSBridge.call("showOptionMenu")
  115. }
  116. function s() {
  117. //WeixinJSBridge.call("hideOptionMenu")
  118. }
  119. function o() {
  120. WeixinJSBridge.call("showToolbar")
  121. }
  122. function u() {
  123. WeixinJSBridge.call("hideToolbar")
  124. }
  125. function a(e) {
  126. e && typeof e == "function" && WeixinJSBridge.invoke("getNetworkType", {},
  127. function(t) {
  128. e(t.err_msg)
  129. })
  130. }
  131. function f() {
  132. WeixinJSBridge.call("closeWindow")
  133. }
  134. function l(e) {
  135. if (e && typeof e == "function") {
  136. var t = this,
  137. n = function() {
  138. e(t)
  139. };
  140. typeof window.WeixinJSBridge == "undefined" ? document.addEventListener ? document.addEventListener("WeixinJSBridgeReady", n, !1) : document.attachEvent && (document.attachEvent("WeixinJSBridgeReady", n), document.attachEvent("onWeixinJSBridgeReady", n)) : n()
  141. }
  142. }
  143. return {
  144. version: "1.8",
  145. ready: l,
  146. shareToTimeline: e,
  147. shareToWeibo: n,
  148. shareToFriend: t,
  149. showOptionMenu: i,
  150. hideOptionMenu: s,
  151. showToolbar: o,
  152. hideToolbar: u,
  153. getNetworkType: a,
  154. imagePreview: r,
  155. closeWindow: f
  156. }
  157. } ();