summaryrefslogtreecommitdiffstats
path: root/samples/TestAzureAD/Scripts/WebForms/Focus.js
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-05-05 15:36:55 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-05-05 15:36:55 -0700
commit49d654965b6cf0ee6aa171dec50b1d0b8fb86e0c (patch)
tree9b836b0b9e94b8aa1e650c68e714bc214439d8da /samples/TestAzureAD/Scripts/WebForms/Focus.js
parent7edb0a63ef796af300c670ce90df8e7670930a10 (diff)
parent489bf70111fe4839e87fa591928d2845341f0059 (diff)
downloadDotNetOpenAuth-49d654965b6cf0ee6aa171dec50b1d0b8fb86e0c.zip
DotNetOpenAuth-49d654965b6cf0ee6aa171dec50b1d0b8fb86e0c.tar.gz
DotNetOpenAuth-49d654965b6cf0ee6aa171dec50b1d0b8fb86e0c.tar.bz2
Adds Azure Active Directory OAuth 2 client.
Closes #271
Diffstat (limited to 'samples/TestAzureAD/Scripts/WebForms/Focus.js')
-rw-r--r--samples/TestAzureAD/Scripts/WebForms/Focus.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/samples/TestAzureAD/Scripts/WebForms/Focus.js b/samples/TestAzureAD/Scripts/WebForms/Focus.js
new file mode 100644
index 0000000..2de90df
--- /dev/null
+++ b/samples/TestAzureAD/Scripts/WebForms/Focus.js
@@ -0,0 +1,93 @@
+//CdnPath=http://ajax.aspnetcdn.com/ajax/4.5/6/Focus.js
+function WebForm_FindFirstFocusableChild(control) {
+ if (!control || !(control.tagName)) {
+ return null;
+ }
+ var tagName = control.tagName.toLowerCase();
+ if (tagName == "undefined") {
+ return null;
+ }
+ var children = control.childNodes;
+ if (children) {
+ for (var i = 0; i < children.length; i++) {
+ try {
+ if (WebForm_CanFocus(children[i])) {
+ return children[i];
+ }
+ else {
+ var focused = WebForm_FindFirstFocusableChild(children[i]);
+ if (WebForm_CanFocus(focused)) {
+ return focused;
+ }
+ }
+ } catch (e) {
+ }
+ }
+ }
+ return null;
+}
+function WebForm_AutoFocus(focusId) {
+ var targetControl;
+ if (__nonMSDOMBrowser) {
+ targetControl = document.getElementById(focusId);
+ }
+ else {
+ targetControl = document.all[focusId];
+ }
+ var focused = targetControl;
+ if (targetControl && (!WebForm_CanFocus(targetControl)) ) {
+ focused = WebForm_FindFirstFocusableChild(targetControl);
+ }
+ if (focused) {
+ try {
+ focused.focus();
+ if (__nonMSDOMBrowser) {
+ focused.scrollIntoView(false);
+ }
+ if (window.__smartNav) {
+ window.__smartNav.ae = focused.id;
+ }
+ }
+ catch (e) {
+ }
+ }
+}
+function WebForm_CanFocus(element) {
+ if (!element || !(element.tagName)) return false;
+ var tagName = element.tagName.toLowerCase();
+ return (!(element.disabled) &&
+ (!(element.type) || element.type.toLowerCase() != "hidden") &&
+ WebForm_IsFocusableTag(tagName) &&
+ WebForm_IsInVisibleContainer(element)
+ );
+}
+function WebForm_IsFocusableTag(tagName) {
+ return (tagName == "input" ||
+ tagName == "textarea" ||
+ tagName == "select" ||
+ tagName == "button" ||
+ tagName == "a");
+}
+function WebForm_IsInVisibleContainer(ctrl) {
+ var current = ctrl;
+ while((typeof(current) != "undefined") && (current != null)) {
+ if (current.disabled ||
+ ( typeof(current.style) != "undefined" &&
+ ( ( typeof(current.style.display) != "undefined" &&
+ current.style.display == "none") ||
+ ( typeof(current.style.visibility) != "undefined" &&
+ current.style.visibility == "hidden") ) ) ) {
+ return false;
+ }
+ if (typeof(current.parentNode) != "undefined" &&
+ current.parentNode != null &&
+ current.parentNode != current &&
+ current.parentNode.tagName.toLowerCase() != "body") {
+ current = current.parentNode;
+ }
+ else {
+ return true;
+ }
+ }
+ return true;
+}