Giter Site home page Giter Site logo

modernizr / modernizr Goto Github PK

View Code? Open in Web Editor NEW
25.6K 900.0 3.0K 18.93 MB

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.

Home Page: https://www.npmjs.com/package/modernizr

License: MIT License

JavaScript 98.70% CSS 0.29% Batchfile 0.01% Shell 0.10% Pug 0.90%
modernizr javascript css3-features javascript-library feature-detection hacktoberfest

modernizr's Introduction

Modernizr

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.

npm version Build Status codecov Inline docs

Modernizr tests which native CSS3 and HTML5 features are available in the current UA and makes the results available to you in two ways: as properties on a global Modernizr object, and as classes on the <html> element. This information allows you to progressively enhance your pages with a granular level of control over the experience.

Breaking changes with v4

  • Dropped support for node versions <= 10, please upgrade to at least version 12

  • Following tests got renamed:

    • class to es6class to keep in line with the rest of the es-tests
  • Following tests got moved in subdirectories:

    • cookies, indexeddb, indexedblob, quota-management-api, userdata moved into the storage subdirectory
    • audio moved into the audio subdirectory
    • battery moved into the battery subdirectory
    • canvas, canvastext moved into the canvas subdirectory
    • customevent, eventlistener, forcetouch, hashchange, pointerevents, proximity moved into the event subdirectory
    • exiforientation moved into the image subdirectory
    • capture, fileinput, fileinputdirectory, formatattribute, input, inputnumber-l10n, inputsearchevent, inputtypes, placeholder, requestautocomplete, validation moved into the input subdirectory
    • svg moved into the svg subdirectory
    • webgl moved into the webgl subdirectory
  • Following tests got removed:

    • touchevents: discussion
    • unicode: discussion
    • templatestrings: duplicate of the es6 detect stringtemplate
    • contains: duplicate of the es6 detect es6string
    • datalistelem: A dupe of Modernizr.input.list

New Asynchronous Event Listeners

Often times people want to know when an asynchronous test is done so they can allow their application to react to it. In the past, you've had to rely on watching properties or <html> classes. Only events on asynchronous tests are supported. Synchronous tests should be handled synchronously to improve speed and to maintain consistency.

The new API looks like this:

// Listen to a test, give it a callback
Modernizr.on("testname", function (result) {
  if (result) {
    console.log("The test passed!");
  } else {
    console.log("The test failed!");
  }
});

We guarantee that we'll only invoke your function once (per time that you call on). We are currently not exposing a method for exposing the trigger functionality. Instead, if you'd like to have control over async tests, use the src/addTest feature, and any test that you set will automatically expose and trigger the on functionality.

Getting Started

  • Clone or download the repository
  • Install project dependencies with npm install

Building Modernizr

From javascript

Modernizr can be used programmatically via npm:

var modernizr = require("modernizr");

A build method is exposed for generating custom Modernizr builds. Example:

var modernizr = require("modernizr");

modernizr.build({}, function (result) {
  console.log(result); // the build
});

The first parameter takes a JSON object of options and feature-detects to include. See lib/config-all.json for all available options.

The second parameter is a function invoked on task completion.

From the command-line

We also provide a command line interface for building modernizr. To see all available options run:

./bin/modernizr

Or to generate everything in 'config-all.json' run this with npm:

npm start
//outputs to ./dist/modernizr-build.js

Testing Modernizr

To execute the tests using mocha-headless-chrome on the console run:

npm test

You can also run tests in the browser of your choice with this command:

npm run serve-gh-pages

and navigating to these two URLs:

http://localhost:8080/test/unit.html
http://localhost:8080/test/integration.html

Code of Conduct

This project adheres to the Open Code of Conduct. By participating, you are expected to honor this code.

License

MIT License

modernizr's People

Contributors

addyosmani avatar alrra avatar anenviousguest avatar cowboy avatar dabretin avatar danbeam avatar doctyper avatar ebidel avatar emilchristensen avatar fearphage avatar greenkeeperio-bot avatar hay avatar jokeyrhyme avatar josh avatar kurafire avatar markel avatar mathiasbynens avatar niksy avatar nschonni avatar patrickkettner avatar paulirish avatar rejas avatar rupl avatar ryanseddon avatar ryanve avatar seutje avatar slexaxton avatar stucox avatar thvd avatar zhorvath avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modernizr's Issues

add video and audio formats

Per Faruk:
"We should support everything that at least 1 browser has implemented and is a common enough format that people would use it"

for video:

  • ogg, h264

for audio:

  • ogg, mp3, wav, .m4a

I'm expecting we'll implement with a Boolean constructor so it'll be, essentially, as follows:

Modernizr.video = new Boolean(true);
Modernizr.video.ogg = true;

Modernizr.video        // true
Modernizr.video.ogg // true

add IE8 "mode" detection

It would be great if Modernizr could tell us what mode IE8 was running in, so that we could tune our CSS on IE for speed when a not-so-fast engine was being used.

P.s. I know you know a little about this, since I learned about it from you in a wonderfully-comprhensive presentation you gave. Thanks!

test style properties if they are empty string or undefined.

that'll skip applying fake styles to an element and querying.

instead:
document.body.style.MozBorderRadius // ''
document.body.style.MozBoxReflect // undefined

tested in ie6+, ff3.5, saf3.2+, op10.

will complete testing and verify results are no different than existing method.

Cookie the test results.

