var OneSignalPlayerId = null; var OneSignal = window.OneSignal || []; function OneSignalInit() { OneSignal.push([ 'init', { appId: '<%= DeviseOnesignal.configuration.app_id %>', autoRegister: <%= DeviseOnesignal.configuration.auto_register ? 'true' : 'false' %>, welcomeNotification: { disable: true, title: '', message: '' }, notifyButton: { enable: false }, persistNotification: <%= DeviseOnesignal.configuration.persist_notification ? 'true' : 'false' %> // Automatically dismiss the notification after ~20 seconds in Chrome Desktop v47+ }]); OneSignal.push(function() { OneSignal.getUserId().then(function(playerId) { if ( playerId != null ) { OneSignalPlayerId = playerId; document.cookie = 'oneSignalPlayerId=' + playerId; }; OneSignal.push([ 'getNotificationPermission', function(permission) { document.cookie = 'oneSignalPlayerPermission=' + permission; }]); }); }); }; function OneSignalSubscribed() { OneSignalPlayerId != null; }; function OneSignalSubscribe() { if (OneSignalSubscribed()) { OneSignal.setSubscription(true); } else { OneSignal.registerForPushNotifications({ modalPrompt: <%= DeviseOnesignal.configuration.subscribe_with_modal ? 'true' : 'false' %> }); }; }; function OneSignalUnsubscribe() { OneSignal.setSubscription(false); };