[Pkg-javascript-commits] [dojo] 20/21: Improve focusin detection support

David Prévot taffit at moszumanska.debian.org
Thu Aug 21 17:39:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag 1.9.2
in repository dojo.

commit f774568707ea95b9a56bf646b2ce46e1c57907f8
Author: Colin Snover <github.com at zetafleet.com>
Date:   Fri Dec 6 20:51:50 2013 +0000

    Improve focusin detection support
    
    This change prevents unintentional scrolling and unfocusing of
    whatever element was in focus before the feature detect in browsers
    that need to do the long feature detect.
    
    Adds test case.
    
    Refs #17599
    
    (cherry picked from commit 2536e5cd0935cc7356d584bab6ac2c73d3ad6164)
    
    Conflicts:
    	tests/on/on.js
---
 on.js                       |  6 +++---
 tests/on/event-focusin.html | 46 +++++++++++++++++++++++++++++++++++++++++++++
 tests/on/on.js              |  8 ++++++--
 3 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/on.js b/on.js
index f4b97cc..ffc0197 100644
--- a/on.js
+++ b/on.js
@@ -15,14 +15,14 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./sniff"], fu
 
 				try {
 					var element = doc.createElement('input'),
-						style = element.style;
-					style.position = 'absolute';
-					style.top = element.style.left = '0';
+						activeElement = doc.activeElement;
+					element.style.position = 'fixed';
 					element.addEventListener('focusin', testFocus, false);
 					doc.body.appendChild(element);
 					element.focus();
 					doc.body.removeChild(element);
 					element.removeEventListener('focusin', testFocus, false);
+					activeElement.focus();
 				} catch (e) {}
 
 				return hasFocusInEvent;
diff --git a/tests/on/event-focusin.html b/tests/on/event-focusin.html
new file mode 100644
index 0000000..44cc298
--- /dev/null
+++ b/tests/on/event-focusin.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<title>dojo/on focusin feature detection</title>
+	</head>
+	<body>
+		<script src="../../dojo.js" data-dojo-config="async:1"></script>
+		<div style="padding: 4000px 0 0 4000px;"><input id="a"></div>
+		<script>
+require([ "doh" ], function(doh){
+	doh.register(function focusInTest(t){
+		function getScrollPosition() {
+			var docElement = document.documentElement,
+				body = document.body;
+
+			return {
+				x: docElement.scrollLeft || body.scrollLeft,
+				y: docElement.scrollTop || body.scrollTop
+			};
+		}
+
+		var dfd = new doh.Deferred(),
+			input = document.getElementById("a");
+
+		input.focus();
+
+		var lastScroll = getScrollPosition();
+
+		t.t(lastScroll.x > 0 && lastScroll.y > 0, "Focus on element should scroll viewport");
+
+		require([ "dojo/has", "dojo/on" ], dfd.getTestCallback(function(has){
+			var newScroll = getScrollPosition();
+			t.is("boolean", typeof has("event-focusin"), "focusin feature detection should have executed");
+			t.is(lastScroll.x, newScroll.x, "Horizontal scroll should not have changed");
+			t.is(lastScroll.y, newScroll.y, "Vertical scroll should not have changed");
+			t.is(input, document.activeElement, "Focus should still be set on the originally focused input");
+		}));
+
+		return dfd;
+	});
+
+	doh.run();
+});
+		</script>
+	</body>
+</html>
diff --git a/tests/on/on.js b/tests/on/on.js
index 6452fc7..c5aeecd 100644
--- a/tests/on/on.js
+++ b/tests/on/on.js
@@ -1,7 +1,7 @@
 define([
-	"doh",
+	"doh", "require",
 	"dojo/_base/declare",  "dojo/Evented", "dojo/has", "dojo/on", "dojo/query", "dojo/topic"
-], function(doh, declare, Evented, has, on, query, topic){
+], function(doh, require, declare, Evented, has, on, query, topic){
 
 	doh.register("tests.on", [
 		function object(t){
@@ -286,4 +286,8 @@ define([
 			t.is(testValue, 3);
 		}
 	]);
+
+	if(has("host-browser")){
+		doh.registerUrl("tests.on.event-focusin", require.toUrl("./event-focusin.html"), 30000);
+	}
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/dojo.git



More information about the Pkg-javascript-commits mailing list