Coder Social home page Coder Social logo

aight's Introduction

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]);
}

aight's People

Contributors

brettz9 avatar drm avatar kennynaoh avatar mhemesath avatar moox avatar pedroteixeira avatar shawnbot avatar usmonster 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

aight's Issues

Is the script type attribute necessary?

Most HTML5 boilerplates/generators omit the type="text/javascript" attribute from script tags. But the snippets in the aight readme do use this attribute.

Is there an IE8-specific reason why type should be specified, or is it personal preference?

Include ES5-sham

Any particular reason you did not include any of the ES5-sham?

d3's style("background-image") doesn't work

Setting CSS background-image with D3 doesn't work in IE8. We've resorted to using jQuery instead:

d3.selectAll(".foo")
  .each(function(d, i) { $(this).css("background-image", d.photo_url); });

Get CSSPIE working properly (or ditch it)

I initially included CSSPIE in this project because I wanted seamless support for simple stuff like border-radius and box-shadow, but it's kind of a boat anchor right now because it's not included in the built JavaScript files yet. This needs to be tested and either included or ditched if it doesn't work as advertised.

Aight CLI bug

Aight cli outputs wrong code when transforming inline if statements.

Ex :

 if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);

is converted to

if (request.setRequestHeader) 
var __hasOwnProperty = Object.prototype.hasOwnProperty.bind(headers);
for (var name in headers) if (__hasOwnProperty(name)) { request.setRequestHeader(name, headers[name]); }

There should be braces around the generated code.

d3.v2 loads but not d3.v3

This code runs ok for d3.v2 but if I try to load d3.v3 I get d3 is undefined in aight.d3. Same error if I d3.html in examples.

BUT - I am running a http://crossbrowsertesting.com emulator. Is it possible this is the problem?

    <script type="text/javascript"  src=" http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript"  src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


    <!--[if lt IE 9]>
    <script type="text/javascript" src="/shared_static/js/aight.js"></script>
    IE8j
    <![endif]-->

   <script src="http://d3js.org/d3.v2.min.js" charset="utf-8"></script>
<script type="text/javascript" src="/shared_static/js/aight.d3.min.js"></script>
Loaded

Upgrade es5-shim

npm install aight now warns when installing es5-shim:

deprecated [email protected]: Please update to the latest version; it overrides noncompliant native methods even in modern implementations

incompatible with modernizr

modernizr uses following test to detect svg support:

var ns = {'svg': 'http://www.w3.org/2000/svg'};
// Thanks to Erik Dahlstrom
tests['svg'] = function() {
    return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect;
};

While the createElementNS spec does define some exceptions there isn't an exception defined for "unsupported namespaces":
http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS

I do unterstand why you're raising an exception but I also see why modernizr does not expect an exception. What speaks against just ignoring ns and creating an element?

fontSize exception on load

Hi,
I'm currently trying put aight in place to shim some IE8 compatibility, but am getting the following exception on load:

SCRIPT5007: Unable to get property 'fontSize' of undefined or null reference: aight.js, line 1535 character 3.

I'm at a loss w/ how to debug this.

Make the build process friendlier

Grunt, for example, has tasks for concatenating and minifying JavaScript. The UglifyJS dependency isn't stated until you run make, which will probably confuse contributors. Alternatively, we could just add aight to npm and add uglify-js to devDependencies in the package.json.

bower warning: mismatch tag version

Hey,
when I run bower install i get the following warning:

bower warn Package aight is still using the deprecated "component.json" file
mismatch The version specified in the component.json of package aight mismatches the tag (1.1.1 vs 1.1.0)
mismatch You should report this problem to the package author

I can only assume that it is complaining about the following mismatch:

"version": "1.1.1",
...
"_id": "[email protected]",

Secondly, if you update the file, I think bower.json should be the correct new name, instead of component.json, which is deprecated.

jQuery UI breaks aight if loaded after

Found I had to load jquery-ui BEFORE aight or I got the this error: currentStyle is null or not an object
jQuery on it's own can go before or after.

This is OK

<script type="text/javascript"  src=" http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript"  src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/shared_static/js/aight.js"></script>
    <![endif]-->

This is NOT:

    <!--[if lt IE 9]>
    <script type="text/javascript" src="/shared_static/js/aight.js"></script>
    <![endif]-->

<script type="text/javascript"  src=" http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript"  src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

Is this an error?

Firefox chokes on textContent shim

Firefox 17.0.1 throws an exception in the textContent shim because its implementation of Object.getOwnPropertyDescriptor returns objects without a get() method. So not only does it fail the initial feature detection (because Object.getOwnPropertyDescriptor(Element.prototype, "textContent").get is undefined), but it also fails both to get a property descriptor for Element.prototype.innerText (which works in IE) and throws and exception when trying to define Element.prototype.textContent.

I've monkey patched production code to wrap this shim in a try/catch block, and we should probably do the same here.

Bump version in js/aight.js

The current tag (1.2.2) doesn't match the version in the file (1.2.1) -- can this be bumped on the next release?

Also, the bower.json file uses the "version" key, which is outdated and ignored by bower anyway, according to the spec, so it should probably just be removed.

Include HTML5shiv

