All Projects → shawnbot → Aight

shawnbot / Aight

Licence: other
JavaScript shims and shams for making IE8-9 behave reasonably

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Aight

Web Series
📚 现代 Web 开发语法基础与工程实践,涵盖 Web 开发基础、前端工程化、应用架构、性能与体验优化、混合开发、React 实践、Vue 实践、WebAssembly 等多方面。
Stars: ✭ 666 (-11.79%)
Mutual labels:  dom
Nanomorph
🚅 - Hyper fast diffing algorithm for real DOM nodes
Stars: ✭ 621 (-17.75%)
Mutual labels:  dom
Dom4j
flexible XML framework for Java
Stars: ✭ 689 (-8.74%)
Mutual labels:  dom
Html2canvas
Screenshots with JavaScript
Stars: ✭ 25,113 (+3226.23%)
Mutual labels:  dom
Displayjs
A simple JavaScript framework for building ambitious UIs 😊
Stars: ✭ 590 (-21.85%)
Mutual labels:  dom
Ramjet
Morph DOM elements from one state to another with smooth animations and transitions
Stars: ✭ 5,455 (+622.52%)
Mutual labels:  dom
Testing Playground
🐸 Simple and complete DOM testing playground that encourage good testing practices.
Stars: ✭ 511 (-32.32%)
Mutual labels:  dom
Maquette
Pure and simple virtual DOM library
Stars: ✭ 729 (-3.44%)
Mutual labels:  dom
Html To Image
✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
Stars: ✭ 595 (-21.19%)
Mutual labels:  dom
Svg
Fork of the ms svg library (http://svg.codeplex.com/)
Stars: ✭ 676 (-10.46%)
Mutual labels:  dom
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+3160.4%)
Mutual labels:  dom
Cash
An absurdly small jQuery alternative for modern browsers.
Stars: ✭ 5,714 (+656.82%)
Mutual labels:  dom
Nanohtml
🐉 HTML template strings for the Browser with support for Server Side Rendering in Node.
Stars: ✭ 651 (-13.77%)
Mutual labels:  dom
React Svg
🎨 A React component that injects SVG into the DOM.
Stars: ✭ 536 (-29.01%)
Mutual labels:  dom
Cssom
CSS Object Model implemented in pure JavaScript. It's also a parser!
Stars: ✭ 691 (-8.48%)
Mutual labels:  dom
Scrollbear
A modern tool that maintains scroll position when images loaded
Stars: ✭ 523 (-30.73%)
Mutual labels:  dom
Nanojs
Minimal standalone JS library for DOM manipulation
Stars: ✭ 636 (-15.76%)
Mutual labels:  dom
Sinuous
🧬 Light, fast, reactive UI library
Stars: ✭ 740 (-1.99%)
Mutual labels:  dom
Arrive
Watch for DOM elements creation and removal
Stars: ✭ 703 (-6.89%)
Mutual labels:  dom
React Archer
🏹 Draw arrows between React elements 🖋
Stars: ✭ 666 (-11.79%)
Mutual labels:  dom

aight

travis build status CDNJS

