From 0f02b74092b5eb9d6645ecb5df094fa0a78d4cb7 Mon Sep 17 00:00:00 2001 From: justinkempton Date: Wed, 10 Dec 2014 10:09:54 -0800 Subject: [PATCH 1/3] added fadeOutInvisible * Added new option to fade out panels that are not visible * fadeOutInvisible : true, will add a class called hiddenPanel to panels not visible --- swipe.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/swipe.js b/swipe.js index 8b29717..cc3844b 100644 --- a/swipe.js +++ b/swipe.js @@ -4,6 +4,9 @@ * Brad Birdsall * Copyright 2013, MIT License * + * modified slightly (Justin Kempton) Docstoc 2014 + * added new option : fadeOutInvisible + * */ function Swipe(container, options) { @@ -107,11 +110,27 @@ function Swipe(container, options) { } + function fadeOutInvisible(to) { + if (options.fadeOutInvisible) { + ;(function() { + if (!slides[0] || !slides[0].classList) return + for (var x = slides.length; x--;) { + if (x === to) { + slides[x].classList.remove("hiddenPanel") + continue + } + slides[x].classList.add("hiddenPanel") + } + }()) + } + } + function slide(to, slideSpeed) { // do nothing if already on requested slide if (index == to) return; + if (browser.transitions) { var direction = Math.abs(index-to) / (index-to); // 1: backward, -1: forward @@ -147,7 +166,9 @@ function Swipe(container, options) { } index = to; - offloadFn(options.callback && options.callback(index, slides[index])); + + fadeOutInvisible(to) + offloadFn(options.callback && options.callback(index, slides[index], slides)); } function move(index, dist, speed) { @@ -395,7 +416,8 @@ function Swipe(container, options) { } - options.callback && options.callback(index, slides[index]); + fadeOutInvisible(index) + options.callback && options.callback(index, slides[index], slides); } else { From f93307fae0b661c1c9cf0933a9f0a4dd5d8491e1 Mon Sep 17 00:00:00 2001 From: justinkempton Date: Wed, 10 Dec 2014 10:11:48 -0800 Subject: [PATCH 2/3] added semi colons --- swipe.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/swipe.js b/swipe.js index cc3844b..6cf9a38 100644 --- a/swipe.js +++ b/swipe.js @@ -4,9 +4,6 @@ * Brad Birdsall * Copyright 2013, MIT License * - * modified slightly (Justin Kempton) Docstoc 2014 - * added new option : fadeOutInvisible - * */ function Swipe(container, options) { @@ -112,16 +109,16 @@ function Swipe(container, options) { function fadeOutInvisible(to) { if (options.fadeOutInvisible) { - ;(function() { + (function() { if (!slides[0] || !slides[0].classList) return for (var x = slides.length; x--;) { if (x === to) { - slides[x].classList.remove("hiddenPanel") - continue + slides[x].classList.remove("hiddenPanel"); + continue; } - slides[x].classList.add("hiddenPanel") + slides[x].classList.add("hiddenPanel"); } - }()) + }()); } } @@ -167,7 +164,8 @@ function Swipe(container, options) { index = to; - fadeOutInvisible(to) + fadeOutInvisible(to); + offloadFn(options.callback && options.callback(index, slides[index], slides)); } @@ -416,7 +414,8 @@ function Swipe(container, options) { } - fadeOutInvisible(index) + fadeOutInvisible(index); + options.callback && options.callback(index, slides[index], slides); } else { From 3335ca7398d919615f86a95415438e6e921e8d3b Mon Sep 17 00:00:00 2001 From: justinkempton Date: Wed, 10 Dec 2014 10:16:49 -0800 Subject: [PATCH 3/3] added checking for classList --- swipe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swipe.js b/swipe.js index 6cf9a38..f6459d1 100644 --- a/swipe.js +++ b/swipe.js @@ -108,7 +108,7 @@ function Swipe(container, options) { } function fadeOutInvisible(to) { - if (options.fadeOutInvisible) { + if (options.fadeOutInvisible && slides[0] && slides[0].classList) { (function() { if (!slides[0] || !slides[0].classList) return for (var x = slides.length; x--;) {