Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE8 Support #159

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .zuul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ browsers:
- name: iphone
version: latest
- name: ie
version: 10..latest
version: 8..latest
4 changes: 2 additions & 2 deletions lib/each.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = function(el, val) {
var args = Array.prototype.slice.apply(arguments);
var len = arr.length;

var splice_args = [len, 0].concat(args)
var splice_args = [len, 0].concat(args);
splice.apply(arr, splice_args);
return arr.length;
};
Expand All @@ -141,7 +141,7 @@ module.exports = function(el, val) {
var args = Array.prototype.slice.apply(arguments);
var len = arr.length;

var splice_args = [0, 0].concat(args)
var splice_args = [0, 0].concat(args);
splice.apply(arr, splice_args);
return arr.length;
};
Expand Down
13 changes: 12 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ Reactive.prototype._bind = function() {
return next(skip);
}
// text
else if (el.nodeType == 3) {
else if (el.nodeType == 3 && inDomTree(el)) {
if (utils.hasInterpolation(el.data)) {
debug('bind text "%s"', el.data);
new TextBinding(self, el);
Expand Down Expand Up @@ -338,3 +338,14 @@ Reactive.prototype.use = function(fn) {
fn(this);
return this;
};


function inDomTree(el) {
try {
return !!el.parentNode;
} catch (e) {
if (e.message == 'Invalid argument.') // IE8 is dumb
return false;
throw e;
}
}
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
],
"main": "lib/index.js",
"dependencies": {
"carry": "0.0.1",
"classes-component": "1.1.3",
"debug": "0.7.4",
"domify": "1.2.1",
"emitter-component": "1.1.1",
"event-component": "0.1.0",
"query-component": "0.0.1",
"emitter-component": "1.1.1",
"domify": "1.2.1",
"carry": "0.0.1",
"debug": "0.7.4"
"reactive-ie8-shims": "^0.1.2"
},
"browser": {
"classes": "classes-component",
Expand All @@ -28,13 +29,14 @@
"clone": "clone-component"
},
"devDependencies": {
"zuul": "~1.5.4",
"clone-component": "component/clone#acfb79aa",
"better-assert": "~1.0.0",
"mocha": "~1.17.0"
"clone-component": "component/clone#acfb79aa",
"mocha": "~1.17.0",
"reactive-ie8-shims": "^0.1.1",
"zuul": "~1.5.4"
},
"scripts": {
"test": "zuul -- test/*.js",
"test-local": "zuul --local -- test/*.js"
}
}
}
2 changes: 2 additions & 0 deletions test/adapters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var domify = require('domify');
var assert = require('assert');
var Emitter = require('emitter');
Expand Down
2 changes: 2 additions & 0 deletions test/attr-interpolation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var domify = require('domify');
var assert = require('assert');

Expand Down
2 changes: 2 additions & 0 deletions test/bindings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var domify = require('domify');
var assert = require('assert');

Expand Down
6 changes: 5 additions & 1 deletion test/each.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var domify = require('domify');
var assert = require('assert');

Expand Down Expand Up @@ -55,7 +57,9 @@ describe('each', function(){
assert.equal(el.children[0].textContent, 'candy');

view.destroy();
assert.equal(el.parentNode, undefined);
assert.equal(el.parentElement, undefined);
// IE8 puts a document fragment above the element
assert(!el.parentNode || el.parentNode.nodeType === 11);

// this should have no effect on the children anymore
view.set('todos', ['milk', 'cereal']);
Expand Down
24 changes: 17 additions & 7 deletions test/reactive.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var classes = require('classes');
var domify = require('domify');
var assert = require('assert');
Expand Down Expand Up @@ -188,7 +190,7 @@ describe('data-html', function(){
var el = domify('<div><p data-html="name"></p></div>');
var user = { name: '<strong>Tobi</strong>' };
var view = reactive(el, user);
assert('<strong>Tobi</strong>' == el.children[0].innerHTML);
assert('<strong>tobi</strong>' == el.children[0].innerHTML.toLowerCase());
})

it('should support computed values', function(){
Expand Down Expand Up @@ -288,7 +290,7 @@ describe('data-checked', function(){
var el = domify('<div><input data-checked="agree" /></div>');
var user = { agree: false };
var view = reactive(el, user);
assert(null == el.children[0].getAttribute('checked'));
assert(!el.children[0].getAttribute('checked')); // IE8 returns "", modern returns null
})
})

Expand All @@ -311,17 +313,17 @@ describe('data-replace', function(){

it('should carryover attributes', function(){
var input = document.createElement('input');
var el = domify('<div><div type="email" data-replace="input"></div>');
var el = domify('<div><div data-value="foobar" data-replace="input"></div>');
var view = reactive(el, {}, { delegate: { input: input } });
assert('email' == input.type);
assert('foobar' == input.getAttribute('data-value'));
})

it('shouldnt wipe out existing attributes', function(){
var input = document.createElement('input');
input.type = 'url'
var el = domify('<div><div type="email" data-replace="input"></div>');
input.setAttribute('data-value','barbaz')
var el = domify('<div><div data-value="foobar" data-replace="input"></div>');
var view = reactive(el, {}, { delegate: { input: input } });
assert('url' == input.type);
assert('barbaz' == input.getAttribute('data-value'));
})

it('should carryover classes', function(){
Expand All @@ -341,3 +343,11 @@ describe('data-[attr]', function(){
assert('Tobi' == el.children[0].value);
})
})

describe('data-html', function () {
it('should replace html content', function(){
var el = domify('<div data-html="value">text to be replaced</div>');
var view = reactive(el, { value: '<div data-html="value"></div>' });
assert(el.innerHTML.toLowerCase() === '<div data-html="value"></div>');
})
})
2 changes: 2 additions & 0 deletions test/text-interpolation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require('reactive-ie8-shims');

var domify = require('domify');
var assert = require('assert');

Expand Down