Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit c5c8264

Browse files
author
Kent C. Dodds
committed
Merge pull request #541 from BarryThePenguin/master
refactor(formly-run): use documentMode for IE detection
2 parents 54fc0d3 + fb562a4 commit c5c8264

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

src/run/formlyCustomTags.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@ export default addCustomTags
33

44
// @ngInject
55
function addCustomTags($document) {
6-
if ($document && $document.get) {
7-
// IE8 check ->
8-
// http://stackoverflow.com/questions/10964966/detect-ie-version-prior-to-v9-in-javascript/10965203#10965203
6+
// IE8 check ->
7+
// https://msdn.microsoft.com/en-us/library/cc196988(v=vs.85).aspx
8+
if ($document && $document.documentMode < 9) {
99
const document = $document.get(0)
10-
const div = document.createElement('div')
11-
div.innerHTML = '<!--[if lt IE 9]><i></i><![endif]-->'
12-
const isIeLessThan9 = (div.getElementsByTagName('i').length === 1)
13-
14-
if (isIeLessThan9) {
15-
// add the custom elements that we need for formly
16-
const customElements = [
17-
'formly-field', 'formly-form', 'formly-custom-validation', 'formly-focus', 'formly-transpose',
18-
]
19-
angular.forEach(customElements, el => {
20-
document.createElement(el)
21-
})
22-
}
10+
// add the custom elements that we need for formly
11+
const customElements = [
12+
'formly-field', 'formly-form',
13+
]
14+
angular.forEach(customElements, el => {
15+
document.createElement(el)
16+
})
2317
}
2418
}

src/run/formlyCustomTags.test.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import angular from 'angular'
33
describe(`formlyCustomTags`, () => {
44

55
beforeEach(window.module(`formly`, $provide => {
6-
const docStub = {
6+
$provide.value(`$document`, {
7+
documentMode: 8,
78
get: sinon.stub().withArgs(0).returnsThis(),
8-
createElement: sinon.stub().withArgs(`div`).returns({
9-
getElementsByTagName: sinon.stub().withArgs(`i`).returns([1]),
10-
}),
11-
}
12-
13-
$provide.value(`$document`, docStub)
9+
createElement: sinon.spy(),
10+
})
1411
}))
1512

1613
let $document
@@ -22,7 +19,7 @@ describe(`formlyCustomTags`, () => {
2219
describe(`addCustomTags`, () => {
2320
it(`should create custom formly tags`, () => {
2421
const customElements = [
25-
`div`, `formly-field`, `formly-form`, `formly-custom-validation`, `formly-focus`, `formly-transpose`,
22+
`formly-field`, `formly-form`,
2623
]
2724

2825
expect($document.get).to.have.been.calledOnce

0 commit comments

Comments
 (0)