Skip to content

Commit

Permalink
v.1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
foo123 committed Dec 1, 2023
1 parent 25c9dd9 commit 65e2a9f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 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.0** (9 kB minified)
**version: 1.5.1** (9 kB minified)


[Live Demo](https://foo123.github.io/examples/touchtouch/)
Expand Down Expand Up @@ -42,6 +42,7 @@ slideshow.dispose(); // dispose the slideshow instance
* `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)
* `fitsize` max size for fit to take place (**default** `Infinity` disabled)
* `auto` boolean flag indicating that passed images are the hrefs of the gallery images themselves, instead of clickable elements (**default** `false`)


Expand Down
23 changes: 12 additions & 11 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.0
* @VERSION: 1.5.1
* @license: MIT License
*
* https://github.com/foo123/touchTouch
Expand Down Expand Up @@ -149,21 +149,21 @@ function loadImage(src, callback)
});
img.src = src;
}
function fit(img, scale)
function fit(img, scale, max)
{
if (!img || ('img' !== (img.tagName||'').toLowerCase())) return img;
var w = img.width,
h = img.height,
ww = scale*(window.innerWidth || document.documentElement.clientWidth),
wh = scale*(window.innerHeight || document.documentElement.clientHeight);
if (h * ww / w > wh)
ww = (window.innerWidth || document.documentElement.clientWidth),
wh = (window.innerHeight || document.documentElement.clientHeight);
if (h * ww > w * wh)
{
img.style.height = String(wh) + 'px';
img.style.height = String(scale*stdMath.min(max, wh)) + 'px';
img.style.width = 'auto';
}
else
{
img.style.width = String(ww) + 'px';
img.style.width = String(scale*stdMath.min(max, ww)) + 'px';
img.style.height = 'auto';
}
return img;
Expand Down Expand Up @@ -219,7 +219,7 @@ function touchTouch(items, options)
touchStart, touchMove, touchEnd, wheelTurn, keyPress,
prevClick, nextClick, itemClick, onResize,
showImage, preload, removeExtraHandlers, transform,
auto = false, fitscale = 0,
auto = false, fitscale = 0, fitsize = Infinity,
factor = 4, threshold = 0.08,
move_m = 15, move_d = 15,
index = 0, tX = 0, tY = 0, sX = 1;
Expand All @@ -234,11 +234,11 @@ function touchTouch(items, options)
loadImage(items[index].href, function() {
if (fitscale)
{
fit(this, fitscale);
fit(this, fitscale, fitsize);
if (!onResize)
{
addEvent(window, 'resize', onResize = debounce(function() {
placeholders.forEach(function(p) {fit(p.children[0], fitscale);});
placeholders.forEach(function(p) {fit(p.children[0], fitscale, fitsize);});
}, 100), {passive:true, capture:false});
}
}
Expand Down Expand Up @@ -290,6 +290,7 @@ function touchTouch(items, options)

auto = !!options.auto;
fitscale = options.fit;
fitsize = null != options.fitsize ? (+options.fitsize) : Infinity;
// undocumented options, for fine-tuning only if needed
if (null != options._factor) factor = +options._factor;
if (null != options._threshold) threshold = +options._threshold;
Expand Down Expand Up @@ -703,7 +704,7 @@ function touchTouch(items, options)
}
};
}
touchTouch.VERSION = '1.5.0';
touchTouch.VERSION = '1.5.1';
touchTouch.prototype = {
constructor: touchTouch,
dispose: noop,
Expand Down
Loading

0 comments on commit 65e2a9f

Please sign in to comment.