!function(i){"use strict";window.jnews.push_notification=window.jnews.push_notification||{};var e=!!("object"==typeof jnews&&"object"==typeof jnews.library)&&jnews.library;window.jnews.push_notification={init:function(n){var t=this;t.element=void 0===n?i("body"):n;var s=t.doSubscribe.bind(t);e&&e.requestAnimationFrame.call(e.win,(function(){e.winLoad(s)}))},doSubscribe:function(){var e=this;e.element.find(".jeg_push_notification").length&&e.element.find(".jeg_push_notification").each((function(){e.container=i(this),e.doSubscribeAction(e.container),e.doSubscribeSubmit(e.container)}))},doSubscribeAction:function(i){var e=this;e.doSubscribeToggle(i,"register"),OneSignal.getUserId((function(n){null!==n&&OneSignal.getTags((function(n){if(Object.keys(n).length>0){if(e.doSubscribeToggle(i,"unsubscribe"),"category"===i.find(".button").attr("data-type"))for(var t=i.find('input[name="post-category"]').val().split(","),s=0;s<t.length;s++)n.hasOwnProperty(t[s])||e.doSubscribeToggle(i,"subscribe")}else"category"===i.find(".button").attr("data-type")&&e.doSubscribeToggle(i,"subscribe")})),i.removeClass("loading")}))},doSubscribeSubmit:function(e){var n=this;e.find(".button").on("click",(function(t){t.preventDefault(),e.addClass("processing");var s=i(this),a=s.attr("data-type"),o=s.attr("data-action");if("general"===a&&("register"===o?OneSignal.push((function(){OneSignal.registerForPushNotifications(),OneSignal.sendTag("all","all"),n.doSubscribeToggle(e,"unsubscribe")})):"subscribe"===o?(OneSignal.sendTag("all","all"),n.doSubscribeToggle(e,"unsubscribe")):"unsubscribe"===o&&OneSignal.getTags((function(i){var t=[];for(var s in i)t.push(s);OneSignal.deleteTags(t),n.doSubscribeToggle(e,"subscribe")}))),"category"===a){for(var r=e.find('input[name="post-category"]').val().split(","),u={},c=0;c<r.length;c++)u[r[c]]=r[c];"register"===o?OneSignal.push((function(){OneSignal.registerForPushNotifications(),OneSignal.deleteTags(["all"]),OneSignal.sendTags(u),n.doSubscribeToggle(e,"unsubscribe")})):"subscribe"===o?(OneSignal.deleteTags(["all"]),OneSignal.sendTags(u),n.doSubscribeToggle(e,"unsubscribe")):"unsubscribe"===o&&(OneSignal.deleteTags(r),n.doSubscribeToggle(e,"subscribe"))}setTimeout((function(){e.removeClass("processing")}),600)}))},doSubscribeToggle:function(i,e){var n=i.find(".button"),t=i.find('input[name="button-processing"]').val(),s=i.find('input[name="button-subscribe"]').val(),a=i.find('input[name="button-unsubscribe"]').val();"subscribe"===e?(n.html('<i class="fa fa-refresh fa-spin"></i>'+t),setTimeout((function(){n.attr("data-action","subscribe"),n.html('<i class="fa fa-bell-o"></i>'+s)}),500)):"register"===e?(n.html('<i class="fa fa-refresh fa-spin"></i>'+t),setTimeout((function(){n.attr("data-action","register"),n.html('<i class="fa fa-bell-o"></i>'+s)}),500)):(n.html('<i class="fa fa-refresh fa-spin"></i>'+t),setTimeout((function(){n.attr("data-action","unsubscribe"),n.html('<i class="fa fa-bell-slash-o"></i>'+a)}),500))}},e&&e.docReady((function(){jnews.push_notification.init()}))}(jQuery);