wk-plugin.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (function _wk_plugin() {
  2. // Check if we are running in WKWebView
  3. if (!window.webkit || !window.webkit.messageHandlers) {
  4. return;
  5. }
  6. // Initialize Ionic
  7. window.Ionic = window.Ionic || {};
  8. function normalizeURL(url) {
  9. console.warn('normalizeURL is deprecated, use window.Ionic.WebView.convertFileSrc');
  10. return window.Ionic.WebView.convertFileSrc(url);
  11. }
  12. if (typeof window.wkRewriteURL === 'undefined') {
  13. window.wkRewriteURL = function (url) {
  14. console.warn('wkRewriteURL is deprecated, use window.Ionic.WebView.convertFileSrc instead');
  15. return window.Ionic.WebView.convertFileSrc(url);
  16. }
  17. }
  18. window.Ionic.normalizeURL = normalizeURL;
  19. var stopScrollHandler = window.webkit.messageHandlers.stopScroll;
  20. if (!stopScrollHandler) {
  21. console.error('Can not find stopScroll handler');
  22. return;
  23. }
  24. var stopScrollFunc = null;
  25. var stopScroll = {
  26. stop: function stop(callback) {
  27. if (!stopScrollFunc) {
  28. stopScrollFunc = callback;
  29. stopScrollHandler.postMessage('');
  30. }
  31. },
  32. fire: function fire() {
  33. stopScrollFunc && stopScrollFunc();
  34. stopScrollFunc = null;
  35. },
  36. cancel: function cancel() {
  37. stopScrollFunc = null;
  38. }
  39. };
  40. window.Ionic.StopScroll = stopScroll;
  41. // deprecated
  42. window.IonicStopScroll = stopScroll;
  43. console.debug("Ionic Stop Scroll injected!");
  44. })();