Aight is a collection of shims and polyfills that get IE8 (and IE9) up to speed with a bare minimum of HTML5 compatibility, providing all of the interfaces necessary to do HTML-only* DOM manipulation with D3 and other libraries that rely on them. It includes:

  • es5-shim, which implements all of the Array prototype methods in the ES5 spec, and other goodies. Both the shims and shams are included.

  • The ie8 and dom4 collections, courtesy of Andrea Giammarchi. My fork of ie8 maintains compatibility with IE9, and dom4 provides Event and DOM JavaScript interface compatibility for any browser.

  • A simple shim for CSSStyleDeclaration's setProperty() and removeProperty() methods.

  • A shim for document.createElementNS(), which throws an error if you pass it an actual namespace (which IE8 doesn't support). This merely provides a facade of interoperability with D3, which calls document.createElementNS() even in cases where the parent's namespaceURI is undefined (as is the case in HTML5, but not XHTML).

  • html5shiv, which monkeypatches IE6-8 to enable manipulation of HTML5 elements in the DOM and applies basic styling for them in IE6-9. If you need to be able to print these elements you will need to bring your own html5shiv-printshiv.js.

  • An IE8-friendly build of D3.

Installation

You have some options:

  1. Download the latest release or grab the latest from GitHub:

    curl -O https://raw.githubusercontent.com/shawnbot/aight/master/aight.js
    # or minified:
    curl -O https://raw.githubusercontent.com/shawnbot/aight/master/aight.min.js
    
  2. Clone this repository with git:

    git clone https://github.com/shawnbot/aight.git
    
  3. Install with bower:

    bower init # if you haven't already
    bower install aight#~2.0
    # then copy it from the bower_components directory
    cp bower_components/aight/aight*.js path/to/js
    
  4. Install with npm:

    npm install aight
    # then copy it from the node_modules directory
    cp node_modules/aight/aight*.js path/to/js
    

Usage

First off, ensure that you're using the right DOCTYPE in your HTML:

<!DOCTYPE html>

And in your <head>, include the following <meta> tag:

<meta http-equiv="X-UA-Compatible" content="IE=Edge">

These two steps ensure that IE8 will run in standards mode. Finally, include aight.min.js (or the un-minified version, aight.js, if you're debugging aight itself) in a conditional comment inside the <head>:

<!--[if lte IE 9]>
<script src="aight.min.js"></script>
<![endif]-->

Bringing it all together, you end up with:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <!--[if lte IE 9]>
    <script src="aight.min.js"></script>
    <![endif]-->
  </head>
  <body>
  </body>
</html>

For your convenience, this snippet is included with aight in template.html.

D3 for IE8

IE8 barfs on some parts of D3's JavaScript. The included d3.ie8.js and minified d3.ie8.min.js (in the d3 directory) are IE8-friendly builds of d3.v3.js with shams for some CSS properties, namely opacity. You'll need to tweak your HTML to use these, e.g.:

<!--[if lte IE 9]><script src="aight.js"></script><![endif]-->
<script src="http://d3js.org/d3.v3.min.js"></script>
<!--[if IE 8]><script src="d3.ie8.js"></script><![endif]-->

Since conditional comments are inaccessible to other browsers, we have to download the "modern" d3.js (which will throw errors in IE8) and the shimmed one (which won't). It's an imperfect solution, obviously. You may serve d3.ie8.js to modern browsers, but there will probably be performance implications depending on how you use D3.

What about SVG?

Shimming SVG support is tricky business. If you need to support IE8, my suggestion is either to degrade gracefully using HTML elements or to try one of the following:

  • Raphaël, the SVG-friendly abstraction that falls back to VML support in IE8.
  • r2d3 uses Raphaël under the hood to provide SVG rendering support to D3.
  • svgweb is a Flash-based SVG renderer. This is beta software which lacks full SVG 1.1 support and will not allow you to style SVG with CSS.

IE9 has great SVG support, though.

aight: the command line tool

As of version 2.0.5, aight comes with a handy command-line script that rewrites JavaScript (specifically, the stuff that shims and shams can't reach) to be IE8-friendly. Just install aight via npm:

npm install -g aight
# leave off the -g to install locally

Then run aight and give it a JavaScript filename (or source via stdin), and it will print JavaScript to stdout:

aight modern.js > ie8-friendly.js
cat modern.js | aight > ie8-friendly.js

You can see how it works by piping in a simple for..in loop:

echo "var obj = {}; for (var key in obj) console.log(key, obj[key]);" | aight

which outputs (with whitespace, for clarity):

var obj = {};
for (var key in obj) if (obj.hasOwnProperty(key)) {
  console.log(key, obj[key]);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].