From 20c5c9d79dedde22dd236c7c9914d7a4a32fbe93 Mon Sep 17 00:00:00 2001 From: Dan Boland Date: Sun, 7 Feb 2016 15:18:00 -0600 Subject: [PATCH 1/2] Modified testAll() to add classes depicting lack of feature --- feature.js | 6 +++--- feature.min.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/feature.js b/feature.js index a3c9e4f..5f1a397 100644 --- a/feature.js +++ b/feature.js @@ -202,10 +202,10 @@ // Run all the tests and add supported classes testAll : function() { - var classes = " js"; + var classes = " js", fail = "no-"; for (var test in this) { - if (test !== "testAll" && test !== "constructor" && this[test]) { - classes += " " + test; + if (test !== "testAll") { + classes += (test !== "constructor" && this[test]) ? " " + test : " " + fail + test; } } docEl.className += classes.toLowerCase(); diff --git a/feature.min.js b/feature.min.js index 445b47a..334aa91 100644 --- a/feature.min.js +++ b/feature.min.js @@ -1,2 +1,2 @@ /*! FEATURE.JS 1.0.1, http://featurejs.com */ -!function(e,t,n){"use strict";var r=t.documentElement,i={create:function(e){return t.createElement(e)},old:!!/(Android\s(1.|2.))|(Silk\/1.)/i.test(navigator.userAgent),pfx:function(){var e=t.createElement("dummy").style,r=["Webkit","Moz","O","ms"],i={};return function(t){if("undefined"==typeof i[t]){var c=t.charAt(0).toUpperCase()+t.substr(1),a=(t+" "+r.join(c+" ")+c).split(" ");i[t]=null;for(var o in a)if(e[a[o]]!==n){i[t]=a[o];break}}return i[t]}}()},c={css3Dtransform:function(){var e=!i.old&&null!==i.pfx("perspective");return!!e}(),cssTransform:function(){var e=!i.old&&null!==i.pfx("transformOrigin");return!!e}(),cssTransition:function(){var e=null!==i.pfx("transition");return!!e}(),addEventListener:!!e.addEventListener,querySelectorAll:!!t.querySelectorAll,matchMedia:!!e.matchMedia,deviceMotion:"DeviceMotionEvent"in e,deviceOrientation:"DeviceOrientationEvent"in e,contextMenu:"contextMenu"in r&&"HTMLMenuItemElement"in e,classList:"classList"in r,placeholder:"placeholder"in i.create("input"),localStorage:function(){var e="x";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(t){return!1}}(),historyAPI:e.history&&"pushState"in e.history,serviceWorker:"serviceWorker"in navigator,viewportUnit:function(e){try{e.style.width="1vw";var t=""!==e.style.width;return!!t}catch(n){return!1}}(i.create("dummy")),remUnit:function(e){try{e.style.width="1rem";var t=""!==e.style.width;return!!t}catch(n){return!1}}(i.create("dummy")),canvas:function(e){return!(!e.getContext||!e.getContext("2d"))}(i.create("canvas")),svg:!!t.createElementNS&&!!t.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect,webGL:function(t){try{return!(!e.WebGLRenderingContext||!t.getContext("webgl")&&!t.getContext("experimental-webgl"))}catch(n){return!1}}(i.create("canvas")),cors:"XMLHttpRequest"in e&&"withCredentials"in new XMLHttpRequest,touch:!!("ontouchstart"in e||e.navigator&&e.navigator.msPointerEnabled&&e.MSGesture||e.DocumentTouch&&t instanceof DocumentTouch),async:"async"in i.create("script"),defer:"defer"in i.create("script"),geolocation:"geolocation"in navigator,srcset:"srcset"in i.create("img"),sizes:"sizes"in i.create("img"),pictureElement:"HTMLPictureElement"in e,testAll:function(){var e=" js";for(var t in this)"testAll"!==t&&"constructor"!==t&&this[t]&&(e+=" "+t);r.className+=e.toLowerCase()}};e.feature=c}(window,document); \ No newline at end of file +!function(e,t,n){"use strict";var r=t.documentElement,i={create:function(e){return t.createElement(e)},old:!!/(Android\s(1.|2.))|(Silk\/1.)/i.test(navigator.userAgent),pfx:function(){var e=t.createElement("dummy").style,r=["Webkit","Moz","O","ms"],i={};return function(t){if("undefined"==typeof i[t]){var c=t.charAt(0).toUpperCase()+t.substr(1),o=(t+" "+r.join(c+" ")+c).split(" ");i[t]=null;for(var a in o)if(e[o[a]]!==n){i[t]=o[a];break}}return i[t]}}()},c={css3Dtransform:function(){var e=!i.old&&null!==i.pfx("perspective");return!!e}(),cssTransform:function(){var e=!i.old&&null!==i.pfx("transformOrigin");return!!e}(),cssTransition:function(){var e=null!==i.pfx("transition");return!!e}(),addEventListener:!!e.addEventListener,querySelectorAll:!!t.querySelectorAll,matchMedia:!!e.matchMedia,deviceMotion:"DeviceMotionEvent"in e,deviceOrientation:"DeviceOrientationEvent"in e,contextMenu:"contextMenu"in r&&"HTMLMenuItemElement"in e,classList:"classList"in r,placeholder:"placeholder"in i.create("input"),localStorage:function(){var e="x";try{return localStorage.setItem(e,e),localStorage.removeItem(e),!0}catch(t){return!1}}(),historyAPI:e.history&&"pushState"in e.history,serviceWorker:"serviceWorker"in navigator,viewportUnit:function(e){try{e.style.width="1vw";var t=""!==e.style.width;return!!t}catch(n){return!1}}(i.create("dummy")),remUnit:function(e){try{e.style.width="1rem";var t=""!==e.style.width;return!!t}catch(n){return!1}}(i.create("dummy")),canvas:function(e){return!(!e.getContext||!e.getContext("2d"))}(i.create("canvas")),svg:!!t.createElementNS&&!!t.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect,webGL:function(t){try{return!(!e.WebGLRenderingContext||!t.getContext("webgl")&&!t.getContext("experimental-webgl"))}catch(n){return!1}}(i.create("canvas")),cors:"XMLHttpRequest"in e&&"withCredentials"in new XMLHttpRequest,touch:!!("ontouchstart"in e||e.navigator&&e.navigator.msPointerEnabled&&e.MSGesture||e.DocumentTouch&&t instanceof DocumentTouch),async:"async"in i.create("script"),defer:"defer"in i.create("script"),geolocation:"geolocation"in navigator,srcset:"srcset"in i.create("img"),sizes:"sizes"in i.create("img"),pictureElement:"HTMLPictureElement"in e,testAll:function(){var e=" js",t="no-";for(var n in this)"testAll"!==n&&(e+="constructor"!==n&&this[n]?" "+n:" "+t+n);r.className+=e.toLowerCase()}};e.feature=c}(window,document); \ No newline at end of file From 15e51c813209ce31c73db6ea9eb365c6aff39ccb Mon Sep 17 00:00:00 2001 From: Dan Boland Date: Sun, 7 Feb 2016 15:29:28 -0600 Subject: [PATCH 2/2] Clarified intent in the unminified version --- feature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature.js b/feature.js index 5f1a397..318ee9b 100644 --- a/feature.js +++ b/feature.js @@ -200,7 +200,7 @@ // Test if Picture element is supported pictureElement : ("HTMLPictureElement" in window), - // Run all the tests and add supported classes + // Run all the tests and add supported and unsupported classes testAll : function() { var classes = " js", fail = "no-"; for (var test in this) {