There would be two benefits

  1. Perf improvement. Tests done have to rerun.. (We're assuming checking a cookie isnt as slow as running the tests..)
  2. Any Async tests would be ready instantly (@font-face,data-uri)

Would likely have to do a cookie with a short timeout (1hr) as browser upgrades would be undetectable. Perhaps a session cookie would work, but they might be retained during a browser upgrade restart..

Idea from Weston Ruter

@font-face returning 'false' on Ubuntu 9.10, FF3.5.6 (includes fix)

The 'serif' bundle on at least my install seems to default to a font that is the same width as the @font-face data uri font, which makes it return false.

Changing:
spn.setAttribute('style','font:99px _,serif;position:absolute;visibility:hidden');

to:
spn.setAttribute('style','font:99px _,helvetica,verdana;position:absolute;visibility:hidden');

should fix this (according to http://www.codestyle.org/css/font-family/sampler-CombinedResults.shtml - these fonts are installed on >99% of the computers out there).

code review from jdalton

some cleanup issues.. tighter code. probably won't do all of this:
thanks john!

[10:59] setProperties (name suggests a method not an array of style properties)
[10:59] !== -1 -> > -1
[11:00] this prolly isnt a concern but IE7 and 7
[11:01] dont respect types unless sent in the createElement()
[11:01] *6 and 7
[11:01] f.setAttribute('type', props[i]);
[11:01] paul: yeah i hate the name of setProperties too
[11:02] paul: "dont respect types" ?
[11:02] paul: the fact that IE doesnt support any of this means its hard to forecast how they will start to pass it
[11:03] paul: but you're saying do a createElement('<input type="search">') right? 
[11:03] ya
[11:03] body = docElement.appendChild(doc.createElement(fontface)); <- insertBefore()
[11:03] paul: insertBefore is safe to use everywhere?
[11:04] yep
[11:04] doc.getElementsByTagName('head')[0].appendChild(st); <- same thing (dont assume head exists yadda yadda)
[11:04] paul: so whats is it again? docElement.firstChild.insertBefore( ?
[11:05] spn.setAttribute('style','font:99px _,serif;position:absolute;visibility:hidden'); _< why use set attribute ?
[11:05] paul: i forget why
[11:05] for head you cold do
[11:06] var head = doc.head || doc.getElementsByTagName('head')[0] || docElement;
head.insertBefore(stuff, head.firstChild);
[11:07] avoid spn.setAttribute('style' ..) if you can its a sore spot in attributes (mainly IE but just to be safe)
[11:08] dont assume there is a global `undefined` value
[11:08] define a var as `var undefined`
[11:08] or var undef
[11:13] might be able to reduce 1 element creation by using a div instead of custom element m = doc.createElement( 'modernizr' ), -> createElement('div')
[11:15] 
instead of

 i = elems.length+1;        while ( --i ) {            elem = doc.createElement( elems[i] );        }
[11:16] maybe

 i = elems.length;        while ( i ) {            elem = doc.createElement( elems[--i] );        }
[11:17] host objects aren't guaranteed to be a specific type
[11:17] so typeof cache.update == 'function'
[11:18] should be something like isHostObject(cache, 'update')
[11:18] typeof is usually `object`, `unknown` or `function` and object[property] is truthy
[11:20] callback && (isCallbackCalled = true) && callback(fontret); can be reduced to
(isCallbackCalled = !!callback) && callback(fontret);

media queries

adding support for CSS media queries might be cool.

Add detection for Flash installed/enabled

True: Flash installed and enabled
False: Flash not installed in browser, not supported (iPhone, iPad, etc.), or not enabled due to Flash blocking plugins.

This is set for Modernizr 1.2

Change homepage copy footnote re: html5 forms

"They are a very under-developed part of the HTML5 spec and only Opera and, to a lesser extent, Safari support any real new parts of this so far."

I'm not sure I agree with the statement that forms are under-developed. In fact, I think development is pretty much done, as far as the spec is concerned. Perhaps you meant to write under-implemented (or something)?

It's true that Opera is the King of html5 forms--but Chrome and Safari have decent-ish behind the scenes support with tickets in Webkit and Mozilla's Bugzilla to implement native UIs (e.g., https://bugs.webkit.org/show_bug.cgi?id=27968).

Firefox and IE8 are the ones lagging here, but Firefox 3.6b4 is introducing 'multiple'.

The phrase "under-developed" could potentially influence people's decisions to implement html5 forms or not--could it be re-phrased, or even removed?

SVG tests

would love community feedback on what sort of SVG tests are needed

Modernizr.inputattrs object ?

Just like inputtypes should we group all input attributes under one object?

Right now we have support for these attributes as defined in the Web Forms spec:
required, list, pattern, multiple, maxlength, placeholder, autofocus

Alternatively they would be reached as:

Modernizr.inputAutofocus
Modernizr.inputPattern

and so on.

mutation events

from remy sharp:
http://gist.github.com/287106

question: if one mutation event is supported are all of them?

from wikipedia:
Mozilla and Opera support DOMAttrModified, DOMNodeInserted, DOMNodeRemoved and DOMCharacterDataModified. Safari, as of version 1.3, also supports these methods.

Support gecko's css gradient proposal

Reported here: http://twitter.com/atwork8_/statuses/3895252369

Per Faruk:
"Right now, the two CSS gradient specs are both mere proposals and both are under heavy scrutiny for changing and synchronizing. I want us to adjust the gradient check in the next release to support both WebKit and Mozilla's proposals, e.g. check for both types. Since Firefox only supports it as of 3.6a and later, but WebKit has had it since Safari 3.1, we'll do the Firefox check second."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.