Skip to content

Commit

Permalink
Merge pull request #38 from shawnbot/v2
Browse files Browse the repository at this point in the history
merge v2
  • Loading branch information
shawnbot committed Jan 26, 2015
2 parents 73a5bce + 9bd6758 commit f2011af
Show file tree
Hide file tree
Showing 36 changed files with 2,933 additions and 1,386 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.sw?
node_modules
.DS_Store
21 changes: 12 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
[submodule "js/es5-shim"]
path = js/es5-shim
url = https://github.com/es-shims/es5-shim.git
[submodule "css/pie"]
path = css/pie
url = https://github.com/lojjic/PIE.git
[submodule "js/classList"]
path = js/classList
url = https://github.com/eligrey/classList.js.git
[submodule "lib/ie8"]
path = lib/ie8
url = [email protected]:shawnbot/ie8.git
[submodule "lib/dom4"]
path = lib/dom4
url = [email protected]:shawnbot/dom4.git
[submodule "lib/es5-shim"]
path = lib/es5-shim
url = [email protected]:es-shims/es5-shim.git
[submodule "lib/html5shiv"]
path = lib/html5shiv
url = https://github.com/aFarkas/html5shiv.git
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- '0.10'
4 changes: 4 additions & 0 deletions .zuul.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ui: qunit
browsers:
- name: ie
version: 8..9
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

ie8 & dom4 LICENSE:

Copyright (C) 2013 by WebReflection

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
29 changes: 17 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
JS_FILES = \
js/aight.js \
js/classList/classList.js \
js/es5-shim/es5-shim.js \
js/computed-style.js \
js/css-properties.js \
js/element-createElementNS.js \
js/element-events.js \
js/element-properties.js
src/start.js \
lib/es5-shim/es5-shim.js \
lib/es5-shim/es5-sham.js \
src/aight.js \
src/before-ie8.js \
lib/ie8/src/ie8.js \
src/after-ie8.js \
lib/dom4/src/dom4.js \
lib/html5shiv/src/html5shiv.js \
src/css-om.js \
src/createElementNS.js \
src/end.js

JS_COMPILER ?= uglifyjs

all: aight.js aight.min.js aight.d3.min.js

clean:
rm -f aight.js aight.min.js
all: aight.js aight.min.js
# TODO aight.d3.min.js

aight.js: $(JS_FILES)
cat $(JS_FILES) > $@

%.min.js: %.js
$(JS_COMPILER) $< > $@

clean:
rm -f aight.js aight.min.js
61 changes: 42 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
# <img src="https://raw.github.com/shawnbot/aight/master/assets/aight.png">

