423c4266e204e4e11456a6dfccc6115bbdb96584f35d80afa801c6a71aef71ea

Source Code:

var Login = Login || {};
(function() {
    var trfq_retries = 0;
    var realm = "";
    var layout = "";

    var init = function () {

        frameBreak();
        onLoadModal();
        formEventHandler();
        waitForTrafficVar();
        $("#editNewPasswordEmail").on("click", function (event) {
            var span = $("#newPasswordEmail");
            var input = $("#newPasswordEmailText");

            if (input.is(":visible") && !input.val()) {
                input.focus();
                return;
            }

            span.hide();
            $(this).hide();
            input.show().focus();
            $("#newPasswordModal").sfDialog('resize');
        });

        $(document.body).on('submit', "#login-form", validateLoginForm);
        $(window).on('resize', function (event) {
            if (activeModal) {
                setModalMode(activeModal);
            }
        });

    };


    function waitForTrafficVar( metric ){
        // Avoid runaway recursions
        if (trfq_retries > 10)
            return false;
        
        if(typeof _trfq !== "undefined")
        {
            realm  = $('input[name="realm"]').val();
            layout = $('input[name="layout"]').val().replace('.html', '').replace('layout.', '');
            if (metric === undefined) {
              var metric = 'sso.login.login_form.' + realm + '.' + layout + '.load';
            }
            _trfq.push(['cmdLogPageEvent', 'load', metric]);
        }
        else
        {   
            ++trfq_retries;
            setTimeout(function(){
                waitForTrafficVar(metric);
            }, 250);
        }            
    };


    var trafficSendable = function (){
      // For now we can't send PASS. We could change this later.
      if(typeof _trfq !== "undefined" && realm == "idp"){
        return true;
      } else {
        return false;
      }
    };
            

    var validateLoginForm = function (event)
    {
        username = $("#username").val();
        pass = $("#password").val();
        Forms.hide_error();
        if(username.length == 0)
        {   
            // AUTH-2170 : Show email specific message for PASS missing username
            realm  = $('input[name="realm"]').val();
            if (realm === 'pass') {
              Forms.show_error(translate_dict['EMAIL_REQUIRED'], "username");
            } else {
              Forms.show_error(translate_dict['USERNAME_REQUIRED'], "username");
            }
            $("#contentContainer").sfMsgOverlay("destroy");
            return false;
        }
        else if(pass.length == 0)
        {
            Forms.show_error(translate_dict['PASSWORD_REQUIRED'], "password");
            $("#contentContainer").sfMsgOverlay("destroy");
            return false;
        }

        // At this point validation is successful, submit!
        if(typeof _trfq !== "undefined")
        {
            realm  = $('input[name="realm"]').val();
            layout = $('input[name="layout"]').val().replace('.html', '').replace('layout.', '');
            _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.login_form.' + realm + '.' + layout + '.submit']);

            if ($('#remember-me').attr('checked')) 
            {
                _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.login_form.' + realm + '.submit.remember_me.on']);
            }
            else 
            {
                _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.login_form.' + realm + '.submit.remember_me.off']);
            }
        }
    };

  var activeModal = null;
  var setModalMode = function( which )
  {
    activeModal = which;
    $("#contentContainer").css('display','none');
    if( which == 'o365' )
    {
      var modal = $(".sf-dialog-modal");
      var top = parseInt( modal.css('top') ) + parseInt( modal.css('height') ) + 50;
      $("#officeLogoFloater").css({ 'position' : 'absolute',
                              'left' : modal.css('left'),
                              'z-index': 150000001, //one higher than the default modal grey out
                              'float' : 'none',
                              'display' : 'block',
                              'top' : top + 'px'
                          });
     $("#footerFloater").css({ 'position' : 'absolute',
                               'bottom' : '10px',
                               'z-index' : 150000001,
                               'width' : '100%',
                               'text-align' : 'center',
                               'display' : 'block'
                               });
    }
  }
  var removeModalMode = function()
  {
    activeModal = null;
    $("#contentContainer").css('display','block');
    $("#officeLogoFloater").hide();
    $("#footerFloater").hide();
  }

  var newPasswordSubmit = function()
  {
    $( ".alert" ).remove();
    if ($('#newPasswordModalNewPassword').val() != $('#newPasswordModalNewPasswordConfim').val())
    {
      $("<div />").sfAlert({ style: "error",
                             message: translate_dict["PASSWORDS_DONT_MATCH"]
                           }).prependTo("#alertStatus");
    }
    else if( $( "#newPasswordModalNewPassword" ).val().replace( /\s/g, "" ) == "" )
    {
      $("<div />").sfAlert({ style: "error",
                             message: translate_dict["PROVIDE_A_PASSWORD"]
                           }).prependTo("#alertStatus");
      $( "#newPasswordModalNewPassword" ).focus();
    }
    else
    {
      $('#new-password-form').submit();
    }
    return false;
  };
/*
  var tempPasswordResult = function( data )
  {
    if( data.error )
    {
      $("#alertStatus").html( data.error );
    }
    else
    {
      $("#alertStatus").html( data )
      $("#o65form").submit();
    }
  }
*/

  var onLoadModal = function( )
  {
    var modal = $("#onLoadModal");
    if( modal.length == 0 )
    {
      return;
    }
    var whichModal = modal.attr( 'name' );
    switch( whichModal )
    {
      case 'tempPassword':
        modal.sfDialog({
            cancelDisabled : true,
            buttons: [{
              text : translate_dict['CONTINUE'],
              onClick : function()
              {
                newPasswordSubmit();
              },
              id : 'modal-button'
            }],
            buttonAlign : 'left',
            autoResize: true,
            onOpen : function(me, a, b){
              $(me).find( '.modal-footer' ).css('background-color','white');
              setModalMode('o365');
            }
          });
          $( "#newPasswordModalNewPassword" ).focus();
      break;
      case 'expiredPassword':
        modal.sfDialog({
            cancelDisabled : true,
            buttons: [{
              text : translate_dict['CONTINUE'],
              onClick : function()
              {
                newPasswordSubmit();
              },
              id : 'modal-button'
            }],
            buttonAlign : 'left',
            autoResize: true,
            // onOpen : function(me, a, b){
            //   $(me).find( '.modal-footer' ).css('background-color','white');
            //   setModalMode('o365');
            // }
          });
          $( "#newPasswordModalNewPassword" ).focus();
      break;
      case 'expiredTempPassword':
        modal.sfDialog({
          cancelDisabled : true,
            buttons : [{
                text : translate_dict['BACK_TO_SIGNIN'],
                onClick : function($sfDialog){
                  $sfDialog.sfDialog('close');
                  removeModalMode();
                },
                id : 'modal-button'
            }],
            buttonAlign : 'left',
            onOpen : function(me, a, b){
              $(me).find( '.modal-footer' ).css('background-color','white');
              setModalMode('o365');
              submitPasswordResetRequest($("#username").val(), 2);
            }
        });
      break;
      case 'fbUserCollision':
        modal.sfDialog({
          cancelDisabled : false,
            buttons : [
            {
                text : translate_dict['SIGN_IN_TITLE_CASE'],
                onClick : function($sfDialog){
                  if(typeof _trfq !== "undefined") {
                    realm  = $('input[name="realm"]').val();
                    _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.user_collision_form.' + realm + '.sign_in.click']);
                  }
                  $sfDialog.sfDialog('close');
                  removeModalMode();
                },
                id : 'sign-in-btn',
                attributes: {'id':'sign-in-btn'},
            },
            {
                text : translate_dict['CREATE_ACCOUNT'],
                id : 'create-acct-btn',
                onClick : function($sfDialog){
                  if(typeof _trfq !== "undefined") {
                    realm  = $('input[name="realm"]').val();
                    _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.user_collision_form.' + realm + '.create_unique.click']);
                  }
                  var fb_redirect_url = $('#create_acct_url').text();
                  window.location.href = fb_redirect_url;
                },
                attributes: {'id':'create-acct-collision-btn'},

            }],
            autoResize: false,
            onOpen : function(me, options, success){
              $(me).find( '.modal-footer' ).css('background-color','white');
              $('button[data-button="sign-in-btn"]').addClass('pull-right fb-modal-sign-in-btn fb-collision-modal-btn');
              $('button[data-button="create-acct-btn"]').removeClass('btn-primary').addClass('btn-default pull-left fb-collision-modal-btn');
              $('button[data-button="create-acct-btn"]').parent().css("margin", 0);
              var realm  = $('input[name="realm"]').val();
              var on_load_metric = 'sso.login.user_collision_form.' + realm + '.load';
              waitForTrafficVar(on_load_metric);
            },
            onClose : function(){
              if(typeof _trfq !== "undefined") {
                realm  = $('input[name="realm"]').val();
                _trfq.push(['cmdLogPageEvent', 'submit', 'sso.login.user_collision_form.' + realm + '.close']);
              }
            },
        });
      break;
    }
  }

  var formEventHandler = function( )
  {
    $(document.body).on("click", "#submitBtn", function(event){
      if(typeof _trfq !== "undefined")
      {
        realm  = $('input[name="realm"]').val()
        _trfq.push(['cmdLogPageEvent', 'click', 'sso.login.login_form.' + realm + '.login.button.click']);
      }
      $('#login-form').submit();
      return false;
    });

    // Make sure password validation gets run for this event:
    $(document.body).on( 'keypress','#newPasswordModalNewPasswordConfim', function(event)
                          {
                              if (event.keyCode == 13)
                              {
                                newPasswordSubmit();
                                return false;
                              }
                          });

    $(document.body).on("click", "#remember-me", function(event) {
        if (typeof _trfq !== "undefined") {
            realm  = $('input[name="realm"]').val()

            if ($('#remember-me').attr('checked')) {
                _trfq.push(['cmdLogPageEvent', 'click', 'sso.login.login_form.' + realm + '.remember_me.checkbox.enabled']);
            }
            else {
                _trfq.push(['cmdLogPageEvent', 'click', 'sso.login.login_form.' + realm + '.remember_me.checkbox.disabled']);
            }
        }
    });

    var usernameField = $("#username");
    var passwordField = $("#password");

    if( usernameField.val() )
    {
      passwordField.focus();
    }
    else
    {
      usernameField.focus();
    }
  }

  var submitPasswordResetRequest = function( username, type )
  {
    if( !username )
    {
      return;
    }
    $.ajax({
      "url" : fixUrl( "/login/sendpasswordreset" ),
      "data" : { "user" : username, "type" : type },
      "success" : function( data ){ passwordResetConfirm( data,type ) },
      "type" : "POST"
    });
  }
  
  var passwordResetConfirm = function( data, type )
  {
    if( data.success == 1 && type == 1 )
    {
      $("#requestPasswordContent").hide();
      $("#confirmContent").show();

      $(".sf-dialog-title").text(translate_dict['WORK_IS_DONE']);
      $("#newPasswordModal").sfDialog( 'setButtons',
                [{
                text : translate_dict['BACK_TO_SIGNIN'],
                onClick : function($sfDialog){ $sfDialog.sfDialog('close'); removeModalMode();}
                }] ).sfDialog('resize');
      setModalMode('o365');
    }

  }


  var fixUrl = function( url ) {
      params = '';
      try {
          params = window.location.search;
      }
      catch(e){

      }

      if (Globals.version) {
          return "/" + Globals.version + url + params;
      }

    return url + params;
  };
  var frameBreak = function()
  {
      if (top != self) top.location=location;
  };

  Login.init = init;

  $(document).ready(function() {
        $(document).sfTipper({ wireup: true });
  });

})();

// Chrome dev tools flag for debugging dynamic loaded js files
//# sourceURL=login.js