Skip to content

Commit

Permalink
update show/hide element functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlanyuan committed Aug 28, 2018
1 parent b8dace9 commit 511ec89
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 120 deletions.
2 changes: 1 addition & 1 deletion dist/min/tiny-slider.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sourcemaps/tiny-slider.js.map

Large diffs are not rendered by default.

60 changes: 24 additions & 36 deletions dist/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,11 @@ function arrayFromNodeList (nl) {
}

function hideElement(el, forceHide) {
if (forceHide) {
if (el.style.display !== 'none') { el.style.display = 'none'; }
} else if (!hasAttr(el, 'hidden')) {
setAttrs(el, {'hidden': ''});
}
if (el.style.display !== 'none') { el.style.display = 'none'; }
}

function showElement(el, forceHide) {
if (forceHide) {
if (el.style.display === 'none') { el.style.display = ''; }
} else if (hasAttr(el, 'hidden')) {
removeAttrs(el, 'hidden');
}
if (el.style.display === 'none') { el.style.display = ''; }
}

function isVisible(el) {
Expand Down Expand Up @@ -1406,7 +1398,7 @@ var tns = function(options) {
// generated nav
} else {
var navHtml = '',
hiddenStr = navAsThumbnails ? '' : 'hidden';
hiddenStr = navAsThumbnails ? '' : 'style="display:none"';
for (var i = 0; i < slideCount; i++) {
// hide nav items by default
navHtml += '<button data-nav="' + i +'" tabindex="-1" aria-selected="false" aria-controls="' + slideItems[initIndex + i].id + '" ' + hiddenStr + ' type="button"></button>';
Expand Down Expand Up @@ -1717,26 +1709,26 @@ var tns = function(options) {
if (controls !== controlsTem) {
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
showElement(prevButton, options.prevButton);
showElement(nextButton, options.nextButton);
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
} else {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
hideElement(prevButton, options.prevButton);
hideElement(nextButton, options.nextButton);
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}
if (nav !== navTem) {
if (nav) {
showElement(navContainer, options.navContainer);
showElement(navContainer);
updateNavVisibility();
} else {
hideElement(navContainer, options.navContainer);
hideElement(navContainer);
}
}
if (touch !== touchTem) {
Expand All @@ -1751,10 +1743,10 @@ var tns = function(options) {
}
if (autoplay !== autoplayTem) {
if (autoplay) {
if (autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { showElement(autoplayButton); }
if (!animating && !autoplayUserPaused) { startAutoplay(); }
} else {
if (autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { hideElement(autoplayButton); }
if (animating) { stopAutoplay(); }
}
}
Expand Down Expand Up @@ -1907,27 +1899,27 @@ var tns = function(options) {
})();

function disableUI () {
if (!autoplay && autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer, options.navContainer); }
if (!autoplay && autoplayButton) { hideElement(autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer); }
if (!controls) {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
if (prevButton) { hideElement(prevButton, options.prevButton); }
if (nextButton) { hideElement(nextButton, options.nextButton); }
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}

function enableUI () {
if (autoplay && autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (nav && navContainer) { showElement(navContainer, options.navContainer); }
if (autoplay && autoplayButton) { showElement(autoplayButton); }
if (nav && navContainer) { showElement(navContainer); }
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
if (prevButton) { showElement(prevButton, options.prevButton); }
if (nextButton) { showElement(nextButton, options.nextButton); }
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
}
}
Expand Down Expand Up @@ -2982,11 +2974,7 @@ var tns = function(options) {

if (visibleNavIndexes !== visibleNavIndexesCached) {
forEachNodeList(navItems, function(el, i) {
if (visibleNavIndexes.indexOf(i) < 0) {
hideElement(el);
} else {
showElement(el);
}
visibleNavIndexes.indexOf(i) < 0 ? hideElement(el) : showElement(el);
});

// cache visible nav indexes
Expand Down
9 changes: 1 addition & 8 deletions src/helpers/hideElement.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { hasAttr } from './hasAttr.js';
import { setAttrs } from './setAttrs.js';

export function hideElement(el, forceHide) {
if (forceHide) {
if (el.style.display !== 'none') { el.style.display = 'none'; }
} else if (!hasAttr(el, 'hidden')) {
setAttrs(el, {'hidden': ''});
}
if (el.style.display !== 'none') { el.style.display = 'none'; }
}
9 changes: 1 addition & 8 deletions src/helpers/showElement.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import { hasAttr } from './hasAttr.js';
import { removeAttrs } from './removeAttrs.js';

export function showElement(el, forceHide) {
if (forceHide) {
if (el.style.display === 'none') { el.style.display = ''; }
} else if (hasAttr(el, 'hidden')) {
removeAttrs(el, 'hidden');
}
if (el.style.display === 'none') { el.style.display = ''; }
}
48 changes: 22 additions & 26 deletions src/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export var tns = function(options) {
// generated nav
} else {
var navHtml = '',
hiddenStr = navAsThumbnails ? '' : 'hidden';
hiddenStr = navAsThumbnails ? '' : 'style="display:none"';
for (var i = 0; i < slideCount; i++) {
// hide nav items by default
navHtml += '<button data-nav="' + i +'" tabindex="-1" aria-selected="false" aria-controls="' + slideItems[initIndex + i].id + '" ' + hiddenStr + ' type="button"></button>';
Expand Down Expand Up @@ -1279,26 +1279,26 @@ export var tns = function(options) {
if (controls !== controlsTem) {
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
showElement(prevButton, options.prevButton);
showElement(nextButton, options.nextButton);
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
} else {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
hideElement(prevButton, options.prevButton);
hideElement(nextButton, options.nextButton);
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}
if (nav !== navTem) {
if (nav) {
showElement(navContainer, options.navContainer);
showElement(navContainer);
updateNavVisibility();
} else {
hideElement(navContainer, options.navContainer);
hideElement(navContainer);
}
}
if (touch !== touchTem) {
Expand All @@ -1313,10 +1313,10 @@ export var tns = function(options) {
}
if (autoplay !== autoplayTem) {
if (autoplay) {
if (autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { showElement(autoplayButton); }
if (!animating && !autoplayUserPaused) { startAutoplay(); }
} else {
if (autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { hideElement(autoplayButton); }
if (animating) { stopAutoplay(); }
}
}
Expand Down Expand Up @@ -1469,27 +1469,27 @@ export var tns = function(options) {
})();

function disableUI () {
if (!autoplay && autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer, options.navContainer); }
if (!autoplay && autoplayButton) { hideElement(autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer); }
if (!controls) {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
if (prevButton) { hideElement(prevButton, options.prevButton); }
if (nextButton) { hideElement(nextButton, options.nextButton); }
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}

function enableUI () {
if (autoplay && autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (nav && navContainer) { showElement(navContainer, options.navContainer); }
if (autoplay && autoplayButton) { showElement(autoplayButton); }
if (nav && navContainer) { showElement(navContainer); }
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
if (prevButton) { showElement(prevButton, options.prevButton); }
if (nextButton) { showElement(nextButton, options.nextButton); }
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
}
}
Expand Down Expand Up @@ -2544,11 +2544,7 @@ export var tns = function(options) {

if (visibleNavIndexes !== visibleNavIndexesCached) {
forEachNodeList(navItems, function(el, i) {
if (visibleNavIndexes.indexOf(i) < 0) {
hideElement(el);
} else {
showElement(el);
}
visibleNavIndexes.indexOf(i) < 0 ? hideElement(el) : showElement(el);
});

// cache visible nav indexes
Expand Down
48 changes: 22 additions & 26 deletions src/tiny-slider.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ export var tns = function(options) {
// generated nav
} else {
var navHtml = '',
hiddenStr = navAsThumbnails ? '' : 'hidden';
hiddenStr = navAsThumbnails ? '' : 'style="display:none"';
for (var i = 0; i < slideCount; i++) {
// hide nav items by default
navHtml += '<button data-nav="' + i +'" tabindex="-1" aria-selected="false" aria-controls="' + slideItems[initIndex + i].id + '" ' + hiddenStr + ' type="button"></button>';
Expand Down Expand Up @@ -1279,26 +1279,26 @@ export var tns = function(options) {
if (controls !== controlsTem) {
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
showElement(prevButton, options.prevButton);
showElement(nextButton, options.nextButton);
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
} else {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
hideElement(prevButton, options.prevButton);
hideElement(nextButton, options.nextButton);
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}
if (nav !== navTem) {
if (nav) {
showElement(navContainer, options.navContainer);
showElement(navContainer);
updateNavVisibility();
} else {
hideElement(navContainer, options.navContainer);
hideElement(navContainer);
}
}
if (touch !== touchTem) {
Expand All @@ -1313,10 +1313,10 @@ export var tns = function(options) {
}
if (autoplay !== autoplayTem) {
if (autoplay) {
if (autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { showElement(autoplayButton); }
if (!animating && !autoplayUserPaused) { startAutoplay(); }
} else {
if (autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (autoplayButton) { hideElement(autoplayButton); }
if (animating) { stopAutoplay(); }
}
}
Expand Down Expand Up @@ -1469,27 +1469,27 @@ export var tns = function(options) {
})();

function disableUI () {
if (!autoplay && autoplayButton) { hideElement(autoplayButton, options.autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer, options.navContainer); }
if (!autoplay && autoplayButton) { hideElement(autoplayButton); }
if (!nav && navContainer) { hideElement(navContainer); }
if (!controls) {
if (controlsContainer) {
hideElement(controlsContainer, options.controlsContainer);
hideElement(controlsContainer);
} else {
if (prevButton) { hideElement(prevButton, options.prevButton); }
if (nextButton) { hideElement(nextButton, options.nextButton); }
if (prevButton) { hideElement(prevButton); }
if (nextButton) { hideElement(nextButton); }
}
}
}

function enableUI () {
if (autoplay && autoplayButton) { showElement(autoplayButton, options.autoplayButton); }
if (nav && navContainer) { showElement(navContainer, options.navContainer); }
if (autoplay && autoplayButton) { showElement(autoplayButton); }
if (nav && navContainer) { showElement(navContainer); }
if (controls) {
if (controlsContainer) {
showElement(controlsContainer, options.controlsContainer);
showElement(controlsContainer);
} else {
if (prevButton) { showElement(prevButton, options.prevButton); }
if (nextButton) { showElement(nextButton, options.nextButton); }
if (prevButton) { showElement(prevButton); }
if (nextButton) { showElement(nextButton); }
}
}
}
Expand Down Expand Up @@ -2544,11 +2544,7 @@ export var tns = function(options) {

if (visibleNavIndexes !== visibleNavIndexesCached) {
forEachNodeList(navItems, function(el, i) {
if (visibleNavIndexes.indexOf(i) < 0) {
hideElement(el);
} else {
showElement(el);
}
visibleNavIndexes.indexOf(i) < 0 ? hideElement(el) : showElement(el);
});

// cache visible nav indexes
Expand Down
Loading

0 comments on commit 511ec89

Please sign in to comment.