You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.0 KiB

4 years ago
  1. //CdnPath=http://ajax.aspnetcdn.com/ajax/4.5.1/1/WebForms.js
  2. function WebForm_FindFirstFocusableChild(control) {
  3. if (!control || !(control.tagName)) {
  4. return null;
  5. }
  6. var tagName = control.tagName.toLowerCase();
  7. if (tagName == "undefined") {
  8. return null;
  9. }
  10. var children = control.childNodes;
  11. if (children) {
  12. for (var i = 0; i < children.length; i++) {
  13. try {
  14. if (WebForm_CanFocus(children[i])) {
  15. return children[i];
  16. }
  17. else {
  18. var focused = WebForm_FindFirstFocusableChild(children[i]);
  19. if (WebForm_CanFocus(focused)) {
  20. return focused;
  21. }
  22. }
  23. } catch (e) {
  24. }
  25. }
  26. }
  27. return null;
  28. }
  29. function WebForm_AutoFocus(focusId) {
  30. var targetControl;
  31. if (__nonMSDOMBrowser) {
  32. targetControl = document.getElementById(focusId);
  33. }
  34. else {
  35. targetControl = document.all[focusId];
  36. }
  37. var focused = targetControl;
  38. if (targetControl && (!WebForm_CanFocus(targetControl)) ) {
  39. focused = WebForm_FindFirstFocusableChild(targetControl);
  40. }
  41. if (focused) {
  42. try {
  43. focused.focus();
  44. if (__nonMSDOMBrowser) {
  45. focused.scrollIntoView(false);
  46. }
  47. if (window.__smartNav) {
  48. window.__smartNav.ae = focused.id;
  49. }
  50. }
  51. catch (e) {
  52. }
  53. }
  54. }
  55. function WebForm_CanFocus(element) {
  56. if (!element || !(element.tagName)) return false;
  57. var tagName = element.tagName.toLowerCase();
  58. return (!(element.disabled) &&
  59. (!(element.type) || element.type.toLowerCase() != "hidden") &&
  60. WebForm_IsFocusableTag(tagName) &&
  61. WebForm_IsInVisibleContainer(element)
  62. );
  63. }
  64. function WebForm_IsFocusableTag(tagName) {
  65. return (tagName == "input" ||
  66. tagName == "textarea" ||
  67. tagName == "select" ||
  68. tagName == "button" ||
  69. tagName == "a");
  70. }
  71. function WebForm_IsInVisibleContainer(ctrl) {
  72. var current = ctrl;
  73. while((typeof(current) != "undefined") && (current != null)) {
  74. if (current.disabled ||
  75. ( typeof(current.style) != "undefined" &&
  76. ( ( typeof(current.style.display) != "undefined" &&
  77. current.style.display == "none") ||
  78. ( typeof(current.style.visibility) != "undefined" &&
  79. current.style.visibility == "hidden") ) ) ) {
  80. return false;
  81. }
  82. if (typeof(current.parentNode) != "undefined" &&
  83. current.parentNode != null &&
  84. current.parentNode != current &&
  85. current.parentNode.tagName.toLowerCase() != "body") {
  86. current = current.parentNode;
  87. }
  88. else {
  89. return true;
  90. }
  91. }
  92. return true;
  93. }