Skip to content

Commit

Permalink
add hasDots condition
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlanyuan committed Dec 11, 2015
1 parent 29074a3 commit dc82d6c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 38 deletions.
45 changes: 26 additions & 19 deletions assets/js/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@
tinyFn.items = getItem (tinyFn.bp, tinyFn.vals, options.items);
tinyFn.speed = (tinyFn.slideByPage) ? options.speed * tinyFn.items : options.speed;
tinySliderCore.prototype.updateContainer(tinyFn);
tinySliderCore.prototype.updateDots(tinyFn);
tinySliderCore.prototype.updateDotsStatus(tinyFn);
if (tinyFn.hasDots) {
tinySliderCore.prototype.updateDots(tinyFn);
tinySliderCore.prototype.updateDotsStatus(tinyFn);
}
}, 100);
});

// on nav click
addEvent(this.next, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, 1); });
addEvent(this.prev, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, -1); });
if (this.hasNav) {
addEvent(this.next, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, 1); });
addEvent(this.prev, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, -1); });
}

// on key down
if (this.keyboard) {
Expand All @@ -100,16 +104,18 @@
}

// on dot click
for (var i = 0; i < this.dots.length; i++) {
addEvent(this.dots[i], 'click', function (e) {
var index;
for (var i = 0; i < tinyFn.dots.length; i++) {
target = (e.currentTarget) ? e.currentTarget : e.srcElement;
if (tinyFn.dots[i] === target) { index = i; }
}
tinySliderCore.prototype.onDotClick(tinyFn, index);
});
};
if (this.hasDots) {
for (var i = 0; i < this.dots.length; i++) {
addEvent(this.dots[i], 'click', function (e) {
var index;
for (var i = 0; i < tinyFn.dots.length; i++) {
target = (e.currentTarget) ? e.currentTarget : e.srcElement;
if (tinyFn.dots[i] === target) { index = i; }
}
tinySliderCore.prototype.onDotClick(tinyFn, index);
});
}
}

// autoplay
if (this.autoplay) {
Expand Down Expand Up @@ -207,8 +213,10 @@
}

this.updateContainer(this);
this.updateDots(this);
this.updateDotsStatus(this);
if (this.hasDots) {
this.updateDots(this);
this.updateDotsStatus(this);
}
},

updateContainer: function (obj) {
Expand Down Expand Up @@ -276,7 +284,7 @@
}

setTimeout(function () {
tinySliderCore.prototype.updateDotsStatus(obj);
if (obj.hasDots) { tinySliderCore.prototype.updateDotsStatus(obj); }
obj.animating = false;
}, obj.speed);
}
Expand Down Expand Up @@ -309,7 +317,7 @@
obj.container.style.left = - (100 * obj.index / obj.items) + '%';

setTimeout(function () {
tinySliderCore.prototype.updateDotsStatus(obj);
if (obj.hasDots) { tinySliderCore.prototype.updateDotsStatus(obj); }
obj.animating = false;
}, obj.speed);
}
Expand Down Expand Up @@ -430,4 +438,3 @@
return tinySlider;
});


46 changes: 27 additions & 19 deletions src/js/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,18 @@
tinyFn.items = getItem (tinyFn.bp, tinyFn.vals, options.items);
tinyFn.speed = (tinyFn.slideByPage) ? options.speed * tinyFn.items : options.speed;
tinySliderCore.prototype.updateContainer(tinyFn);
tinySliderCore.prototype.updateDots(tinyFn);
tinySliderCore.prototype.updateDotsStatus(tinyFn);
if (tinyFn.hasDots) {
tinySliderCore.prototype.updateDots(tinyFn);
tinySliderCore.prototype.updateDotsStatus(tinyFn);
}
}, 100);
});

// on nav click
addEvent(this.next, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, 1); });
addEvent(this.prev, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, -1); });
if (this.hasNav) {
addEvent(this.next, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, 1); });
addEvent(this.prev, 'click', function () { tinySliderCore.prototype.onNavClick(tinyFn, -1); });
}

// on key down
if (this.keyboard) {
Expand All @@ -100,16 +104,18 @@
}

// on dot click
for (var i = 0; i < this.dots.length; i++) {
addEvent(this.dots[i], 'click', function (e) {
var index;
for (var i = 0; i < tinyFn.dots.length; i++) {
target = (e.currentTarget) ? e.currentTarget : e.srcElement;
if (tinyFn.dots[i] === target) { index = i; }
}
tinySliderCore.prototype.onDotClick(tinyFn, index);
});
};
if (this.hasDots) {
for (var i = 0; i < this.dots.length; i++) {
addEvent(this.dots[i], 'click', function (e) {
var index;
for (var i = 0; i < tinyFn.dots.length; i++) {
target = (e.currentTarget) ? e.currentTarget : e.srcElement;
if (tinyFn.dots[i] === target) { index = i; }
}
tinySliderCore.prototype.onDotClick(tinyFn, index);
});
}
}

// autoplay
if (this.autoplay) {
Expand Down Expand Up @@ -207,8 +213,10 @@
}

this.updateContainer(this);
this.updateDots(this);
this.updateDotsStatus(this);
if (this.hasDots) {
this.updateDots(this);
this.updateDotsStatus(this);
}
},

updateContainer: function (obj) {
Expand Down Expand Up @@ -276,7 +284,7 @@
}

setTimeout(function () {
tinySliderCore.prototype.updateDotsStatus(obj);
if (obj.hasDots) { tinySliderCore.prototype.updateDotsStatus(obj); }
obj.animating = false;
}, obj.speed);
}
Expand Down Expand Up @@ -309,7 +317,7 @@
obj.container.style.left = - (100 * obj.index / obj.items) + '%';

setTimeout(function () {
tinySliderCore.prototype.updateDotsStatus(obj);
if (obj.hasDots) { tinySliderCore.prototype.updateDotsStatus(obj); }
obj.animating = false;
}, obj.speed);
}
Expand Down Expand Up @@ -428,4 +436,4 @@
}

return tinySlider;
});
});

0 comments on commit dc82d6c

Please sign in to comment.