Skip to content

Commit

Permalink
Stop overriding the window onchange event like an adult, bumping vers…
Browse files Browse the repository at this point in the history
…ion, cleaning up lint
  • Loading branch information
kenwheeler committed Apr 22, 2015
1 parent 98b54ae commit 1eb582c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nuka-carousel",
"main": "index.js",
"version": "0.0.5",
"version": "0.0.6",
"homepage": "https://github.com/kenwheeler/nuka-carousel",
"authors": [
"Ken Wheeler <[email protected]>"
Expand Down
20 changes: 18 additions & 2 deletions lib/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ var _assign2 = _interopRequireWildcard(_assign);

_React2['default'].initializeTouchEvents(true);

var addEvent = function addEvent(elem, type, eventHandle) {
if (elem == null || typeof elem === 'undefined') {
return;
}
if (elem.addEventListener) {
elem.addEventListener(type, eventHandle, false);
} else if (elem.attachEvent) {
elem.attachEvent('on' + type, eventHandle);
} else {
elem['on' + type] = eventHandle;
}
};

var Carousel = _React2['default'].createClass({
displayName: 'Carousel',

Expand Down Expand Up @@ -357,9 +370,12 @@ var Carousel = _React2['default'].createClass({

bindEvents: function bindEvents() {
var self = this;
window.onresize = function () {
addEvent(window, 'resize', function () {
self.setDimensions();
};
});
addEvent(document, 'readystatechange', function () {
self.setDimensions();
});
},

formatChildren: function formatChildren(children) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuka-carousel",
"version": "0.0.5",
"version": "0.0.6",
"description": "Pure React Carousel",
"main": "index.js",
"dependencies": {
Expand Down
26 changes: 21 additions & 5 deletions src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ import assign from 'object-assign';

React.initializeTouchEvents(true);

const addEvent = function(elem, type, eventHandle) {
if (elem == null || typeof (elem) === 'undefined') {
return;
}
if (elem.addEventListener) {
elem.addEventListener(type, eventHandle, false);
} else if (elem.attachEvent) {
elem.attachEvent('on' + type, eventHandle);
} else {
elem['on'+type] = eventHandle;
}
};

const Carousel = React.createClass({
displayName: 'Carousel',

Expand Down Expand Up @@ -40,12 +53,12 @@ const Carousel = React.createClass({
dragging: true,
easing: 'easeOutCirc',
edgeEasing: 'easeOutElastic',
framePadding: "0px",
framePadding: '0px',
slidesToShow: 1,
slidesToScroll: 1,
slideWidth: 1,
speed: 500,
width: "100%"
width: '100%'
}
},

Expand Down Expand Up @@ -346,9 +359,12 @@ const Carousel = React.createClass({

bindEvents() {
var self = this;
window.onresize = function() {
addEvent(window, 'resize', function() {
self.setDimensions();
}
});
addEvent(document, 'readystatechange', function() {
self.setDimensions();
});
},

formatChildren(children) {
Expand Down Expand Up @@ -400,7 +416,7 @@ const Carousel = React.createClass({
display: 'block',
top: 0,
left: this.getTweeningValue('left'),
margin: "0px " + (this.props.cellSpacing / 2) * -1 + "px",
margin: '0px ' + (this.props.cellSpacing / 2) * -1 + 'px',
padding: 0,
width: listWidth + spacingOffset,
cursor: this.state.dragging === true ? 'pointer' : 'inherit',
Expand Down

0 comments on commit 1eb582c

Please sign in to comment.