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

Commit 7caf7bc

Browse files
author
Julien Bouquillon
committed
Merge pull request #233 from rdubigny/ie8-support
feat (directive): IE8 Support (updated)
2 parents 6393a02 + 568f628 commit 7caf7bc

File tree

2 files changed

+51
-40
lines changed

2 files changed

+51
-40
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ You can add position indicators by adding this directive where you want :
6161

6262
## Notes :
6363
- if you use IE<=9, iOS<7 or Android<4 please include the [requestAnimationFrame polyfill](https://github.com/darius/requestAnimationFrame/blob/master/requestAnimationFrame.js) in your application.
64+
- if you use IE<=8 include the [es5-shim polyfill](https://github.com/es-shims/es5-shim/blob/master/es5-shim.min.js) in your application.
6465
- don't set any style attribute to your li's. they would be overwritten by the carousel (use classes instead).
6566
- angular-carousel use the great [shifty.js](https://github.com/jeremyckahn/shifty) for the animations
6667

src/directives/rn-carousel.js

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
// detect supported CSS property
99
function detectTransformProperty() {
1010
var transformProperty = 'transform';
11-
['webkit', 'moz', 'o', 'ms'].every(function(prefix) {
12-
var e = '-' + prefix + '-transform';
13-
if (typeof document.body.style[e] !== 'undefined') {
14-
transformProperty = e;
15-
return false;
16-
}
17-
return true;
18-
});
11+
if (typeof document.body.style[transformProperty] !== 'undefined') {
12+
['webkit', 'moz', 'o', 'ms'].every(function (prefix) {
13+
var e = '-' + prefix + '-transform';
14+
if (typeof document.body.style[e] !== 'undefined') {
15+
transformProperty = e;
16+
return false;
17+
}
18+
return true;
19+
});
20+
} else {
21+
transformProperty = undefined;
22+
}
1923
return transformProperty;
2024
}
2125

@@ -58,37 +62,42 @@
5862
slideTransformValue = DeviceCapabilities.has3d ? 'translate3d(' + absoluteLeft + '%, 0, 0)' : 'translate3d(' + absoluteLeft + '%, 0)',
5963
distance = ((100 - Math.abs(absoluteLeft)) / 100);
6064

61-
if (transitionType == 'fadeAndSlide') {
62-
style[DeviceCapabilities.transformProperty] = slideTransformValue;
63-
opacity = 0;
64-
if (Math.abs(absoluteLeft) < 100) {
65-
opacity = 0.3 + distance * 0.7;
66-
}
67-
style.opacity = opacity;
68-
} else if (transitionType == 'hexagon') {
69-
var transformFrom = 100,
70-
degrees = 0,
71-
maxDegrees = 60 * (distance - 1);
72-
73-
transformFrom = offset < (slideIndex * -100) ? 100 : 0;
74-
degrees = offset < (slideIndex * -100) ? maxDegrees : -maxDegrees;
75-
style[DeviceCapabilities.transformProperty] = slideTransformValue + ' ' + 'rotateY(' + degrees + 'deg)';
76-
style['transform-origin'] = transformFrom + '% 50%';
77-
} else if (transitionType == 'zoom') {
78-
style[DeviceCapabilities.transformProperty] = slideTransformValue;
79-
var scale = 1;
80-
if (Math.abs(absoluteLeft) < 100) {
81-
scale = 1 + ((1 - distance) * 2);
82-
}
83-
style[DeviceCapabilities.transformProperty] += ' scale(' + scale + ')';
84-
style['transform-origin'] = '50% 50%';
85-
opacity = 0;
86-
if (Math.abs(absoluteLeft) < 100) {
87-
opacity = 0.3 + distance * 0.7;
88-
}
89-
style.opacity = opacity;
65+
if (!DeviceCapabilities.transformProperty) {
66+
// fallback to default slide if transformProperty is not available
67+
style['margin-left'] = absoluteLeft + '%';
9068
} else {
91-
style[DeviceCapabilities.transformProperty] = slideTransformValue;
69+
if (transitionType == 'fadeAndSlide') {
70+
style[DeviceCapabilities.transformProperty] = slideTransformValue;
71+
opacity = 0;
72+
if (Math.abs(absoluteLeft) < 100) {
73+
opacity = 0.3 + distance * 0.7;
74+
}
75+
style.opacity = opacity;
76+
} else if (transitionType == 'hexagon') {
77+
var transformFrom = 100,
78+
degrees = 0,
79+
maxDegrees = 60 * (distance - 1);
80+
81+
transformFrom = offset < (slideIndex * -100) ? 100 : 0;
82+
degrees = offset < (slideIndex * -100) ? maxDegrees : -maxDegrees;
83+
style[DeviceCapabilities.transformProperty] = slideTransformValue + ' ' + 'rotateY(' + degrees + 'deg)';
84+
style['transform-origin'] = transformFrom + '% 50%';
85+
} else if (transitionType == 'zoom') {
86+
style[DeviceCapabilities.transformProperty] = slideTransformValue;
87+
var scale = 1;
88+
if (Math.abs(absoluteLeft) < 100) {
89+
scale = 1 + ((1 - distance) * 2);
90+
}
91+
style[DeviceCapabilities.transformProperty] += ' scale(' + scale + ')';
92+
style['transform-origin'] = '50% 50%';
93+
opacity = 0;
94+
if (Math.abs(absoluteLeft) < 100) {
95+
opacity = 0.3 + distance * 0.7;
96+
}
97+
style.opacity = opacity;
98+
} else {
99+
style[DeviceCapabilities.transformProperty] = slideTransformValue;
100+
}
92101
}
93102
return style;
94103
};
@@ -206,7 +215,7 @@
206215
});
207216

208217
function getSlidesDOM() {
209-
return iElement[0].querySelectorAll(':scope > li');
218+
return iElement[0].querySelectorAll('ul[rn-carousel] > li');
210219
}
211220

212221
function documentMouseUpEvent(event) {
@@ -286,7 +295,8 @@
286295
}
287296

288297
function getContainerWidth() {
289-
return iElement[0].getBoundingClientRect().width;
298+
var rect = iElement[0].getBoundingClientRect();
299+
return rect.width ? rect.width : rect.right - rect.left;
290300
}
291301

292302
function updateContainerWidth() {

0 commit comments

Comments
 (0)