Created
September 21, 2012 02:15
-
-
Save sdesai/3759406 to your computer and use it in GitHub Desktop.
Fix for onbeforeactivate feature test to support Win8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
storechild-lm: yui3 [ie10] $ git show f771c6e6629d3d4ac6cee8408cdb9b373827c432 | |
commit f771c6e6629d3d4ac6cee8408cdb9b373827c432 | |
Author: Satyen Desai <[email protected]> | |
Date: Thu Sep 20 19:01:29 2012 -0700 | |
Fixed onbeforeactivate feature test so that it works in Win 8 packaged apps. | |
In Win 8 packaged JS app environments, innerHTML cannot contain inline handlers, | |
which the feature test was relying on. | |
Changed the structure of the test, to avoid the inline handler. | |
Verified that the feature test is still true for all IEs and false for Webkit/Gecko, | |
including iOS. | |
Added unit test to test the feature test output. | |
Ran unit tests on IE6, IE9, IE10, Chrome, Safari (MacOS and iOS). | |
diff --git a/src/event/HISTORY.md b/src/event/HISTORY.md | |
index 223b988..d70a6ed 100644 | |
--- a/src/event/HISTORY.md | |
+++ b/src/event/HISTORY.md | |
@@ -1,6 +1,12 @@ | |
Event Infrastructure Change History | |
=================================== | |
+3.8.0 | |
+----- | |
+ | |
+* Changed onbeforeactivate feature test to account for Win 8 packaged Apps, which | |
+ don't allow inline JS code in innerHTML. | |
+ | |
3.7.0 | |
----- | |
diff --git a/src/event/js/focusblur.js b/src/event/js/focusblur.js | |
index 6f952f3..5e7d38e 100644 | |
--- a/src/event/js/focusblur.js | |
+++ b/src/event/js/focusblur.js | |
@@ -5,17 +5,42 @@ | |
* @submodule event-focus | |
*/ | |
var Event = Y.Event, | |
+ | |
YLang = Y.Lang, | |
+ | |
isString = YLang.isString, | |
+ | |
arrayIndex = Y.Array.indexOf, | |
- useActivate = YLang.isFunction( | |
- Y.DOM.create('<p onbeforeactivate=";"/>').onbeforeactivate); | |
+ | |
+ useActivate = (function() { | |
+ | |
+ // Changing the structure of this test, so that it doesn't use inline JS in HTML, | |
+ // which throws an exception in Win8 packaged apps, due to additional security restrictions: | |
+ // http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences | |
+ | |
+ var p = document.createElement("p"), | |
+ listener; | |
+ | |
+ p.setAttribute("onbeforeactivate", ";"); | |
+ listener = p.onbeforeactivate; | |
+ | |
+ // listener is a function in IE8+. | |
+ // listener is a string in IE6,7. | |
+ // listener is a function in IE10, in a Win8 App environment (no exception running the test). | |
+ | |
+ // listener is undefined in Webkit/Gecko. | |
+ // listener is a function in Webkit/Gecko if it's a supported event (e.g. onclick). | |
+ | |
+ return (listener !== undefined); | |
+ }()); | |
function define(type, proxy, directEvent) { | |
var nodeDataKey = '_' + type + 'Notifiers'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment