webviewjsbridge.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // identity function for calling harmony imports with the correct context
  37. /******/ __webpack_require__.i = function(value) { return value; };
  38. /******/
  39. /******/ // define getter function for harmony exports
  40. /******/ __webpack_require__.d = function(exports, name, getter) {
  41. /******/ if(!__webpack_require__.o(exports, name)) {
  42. /******/ Object.defineProperty(exports, name, {
  43. /******/ configurable: false,
  44. /******/ enumerable: true,
  45. /******/ get: getter
  46. /******/ });
  47. /******/ }
  48. /******/ };
  49. /******/
  50. /******/ // getDefaultExport function for compatibility with non-harmony modules
  51. /******/ __webpack_require__.n = function(module) {
  52. /******/ var getter = module && module.__esModule ?
  53. /******/ function getDefault() { return module['default']; } :
  54. /******/ function getModuleExports() { return module; };
  55. /******/ __webpack_require__.d(getter, 'a', getter);
  56. /******/ return getter;
  57. /******/ };
  58. /******/
  59. /******/ // Object.prototype.hasOwnProperty.call
  60. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  61. /******/
  62. /******/ // __webpack_public_path__
  63. /******/ __webpack_require__.p = "";
  64. /******/
  65. /******/ // Load entry module and return exports
  66. /******/ return __webpack_require__(__webpack_require__.s = 3);
  67. /******/ })
  68. /************************************************************************/
  69. /******/ ([
  70. /* 0 */
  71. /***/ (function(module, exports, __webpack_require__) {
  72. "use strict";
  73. /**
  74. * Add base64 tag, like data:image/img;base64
  75. * @param responseData
  76. */
  77. module.exports = function handleImgBase64Data(responseData) {
  78. var headers = responseData.headers || {};
  79. var contentType = (headers["content-type"] || headers["Content-Type"] || "").toString().toLowerCase();
  80. if (contentType.indexOf("image") !== -1 && responseData.responseText.indexOf("base64") === -1) {
  81. responseData.responseText = "data:" + contentType + ";base64," + responseData.responseText;
  82. }
  83. };
  84. /***/ }),
  85. /* 1 */,
  86. /* 2 */,
  87. /* 3 */
  88. /***/ (function(module, exports, __webpack_require__) {
  89. function KEEP(_,cb){cb();}
  90. 'use strict';
  91. var handleImgBase64Data = __webpack_require__(0);
  92. // Reference from https://github.com/marcuswestin/WebViewJavascriptBridge
  93. function setupWebViewJavascriptBridge(callback) {
  94. if (window.WebViewJavascriptBridge) {
  95. return callback(WebViewJavascriptBridge);
  96. }
  97. if (window.WVJBCallbacks) {
  98. return window.WVJBCallbacks.push(callback);
  99. }
  100. window.WVJBCallbacks = [callback];
  101. var WVJBIframe = document.createElement('iframe');
  102. WVJBIframe.style.display = 'none';
  103. WVJBIframe.src = 'https://__bridge_loaded__';
  104. document.documentElement.appendChild(WVJBIframe);
  105. setTimeout(function () {
  106. document.documentElement.removeChild(WVJBIframe);
  107. }, 0);
  108. }
  109. function adapter(request, responseCallBack) {
  110. setupWebViewJavascriptBridge(function (bridge) {
  111. bridge.callHandler("onAjaxRequest", request, function (responseData) {
  112. responseData = JSON.parse(responseData);
  113. if (request.responseType === "stream") {
  114. handleImgBase64Data(responseData);
  115. }
  116. responseCallBack(responseData);
  117. });
  118. });
  119. }
  120. //build环境定义全局变量
  121. KEEP("cdn||cdn-min", function () {
  122. window.wjsbAdapter = adapter;
  123. });
  124. module.exports = adapter;
  125. /***/ })
  126. /******/ ]);