BxDolPushWonderPush.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. <script src="https://cdn.by.wonderpush.com/sdk/1.1/wonderpush-loader.min.js" async></script>
  3. <script>
  4. window.WonderPush = window.WonderPush || [];
  5. WonderPush.push(["init", {
  6. webKey: "cf4d2facd6a1c50b2fdaadec76b88ad8322397c11b28a4789648df6251cbfb74",
  7. }]);
  8. </script>
  9. */
  10. function BxDolPushOneSignal(oOptions) {
  11. this._sObjName = oOptions.sObjName == undefined ? 'oBxDolPushOneSignal' : oOptions.sObjName;
  12. this._sSiteName = oOptions.sSiteName == undefined ? '' : oOptions.sSiteName;
  13. this._aTags = oOptions.aTags == undefined ? {} : oOptions.aTags;
  14. this._sWebKey = oOptions.sWebKey == undefined ? '' : oOptions.sAppId;
  15. var $this = this;
  16. $(document).ready(function() {
  17. $this.init();
  18. });
  19. }
  20. BxDolPushOneSignal.prototype.init = function() {
  21. var $this = this;
  22. window.WonderPush = window.WonderPush || [];
  23. OneSignal.push(function() {
  24. OneSignal.SERVICE_WORKER_UPDATER_PATH = "OneSignalSDKUpdaterWorker.js.php";
  25. OneSignal.SERVICE_WORKER_PATH = "OneSignalSDKWorker.js.php";
  26. OneSignal.SERVICE_WORKER_PARAM = { scope: '/' }; /* This registers the workers at the root scope, which is allowed by the HTTP header "Service-Worker-Allowed: /" */
  27. });
  28. OneSignal.push(["init", {
  29. appId: $this._sAppId,
  30. autoRegister: true, /* Set to true to automatically prompt visitors */
  31. subdomainName: $this._sShortName, /* required only for http sites */
  32. safari_web_id: $this._sSafariWebId,
  33. path: $this._sSubfolder, /* A trailing slash is required */
  34. persistNotification: false,
  35. welcomeNotification: {
  36. disable:false
  37. },
  38. httpPermissionRequest: {
  39. enable: true
  40. },
  41. promptOptions: {
  42. /* These prompt options values configure both the HTTP prompt and the HTTP popup. */
  43. /* actionMessage limited to 90 characters */
  44. actionMessage: $this._sTxtNotificationRequest,
  45. /* acceptButtonText limited to 15 characters */
  46. acceptButtonText: $this._sTxtNotificationRequestYes,
  47. /* cancelButtonText limited to 15 characters */
  48. cancelButtonText: $this._sTxtNotificationRequestNo
  49. }
  50. }]);
  51. OneSignal.push(function() {
  52. var isPushSupported = OneSignal.isPushNotificationsSupported();
  53. OneSignal.setDefaultNotificationUrl($this._sNotificationUrl);
  54. OneSignal.isPushNotificationsEnabled().then(function(isEnabled) {
  55. if('undefined' !== typeof($this._aTags['email'])) {
  56. OneSignal.setEmail($this._aTags['email'], $this._aTags['email_hash']);
  57. delete $this._aTags['email'];
  58. delete $this._aTags['email_hash'];
  59. }
  60. OneSignal.sendTags($this._aTags); // set tags for onesiganl, some of these tags will be used to send notification
  61. if(!isEnabled && isPushSupported)
  62. OneSignal.showHttpPermissionRequest();
  63. });
  64. });
  65. if(navigator.userAgent.indexOf('gonative') > -1) {
  66. var json = JSON.stringify($this._aTags);
  67. $(document).ready(function () {
  68. window.location.href='gonative://registration/send?customData=' + encodeURIComponent(json);
  69. });
  70. }
  71. };