Mini Kabibi Habibi

Current Path : C:/Program Files/McAfee/WebAdvisor/MFW/packages/webadvisor/
Upload File :
Current File : C:/Program Files/McAfee/WebAdvisor/MFW/packages/webadvisor/wa-sstoast-toggle-rebranding.js

(function (wa, $) {
  var ui = wa.UI = wa.UI || {};
  var _window = wa.Core.Window;
  var _external = wa.Utils.External;
  var _instrument = wa.Utils.Instrument;
  var _settings = wa.Utils.Settings;
  var _misc = wa.Utils.Misc;
  var TOGGLE_COUNT = "toggle_count";
  var currentWindowHeight = "575";

  ui.accept_extension = function () {
    var $el = {
      progressPic: $("#progress"),
      contentInfoTitle: $("#info-title"),
      contentInfoText: $("#info-text"),
      expiredSection: $(".expired__section"),
      expiredLabel: $("#expired-label"),
      expiredName: $("#expired-name"),
      feature1Label: $("#feature-1-label"),
      feature1Name: $("#feature-1-name"),
      freeLabel1: $("#free-label-1"),
      feature1Desc: $("#feature-1-desc"),
      feature2Name: $("#feature-2-name"),
      freeLabel2: $("#free-label-2"),
      feature2Desc: $("#feature-2-desc"),
      checkboxInput: $("#set-secure-search-checkbox"),
      doneButton: $("#done"),
      expiredLabelContainer: $("#expired-label-container"),
      toast: $("#toast"),
      closeIcon: $("#close-icon"),
    };

    var variationMap = {
      0: { // Common L10Ns among all variations
        ExpiredLabel: "SEARCH_TOAST_TOGGLE_EXPIRED_LABEL",
        ExpiredName: "SEARCH_TOAST_TOGGLE_EXPIRED_NAME",
        Feature1Label: "SEARCH_TOAST_TOGGLE_FEATURE_1_ON",
        Feature1Name: "SEARCH_TOAST_TOGGLE_FEATURE_1_NAME",
        Feature1Desc: "SEARCH_TOAST_TOGGLE_FEATURE_1_DESC",
        FreeLabel1: "SEARCH_TOAST_TOGGLE_FREE_LABEL",
        Feature2Name: "SEARCH_TOAST_TOGGLE_FEATURE_2_NAME",
        Feature2Desc: "SEARCH_TOAST_TOAST_COPY_VARIANT_3",
        FreeLabel2: "SEARCH_TOAST_TOGGLE_FREE_LABEL",
        ButtonWant: "SEARCH_TOAST_TOGGLE_BUTTON_SS_PROTECTED",
        ButtonDontWant: "SEARCH_TOAST_TOGGLE_BUTTON_SS_UNPROTECTED",
        ProgressPicChangable: {
            Checked: "wacore:mfw\\packages\\builtin\\wa-sstoast-toggle-rebranding-step2.png",
            Unchecked: "wacore:mfw\\packages\\builtin\\wa-sstoast-toggle-rebranding-step1.png",
        },
      },
      1: {
        VariantId: 1,
        InfoTitle: "SEARCH_TOAST_TOGGLE_VARIANT_1_HEADER",
        InfoText: "SEARCH_TOAST_TOGGLE_VARIANT_1_INFO",
        ToastType: "toggle_toast_rebranding_confidence_variantion_1",
      },
      2: {
        VariantId: 2,
        InfoTitle: "SEARCH_TOAST_TOGGLE_VARIANT_2_HEADER",
        InfoText: "SEARCH_TOAST_TOGGLE_VARIANT_2_INFO",
        ToastType: "toggle_toast_rebranding_working_behind_the_scene_variantion_2",
      },
      3: {
        VariantId: 3,
        InfoTitle: "SEARCH_TOAST_TOGGLE_VARIANT_3_HEADER",
        InfoText: "SEARCH_TOAST_TOGGLE_VARIANT_3_INFO",
        ToastType: "toggle_toast_rebranding_safe_guard_variantion_3",
      },
    }

    function resizeToast() {
        var scrollHeight = $el.toast[0].scrollHeight;
        if (scrollHeight > Number(currentWindowHeight)) {
            $el.toast.css({ height: scrollHeight.toString() + 'px' });
            _window.setHeight(scrollHeight.toString());
        }
    }
    function adjustVersionUI(cohort) {
      // different css styling for same html elements
      var windowHeight = "575";
      var windowWidth = "781";

      if (cohort === 4) {
        $el.expiredSection.addClass('hide');
        $el.doneButton.addClass('button__high__top');
      }
      else
      {
        $el.doneButton.addClass('button__short__top');
      }

      _window.setWidth(windowWidth);
      _window.setHeight(windowHeight);
      currentWindowHeight = windowHeight;
    }

    function getToggleCount() {
        var tc = _settings.getSettingScopedWithDefault(-1, "0", TOGGLE_COUNT);
        return tc.toString();
    }
    function initComponents(cohort, variationInfo, commonInfo, showCloseBtn) {

      //Toggle Listener
      $el.checkboxInput.click(function () {
      
        _settings.increment_setting(TOGGLE_COUNT, "0");
  
        
        var progressPicPath = "";

        if ($el.checkboxInput.is(":checked")) {
            progressPicPath = commonInfo.ProgressPicChangable && commonInfo.ProgressPicChangable.Checked;
        }
        else {
            progressPicPath = commonInfo.ProgressPicChangable && commonInfo.ProgressPicChangable.Unchecked;
        }
  
        if (progressPicPath)
        {
        $el.progressPic.attr("src", progressPicPath);
        }
        })

      var toast_type = _misc.getQualifiedToastType(variationInfo.ToastType, cohort);
      var browserCode = _instrument.getBrowserTypeCode();
      var provider = _instrument.getSecureSearchProvider();
      var metadata = _instrument.getSecureSearchToastMetadata(showCloseBtn, browserCode);

      //Close Button listener
      if (showCloseBtn) {
        $el.closeIcon.removeClass("invisible");
        _window.setDraggableOffset(0, 60);
          $el.closeIcon.click(function () {
          _instrument.sendSecureSearchToastEvent("Closed_Explicit", browserCode, provider, toast_type, metadata, getToggleCount());
          _window.close();
        });
      }

      //Done button listener
      $el.doneButton.click(function () {
      var isChecked = $el.checkboxInput.is(":checked");
      var telemetryActionType = isChecked ? "Accepted" : "Declined";
      _instrument.sendSecureSearchToastEvent(telemetryActionType, browserCode, provider, toast_type, metadata, getToggleCount());
        
      if (isChecked) {
        wa.Core.SecureSearch.enable();
      }
      else {
        wa.Core.SecureSearch.disable();
      }

      _window.close();
      });
   }

   function fillText(variationInfo, commonInfo, lang) {
      $el.contentInfoTitle.text(lang(variationInfo.InfoTitle));
      $el.contentInfoText.text(lang(variationInfo.InfoText));
      $el.feature2Name.text(lang(commonInfo.Feature2Name));
      $el.feature2Desc.text(lang(commonInfo.Feature2Desc));
      $el.freeLabel2.text(lang(commonInfo.FreeLabel2));
      $el.doneButton.val(lang(commonInfo.ButtonWant));
      $el.expiredLabel.text(lang(commonInfo.ExpiredLabel));

      //Need this fix for when expired label text is too long e.g. CZ locale
      if ($el.expiredLabel.text().length > 10) {
           $el.expiredLabelContainer.css({
              'height': 'auto',
              'min-height': '24px'});
      }
	
      $el.expiredName.text(lang(commonInfo.ExpiredName));
      $el.feature1Label.text(lang(commonInfo.Feature1Label));
      $el.feature1Name.text(lang(commonInfo.Feature1Name));
      $el.feature1Desc.text(lang(commonInfo.Feature1Desc));
      $el.freeLabel1.text(lang(commonInfo.FreeLabel1));
    }

      var show = function () {
          window.external.log("IE Big toggle inside show " + _window.toString());

          _window.ready(function () {
              window.external.log("IE Big toggle: _window.ready start");
              var payload = JSON.parse(_external.getArgument("toast_data"));
              init(payload);

              
              setTimeout(function () {
                  resizeToast();
                  setTimeout(resizeToast, 60);
                  setTimeout(resizeToast, 180);
                  _settings.increment_setting("toast_variation_phase_2_show_count", "0");
                  _window.show();
              }, 120);

              window.external.log("IE Big toggle _window.ready end");
          })
      };

    var init = function (payload) {

      var lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SSTOAST).get;
      
        
        var cohort = Number(payload["ss_toggle_cohort"]);

        if (cohort !== 2 && cohort !== 4) {   
           cohort = 4 // Default to standalone
        }

        var variation = Number(payload["toggle_toast_count"]);
        if (!(variation >= 0 && variation <= 2)) {
            variation = 0;
        }
        variation = variation + 1; // +1 because %3 in lua and variationMap starts from 1
        
        var variationInfo = variationMap[variation];
        var commonInfo = variationMap[0];

        if (!variationInfo || !commonInfo)
        {
          _window.close();
          return;
        }

        //Check if close button should be shown
        var showCloseBtn = _settings.getSettingScopedWithDefault(false, "1", "ss_toast_close_btn_enable");

        initComponents(cohort, variationInfo, commonInfo, showCloseBtn);
        adjustVersionUI(cohort);
        fillText(variationInfo, commonInfo, lang);
        var toast_type = _misc.getQualifiedToastType(variationInfo.ToastType, cohort);

      //Reset toggle count setting 
        window.external.SetSetting("0", TOGGLE_COUNT, 0);
        var browserCode = _instrument.getBrowserTypeCode();
        var metadata = _instrument.getSecureSearchToastMetadata(showCloseBtn, browserCode);
        var provider = _instrument.getSecureSearchProvider();
        _instrument.sendSecureSearchToastEvent("Impression", browserCode, provider, toast_type, metadata);
    }

    return {
      show: show
    }
  };

}(window.WebAdvisor = window.WebAdvisor || {}, jQuery));

// Show secure search toggle toast
$(function () {
    window.external.log("the very start");
    var toast = new WebAdvisor.UI.accept_extension();
    toast.show();
});

//AD7B84B2951FB92A5BF549EC9889D449CCD6CA06370F608E3B866C241E94F670A410699B3F5CFD3D9DC35BDE9786606A7F0FC362B393EB0EB9B54A57FFE5022C++