Advertisement
Guest User

Untitled

a guest
May 25th, 2021
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery(function () {
  2.     "use strict";
  3.  
  4.     function init_select($elems) {
  5.         if ($elems === undefined || !$elems.length) {
  6.             return;
  7.         }
  8.         $elems.each(function () {
  9.             var $elem = jQuery(this);
  10.  
  11.             var data = {
  12.                 dir: wpnotifobj.direction,
  13.                 minimumResultsForSearch: 8,
  14.                 dropdownCssClass: "wpnotif-select-dropdown",
  15.                 theme: "default wpnotif-select",
  16.             };
  17.             if ($elem.data('source')) {
  18.                 data['minimumInputLength'] = 0;
  19.                 data['ajax'] = {
  20.                     url: wpnotifobj.ajax_url,
  21.                     dataType: 'json',
  22.                     delay: 1000,
  23.                     cache: true,
  24.                     data: function (params) {
  25.                         var query = {
  26.                             search: params.term,
  27.                             action: jQuery(this).data('source'),
  28.                             nonce: jQuery(this).data('nonce'),
  29.                         };
  30.                         return query;
  31.                     }
  32.                 };
  33.             }
  34.  
  35.             $elem.untselect(data);
  36.  
  37.         });
  38.     }
  39.  
  40.     init_select(jQuery(".wpnotif_admin_fields").find("select").not('.wpnotif_multiselect_dynamic_enable'));
  41.  
  42.     jQuery(".wpnotif_multiselect_dynamic_enable").untselect({
  43.         dir: wpnotifobj.direction,
  44.         tags: true,
  45.         tokenSeparators: [',', ' '],
  46.         dropdownCssClass: "wpnotif-select-dropdown",
  47.         theme: "default wpnotif-select"
  48.     });
  49.     var gatewayInp = jQuery(".wpnotif_gateways");
  50.  
  51.     var gatewayBoxTemplate = jQuery("#gateway_template").html();
  52.     var apisettingsTab = jQuery(".wpnotif_gateway_settings");
  53.     var gateway_table_list = jQuery(".gateway_table");
  54.  
  55.  
  56.     var allowUpdate = false;
  57.     var gatewayList = [];
  58.     if (gatewayInp.length) {
  59.         gatewayList = jQuery.parseJSON(gatewayInp.val());
  60.     }
  61.     var updateNotificationBasedGateways = false;
  62.     jQuery(document).on("change", ".wpnotif_gateway_box input,.wpnotif-gs-trigger select", function () {
  63.         var thisGatewayBox = jQuery(this).closest('.wpnotif_gateway_box');
  64.         var gatewaySelect = thisGatewayBox.find('.wpnotif_gateway');
  65.         var gateway = gatewaySelect.val();
  66.         var countriesBox = thisGatewayBox.find('.gateway_countries select');
  67.  
  68.         var countries;
  69.         if (!gateway || gateway == undefined) return;
  70.  
  71.         var values = {};
  72.         values['ccodes'] = 0;
  73.         values['countries'] = '';
  74.         if (thisGatewayBox.attr('all')) {
  75.             values['countries'] = 'all';
  76.             values['all'] = 1;
  77.             values['ccodes'] = 0;
  78.             updateNotificationBasedGateways = true;
  79.         } else {
  80.             values['all'] = 0;
  81.             if (countriesBox.val() != null) {
  82.                 var countriesBoxValue = countriesBox.val();
  83.                 values['ccodes'] = countriesBoxValue.join();
  84.                 var countryList = [];
  85.                 countriesBox.find("option:selected").each(function () {
  86.                     countryList.push(jQuery(this).attr('data-country'));
  87.                 });
  88.                 var countryListString = countryList.join();
  89.                 values['countries'] = countryListString;
  90.                 thisGatewayBox.find('.wpnotif_ctr_list').text(countryListString);
  91.             }
  92.         }
  93.  
  94.  
  95.         var prevGateway;
  96.         if (jQuery(this).hasClass('wpnotif_gateway') && thisGatewayBox.attr('wpnotif-gateway')) {
  97.             prevGateway = thisGatewayBox.attr('wpnotif-gateway');
  98.             enableGateway(prevGateway);
  99.         } else {
  100.             prevGateway = gateway;
  101.         }
  102.         values['gateway'] = gateway;
  103.         if (thisGatewayBox.find('.input-switch input').prop("checked") == true) {
  104.             values['enable'] = 'on';
  105.         } else {
  106.             values['enable'] = 'off';
  107.         }
  108.  
  109.         thisGatewayBox.attr('enable', values['enable']);
  110.  
  111.         if (gateway == 1001) {
  112.             values['data-label'] = 'Whatsapp';
  113.             values['class'] = 'hideGatewayList';
  114.  
  115.         }
  116.  
  117.  
  118.         disableGateway(gatewaySelect, gateway);
  119.  
  120.  
  121.         var dataString;
  122.         if (gatewayList.hasOwnProperty('gc_' + prevGateway)) {
  123.             gatewayList['gc_' + prevGateway] = values;
  124.             dataString = JSON.stringify(gatewayList);
  125.             dataString = dataString.replace('"gc_' + prevGateway + '":{', '"gc_' + gateway + '":{');
  126.             gatewayList = JSON.parse(dataString);
  127.  
  128.         } else {
  129.             gatewayList['gc_' + gateway] = values;
  130.             dataString = JSON.stringify(gatewayList);
  131.         }
  132.  
  133.  
  134.         gatewayInp.val(dataString);
  135.  
  136.  
  137.         var $this = jQuery(this);
  138.         setTimeout(function () {
  139.             if ($this.hasClass('wpnotif_gateway')) {
  140.                 updateDigGatewayFields($this);
  141.             }
  142.             if (updateNotificationBasedGateways) {
  143.                 jQuery(".gateway_based_notifications .wpnotif_gate_allcountries").first().attr('wpnotif-gateway', gateway).find('input').first().trigger('change');
  144.                 updateNotificationBasedGateways = false;
  145.             }
  146.         });
  147.  
  148.  
  149.         if (allowUpdate) {
  150.             allowUpdateSettings();
  151.         }
  152.     });
  153.  
  154.     var otpSettings = jQuery(".disotp");
  155.  
  156.     function updateDigGatewayFields($this) {
  157.  
  158.  
  159.         var selected = $this.find("option:selected");
  160.         var han = selected.attr('han');
  161.  
  162.         var gatewayName = selected.text();
  163.         var val = $this.val();
  164.         var thisGatewayBox = $this.closest('.wpnotif_gateway_box');
  165.         var table = thisGatewayBox.find('.selected_gateway_conf');
  166.         table.find('.gateway_conf').appendTo(gateway_table_list);
  167.         gateway_table_list.find('.' + han + 'cred').show().appendTo(table);
  168.  
  169.         if (selected.data('addon') == 1) {
  170.             thisGatewayBox.find(".require_addon_text").show();
  171.         } else {
  172.             thisGatewayBox.find(".require_addon_text").hide();
  173.         }
  174.  
  175.         if (selected.data('document_link') == 1) {
  176.             jQuery(".wpn_gateway_document_link").show().closest('td').addClass('wpn_gateway_document_visible');
  177.         }
  178.  
  179.  
  180.         if (!thisGatewayBox.attr('all')) thisGatewayBox.find('.wpnotif_gateway_target_head').text(gatewayName);
  181.         else if (thisGatewayBox.attr('data-label'))
  182.             thisGatewayBox.find('.wpnotif_gateway_target_head').text(thisGatewayBox.attr('data-label'));
  183.  
  184.         if (thisGatewayBox.attr('enable') != 'on') {
  185.             thisGatewayBox.find('.input-switch input').prop('checked', false).trigger('change');
  186.         } else {
  187.             thisGatewayBox.find('.input-switch input').prop('checked', true).trigger('change');
  188.         }
  189.  
  190.         thisGatewayBox.attr('wpnotif-gateway', val);
  191.  
  192.  
  193.         var size = Object.keys(gatewayList).length;
  194.         if (
  195.             (size == 1 && (gatewayList.hasOwnProperty('gc_1') || gatewayList.hasOwnProperty('gc_13'))) ||
  196.             (size == 2 && gatewayList.hasOwnProperty('gc_1') && gatewayList.hasOwnProperty('gc_13'))) {
  197.             otpSettings.hide();
  198.         } else {
  199.             otpSettings.show();
  200.         }
  201.     };
  202. //thisGatewayBox.find(".disotp").hide();
  203.     jQuery.each(gatewayList, function (gatewayCode, values) {
  204.  
  205.         allowUpdate = false;
  206.         addUpdateGatewayBox(values['gateway'], values);
  207.         jQuery(".wpnotif_admin_conf .active").removeClass('active').find(".wpnotif_gateway_configuation_expand_box").hide();
  208.         jQuery(".wpnotif_admin_conf .wpnotif_gateway_box").first().addClass('active').find(".wpnotif_gateway_configuation_expand_box").show();
  209.  
  210.         allowUpdate = true;
  211.  
  212.     });
  213.  
  214.     jQuery(".apisettingstab .wpnotif_gateway_settings").find(".hideGatewayList").after('<div class="country_specific"><div class="wpnotif_admin_head"><span>Country Specific</span></div></div>');
  215.  
  216.     jQuery(".add_gateway_group_button").on('click', function () {
  217.         allowUpdate = true;
  218.         addUpdateGatewayBox(-1, null);
  219.     })
  220.  
  221.     function addUpdateGatewayBox(gatewayCode, values) {
  222.         var gatewayBox = jQuery(gatewayBoxTemplate).clone();
  223.         apisettingsTab.append(gatewayBox);
  224.  
  225.  
  226.         var gatewaySelectbox = gatewayBox.find('.wpnotif_gateway');
  227.         var gatewayCountries = gatewayBox.find('.gateway_countries select');
  228.  
  229.         var expand = false;
  230.         if (values != null) {
  231.  
  232.             if (values['all'] == 1) {
  233.                 gatewayBox.attr('all', '1').addClass("wpnotif_gate_allcountries active");
  234.                 expandGateway(gatewayBox, false, false);
  235.  
  236.  
  237.                 if (values['data-label'])
  238.                     gatewayBox.attr('data-label', values['data-label']);
  239.  
  240.                 if (values['class'])
  241.                     gatewayBox.addClass(values['class']);
  242.  
  243.  
  244.             } else {
  245.                 gatewayBox.removeAttr('all');
  246.                 var countriesString = values['countries'];
  247.                 gatewayBox.find('.wpnotif_ctr_list').text(countriesString);
  248.  
  249.                 gatewayBox.find('.wpnotif_gateway_configuation_expand_box').hide();
  250.  
  251.                 var countriesArray = countriesString.split(',');
  252.                 jQuery.each(countriesArray, function (key, country) {
  253.                     gatewayCountries.find('[data-country="' + country + '"]').attr('selected', 'selected');
  254.                 })
  255.  
  256.  
  257.             }
  258.  
  259.             gatewaySelectbox.val(gatewayCode);
  260.         } else {
  261.             collapseGateway();
  262.  
  263.  
  264.             expandGateway(gatewayBox, true, true);
  265.  
  266.             jQuery.each(gatewayList, function (gc, values) {
  267.                 var gatewayCode = values['gateway'];
  268.                 gatewaySelectbox.find('[data-value=' + gatewayCode + ']').addClass('disabled').attr('disabled', 'disabled');
  269.             });
  270.             var selNotDisabled = gatewaySelectbox.find('option:not([disabled]):first').val();
  271.             gatewaySelectbox.val(selNotDisabled);
  272.  
  273.  
  274.         }
  275.  
  276.         var input_switch = gatewayBox.find('.input-switch');
  277.         var random = Math.random();
  278.         input_switch.find('input').attr('id', random);
  279.         input_switch.find('label').attr('for', random);
  280.  
  281.  
  282.         if (values == null || values['enable'] != 'on') {
  283.             input_switch.find('input').prop('checked', false).trigger('change');
  284.         } else {
  285.             input_switch.find('input').prop('checked', true).trigger('change');
  286.         }
  287.         //gatewayBox.attr('enable',values['enable']);
  288.  
  289.         if (!gatewaySelectbox.data('untselect-id')) {
  290.             init_select(gatewaySelectbox);
  291.             init_select(gatewayCountries);
  292.         }
  293.         gatewaySelectbox.trigger('change');
  294.         gatewayCountries.trigger('change');
  295.  
  296.  
  297.     }
  298.  
  299.     jQuery(document).on("click", ".wpnotif_gateway_box_close,.wpnotif_gateway_settings .inactive,.wpnotif_gateway_settings .wpnotif_gateay_conf_expand", function (e) {
  300.         if (jQuery(e.target).hasClass('wpnotif_gateay_conf_delete')) return;
  301.  
  302.  
  303.         var showGatewayBox = jQuery(this).closest('.wpnotif_gateway_box');
  304.         if (!showGatewayBox.hasClass('active')) {
  305.             collapseGateway();
  306.  
  307.             showGatewayBox.addClass('active');
  308.             expandGateway(showGatewayBox, false, true);
  309.         } else {
  310.             collapseGateway();
  311.         }
  312.  
  313.  
  314.     });
  315.  
  316.  
  317.     jQuery(".whatsapp_whatsapp_gateway").on('change', function () {
  318.         var value = jQuery(this).val();
  319.         var name = jQuery(this).attr('name');
  320.  
  321.         if(value>2){
  322.             jQuery(".whatsapp_additional_addon p").show();
  323.         }else{
  324.             jQuery(".whatsapp_additional_addon p").hide();
  325.         }
  326.  
  327.         if(value == 3){
  328.             jQuery('.wpn_gateway_document_link').show().closest('td').addClass('wpn_gateway_document_visible');
  329.         }
  330.  
  331.         jQuery('.' + name + '_active').hide();
  332.         jQuery('.whatsapp_gateway_' + value).addClass(name + '_active').show();
  333.     });
  334.     setTimeout(function () {
  335.         jQuery(".wpnotif-hide-elem").hide();
  336.         jQuery(".whatsapp_whatsapp_gateway").trigger('change');
  337.     })
  338.  
  339.     function enableGateway(gateway) {
  340.         jQuery(".wpnotif-gs-gatway-select-td").find('[data-value=' + gateway + ']').removeClass('disabled').removeAttr('disabled');
  341.     }
  342.  
  343.     function disableGateway(gatewaySelect, gateway) {
  344.         jQuery(".wpnotif-gs-gatway-select-td").find('[data-value=' + gateway + ']').addClass('disabled').attr('disabled', 'disabled');
  345.         gatewaySelect.find('[data-value=' + gateway + ']').removeClass('disabled').removeAttr('disabled');
  346.     }
  347.  
  348.     jQuery(document).on("click", ".wpnotif_gateay_conf_delete", function (e) {
  349.  
  350.         var thisGatewayBox = jQuery(this).closest('.wpnotif_gateway_box');
  351.         var gc = thisGatewayBox.attr('wpnotif-gateway');
  352.         if (thisGatewayBox.attr('all')) {
  353.             jQuery(this).remove();
  354.             return;
  355.         }
  356.  
  357.         enableGateway(gc);
  358.         delete gatewayList['gc_' + gc];
  359.         gatewayInp.val(JSON.stringify(gatewayList));
  360.  
  361.  
  362.         var table = thisGatewayBox.find('.selected_gateway_conf');
  363.         table.find('.gateway_conf').appendTo(gateway_table_list);
  364.  
  365.         thisGatewayBox.slideUp('fast').remove();
  366.  
  367.         allowUpdateSettings();
  368.     });
  369.  
  370.  
  371.     function collapseGateway() {
  372.         jQuery(".wpnotif_admin_conf .active").removeClass('active').find(".wpnotif_gateway_configuation_expand_box").slideUp('fast');
  373.  
  374.  
  375.     }
  376.  
  377.     var activeGb;
  378.  
  379.     function expandGateway(gatewayBox, isNew, autoScroll) {
  380.  
  381.         activeGb = gatewayBox;
  382.         gatewayBox.addClass('active').find(".wpnotif_gateway_configuation_expand_box").stop().slideDown('fast', function () {
  383.             if (!autoScroll) return;
  384.             if (!isNew) {
  385.                 gatewayScroll();
  386.             } else {
  387.                 setTimeout(function () {
  388.                     gatewayScroll();
  389.                 }, 190)
  390.             }
  391.         });
  392.  
  393.  
  394.     }
  395.  
  396.     function gatewayScroll() {
  397.         jQuery('html, body').stop().animate({
  398.             scrollTop: activeGb.offset().top - 100
  399.         }, 300);
  400.     }
  401.  
  402.     function allowUpdateSettings() {
  403.         jQuery(".wpnotif_admin_submit").removeAttr("disabled");
  404.  
  405.     }
  406.  
  407.  
  408.     var wpnotif_sort_fields = jQuery(".wpnotif-reg-fields").find('tbody');
  409.  
  410.     if (wpnotif_sort_fields.length) {
  411.         var wpnotif_sortorder = jQuery("#wpnotif_sortorder");
  412.  
  413.  
  414.         var sortorder = wpnotif_sortorder.val().split(',');
  415.  
  416.         wpnotif_sort_fields.find('tr').sort(function (a, b) {
  417.             var ap = jQuery.inArray(a.id, sortorder);
  418.             var bp = jQuery.inArray(b.id, sortorder);
  419.             return (ap < bp) ? -1 : (ap > bp) ? 1 : 0;
  420.  
  421.  
  422.         }).appendTo(wpnotif_sort_fields);
  423.  
  424.  
  425.         wpnotif_sort_fields.sortable({
  426.             update: function (event, ui) {
  427.                 var sortOrder = jQuery(this).sortable('toArray').toString();
  428.                 wpnotif_sortorder.val(sortOrder);
  429.  
  430.                 allowUpdateSettings();
  431.             }
  432.         });
  433.  
  434.     }
  435.  
  436.     var dpc = jQuery('#wpnotif_purchasecode');
  437.  
  438.  
  439.     var wpnotif_tab_wrapper = jQuery(".wpnotif-tab-wrapper");
  440.     if (wpnotif_tab_wrapper.length) {
  441.         var wpnotif_admin_submit = jQuery(".wpnotif_admin_submit");
  442.         var width_wpnotif_admin_submit = wpnotif_admin_submit.outerWidth(true) + 24;
  443.         var wpnotif_left_side = jQuery(".wpnotif_admin_left_side");
  444.         jQuery(window).on('load', function () {
  445.             update_tab_width();
  446.         });
  447.         jQuery(window).on('resize', function () {
  448.             update_tab_width();
  449.             update_tab_sticky();
  450.             update_tb_line();
  451.  
  452.         });
  453.  
  454.         var respon_win = 822;
  455.         var tb_top = wpnotif_tab_wrapper.offset().top;
  456.         var ad_bar_height = jQuery("#wpadminbar").outerHeight(true);
  457.         jQuery(window).on('scroll', function () {
  458.             update_tab_sticky();
  459.         });
  460.  
  461.  
  462.         jQuery(window).trigger('scroll');
  463.  
  464.     }
  465.  
  466.     function update_tab_sticky() {
  467.         var w_top = jQuery(window).scrollTop();
  468.         var sb = tb_top - w_top;
  469.         if (sb <= ad_bar_height && jQuery(window).width() >= respon_win) {
  470.             wpnotif_tab_wrapper.addClass("wpnotif-tab-wrapper-fixed").css({'top': ad_bar_height});
  471.         } else {
  472.             wpnotif_tab_wrapper.removeClass("wpnotif-tab-wrapper-fixed");
  473.         }
  474.     }
  475.  
  476.     function update_tab_width() {
  477.         var w = wpnotif_left_side.width();
  478.         wpnotif_tab_wrapper.outerWidth(w);
  479.         wpnotif_admin_submit.css({'left': wpnotif_left_side.offset().left + w - 168});
  480.  
  481.     }
  482.  
  483.     var $mainNav = jQuery(".wpnotif-tab-ul");
  484.  
  485.     jQuery(document).on("click", ".wpnotif_popmessage", function () {
  486.  
  487.         jQuery(this).closest('.wpnotif_popmessage').slideUp('fast', function () {
  488.             jQuery(this).remove();
  489.         });
  490.     })
  491.  
  492.     var $el, leftPos, newWidth;
  493.  
  494.     $mainNav.append("<li id='wpnotif-tab-magic-line' style='display:none;'></li>");
  495.     var $magicLine = jQuery("#wpnotif-tab-magic-line");
  496.  
  497.     setTimeout(function () {
  498.         $magicLine.show();
  499.         update_tb_line();
  500.     })
  501.  
  502.     function update_tb_line() {
  503.         var wpnotif_active_tab = jQuery(".wpnotif-nav-tab-active");
  504.  
  505.         if (!wpnotif_active_tab.length) {
  506.             $magicLine.hide();
  507.             return;
  508.         }
  509.  
  510.         var wpnotif_active_tab_par_pos = wpnotif_active_tab.parent().position();
  511.         $magicLine
  512.             .width(wpnotif_active_tab.parent().width())
  513.             .css({
  514.                 "left": wpnotif_active_tab_par_pos.left,
  515.                 "top": wpnotif_active_tab_par_pos.top + 21
  516.             })
  517.             .data("origLeft", $magicLine.position().left)
  518.             .data("origWidth", $magicLine.width());
  519.         if (wpnotif_active_tab.hasClass("wpnotif_ngmc") && !wpnotif_active_tab.hasClass("customfieldsNavTab")) {
  520.  
  521.             $magicLine.hide().css({'top': 45});
  522.         }
  523.     }
  524.  
  525.     jQuery(".wpnotif_admin_conf .updatetabview").on('click', function () {
  526.  
  527.  
  528.         var c = jQuery(this).attr('tab');
  529.  
  530.         var acr = jQuery(this).attr('acr');
  531.  
  532.         var refresh = jQuery(this).attr('refresh');
  533.  
  534.         if (typeof refresh !== typeof undefined && refresh !== false) {
  535.             location.reload();
  536.             return true;
  537.         }
  538.  
  539.         if (typeof acr !== typeof undefined && acr !== false) {
  540.             var inv = 0;
  541.         }
  542.  
  543.         var tab = jQuery("." + c);
  544.  
  545.         if (tab.hasClass('digcurrentactive')) return false;
  546.  
  547.         var $this = jQuery(this);
  548.  
  549.         if (tab.data('attach')) {
  550.             $this = jQuery('.' + tab.data('attach'));
  551.         }
  552.  
  553.         if (!$this.hasClass("wpnotif_ngmc")) {
  554.             $magicLine.show();
  555.             $el = $this.parent();
  556.             leftPos = $el.position().left;
  557.             newWidth = $el.width();
  558.             $magicLine.stop().animate({
  559.                 left: leftPos,
  560.                 width: newWidth,
  561.                 top: $el.position().top + 21
  562.             }, 'fast');
  563.         } else {
  564.             $magicLine.hide();
  565.         }
  566.  
  567.         jQuery(".digcurrentactive").removeClass("digcurrentactive").hide();
  568.  
  569.         tab.fadeIn(150).addClass("digcurrentactive");
  570.  
  571.  
  572.         if (jQuery(".wpnotif-tab-wrapper-fixed").length)
  573.             jQuery('html, body').animate({scrollTop: tab.offset().top - 90}, 220);
  574.  
  575.  
  576.         jQuery(".wpnotif-nav-tab-active").removeClass("wpnotif-nav-tab-active");
  577.         jQuery(this).addClass("wpnotif-nav-tab-active");
  578.  
  579.  
  580.         updateURL("tab", c.slice(0, -3));
  581.  
  582.         return false;
  583.     });
  584.  
  585.     function updateURL(key, val) {
  586.         var url = window.location.href;
  587.         var reExp = new RegExp("[\?|\&]" + key + "=[0-9a-zA-Z\_\+\-\|\.\,\;]*");
  588.  
  589.         if (reExp.test(url)) {
  590.             // update
  591.             var reExp = new RegExp("[\?&]" + key + "=([^&#]*)");
  592.             var delimiter = reExp.exec(url)[0].charAt(0);
  593.             url = url.replace(reExp, delimiter + key + "=" + val);
  594.         } else {
  595.             // add
  596.             var newParam = key + "=" + val;
  597.             if (!url.indexOf('?')) {
  598.                 url += '?';
  599.             }
  600.  
  601.             if (url.indexOf('#') > -1) {
  602.                 var urlparts = url.split('#');
  603.                 url = urlparts[0] + "&" + newParam + (urlparts[1] ? "#" + urlparts[1] : '');
  604.             } else {
  605.                 url += "&" + newParam;
  606.             }
  607.         }
  608.         window.history.pushState(null, document.title, url);
  609.     }
  610.  
  611.  
  612.     var chn = false;
  613.     jQuery(".wpnotif_admin_conf textarea,.wpnotif_admin_conf input").on('keyup', function () {
  614.         if (!jQuery(this).attr("readonly") && !jQuery(this).attr('wpnotif-save')) {
  615.             var pcheck = jQuery(this).closest('.digcon');
  616.             if (!pcheck.length) enableSave();
  617.         }
  618.  
  619.     });
  620.     jQuery(".wpnotif_admin_conf input,.wpnotif_admin_conf select,.wpnotif_activation_form input").on('change', function () {
  621.  
  622.         if (!jQuery(this).attr("readonly") && !jQuery(this).attr('wpnotif-save')) enableSave();
  623.     });
  624.  
  625.  
  626.     var wpnotif_pc = jQuery("#wpnotif_purchasecode");
  627.  
  628.     wpnotif_pc.on('change', function () {
  629.         if (jQuery(this).attr('readonly')) return;
  630.         jQuery(".customfieldsNavTab").attr('refresh', 1);
  631.     });
  632.     wpnotif_pc.on('keyup', function () {
  633.  
  634.         if (jQuery(this).attr('readonly')) return;
  635.  
  636.             jQuery(".wpnotif_prc_ver").hide();
  637.             jQuery(".wpnotif_prc_nover").hide();
  638.        
  639.     });
  640.  
  641.     function enableSave() {
  642.         if (!chn) {
  643.             chn = true;
  644.             allowUpdateSettings();
  645.         }
  646.     }
  647.  
  648.     function allowUpdateSettings() {
  649.         jQuery(".wpnotif_admin_submit").removeAttr("disabled");
  650.  
  651.     }
  652.  
  653.     jQuery(document).on('click', '.wpnotif_copy_shortcode', function (e) {
  654.         var a = jQuery(this).parent();
  655.         var i = a.find("input");
  656.         copyShortcode(i);
  657.     });
  658.  
  659.     function copyShortcode(i) {
  660.         if (i.attr("nocop")) return;
  661.         i.attr('nocop', 1);
  662.         i.select();
  663.         document.execCommand("copy");
  664.         var v = i.val();
  665.         i.val(wpnotifobj.Copiedtoclipboard);
  666.         setTimeout(
  667.             function () {
  668.                 i.val(v);
  669.                 i.removeAttr('nocop');
  670.             }, 800);
  671.     }
  672.  
  673.     if (jQuery.fn.mask) {
  674.         dpc.mask('AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA');
  675.     }
  676.  
  677.     var wpnotif_tapp = jQuery("#wpnotif_tapp");
  678.  
  679.     var sgs = jQuery(".wpnotif_load_overlay_gs");
  680.  
  681.     var se = sgs.length;
  682.  
  683.  
  684.     var wpnotif_test_api_status = 0;
  685.  
  686.     jQuery(".wpnotif_request_server_addition").on('click', function () {
  687.         var hr = jQuery(this).attr('href');
  688.         window.open(hr, '_target');
  689.     })
  690.     var refreshCode = 0;
  691.     jQuery(".wpnotif_domain_type").find('button').on('click', function () {
  692.         var value = jQuery(this).attr('val');
  693.         jQuery("input[name='wpnotif_license_type']").val(value);
  694.         if (refreshCode != 1) {
  695.             refreshCode = 0;
  696.             jQuery("#wpnotif_purchasecode").val('').removeAttr('readonly');
  697.         }
  698.         jQuery(".wpnotif_prchcde").fadeIn('fast');
  699.         jQuery(".wpnotif_domain_type").hide();
  700.         jQuery(".wpnotif_btn_unregister").hide();
  701.  
  702.         if (value != 1) {
  703.             jQuery(".request_live_server_addition").show();
  704.             jQuery(".request_testing_server_addition").hide();
  705.         } else {
  706.             jQuery(".request_live_server_addition").hide();
  707.             jQuery(".request_testing_server_addition").show();
  708.         }
  709.     })
  710.     jQuery(".wpnotif_btn_unregister").on('click', function () {
  711.  
  712.         sgs.find('.circle-loader').removeClass('load-complete');
  713.         sgs.find('.checkmark').hide();
  714.         sgs.fadeIn();
  715.  
  716.  
  717.         var code = 'BABIATOO-AAAA-AAAA-AAAA-AAAAAAAAAAAA';
  718.         jQuery.post('https://bridge.unitedover.com/updates/verify.php',
  719.             {
  720.                 code: code,
  721.                 slug: 'wpnotif',
  722.                 request_site: encodeURIComponent(jQuery("input[name='wpnotif_domain']").val()),
  723.                 license_type: jQuery("input[name='wpnotif_license_type']").val(),
  724.                 unregister: 1,
  725.                 version: jQuery("input[name='wpnotif_version']").val(),
  726.                 settings: 1,
  727.             }, function (data, status) {
  728.                 data = 1;
  729.                     jQuery(".wpnotif_domain_type").fadeIn('fast');
  730.                     jQuery(".wpnotif_prchcde").fadeOut();
  731.                     jQuery(".wpnotif_prc_ver").fadeOut();
  732.                     jQuery(".wpnotif_prc_nover").hide();
  733.                     jQuery("#wpnotif_purchasecode").val('').removeAttr('readonly').trigger('change');
  734.                
  735.                 jQuery(".wpnotif_activation_form").submit();
  736.  
  737.                 return false;
  738.             }
  739.         );
  740.  
  741.     })
  742.  
  743.     jQuery(".wpnotif_btn_unregister").on('click', function () {
  744.  
  745.         sgs.find('.circle-loader').removeClass('load-complete');
  746.         sgs.find('.checkmark').hide();
  747.         sgs.fadeIn();
  748.  
  749.  
  750.         var code = 'BABIATOO-AAAA-AAAA-AAAA-AAAAAAAAAAAA';
  751.         jQuery.post('https://bridge.unitedover.com/updates/verify.php',
  752.             {
  753.                 code: code,
  754.                 slug: 'wpnotif',
  755.                 request_site: encodeURIComponent(jQuery("input[name='wpnotif_domain']").val()),
  756.                 license_type: jQuery("input[name='wpnotif_license_type']").val(),
  757.                 addons: jQuery("input[name='wpnotif_addons_list']").val(),
  758.                 unregister: 1,
  759.                 version: jQuery("input[name='wpnotif_version']").val(),
  760.                 settings: 1,
  761.             }, function (data, status) {
  762.                 jQuery(".wpnotif_btn_unregister").hide();
  763.  
  764.                 jQuery("#wpnotif_purchasecode").val('').removeAttr('readonly').trigger('change');
  765.                 jQuery(".wpnotif_activation_form").submit();
  766.  
  767.                 return false;
  768.             }
  769.         );
  770.  
  771.     })
  772.  
  773.  
  774.     var dac;
  775.     jQuery('.wpnotif_admin_submit').on('click', function () {
  776.         jQuery(this).closest('form').submit();
  777.     })
  778.  
  779.     jQuery('.wpnotif_admin_form').on("submit", function (e) {
  780.         e.preventDefault();
  781.         loader.show();
  782.         var form_data = jQuery(this).serialize();
  783.         jQuery.ajax({
  784.             type: "POST",
  785.             url: wpnotifobj.ajax_url,
  786.             data: form_data,
  787.             success: function (data) {
  788.                 loader.hide();
  789.             },
  790.             error: function () {
  791.                 showWPNotifErrorMessage(wpnotifobj.Error);
  792.             }
  793.         });
  794.  
  795.         return false;
  796.     });
  797.  
  798.     var refreshCode = 0;
  799.     jQuery("#wpnotif_setting_update").on("submit", function () {
  800.         dac = jQuery(this);
  801.  
  802.  
  803.         //wpnotif_hideMessage();
  804.  
  805.         var isOpt = false;
  806.         var fd = dac.serialize();
  807.  
  808.         if (wpnotif_test_api_status != 1) {
  809.             sgs.find('.circle-loader').removeClass('load-complete');
  810.             sgs.find('.checkmark').hide();
  811.             sgs.fadeIn();
  812.         }
  813.  
  814.         var code = dpc.val();
  815.         if (code.length == 0) {
  816.  
  817.             jQuery(".wpnotif_prc_ver").hide();
  818.             jQuery(".wpnotif_prc_nover").hide();
  819.  
  820.             updateSettings(fd, -1);
  821.             return false;
  822.         } else if (code.length != 36) {
  823.             wpnotif_showMessage(wpnotifobj.invalidpurchasecode);
  824.  
  825.             jQuery(".wpnotif_prc_ver").hide();
  826.             jQuery(".wpnotif_prc_nover").show();
  827.             updateSettings(fd, -1);
  828.             return false;
  829.         }
  830.  
  831.         if (isBusy) return false;
  832.         isBusy = true;
  833.  
  834.         jQuery.post('',
  835.             {
  836.                 json: 1,
  837.                 code: code,
  838.                 slug: 'wpnotif',
  839.                 request_site: encodeURIComponent(jQuery("input[name='wpnotif_domain']").val()),
  840.                 settings: 1,
  841.                 license_type: jQuery("input[name='wpnotif_license_type']").val(),
  842.                 version: jQuery("input[name='wpnotif_version']").val(),
  843.             }, function (response, status) {
  844.                 isBusy = false;
  845.                 var data = 1;
  846.                 var type = 1;
  847.                
  848.                 refreshCode = 1;
  849.                
  850.                 jQuery(".wpnotif_domain_type").find('button[val=' + type + ']').trigger('click');
  851.                
  852.                
  853.                 fd = dac.serialize();
  854.  
  855.                 if (data != 1) {
  856.                     invPC(se);
  857.                     dpc.attr('invalid', 1);
  858.  
  859.                 } else {
  860.                     jQuery(".wpnotif_prc_ver").show();
  861.                     jQuery(".wpnotif_prc_nover").hide();
  862.                     dpc.attr('invalid', 0);
  863.  
  864.                 }
  865.  
  866.                 if (data == 0) {
  867.                     wpnotif_showMessage(wpnotifobj.invalidpurchasecode);
  868.                     if (!sgs.attr("ajxsu")) {
  869.                         updateSettings(fd, -1);
  870.                     }
  871.  
  872.                 } else if (data == 1) {
  873.  
  874.                     jQuery(".wpnotif_btn_unregister").show();
  875.  
  876.                     if (sgs.attr("ajxsu")) {
  877.                         jQuery(".wpnotif_activation_form").unbind("submit").submit();
  878.                     } else {
  879.                         updateSettings(fd, 1);
  880.                         jQuery(".wpnotif_pc_notice").hide();
  881.                     }
  882.                 } else {
  883.                     if (data == -1) {
  884.                         wpnotif_showMessage("This purchase code is already being used on another site.");
  885.                     } else wpnotif_showMessage(response.msg);
  886.  
  887.  
  888.                     if (!sgs.attr("ajxsu")) {
  889.                         updateSettings(fd, -1);
  890.                     }
  891.                 }
  892.  
  893.  
  894.             }
  895.         );
  896.  
  897.  
  898.         return false;
  899.     });
  900.  
  901.  
  902.     function invPC(se) {
  903.         jQuery("#wpnotif_purchasecode").removeAttr('readonly');
  904.         jQuery(".wpnotif_prc_ver").hide();
  905.         jQuery(".wpnotif_prc_nover").show();
  906.         if (se > 0) sgs.hide();
  907.     }
  908.  
  909.     var isBusy = false;
  910.  
  911.     function updateSettings(fd, activate) {
  912.         if (isBusy) return;
  913.         isBusy = true;
  914.         jQuery.ajax({
  915.             type: "POST",
  916.             url: wpnotifobj.ajax_url,
  917.             data: fd + '&action=wpnotif_save_settings&pca=' + activate,
  918.             success: function (data) {
  919.                 isBusy = false;
  920.                 sgs.find('.circle-loader').addClass('load-complete');
  921.                 sgs.find('.checkmark').show();
  922.                 setTimeout(
  923.                     function () {
  924.                         sgs.fadeOut();
  925.                         chn = false;
  926.                         jQuery(".wpnotif_admin_submit").attr("disabled", "disabled");
  927.                         if (wpnotif_test_api_status == 1) {
  928.                             digCallTestApi();
  929.                         }
  930.                     }, 1500);
  931.  
  932.  
  933.             },
  934.             error: function () {
  935.                 isBusy = false;
  936.                 invPC();
  937.                 showWPNotifErrorMessage(wpnotifobj.Error);
  938.             }
  939.         });
  940.  
  941.     }
  942.  
  943.  
  944.     var wpnotif_api_test;
  945.  
  946.     var loader = jQuery(".wpnotif_load_overlay");
  947.  
  948.     jQuery(document).on("click", ".wpnotif_call_test_api_btn", function () {
  949.  
  950.  
  951.         wpnotif_api_test = jQuery(this).closest(".wpnotif_api_test");
  952.  
  953.         var wpnotif_test_cont = wpnotif_api_test.find(".digcon");
  954.         var mobile = wpnotif_test_cont.find(".mobile").val();
  955.         var countrycode = wpnotif_test_cont.find(".wpnotif_countrycode").val();
  956.  
  957.         if (mobile.length == 0 || !jQuery.isNumeric(mobile) || countrycode.length == 0 || !jQuery.isNumeric(countrycode)) {
  958.             showWPNotifErrorMessage(wpnotifobj.validnumber);
  959.             return false;
  960.         }
  961.  
  962.         wpnotif_test_api_status = 1;
  963.  
  964.         loader.show();
  965.  
  966.         if (jQuery(".wpnotif_admin_submit").attr("disabled")) {
  967.             digCallTestApi();
  968.         } else jQuery(".wpnotif_activation_form").trigger("submit");
  969.  
  970.  
  971.     });
  972.  
  973.     var sms_processing = false;
  974.     var sms_processing_elem = jQuery(".wpnotif_sms_processing");
  975.     var hide_message_timeout;
  976.     jQuery(".send_quick_sms").on('click', function (e) {
  977.  
  978.         e.preventDefault();
  979.         if (sms_processing) return;
  980.         clearTimeout(hide_message_timeout);
  981.         var send_button = jQuery(this);
  982.         send_button.addClass('processing').find('span').text(send_button.attr('data-processing')).parent().find('div').addClass('wpnotif_sms_processing');
  983.         sms_processing = true;
  984.         sms_processing_elem.show();
  985.         var box = jQuery(this).closest('.quick_sms_grid');
  986.         var mobile = box.find(".mobile").val();
  987.         wpnotif_test_api_status = 0;
  988.         var response_box = jQuery(".quick_sms_response_box");
  989.         var message = box.find("#quick_message").val();
  990.         var trigger_order_status = 0;
  991.         var order_id = jQuery('.wpnotif_order_id').val();
  992.         if (jQuery(this).hasClass('trigger_order_status')) {
  993.             trigger_order_status = 1;
  994.         }
  995.         var wpnotif_nonce = jQuery(".wpnotif_nonce").val();
  996.  
  997.         var post_notification = 0;
  998.         if (jQuery('.wpnotif_post_notification').length) {
  999.             post_notification = jQuery('.wpnotif_post_notification').val();
  1000.         }
  1001.  
  1002.         response_box.hide();
  1003.         jQuery.ajax({
  1004.             type: 'post',
  1005.             async: true,
  1006.             url: wpnotifobj.ajax_url,
  1007.             data: {
  1008.                 action: 'wpnotif_send_quick_sms',
  1009.                 mobile: mobile,
  1010.                 quick_message: message,
  1011.                 trigger_order_status: trigger_order_status,
  1012.                 post_id: order_id,
  1013.                 wpnotif_nonce: wpnotif_nonce,
  1014.                 post_notification: post_notification
  1015.             },
  1016.             success: function (res) {
  1017.                 box.find("#quick_message").val('');
  1018.                 send_button.removeClass('processing').find('span').text(send_button.attr('data-send')).parent().find('div').removeClass('wpnotif_sms_processing');
  1019.                 sms_processing = false;
  1020.                 sms_processing_elem.hide();
  1021.  
  1022.                 if (res.success == 0) {
  1023.                     response_box.addClass('msg_send_failed').removeClass('msg_send_success');
  1024.                 } else {
  1025.                     response_box.addClass('msg_send_success').removeClass('msg_send_failed');
  1026.  
  1027.                     if (res.data.data != null && wpnotifobj.isWhatsappWebEnabled) {
  1028.                         try {
  1029.                             var data = res.data.data;
  1030.                             jQuery.each(data, function (no, msg) {
  1031.                                 sendWhatsWebMessage(no, msg);
  1032.                             });
  1033.                             if (Object.keys(data).length > 1) {
  1034.                                 update_message(0);
  1035.                             }
  1036.  
  1037.                         } catch (e) {
  1038.  
  1039.                         }
  1040.                     }
  1041.  
  1042.                 }
  1043.                 response_box.find('.msg').text(res.data.msg).parent().stop().fadeIn('fast');
  1044.                 hide_message_timeout = setTimeout(function () {
  1045.                     response_box.fadeOut('fast')
  1046.                 }, 3000);
  1047.             },
  1048.             error: function (res) {
  1049.                 send_button.removeClass('processing').find('span').text(send_button.attr('data-send')).parent().find('div').removeClass('wpnotif_sms_processing');
  1050.                 sms_processing = false;
  1051.                 sms_processing_elem.hide();
  1052.                 response_box.addClass('msg_send_failed').removeClass('msg_send_success').find('.msg').text(wpnotifobj.Error).parent().stop().fadeIn('fast');
  1053.  
  1054.                 hide_message_timeout = setTimeout(function () {
  1055.                     response_box.fadeOut('fast')
  1056.                 }, 3000);
  1057.             }
  1058.         });
  1059.         return false;
  1060.     })
  1061.  
  1062.  
  1063.     function digCallTestApi() {
  1064.         if (wpnotif_test_api_status != 1) return;
  1065.         loader.show();
  1066.         var wpnotif_test_cont = wpnotif_api_test.find(".digcon");
  1067.         var mobile = wpnotif_test_cont.find(".mobile").val();
  1068.         var countrycode = wpnotif_test_cont.find(".wpnotif_countrycode").val();
  1069.  
  1070.         var gatewayBox = wpnotif_api_test.closest('.wpnotif_gateway_box');
  1071.  
  1072.         var gateway;
  1073.         if (gatewayBox.length) {
  1074.             gateway = gatewayBox.find(".wpnotif_gateway").val();
  1075.         } else {
  1076.             gateway = jQuery(".wpnotif_gateway").val();
  1077.         }
  1078.         wpnotif_test_api_status = 0;
  1079.         jQuery.ajax({
  1080.             type: 'post',
  1081.             async: true,
  1082.             url: wpnotifobj.ajax_url,
  1083.             data: {
  1084.                 action: 'wpnotif_test_api',
  1085.                 digt_mobile: mobile,
  1086.                 gateway: gateway,
  1087.                 digt_countrycode: countrycode
  1088.  
  1089.             },
  1090.             success: function (res) {
  1091.                 showTestResponse(res);
  1092.             },
  1093.             error: function (res) {
  1094.                 showTestResponse(res);
  1095.             }
  1096.         });
  1097.     }
  1098.  
  1099.  
  1100.     function showTestResponse(msg) {
  1101.         wpnotif_test_api_status = 0;
  1102.         wpnotif_api_test.find(".wpnotif_call_test_response").show();
  1103.         wpnotif_api_test.find(".wpnotif_call_test_response_msg").text(msg);
  1104.         loader.hide();
  1105.  
  1106.     }
  1107.  
  1108.     wpnotif_tapp.on('change', function () {
  1109.         var val = jQuery(this).val();
  1110.  
  1111.         var te = wpnotif_tapp.find("option:selected").attr('han');
  1112.  
  1113.         te = te.replace(".", "_");
  1114.  
  1115.         jQuery('.wpnotif_call_test_response').hide();
  1116.         if (val == 1 || val == 13) {
  1117.  
  1118.             jQuery(".wpnotif_api_test").hide();
  1119.             jQuery(".disotp").hide();
  1120.             jQuery(".wpnotif_current_gateway").hide();
  1121.         } else {
  1122.             jQuery(".wpnotif_api_test").show();
  1123.             jQuery(".disotp").show();
  1124.             jQuery(".wpnotif_current_gateway").show().find("span").text(wpnotif_tapp.find("option:selected").text());
  1125.         }
  1126.  
  1127.  
  1128.         wpnotif_tapp.find('option').each(function (index, element) {
  1129.             var hanc = jQuery(this).attr("han");
  1130.             if (hanc != te) {
  1131.                 jQuery("." + hanc + "cred").each(function () {
  1132.                     jQuery(this).hide().find("input").removeAttr("required");
  1133.                 });
  1134.  
  1135.             }
  1136.         });
  1137.         jQuery("." + te + "cred").each(function () {
  1138.             var input = jQuery(this).show().find("input");
  1139.             var optional = input.attr('wpnotif-optional');
  1140.             if (optional && optional == 1) return;
  1141.  
  1142.             input.attr("required", "required");
  1143.         });
  1144.  
  1145.     });
  1146.  
  1147.     jQuery(document).on("change update", ".input-switch input", function () {
  1148.         if (jQuery(this).prop("checked") == true) {
  1149.             jQuery(this).parent().addClass('checked');
  1150.         } else {
  1151.             jQuery(this).parent().removeClass('checked');
  1152.         }
  1153.     });
  1154.     var manual_call = false;
  1155.     jQuery(document).on("change", ".notification_toggle", function () {
  1156.         var table = jQuery(this).closest('table');
  1157.         var msg = table.next();
  1158.         if (jQuery(this).prop("checked") == true) {
  1159.             if (manual_call) {
  1160.                 msg.show();
  1161.             } else {
  1162.                 msg.stop().slideDown('fast', function () {
  1163.                     jQuery(this).show();
  1164.                 });
  1165.             }
  1166.         } else {
  1167.             if (manual_call) {
  1168.                 msg.hide();
  1169.             } else {
  1170.                 msg.stop().slideUp('fast');
  1171.             }
  1172.         }
  1173.     });
  1174.  
  1175.  
  1176.     var country_based = jQuery("#country_based");
  1177.     var gateway_based_notifications = jQuery(".gateway_based_notifications");
  1178.     var simple_user_notifications = jQuery(".simple_user_notifications");
  1179.     var user_notifications_temp = jQuery(".user_notifications");
  1180.     country_based.on('change', function () {
  1181.         updateCountryBasedNotifications();
  1182.     })
  1183.     setTimeout(function () {
  1184.         updateCountryBasedNotifications();
  1185.     });
  1186.  
  1187.     function updateCountryBasedNotifications() {
  1188.  
  1189.         if (country_based.prop("checked") == true) {
  1190.             var apiSettingsClone = apisettingsTab.clone();
  1191.             apiSettingsClone.find('.country_specific').remove();
  1192.  
  1193.             apiSettingsClone.find('.wpnotif_gateway_configuation_expand_box_contents').empty().each(function () {
  1194.                 var clone = user_notifications_temp.clone();
  1195.  
  1196.                 clone.find('tr').each(function () {
  1197.                     var id = "a_" + Math.random();
  1198.                     var $this = jQuery(this);
  1199.                     $this.find('input, textarea').attr('id', id);
  1200.                     $this.find('label').attr('for', id);
  1201.  
  1202.                 });
  1203.                 jQuery(this).append('<div class="wpnotif_gateway_sep_line"></div>').append(clone);
  1204.             });
  1205.  
  1206.             gateway_based_notifications.empty().append(apiSettingsClone);
  1207.             gateway_based_notifications.stop().slideDown('fast');
  1208.             simple_user_notifications.hide();
  1209.             updateCountryBasedNotifications_ui();
  1210.  
  1211.         } else {
  1212.             gateway_based_notifications.hide();
  1213.             simple_user_notifications.show();
  1214.         }
  1215.     }
  1216.  
  1217.     var notifications_json;
  1218.     var notifications = jQuery("#wpnotif_gateway_customer_notifications");
  1219.     setTimeout(function () {
  1220.  
  1221.         jQuery(document).on("change", ".gateway_based_notifications input,.gateway_based_notifications textarea", function (e) {
  1222.             updateCountryBasedNotifications_data();
  1223.         });
  1224.  
  1225.         updateCountryBasedNotifications_ui();
  1226.  
  1227.     }, 10);
  1228.  
  1229.     function updateCountryBasedNotifications_data() {
  1230.         var json = {};
  1231.         gateway_based_notifications.find('.wpnotif_gateway_box').each(function () {
  1232.             var gateway = jQuery(this).attr('wpnotif-gateway');
  1233.             var values = {};
  1234.             jQuery(this).find('.form-switch').each(function () {
  1235.                 var input = jQuery(this).find('input');
  1236.                 var key = input.attr('name');
  1237.                 var checked = '';
  1238.                 if (input.prop("checked") == true) {
  1239.                     checked = 'on';
  1240.  
  1241.                 }
  1242.                 var message = jQuery(this).next().find('textarea').val();
  1243.                 values[key] = {'enable': checked, 'msg': message};
  1244.             });
  1245.             json['wpnotif_' + gateway] = values;
  1246.  
  1247.         });
  1248.         notifications.val(JSON.stringify(json));
  1249.         enableSave();
  1250.     }
  1251.  
  1252.  
  1253.  
  1254.  
  1255.     function stripslashes (str) {
  1256.         return (str + '').replace(/\\(.?)/g, function (s, n1) {
  1257.             switch (n1) {
  1258.                 case '\\':
  1259.                     return '\\';
  1260.                 case '0':
  1261.                     return '\u0000';
  1262.                 case '':
  1263.                     return '';
  1264.                 default:
  1265.                     return n1;
  1266.             }
  1267.         });
  1268.     }
  1269.  
  1270.     function addslashes(string) {
  1271.         return string.replace(/\\/g, '\\\\').
  1272.         replace(/\u0008/g, '\\b').
  1273.         replace(/\t/g, '\\t').
  1274.         replace(/\n/g, '\\n').
  1275.         replace(/\f/g, '\\f').
  1276.         replace(/\r/g, '\\r').
  1277.         replace(/'/g, '\\\'').
  1278.         replace(/"/g, '\\"');
  1279.     }
  1280.  
  1281.     function updateCountryBasedNotifications_ui() {
  1282.         try {
  1283.  
  1284.             notifications_json = notifications.val();
  1285.             notifications_json = stripslashes(notifications_json);
  1286.             notifications_json = JSON.parse(notifications_json);
  1287.             jQuery.each(notifications_json, function (gateway_key, data) {
  1288.                 var gateway = gateway_key.replace(/\D/g, '');
  1289.  
  1290.                 var gatewaybox = gateway_based_notifications.find('div[wpnotif-gateway="' + gateway + '"]');
  1291.                 if (gatewaybox.length) {
  1292.                     jQuery.each(data, function (key, values) {
  1293.                         var input = gatewaybox.find('input[name="' + key + '"]');
  1294.                         if (values['enable'] == 'on') {
  1295.                             input.prop("checked", true).parent().addClass('checked');
  1296.                             gatewaybox.find('textarea[name="' + key + '_msg"]').val(values['msg']).closest('.notification_message').show();
  1297.                         } else {
  1298.                             input.prop("checked", false).parent().removeClass('checked');
  1299.                             gatewaybox.find('textarea[name="' + key + '_msg"]').val(values['msg']).closest('.notification_message').hide();
  1300.                         }
  1301.  
  1302.                     });
  1303.                 }
  1304.             })
  1305.  
  1306.            notifications.val(addslashes(JSON.stringify(notifications_json)));
  1307.  
  1308.         } catch (e) {
  1309.  
  1310.         }
  1311.  
  1312.     }
  1313.  
  1314.     chn = true;
  1315.     manual_call = true;
  1316.     wpnotif_tapp.trigger('change');
  1317.     jQuery(".input-switch input").trigger('change');
  1318.  
  1319.     chn = false;
  1320.  
  1321.     jQuery("#wpnotif_loading_container").fadeOut('fast');
  1322.  
  1323.     setTimeout(function () {
  1324.         manual_call = false;
  1325.     })
  1326.     jQuery("#wp-admin-bar-wpnotif-pending-messages").on('click', function () {
  1327.         jQuery(".wpnotif-box").fadeToggle('fast');
  1328.         return false;
  1329.     });
  1330.     jQuery(document).on('click', '.wpnotif-whatsapp-send', function (e) {
  1331.         e.preventDefault();
  1332.         var container = jQuery(this).closest('.wpnotif-list');
  1333.         var mobile = container.attr('data-mobile');
  1334.         var msg = container.find('.wpnotif-message').text();
  1335.         var id = container.attr('data-id');
  1336.  
  1337.         sendWhatsWebMessage(mobile, msg);
  1338.  
  1339.         container.fadeOut('fast', function () {
  1340.             jQuery(this).remove();
  1341.         });
  1342.  
  1343.         update_message(id);
  1344.         return false;
  1345.     });
  1346.  
  1347.     function sendWhatsWebMessage(phone, msg) {
  1348.         phone = phone.replace('+','');
  1349.         msg = msg.replace(/[\u200B-\u200D\uFEFF]/g, '');
  1350.         msg = encodeURIComponent(msg);
  1351.         var url = 'https://web.whatsapp.com/send?phone=' + phone + '&text='+msg;
  1352.         if(wpnotifobj.usingWhatsAppDesktop || isMobile.any()){
  1353.             url = 'https://api.whatsapp.com/send?phone=' + phone + '&text='+msg;
  1354.         }
  1355.         window.open(url);
  1356.     }
  1357.  
  1358.     function update_message(id) {
  1359.  
  1360.  
  1361.         var data_pending = jQuery(".wp-notif-total_messages");
  1362.  
  1363.         jQuery.ajax({
  1364.             type: 'post',
  1365.             async: true,
  1366.             url: wpnotifobj.ajax_url,
  1367.             data: {
  1368.                 action: 'wpnotif_update_message',
  1369.                 id: id,
  1370.                 wpnotif_nonce: jQuery(".wpnotif_del_nonce").val(),
  1371.  
  1372.             },
  1373.             success: function (res) {
  1374.                 loader.hide();
  1375.                 res = jQuery.parseHTML(res);
  1376.                 var notif_box = jQuery(".wpnotif-box");
  1377.                 notif_box.replaceWith(res);
  1378.                 var count = jQuery(".wpnotif-box").find(".wpnotif-pending-whatsapp-messages").length;
  1379.  
  1380.  
  1381.                 if (id == -1) {
  1382.                     jQuery(".wpnotif-box").fadeOut('fast');
  1383.                 } else {
  1384.                     jQuery(".wpnotif-box").show();
  1385.                 }
  1386.                 data_pending.text(count);
  1387.                 showTime();
  1388.  
  1389.             }, error: function () {
  1390.                 loader.hide();
  1391.             }
  1392.         });
  1393.     }
  1394.  
  1395.     var notify_user_sms = jQuery("#user_notify_user");
  1396.     var notify_user_whatsapp_message = jQuery("#user_whatsapp_message");
  1397.     var notify_both = jQuery("#user_combine_both");
  1398.     jQuery("#user_notify_user,#user_whatsapp_message").on('change', function () {
  1399.         updateUserConsent();
  1400.     })
  1401.     notify_both.on('change', function () {
  1402.  
  1403.         if (notify_both.prop("checked") == true) {
  1404.             if (notify_user_sms.prop("checked") == true) notify_user_sms.closest('table').next().slideUp();
  1405.             if (notify_user_whatsapp_message.prop("checked") == true) notify_user_whatsapp_message.closest('table').next().slideUp();
  1406.         } else {
  1407.             if (notify_user_sms.prop("checked") == true) notify_user_sms.closest('table').next().slideDown();
  1408.             if (notify_user_whatsapp_message.prop("checked") == true) notify_user_whatsapp_message.closest('table').next().slideDown();
  1409.         }
  1410.     })
  1411.     notify_both.trigger('change');
  1412.     updateUserConsent();
  1413.  
  1414.     function updateUserConsent() {
  1415.         if (notify_user_sms.prop("checked") == true &&
  1416.             notify_user_whatsapp_message.prop("checked") == true) {
  1417.             notify_both.closest('tr').show();
  1418.         } else {
  1419.             notify_both.prop("checked", false).trigger('change');
  1420.             notify_both.closest('tr').hide();
  1421.         }
  1422.     }
  1423.  
  1424.     jQuery(document).on('click', '.clear_message', function (e) {
  1425.         var parent = jQuery(this).closest('.wpnotif-list');
  1426.         var id = parent.attr('data-id');
  1427.         update_message(id);
  1428.         parent.slideUp('fast');
  1429.  
  1430.     })
  1431.  
  1432.     jQuery(document).on('click', '.whatsapp_clear_all', function (e) {
  1433.         loader.show();
  1434.         update_message(-1);
  1435.     })
  1436.  
  1437.     jQuery(".wpnotif_field_floating_text").find("input").on('keyup change', function () {
  1438.         var inp = jQuery(this).val();
  1439.         var size = inp.length;
  1440.         var spn_lbl = jQuery(this).parent().find("span");
  1441.  
  1442.         spn_lbl.stop().animate({'left': Math.max(size * 9 + 33, jQuery(this).attr('dig-min'))}, 'fast');
  1443.     }).trigger('keyup');
  1444.  
  1445.     jQuery('.wpnotif_show_image').on('click', function () {
  1446.  
  1447.         var src = jQuery(this).data('src');
  1448.         var p = jQuery(".wpnotif_preview_overlay");
  1449.  
  1450.         p.find('img').attr('src', '').attr('src', src);
  1451.         p.fadeIn('fast');
  1452.         return false;
  1453.     });
  1454.  
  1455.     jQuery('.wpnotif_preview_overlay').on('click', function () {
  1456.         jQuery(this).fadeOut('fast');
  1457.     });
  1458.  
  1459.  
  1460.     var wpnotif_post_container = jQuery(".wpnotif-post_notifications");
  1461.     var wpnotif_post_msg_row = wpnotif_post_container.find(".wpnotif_post_msg_row");
  1462.     var wpnotif_post_label = wpnotif_post_container.find(".wpnotif-notification_post_name");
  1463.     var wpnotif_post_type = jQuery("#wpnotif_post_type");
  1464.     var enable_post_notifications = jQuery("#enable_post_notifications");
  1465.     var wpnotif_post_msg = jQuery("#wpnotif_post_msg");
  1466.     var wpnotif_post_route = wpnotif_post_container.find('#wpnotif_post_route');
  1467.     var post_details_selector = jQuery("#wpnotif_post_msg_details");
  1468.     var post_usergroup = wpnotif_post_container.find('.wpnotif-user_group');
  1469.  
  1470.     var post_details = {};
  1471.     try {
  1472.         post_details = JSON.parse(post_details_selector.val());
  1473.     } catch (e) {
  1474.         post_details = {};
  1475.     }
  1476.     if (post_details == null) {
  1477.         post_details = {};
  1478.     }
  1479.     wpnotif_post_type.on('change update', function () {
  1480.         var message = '';
  1481.         var type = jQuery(this).val();
  1482.         var group = '';
  1483.         var route = 1;
  1484.         if (post_details.hasOwnProperty(type)) {
  1485.             var data = post_details[type];
  1486.             message = data['message'];
  1487.             group = data['group'];
  1488.             route = data['route'];
  1489.  
  1490.             if (data['enable'] == 'on') {
  1491.                 wpnotif_post_msg_row.removeClass('wpnotif-hide');
  1492.                 enable_post_notifications.prop('checked', true).trigger('update');
  1493.             } else {
  1494.                 disable_post_notification();
  1495.             }
  1496.         } else {
  1497.             disable_post_notification();
  1498.         }
  1499.  
  1500.         wpnotif_post_label.text(jQuery(this).find("option:selected").text());
  1501.  
  1502.         wpnotif_post_msg.val(message);
  1503.         wpnotif_post_route.val(route).trigger('change');
  1504.  
  1505.         if (group && group.length > 0) {
  1506.             group = group.split(",");
  1507.             jQuery.each(group, function (i, e) {
  1508.                 post_usergroup.untselect().val(e);
  1509.             });
  1510.             post_usergroup.trigger('change');
  1511.         }
  1512.     }).trigger('update');
  1513.  
  1514.  
  1515.     wpnotif_post_route.on('change', function () {
  1516.         update_post_notifications();
  1517.     });
  1518.  
  1519.     enable_post_notifications.on('change', function () {
  1520.         update_post_notifications();
  1521.     });
  1522.  
  1523.     wpnotif_post_msg.on('change', function (e) {
  1524.         update_post_notifications();
  1525.     });
  1526.     post_usergroup.on('change', function () {
  1527.         update_post_notifications();
  1528.     })
  1529.  
  1530.     function disable_post_notification() {
  1531.         wpnotif_post_msg_row.addClass('wpnotif-hide');
  1532.         enable_post_notifications.prop('checked', false).trigger('update');
  1533.         post_usergroup.untselect('val', []);
  1534.     }
  1535.  
  1536.     function update_post_notifications() {
  1537.         var type = wpnotif_post_type.val();
  1538.         var message = wpnotif_post_msg.val();
  1539.         var group = post_usergroup.val();
  1540.         var route = wpnotif_post_route.val();
  1541.         if (group && group.length > 0) {
  1542.             group = group.join(',');
  1543.         }
  1544.         var data = {};
  1545.  
  1546.  
  1547.         if (enable_post_notifications.is(":checked")) {
  1548.             wpnotif_post_msg_row.removeClass('wpnotif-hide');
  1549.             data['enable'] = 'on';
  1550.         } else {
  1551.             wpnotif_post_msg_row.addClass('wpnotif-hide');
  1552.             data['enable'] = '';
  1553.         }
  1554.         data['group'] = group;
  1555.         data['message'] = message;
  1556.         data['route'] = route;
  1557.  
  1558.         post_details[type] = data;
  1559.         post_details_selector.val(JSON.stringify(post_details));
  1560.     }
  1561.  
  1562.     jQuery(".wpnotif_use_as_newsletter_inp").on('change', function () {
  1563.         var value = jQuery(this).val();
  1564.         var form = jQuery(this).closest('form');
  1565.  
  1566.         if (value == 1) {
  1567.             form.find('.wpnotif_use_newsletter').closest('tr').removeClass('wpnotif-hide');
  1568.         } else {
  1569.             form.find('.wpnotif_use_newsletter').closest('tr').addClass('wpnotif-hide');
  1570.         }
  1571.     }).trigger('change');
  1572.  
  1573.  
  1574.     jQuery(document).on("keyup update", ".wpnotif_textarea, .wpnotif_admin_conf textarea,.wpnotif_admin_conf textarea,#quick_message", function () {
  1575.         var arabic = /[\u0600-\u06FF]/;
  1576.  
  1577.         if (arabic.test(jQuery(this).val()) === true) {
  1578.             jQuery(this).addClass('wpnotif_rtl').removeClass('wpnotif_ltr');
  1579.         } else {
  1580.             jQuery(this).removeClass('wpnotif_rtl').addClass('wpnotif_ltr');
  1581.         }
  1582.     }).trigger("update");
  1583.  
  1584.     jQuery("#wpnotif_cron_method").on('change update', function () {
  1585.         var val = jQuery(this).val();
  1586.         jQuery('.wpnotif_cron_desc').hide();
  1587.         jQuery('.wpnotif_' + val).show();
  1588.     }).trigger('update');
  1589.  
  1590.  
  1591.     function showTime() {
  1592.  
  1593.         var date_options = {
  1594.             year: 'numeric',
  1595.             month: 'short',
  1596.             day: 'numeric',
  1597.             hour: 'numeric',
  1598.             minute: 'numeric',
  1599.         };
  1600.  
  1601.         jQuery(".wpnotif-time").each(function () {
  1602.             var $this = jQuery(this);
  1603.  
  1604.             $this.removeClass(".wpnotif-time");
  1605.             var time = $this.data('time');
  1606.             var date_time = new Date(time * 1000);
  1607.             $this.text(date_time.toLocaleDateString("en-US", date_options));
  1608.  
  1609.         });
  1610.     }
  1611.  
  1612.     showTime();
  1613.  
  1614.     var isMobile = {
  1615.         Android: function() {
  1616.             return navigator.userAgent.match(/Android/i);
  1617.         },
  1618.         BlackBerry: function() {
  1619.             return navigator.userAgent.match(/BlackBerry/i);
  1620.         },
  1621.         iOS: function() {
  1622.             return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  1623.         },
  1624.         Opera: function() {
  1625.             return navigator.userAgent.match(/Opera Mini/i);
  1626.         },
  1627.         Windows: function() {
  1628.             return navigator.userAgent.match(/IEMobile/i) || navigator.userAgent.match(/WPDesktop/i);
  1629.         },
  1630.         any: function() {
  1631.             return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  1632.         }
  1633.     };
  1634. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement