[Commits] r2540 - in sandbox/cmoullet/ux: . MobileEvents

commits at geoext.org commits at geoext.org
Tue Dec 28 05:58:12 CET 2010


Author: cmoullet
Date: 2010-12-28 05:58:12 +0100 (Tue, 28 Dec 2010)
New Revision: 2540

Added:
   sandbox/cmoullet/ux/MobileEvents/
   sandbox/cmoullet/ux/MobileEvents/eventTester.html
   sandbox/cmoullet/ux/MobileEvents/eventTester.js
Log:
Mobile event tester sandbox

Added: sandbox/cmoullet/ux/MobileEvents/eventTester.html
===================================================================
--- sandbox/cmoullet/ux/MobileEvents/eventTester.html	                        (rev 0)
+++ sandbox/cmoullet/ux/MobileEvents/eventTester.html	2010-12-28 04:58:12 UTC (rev 2540)
@@ -0,0 +1,12 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
+   "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+  <head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <title>Mobile Event Tester </title>
+  </head>
+  <body> 
+    <script src="eventTester.js" type="text/javascript"></script>
+    <a href="http://perfectionkills.com/detecting-event-support-without-browser-sniffing/">Original source code</a> 
+  </body>
+</html>
\ No newline at end of file

Added: sandbox/cmoullet/ux/MobileEvents/eventTester.js
===================================================================
--- sandbox/cmoullet/ux/MobileEvents/eventTester.js	                        (rev 0)
+++ sandbox/cmoullet/ux/MobileEvents/eventTester.js	2010-12-28 04:58:12 UTC (rev 2540)
@@ -0,0 +1,100 @@
+var isEventSupported = (function(undef) {
+
+    var TAGNAMES = {
+        'select':'input','change':'input',
+        'submit':'form','reset':'form',
+        'error':'img','load':'img','abort':'img'
+    };
+
+    function isEventSupported(eventName, element) {
+
+        element = element || document.createElement(TAGNAMES[eventName] || 'div');
+        eventName = 'on' + eventName;
+
+        var isSupported = (eventName in element);
+
+        if (!isSupported) {
+            // if it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element
+            if (!element.setAttribute) {
+                element = document.createElement('div');
+            }
+            if (element.setAttribute && element.removeAttribute) {
+                element.setAttribute(eventName, '');
+                isSupported = typeof element[eventName] == 'function';
+
+                // if property was created, "remove it" (by setting value to `undefined`)
+                if (typeof element[eventName] != 'undefined') {
+                    element[eventName] = undef;
+                }
+                element.removeAttribute(eventName);
+            }
+        }
+
+        element = null;
+        return isSupported;
+    }
+
+    return isEventSupported;
+})();
+
+function w(category, name, element) {
+  document.write('<tr><td>' + category + '</td><td>' + name + '</td><td> ' + (
+    isEventSupported(name, element)
+      ? '<span style="background-color:green;color:white;">true</span></td>'
+      : '<span style="background-color:red;color:white;">false</span></td>'
+    ) + '<tr>');
+}
+
+document.write("<table>");
+
+w('mouse', 'click');
+w('mouse', 'dblclick');
+w('mouse', 'mousedown');
+w('mouse', 'mouseup');
+w('mouse', 'mouseover');
+w('mouse', 'mousemove');
+w('mouse', 'mouseout');
+
+w('key','keypress');
+w('key','keydown');
+w('key','keyup');
+
+w('HTML', 'load');
+w('HTML','unload', window);
+w('HTML','abort');
+w('HTML','error');
+
+w('view', 'resize', window);
+w('view', 'scroll');
+
+w('form', 'submit');
+w('form','reset');
+
+w('form control', 'select');
+w('form control', 'change');
+
+w('activation', 'focus');
+w('activation', 'blur');
+
+w('touch', 'touchstart');
+w('touch', 'touchend');
+w('touch', 'touchmove');
+w('touch', 'touchcancel');
+
+w('gesture', 'gesturestart');
+w('gesture','gesturechange');
+w('gesture', 'gestureend');
+
+w('HTML5', 'hashchange', document.body);
+w('HTML5','online', document.body);
+w('HTML5','offline', document.body);
+w('HTML5','message', window);
+w('HTML5','undo', document.body);
+w('HTML5','redo', document.body);
+w('HTML5','storage', window);
+w('HTML5','popstate', window);
+w('HTML5','canplay', document.createElement('video'));
+w('HTML5','seeking', document.createElement('video'));
+w('HTML5','seekend', document.createElement('video'));
+
+document.write("</table>");
\ No newline at end of file



More information about the Commits mailing list