[Pkg-javascript-commits] [dojo] 19/27: Use IE's native focusin/focusout support for IE9+ too. Avoids asynchronous focus notification.
David Prévot
taffit at moszumanska.debian.org
Sun Sep 14 16:23:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag 1.7.6
in repository dojo.
commit 570591de9d865daa499e7a04605c158c03585c52
Author: Bill Keese <bill at dojotoolkit.org>
Date: Tue Dec 31 15:31:40 2013 -0500
Use IE's native focusin/focusout support for IE9+ too.
Avoids asynchronous focus notification.
Squash commit of:
* b9ab7f580c8a123ff07ebd9a3b0695e24cf5c5ba
* ca391f932e3a3f032dd8b84566c4176857eb8ac3
* f774568707ea95b9a56bf646b2ce46e1c57907f8
* ab088a9741a6383495a20bc34e84403e2962ed03
* df47713a809bb5dfdd9a6dad472b6693c501b866
Fixes #16968, #16970, #17599, and refs #16926, #16972.
---
on.js | 11 ++++-----
tests/on/event-focusin.html | 58 +++++++++++++++++++++++++++++++++++++++++++++
tests/on/on.js | 8 +++++--
3 files changed, 68 insertions(+), 9 deletions(-)
diff --git a/on.js b/on.js
index 5fc7c97..54f9082 100644
--- a/on.js
+++ b/on.js
@@ -1,4 +1,7 @@
define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./has"], function(aspect, dojo, has){
+ has.add("event-focusin", function(global, doc, element){
+ return 'onfocusin' in element;
+ });
// summary:
// The export of this module is a function that provides core event listening functionality. With this function
// you can provide a target, event type, and listener to be notified of
@@ -263,17 +266,11 @@ define(["./has!dom-addeventlistener?:./aspect", "./_base/kernel", "./has"], func
}while(event && event.bubbles && (target = target.parentNode));
return event && event.cancelable && event; // if it is still true (was cancelable and was cancelled), return the event to indicate default action should happen
};
- var captures = {};
+ var captures = has("event-focusin") ? {} : {focusin: "focus", focusout: "blur"};
if(has("dom-addeventlistener")){
- // normalize focusin and focusout
- captures = {
- focusin: "focus",
- focusout: "blur"
- };
if(has("opera")){
captures.keydown = "keypress"; // this one needs to be transformed because Opera doesn't support repeating keys on keydown (and keypress works because it incorrectly fires on all keydown events)
}
-
// emiter that works with native event handling
on.emit = function(target, type, event){
if(target.dispatchEvent && document.createEvent){
diff --git a/tests/on/event-focusin.html b/tests/on/event-focusin.html
new file mode 100644
index 0000000..646e704
--- /dev/null
+++ b/tests/on/event-focusin.html
@@ -0,0 +1,58 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>dojo/on focusin feature detection</title>
+ </head>
+ <body>
+ <script src="../../dojo.js" data-dojo-config="async:1,has:{'dojo-undef-api':1}"></script>
+ <div style="padding: 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");
+
+ input.blur();
+ window.scrollTo(0, 0);
+ delete has.cache["event-focusin"];
+ require.undef("dojo/on");
+ require([ "dojo/on" ], function () {
+ t.is("boolean", typeof has("event-focusin"), "focusin feature detection should have executed (2)");
+
+ var scrollPosition = getScrollPosition();
+ t.is(0, scrollPosition.x, "Horizontal scroll should not have changed (2)");
+ t.is(0, scrollPosition.y, "Vertical scroll should not have changed (2)");
+ });
+ }));
+
+ return dfd;
+ });
+
+ doh.run();
+});
+ </script>
+ </body>
+</html>
diff --git a/tests/on/on.js b/tests/on/on.js
index b47c283..b0241c2 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){
@@ -309,4 +309,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