Skip to content

Commit

Permalink
v.1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
foo123 committed Dec 30, 2023
1 parent 65e2a9f commit 4b95e04
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Enhanced Vanilla JavaScript version of [touchTouch Optimized Mobile Gallery](htt
![touchTouch Optimized Mobile Gallery](/touchtouch.jpg)


**version: 1.5.1** (9 kB minified)
**version: 1.5.2** (9.8 kB minified)


[Live Demo](https://foo123.github.io/examples/touchtouch/)
Expand Down Expand Up @@ -39,6 +39,7 @@ slideshow.dispose(); // dispose the slideshow instance
* `prevArrow` custom css class for previous button
* `nextArrow` custom css class for next button
* `showCaption` boolean flag to show image numbering (**default** `false`)
* `customCaption` boolean flag to take caption from image title (**default** `false`)
* `caption` custom css class for caption
* `swipe` duration in `ms` for swipe animation (**default** `400`)
* `fit` scale factor in `[0, 1]` (relative to viewport dimensions) to fit image dimensions to current viewport (**default** `0` disabled)
Expand Down
1 change: 1 addition & 0 deletions src/touchTouch.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* https://github.com/foo123/touchTouch */
.tt-gallery-overlay {
position: fixed;
display: none;
Expand Down
26 changes: 19 additions & 7 deletions src/touchTouch.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* touchTouch.js
* Enhanced Vanilla JavaScript version of https://github.com/tutorialzine/touchTouch Optimized Mobile Gallery by Martin Angelov
* @VERSION: 1.5.1
* @VERSION: 1.5.2
* @license: MIT License
*
* https://github.com/foo123/touchTouch
Expand Down Expand Up @@ -215,10 +215,10 @@ function touchTouch(items, options)
if (!(self instanceof touchTouch)) return new touchTouch(items, options);

/* Private variables */
var slider, prevArrow, nextArrow, caption, placeholders,
var slider, prevArrow, nextArrow, caption, customCaption = false, placeholders,
touchStart, touchMove, touchEnd, wheelTurn, keyPress,
prevClick, nextClick, itemClick, onResize,
showImage, preload, removeExtraHandlers, transform,
showImage, preload, removeExtraHandlers, showCaption, transform,
auto = false, fitscale = 0, fitsize = Infinity,
factor = 4, threshold = 0.08,
move_m = 15, move_d = 15,
Expand Down Expand Up @@ -248,6 +248,17 @@ function touchTouch(items, options)
});
}
};
showCaption = function(index) {
if (caption && items && items.length)
{
var item = items[index], text = String(index + 1) + '/' + String(items.length);
if (customCaption)
{
text = (item.hasAttribute ? (item.hasAttribute('data-caption') ? item.getAttribute('data-caption') : (item.hasAttribute('title') ? item.getAttribute('title') : text)) : items[index].caption) || text;
}
caption.textContent = text;
}
};
preload = function preload(index) {
if (index < 0 || index >= items.length) return false;
setTimeout(function() {showImage(index);}, 200);
Expand Down Expand Up @@ -316,6 +327,7 @@ function touchTouch(items, options)
{
caption = addClass(document.createElement('div'), 'tt-caption');
if (options.caption) addClass(caption, options.caption);
customCaption = !!options.customCaption;
}

placeholders = items.map(function(item) {
Expand Down Expand Up @@ -602,7 +614,7 @@ function touchTouch(items, options)
if (items.length) transform(placeholders[index].children[0]);
// Move the slider to the correct image
offsetSlider(slider, index);
if (caption && items.length) caption.textContent = String(index + 1) + '/' + String(items.length);
showCaption(index);
showOverlay(self);
addEvent(window, 'keydown', keyPress, {passive:false, capture:false});
showImage(index);
Expand Down Expand Up @@ -634,7 +646,7 @@ function touchTouch(items, options)
++index;
transform(placeholders[index].children[0]);
offsetSlider(slider, index);
if (caption && items.length) caption.textContent = String(index + 1) + '/' + String(items.length);
showCaption(index);
preload(index + 1);
}
else
Expand All @@ -655,7 +667,7 @@ function touchTouch(items, options)
--index;
transform(placeholders[index].children[0]);
offsetSlider(slider, index);
if (caption && items.length) caption.textContent = String(index + 1) + '/' + String(items.length);
showCaption(index);
preload(index - 1);
}
else
Expand Down Expand Up @@ -704,7 +716,7 @@ function touchTouch(items, options)
}
};
}
touchTouch.VERSION = '1.5.1';
touchTouch.VERSION = '1.5.2';
touchTouch.prototype = {
constructor: touchTouch,
dispose: noop,
Expand Down
1 change: 1 addition & 0 deletions src/touchTouch.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4b95e04

Please sign in to comment.