Skip to content

WoollyMittens/useful-polyfills

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polyfills.js: Polyfill Library

A library of useful polyfills to ease working with HTML5 in legacy environments.

How to include the script

This include can be added to the header or placed inline before the script is invoked.

<script src="js/polyfills.js"></script>

Or use Require.js.

requirejs([
	'js/polyfills.js'
], function(polyfills) {
	...
});

Or import into an MVC framework.

var polyfills = require('js/polyfills.js');

How to control the script

html5

	polyfills.html5();

Add support for HTML5 elements in Internet Explorer 8 and lower.

arrayIndexOf

	polyfills.arrayIndexOf();

Adds support for array.indexOf.

querySelectorAll

	polyfills.querySelectorAll();

Adds support for document.querySelectorAll (1).

addEventListener

	polyfills.addEventListener();

Adds support for element.addEventListener, element.removeEventListener and element.dispatchEvent (2).

consoleLog

	polyfills.consoleLog();

Adds support for console.log.

objectCreate

	polyfills.objectCreate();

Adds support for object.create (3).

stringTrim

	polyfills.stringTrim();

Adds support for string.trim, string.ltrim, string.rtrim and string.fulltrim (4).

localStorage

	polyfills.localStorage();

Adds support for localStorage.getItem, localStorage.key, localStorage.setItem, localStorage.length, localStorage.removeItem (5).

How to build the script

This project uses node.js from http://nodejs.org/

This project uses gulp.js from http://gulpjs.com/

The following commands are available for development:

  • npm install - Installs the prerequisites.
  • gulp import - Re-imports libraries from supporting projects to ./src/libs/ if available under the same folder tree.
  • gulp dev - Builds the project for development purposes.
  • gulp dist - Builds the project for deployment purposes.
  • gulp watch - Continuously recompiles updated files during development sessions.
  • gulp serve - Serves the project on a temporary web server at http://localhost:8500/.
  • gulp php - Serves the project on a temporary php server at http://localhost:8500/.

Sources

  1. Connolley, Paul. "IE7 querySelectorAll polyfill", https://gist.github.com/connrs/2724353
  2. Neal, Jonathan. "Polyfill the EventListener interface in IE8", https://gist.github.com/jonathantneal/3748027
  3. Gasparini, Ryan. "HTML5 API Polyfills", https://gist.github.com/rxgx/1597825
  4. Perelman, Eli. "String.prototype.trim polyfill for 140byt.es", https://gist.github.com/eliperelman/1035982
  5. Mozilla Developer Network. "DOM Storage guide", https://developer.mozilla.org/en/docs/Web/Guide/API/DOM/Storage

License

This work is licensed under a MIT License. The latest version of this and other scripts by the same author can be found on Github and at WoollyMittens.nl.

About

A library of useful polyfills to ease working with HTML5 in legacy environments.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published