Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2.  
  3. // This file contains several workarounds on inconsistent browser behaviors that administrators may customize.
  4. "use strict";
  5.  
  6. // iPhone email friendly keyboard does not include "\" key, use regular keyboard instead.
  7. // Note change input type does not work on all versions of all browsers.
  8. if (navigator.userAgent.match(/iPhone/i) != null) {
  9. var emails = document.querySelectorAll("input[type='email']");
  10. if (emails) {
  11. for (var i = 0; i < emails.length; i++) {
  12. emails[i].type = 'text';
  13. }
  14. }
  15. }
  16.  
  17. // In the CSS file we set the ms-viewport to be consistent with the device dimensions,
  18. // which is necessary for correct functionality of immersive IE.
  19. // However, for Windows 8 phone we need to reset the ms-viewport's dimension to its original
  20. // values (auto), otherwise the viewport dimensions will be wrong for Windows 8 phone.
  21. // Windows 8 phone has agent string 'IEMobile 10.0'
  22. if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
  23. var msViewportStyle = document.createElement("style");
  24. msViewportStyle.appendChild(
  25. document.createTextNode(
  26. "@-ms-viewport{width:auto!important}"
  27. )
  28. );
  29. msViewportStyle.appendChild(
  30. document.createTextNode(
  31. "@-ms-viewport{height:auto!important}"
  32. )
  33. );
  34. document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
  35. }
  36.  
  37. // If the innerWidth is defined, use it as the viewport width.
  38. if (window.innerWidth && window.outerWidth && window.innerWidth !== window.outerWidth) {
  39. var viewport = document.querySelector("meta[name=viewport]");
  40. viewport.setAttribute('content', 'width=' + window.innerWidth + ', initial-scale=1.0, user-scalable=1');
  41. }
  42.  
  43. // Gets the current style of a specific property for a specific element.
  44. function getStyle(element, styleProp) {
  45. var propStyle = null;
  46.  
  47. if (element && element.currentStyle) {
  48. propStyle = element.currentStyle[styleProp];
  49. }
  50. else if (element && window.getComputedStyle) {
  51. propStyle = document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProp);
  52. }
  53.  
  54. return propStyle;
  55. }
  56.  
  57. // The script below is used for downloading the illustration image
  58. // only when the branding is displaying. This script work together
  59. // with the code in PageBase.cs that sets the html inline style
  60. // containing the class 'illustrationClass' with the background image.
  61. var computeLoadIllustration = function () {
  62. var branding = document.getElementById("branding");
  63. var brandingDisplay = getStyle(branding, "display");
  64. var brandingWrapperDisplay = getStyle(document.getElementById("brandingWrapper"), "display");
  65.  
  66. if (brandingDisplay && brandingDisplay !== "none" &&
  67. brandingWrapperDisplay && brandingWrapperDisplay !== "none") {
  68. var newClass = "illustrationClass";
  69.  
  70. if (branding.classList && branding.classList.add) {
  71. branding.classList.add(newClass);
  72. } else if (branding.className !== undefined) {
  73. branding.className += " " + newClass;
  74. }
  75. if (window.removeEventListener) {
  76. window.removeEventListener('load', computeLoadIllustration, false);
  77. window.removeEventListener('resize', computeLoadIllustration, false);
  78. }
  79. else if (window.detachEvent) {
  80. window.detachEvent('onload', computeLoadIllustration);
  81. window.detachEvent('onresize', computeLoadIllustration);
  82. }
  83. }
  84. };
  85.  
  86. if (window.addEventListener) {
  87. window.addEventListener('resize', computeLoadIllustration, false);
  88. window.addEventListener('load', computeLoadIllustration, false);
  89. }
  90. else if (window.attachEvent) {
  91. window.attachEvent('onresize', computeLoadIllustration);
  92. window.attachEvent('onload', computeLoadIllustration);
  93. }
  94.  
  95. // Function to change illustration image. Usage example below.
  96. function SetIllustrationImage(imageUri) {
  97. var illustrationImageClass = '.illustrationClass {background-image:url(' + imageUri + ');}';
  98.  
  99. var css = document.createElement('style');
  100. css.type = 'text/css';
  101.  
  102. if (css.styleSheet) css.styleSheet.cssText = illustrationImageClass;
  103. else css.appendChild(document.createTextNode(illustrationImageClass));
  104.  
  105. document.getElementsByTagName("head")[0].appendChild(css);
  106. }
  107.  
  108. // Example to change illustration image on HRD page after adding the image to active theme:
  109. // PSH> Set-AdfsWebTheme -TargetName <activeTheme> -AdditionalFileResource @{uri='/adfs/portal/images/hrd.jpg';path='.\hrd.jpg'}
  110. //
  111. //if (typeof HRD != 'undefined') {
  112. // SetIllustrationImage('/adfs/portal/images/hrd.jpg');
  113. //}
  114.  
  115. // Check whether the loginMessage element is present on this page.
  116. var loginMessage = document.getElementById('loginMessage');
  117. if (loginMessage)
  118. {
  119. // loginMessage element is present, modify its properties.
  120. loginMessage.innerHTML = 'Sign in with your school account';
  121. }
  122.  
  123. if (typeof Login != 'undefined'){
  124. Login.submitLoginRequest = function () {
  125. var u = new InputUtil();
  126. var e = new LoginErrors();
  127. var userName = document.getElementById(Login.userNameInput);
  128. var password = document.getElementById(Login.passwordInput);
  129. if (userName.value && !userName.value.match('[@\\\\]'))
  130. {
  131. var userNameValue = userName.value + '@trafalgarhs.vic.edu.au';
  132. document.forms['loginForm'].UserName.value = userNameValue;
  133. }
  134.  
  135. if (!userName.value) {
  136. u.setError(userName, e.userNameFormatError);
  137. return false;
  138. }
  139.  
  140. if (!password.value)
  141. {
  142. u.setError(password, e.passwordEmpty);
  143. return false;
  144. }
  145. document.forms['loginForm'].submit();
  146. return false;
  147. };
  148. }
  149.  
  150. var userNameInput = document.getElementById('userNameInput');
  151. if (userNameInput)
  152. {
  153. userNameInput.placeholder = "example@trafalgarhs.vic.edu.au";
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement