doorman-js
Version:
A small javascript library that identifies older browsers via feature detection and (politely) turns them away.
1 lines • 2.5 kB
JavaScript
"function"!=typeof Object.create&&(Object.create=function(t){function e(){}return e.prototype=t,new e}),"function"!=typeof Array.contains&&(Array.prototype.contains=function(t){if("string"!=typeof t)throw new TypeError("Parameter "+t+" is not a string.");for(var e=this,n=0,r=this.length;r>n;n++)if(e[n]===t)return!0;return!1}),"function"!=typeof String.removeChar&&(String.prototype.removeChar=function(t){var e=this;return e.split(t).join("")});var doorman=function(){var t={valid:!0,failedTest:""};return Object.create(t)}();!function(t){var e=function(){var t=function(t,e){try{return"object"==typeof e&&t in e&&null!==e[t]}catch(n){return!1}},e=function(t,e,n){return n?document.createElement(t)[e](n):document.createElement(t)[e]},n=function(){return!!e("canvas","getContext")},r=function(){if(!n())return!1;var t=e("canvas","getContext","2d");return"function"==typeof t.fillText},o=function(){return t("autofocus",document.createElement("input"))},i=function(){return t("geolocation",navigator)},a=function(){return t("history",window)&&t("pushState",window.history)},c=function(){return t("localStorage",window)},u=function(){return t("applicationCache",window)},f=function(){return t("placeholder",document.createElement("input"))},l=function(){return t("Worker",window)},s=function(){return!!e("video","canPlayType")},p=function(){for(var t=["search","number","range","tel","url","email"],e=0,n=t.length;n>e;e++){var r=document.createElement("input");if(r.setAttribute("type",t[e]),"text"===r.type)return!1}return!0},d={autofocus:o,canvas:n,canvastext:r,geolocation:i,history:a,inputtypes:p,localstorage:c,offline:u,placeholder:f,webworkers:l,video:s};return Object.create(d)};return t.browserTest=Object.create(e())}(doorman||{}),function(t){var e=!1,n=function(t,e){var n=[];if("undefined"==typeof t){var r=[];for(var o in e)try{"function"==typeof e[o]&&r.push(o)}catch(i){}n=r}else"string"==typeof t?n.push(t):n=t;return n},r=function(){for(var r,o,i=Array.prototype.slice.call(arguments),a=0,c=i.length;c>a;a++)"function"==typeof i[a]?o=i[a]:r=i[a];for(var u=function(t){e||(e=!0,window.location.replace(t||"http://whatbrowser.org/"))},f=t.browserTest,l=n(r,f),s=0,p=l.length;p>s&&t.valid;s++){var d=l[s].removeChar("-").toLowerCase();if("function"!=typeof f[d])throw new Error(d+" is not a valid browser test.");t.valid=f[d](),t.failedTest=t.valid?"":d}return"undefined"!=typeof o?(o({valid:t.valid,failedTest:t.failedTest},u),this):t.valid?this:void u()};return t.check=r}(doorman||{});