GithubHelp home page GithubHelp logo

necolas / dom-shims Goto Github PK

View Code? Open in Web Editor NEW
34.0 4.0 4.0 375 KB

Complete and well-tested shims / polyfills for various DOM API's missing in not-so-modern browsers

License: MIT License

JavaScript 100.00%

dom-shims's Introduction

dom-shims

Build Status

Sauce Test Status

Complete and well-tested shims / polyfills for various DOM API's missing in not-so-modern browsers.

Installation

npm install --save dom-shims

Apply all the shims by requiring the module without assignment:

require('dom-shims');

Or apply specific shims:

require('dom-shims/shim/CustomEvent');
require('dom-shims/shim/Element.classList');
require('dom-shims/shim/Element.matches');

Features

Event polyfills

Element.prototype shims

NOTES:

  1. Ensures all browsers have classList support for SVG elements, multiple-argument support for add and remove, force-argument support for toggle, and correct length and item values even when the class value is mutated by means other than classList.

  2. Patches IE 9's implementation, which lacks support for Elements not attached to the document.

Element mutation

DOM Level 4 mutation macros for:

  • Element#append()
  • Element#prepend()
  • Element#after()
  • Element#before()
  • Element#remove()
  • Element#replace()

Other shims

Browser support

Intended support for:

  • Chrome
  • Firefox
  • IE9+
  • Safari 6+
  • Android 4+
  • Safari iOS 5.1+
  • Opera

Acknowledgements

Thanks to the following libraries for inspiration, ideas, and workarounds:

dom-shims's People

Contributors

angus-c avatar jfsiii avatar necolas 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

Watchers

 avatar  avatar  avatar  avatar

dom-shims's Issues

Firefox error: 'add' is read-only

Firefox 29.0.0 (Linux) ERROR
  TypeError: "add" is read-only
  at /home/travis/build/necolas/dom-shims/shim/Element.classList.js:51
Firefox 29.0.0 (Linux) ERROR
  TypeError: "add" is read-only
  at /home/travis/build/necolas/dom-shims/shim/Element.classList.js:51
Firefox 29.0.0 (Linux): Executed 0 of 0 ERROR (0.755 secs / 0 secs)

when running CustomEvent in strict mode, `window` is undefined

If the CustomEvent module is itself used in a strict mode environment (and all modules run in strict mode in ES6) window will be undefined.

This is because the value of this (the parameter to the outer function wrapper) is undefined in a null-reffed function call in strict mode (it's the global object in non-strict mode).

Two workarounds come to mind:

  1. Always reference the window object directly (fails in node.js, but might be ok since this is a DOM shim)

  2. Use an indirect eval call to access the global value:
    var window = (0, eval)('this');

Indirect evals are guaranteed to run in the global scope (and are safe):
http://perfectionkills.com/unnecessarily-comprehensive-look-into-a-rather-insignificant-issue-of-global-objects-creation/#ecmascript_5_strict_mode

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.