Aight is a collection of shims and polyfills that get IE8 up to speed with
a bare minimum of HTML5 compatibility, providing all of the interfaces
necessary to do HTML-only DOM manipulation with d3.js (and other libraries that
rely on those interfaces). It includes:
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[*](#svg) DOM manipulation with [D3](http://d3js.org)
and other libraries that rely on them. It includes:

* [es5-shim](https://github.com/kriskowal/es5-shim), which implements all of
the Array prototype methods in the ES5 spec, and other goodies.
the Array prototype methods in the ES5 spec, and other goodies. Both the
[shims](https://github.com/es-shims/es5-shim#shims) and
[shams](https://github.com/es-shims/es5-shim#shams) are included.

* [classList.js](https://github.com/eligrey/classList.js), which implements the
Element prototype's classList property, for intelligently adding and removing
classes from HTML elements.
* The [ie8](https://github.com/WebReflection/ie8) and
[dom4](https://github.com/WebReflection/dom4) collections, courtesy of
[Andrea Giammarchi](https://github.com/WebReflection). My
[fork of ie8](https://github.com/shawnbot/ie8/tree/ie9) maintains
compatibility with IE9, and dom4 provides Event and DOM JavaScript interface
compatibility for *any* browser.

* A shim for [CSSStyleDeclaration](http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration)'s
setProperty() and removeProperty() methods
* A simple shim for
[CSSStyleDeclaration](http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSStyleDeclaration)'s
`setProperty()` and `removeProperty()` methods.

* A shim for [document.createElementNS()](http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-DocCrElNS),
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
support). This merely provides a facade of interoperability with D3, which
calls createElementNS() even in cases where the parent's namespaceURI is
undefined (as is the case in HTML5, but *not* XHTML).

* A shim for [window.getComputedStyle()](http://www.w3.org/TR/DOM-Level-2-Style/css.html#CSS-CSSview-getComputedStyle)

* A shim for the Element prototype's addEventListener() and
removeEventListener() methods, per the [DOM2 EventTarget](http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget).
* [html5shiv](https://github.com/aFarkas/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](https://github.com/aFarkas/html5shiv/#html5shiv-printshivjs).

## Usage
Using aight is simple. First off, be sure that you're using the right `DOCTYPE`
in your HTML:
First off, ensure that you're using the [right
DOCTYPE](http://ejohn.org/blog/html5-doctype/) in your HTML:

```html
<!DOCTYPE html>
Expand All @@ -47,7 +54,7 @@ you're debugging aight itself) in a [conditional
comment](http://www.quirksmode.org/css/condcom.html) inside the `<head>`:

```html
<!--[if lt IE 9]>
<!--[if lte IE 9]>
<script type="text/javascript" src="aight.min.js"></script>
<![endif]-->
```
Expand All @@ -60,7 +67,7 @@ Bringing it all together, you end up with:
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<!--[if lt IE 9]>
<!--[if lte IE 9]>
<script type="text/javascript" src="aight.min.js"></script>
<![endif]-->
</head>
Expand All @@ -70,3 +77,19 @@ Bringing it all together, you end up with:
```

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

## What about SVG? <a name="svg"></a>
Shimming SVG support is tricky business. If you need to support IE8, my
suggestion is either to [degrade gracefully](https://www.google.com/search?q=graceful%20degradation)
using HTML elements or to try one of the following:

- [Raphaël](http://raphaeljs.com/), the SVG-friendly abstraction that falls
back to VML support in IE8.
- [r2d3](https://github.com/mhemesath/r2d3/) uses Raphaël under the hood to
provide SVG rendering support to [D3](http://d3js.org).
- [svgweb](https://code.google.com/p/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](http://blogs.msdn.com/b/ie/archive/2010/03/18/svg-in-ie9-roadmap.aspx),
though.
111 changes: 61 additions & 50 deletions aight.d3.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,68 @@
(function(exports) {

aight.d3 = {};

if (aight.browser.ie8) {
function mapped(property, format, parse) {
var read = function(p) {
var value = this.node().style[property];
return parse
? parse.call(this, value, p)
: value;
},
write = function(p, value) {
return this.each(function() {
var v = (typeof value === "function")
? value.apply(this, arguments)
: value;
this.style[property] = format
? format.call(this, v, p)
: v;
});
};
return function() {
return arguments.length > 1
? write.apply(this, arguments)
: read.call(this);
};
}

var aight_d3_style = {
"background-image": mapped("backgroundImage"),
"background-repeat": mapped("backgroundRepeat"),
"background-position": mapped("backgroundPosition"),
"background-color": mapped("backgroundColor"),

"opacity": mapped("filter",
function opacity_to_filter(opacity) {
return ["alpha(opacity=", Math.round(opacity * 100), ")"].join("");
},
function filter_to_opacity(filter) {
var opacity = (filter || "").match(/opacity=(\d+)/)[1] || 100;
return opacity / 100;
})
};

aight.d3.style = aight_d3_style;
aight.d3 = {};

var d3_style = d3.selection.prototype.style;
d3.selection.prototype.style = function(prop) {
var style = aight_d3_style.hasOwnProperty(prop)
? aight_d3_style[prop]
: d3_style;
return style.apply(this, arguments);
if (aight.browser.ie8) {
function mappedProperty(property, format, parse) {
var read = function(p) {
var value = this.node().style[property];
return parse
? parse.call(this, value, p)
: value;
},
write = function(p, value) {
if (value === null) {
return this.style(property, null);
}
return this.each(function() {
var v = (typeof value === "function")
? value.apply(this, arguments)
: value;
if (v === null) {
this.style.removeProperty(property);
} else {
this.style[property] = format
? format.call(this, v, p)
: v;
}
});
};
return function() {
return arguments.length > 1
? write.apply(this, arguments)
: read.call(this);
};
}

var aight_d3_style = {
// background styles need to be mapped explicitly
"background-image": mappedProperty("backgroundImage"),
"background-repeat": mappedProperty("backgroundRepeat"),
"background-position": mappedProperty("backgroundPosition"),
"background-color": mappedProperty("backgroundColor"),

"opacity": mappedProperty("filter",
function opacity_to_filter(opacity) {
return isNaN(opacity)
? null
: ["alpha(opacity=", Math.round(opacity * 100), ")"].join("");
},
function filter_to_opacity(filter) {
var match = (filter || "").match(/alpha\(opacity=(\d+)\)/);
return match ? match[1] / 100 : 1;
})
};

aight.d3.style = aight_d3_style;

var d3_style = d3.selection.prototype.style;
d3.selection.prototype.style = function(prop) {
var style = aight_d3_style.hasOwnProperty(prop)
? aight_d3_style[prop]
: d3_style;
return style.apply(this, arguments);
};

}

})(this);
Loading

0 comments on commit f2011af

Please sign in to comment.