What do you think of including also a html5shiv, to allow us using html5 element (like <header>, <nav>...) with some styles (because IE<9 doesn't allow CSS on unknown html elements.

jQuery.parseHTML breaks in IE8 with aight

$.parseHTML behaves incorrectly with aight when the html contains "{{ ... }}" in text.
It fails at buildFragment(...) {
...
// alert(nodes[0].outerHTML); // DIV contains correct info
tmp.textContent = "";
// alert(nodes[0].outerHTML); // DIV becomes empty
...
}

using es5-shim.js does not have this issue.
Here is the code to test:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <!--[if lt IE 9]>
        <script type="text/javascript" src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script type="text/javascript" src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->
        <script type="text/javascript" src="js/3rdParty/aight-1.2.1/aight.min.js"></script>
            <!-- <script type="text/javascript" src="js/3rdParty/es5-shim/es5-shim.min.js"></script> -->
    <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
  <meta charset="utf-8">
  <title>$.parseHTML</title>
</head>
<body>
    <script type="text/javascript">
        var result = $.parseHTML('<DIV><SPAN>{{ asdf }}</SPAN></DIV>');
        alert(result[0].outerHTML);
    </script>
</body>
</html>

Non standard / breaking polyfills

Some included file might trick the surrounding logic with non standard implementations / behavior.

ie8 fixes for real events and custom events and bubbling, whatever you are using here is a partially broken sham, not a polyfill.

All tests in place that are more standard and green in IE8 than Safari, as example.

dom4 brings CustomEevent, classList (for real, with all tests as meant by W3C) and others DOM4 things to all browsers including IE8 if used after the previous polyfill.

I wonder why this project decided to not go for standards polyfill and use some library not fully tested against W3C standards … maybe three's room for improvements?

Best Regards

Make a real website

  • register aight.ie aight.io
  • create gh-pages branch
  • add CNAME to TLD
  • write some HTML & CSS

More unit tests!

The d3-specific and purely visual test doc is no longer sufficient. We need a real unit tests that run in IE8 (maybe QUnit?).

Test for getComputedStyle is broken in browsers that implement the current Web IDL specification

This test in computed-style.js:

'getComputedStyle' in Window.prototype

is broken in browsers that implement the current Web IDL specification for Window (e.g. Firefox 32), because per that specification the property lives on the window object directly, not on the prototype.

The right test is:

'getComputedStyle' in window

which should work in both browsers that put the property on the window directly and ones that put it on the prototype.

This issue causes aight to try to use the IE-only .currentStyle in Firefox 32, which of course doesn't work very well.

Additional work on CSSStyleDeclaration

Regarding css-properties.js, would you take a look at https://github.com/brettz9/jml/blob/master/shims/CSSStyleDeclaration.js and let me know if that content interests you in some manner? I added some more methods to CSSStyleDeclaration such as getPropertyPriority() and adding more type checking and conversions.

Note there are a few dependencies:

  1. One is a shim for DOMException (e.g., my fork of @inexorabletash 's copy is at https://github.com/brettz9/jml/blob/master/shims/DOMException.js which indicates it also depends on shims for Object.keys and Array.prototype.forEach as also found in https://github.com/brettz9/jml/tree/master/shims ) which adds a convenience method DOMException.create() since the real DOMException does not allow itself to be instantiation through "new DOMException". Although I'm normally not a fan of adding non-standard properties (even if on a namespace), I think this one is unobtrusive enough and more convenient than packing all the code into each file that uses it.
  2. Object.defineProperty as shimmed by https://github.com/eligrey/Xccessors/blob/master/xccessors-standard.js

Array.prototype checks printing out in D3.js (IE 8)

While rather successfully using AIGHT to shim D3.js for a project that I'm working on, I am stuck on one problem.

I'm outputting data in a tabular format. In this instance, there are 6 columns of data across. While AIGHT manages to get my code to work in IE 8, it is, for some reason, grabbing the Array.prototype check code (roughly from like 532 and onward) and prints it out, treating it like useful data.

Has anyone come across this issue? It's an odd one. Thank you!

Include Respond.js

Respond.js is a fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more), which is required for Bootstrap 2.3.0 + support in IE7 and above. Does this library already include it? If not, is there any plans to do so?

SCRIPT438: Object doesn't support property or method 'getContext' in IE8

Trying to draw word cloud using d3.layout.cloud.js in IE8 and getting SCRIPT438: Object doesn't support property or method 'getContext' and SCRIPT438: Object doesn't support property or method 'cloud' errors.

List of files included with meta tags:
charset="utf-8"
http-equiv="X-UA-Compatible" content="IE=Edge"

src="../aight.js"
src="http://d3js.org/d3.v3.min.js"
src="../aight.d3.js"
src="../d3.layout.cloud.js"

Please let me know if you need more information or working example.

Thanks..

setProperty() is not working for some rules

Hi,

CSSStyleDeclaration.prototype.setProperty is not working on properties with hyphen (margin-left, padding-left ect ...)

It is because the the property name passed to setAttribute must be camel cased.

I noticed the bug on IE8 (real IE8, not a more recent one in IE8 mode)

Test case:

<!DOCTYPE html>
<html>
<body>
<span id="item"> abc </span>
<script>
var item = document.getElementById("item")

item.style.setAttribute('margin-left', '40px') //Not working

item.style.setAttribute('marginLeft', '40px') // Working \o/
</script>
</body>
</html>

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.