vendor/assets/javascripts/fotorama.js in fotoramajs-4.4.8 vs vendor/assets/javascripts/fotorama.js in fotoramajs-4.4.9

- old
+ new

@@ -1,7 +1,7 @@ /*! - * Fotorama 4.4.8 | http://fotorama.io/license/ + * Fotorama 4.4.9 | http://fotorama.io/license/ */ (function (window, document, location, $, undefined) { "use strict"; var _fotoramaClass = 'fotorama', _fullscreenClass = 'fullscreen', @@ -14,16 +14,16 @@ wrapSlideClass = wrapClass + '--slide', wrapNoControlsClass = wrapClass + '--no-controls', wrapNoShadowsClass = wrapClass + '--no-shadows', wrapPanYClass = wrapClass + '--pan-y', wrapRtlClass = wrapClass + '--rtl', + wrapOnlyActiveClass = wrapClass + '--only-active', stageClass = _fotoramaClass + '__stage', stageFrameClass = stageClass + '__frame', stageFrameVideoClass = stageFrameClass + '--video', stageShaftClass = stageClass + '__shaft', - stageOnlyActiveClass = stageClass + '--only-active', grabClass = _fotoramaClass + '__grab', pointerClass = _fotoramaClass + '__pointer', arrClass = _fotoramaClass + '__arr', @@ -1267,14 +1267,15 @@ (_options.onStart || noop).call(this, e); }, onMove: _options.onMove || noop, onTouchEnd: _options.onTouchEnd || noop, onEnd: function (result) { - if (result.moved || _options.tail.checked) return; + //console.log('smartClick → result.moved', result.moved); + if (result.moved) return; fn.call(this, startEvent); } - }), _options.tail); + }), {noMove: true}); }); } function div (classes, child) { return '<div class="' + classes + '">' + (child || '') + '</div>'; @@ -1341,12 +1342,16 @@ function getDirectionSign (forward) { return forward ? '>' : '<'; } function slide ($el, options) { - var elPos = Math.round(options.pos), - onEndFn = options.onEnd || noop; + var elData = $el.data(), + elPos = Math.round(options.pos), + onEndFn = function () { + elData.sliding = false; + (options.onEnd || noop)(); + }; if (typeof options.overPos !== 'undefined' && options.overPos !== options.pos) { elPos = options.overPos; onEndFn = function () { slide($el, $.extend({}, options, {overPos: options.pos, time: Math.max(TRANSITION_DURATION, options.time / 2)})) @@ -1355,10 +1360,12 @@ //console.time('var translate = $.extend'); var translate = $.extend(getTranslate(elPos, options._001), options.width && {width: options.width}); //console.timeEnd('var translate = $.extend'); + elData.sliding = true; + if (CSS3) { $el.css($.extend(getDuration(options.time), translate)); if (options.time > 10) { //console.time('afterTransition'); afterTransition($el, 'transform', onEndFn, options.time); @@ -1418,10 +1425,11 @@ function extendEvent (e) { var touch = (e.touches || [])[0] || e; e._x = touch.pageX; e._y = touch.clientY; + e._now = $.now(); } function touch ($el, options) { var el = $el[0], tail = {}, @@ -1429,15 +1437,17 @@ startEvent, $target, controlTouch, touchFLAG, targetIsSelectFLAG, - targetIsLinkFlag; + targetIsLinkFlag, + tolerance, + moved; function onStart (e) { $target = $(e.target); - tail.checked = targetIsSelectFLAG = targetIsLinkFlag = false; + tail.checked = targetIsSelectFLAG = targetIsLinkFlag = moved = false; if (touchEnabledFLAG || tail.flow || (e.touches && e.touches.length > 1) || e.which > 1 @@ -1445,10 +1455,12 @@ || (targetIsSelectFLAG = options.select && $target.is(options.select, el))) return targetIsSelectFLAG; touchFLAG = e.type === 'touchstart'; targetIsLinkFlag = $target.is('a, a *', el); + tolerance = (tail.noMove || tail.noSwipe) ? 16 : !tail.snap ? 4 : 0; + extendEvent(e); startEvent = lastEvent = e; moveEventType = e.type.replace(/down|start/, 'move').replace(/Down/, 'Move'); controlTouch = tail.control; @@ -1486,10 +1498,14 @@ //console.log('onMove e.preventDefault'); stopEvent(e); (options.onMove || noop).call(el, e, {touch: touchFLAG}); } + if (!moved && Math.sqrt(Math.pow(xDiff, 2) + Math.pow(yDiff, 2)) > tolerance) { + moved = true; + } + tail.checked = tail.checked || xWin || yWin; } function onEnd (e) { ////console.time('touch.js onEnd'); @@ -1510,11 +1526,12 @@ preventEvent = true; clearTimeout(preventEventTimeout); preventEventTimeout = setTimeout(function () { preventEvent = false; }, 1000); - (options.onEnd || noop).call(el, {moved: tail.checked, $target: $target, control: controlTouch, touch: touchFLAG, startEvent: startEvent, aborted: !e || e.type === 'MSPointerCancel'}); + + (options.onEnd || noop).call(el, {moved: moved, $target: $target, control: controlTouch, touch: touchFLAG, startEvent: startEvent, aborted: !e || e.type === 'MSPointerCancel'}); ////console.timeEnd('touch.js onEnd'); } function onOtherStart () { if (tail.flow) return; @@ -1575,52 +1592,52 @@ min, max, snap, slowFLAG, controlFLAG, - movedFLAG; + moved, + tracked; function startTracking (e) { + tracked = true; startCoo = coo = e._x; - startTime = $.now(); + startTime = e._now; moveTrack = [ [startTime, startCoo] ]; startElPos = moveElPos = tail.noMove ? 0 : stop($el, (options.getPos || noop)(), options._001); - // startTime - endTime < TOUCH_TIMEOUT * 3 && e.preventDefault(); // double tap - (options.onStart || noop).call(el, e); } function onStart (e, result) { - min = elData.min; - max = elData.max; - snap = elData.snap; + min = tail.min; + max = tail.max; + snap = tail.snap; slowFLAG = e.altKey; - movedFLAG = false; + tracked = moved = false; controlFLAG = result.control; - if (!controlFLAG) { + if (!controlFLAG && !elData.sliding) { startTracking(e); } } function onMove (e, result) { - if (controlFLAG) { + if (!tracked) { controlFLAG = false; startTracking(e); } if (!tail.noSwipe) { coo = e._x; - moveTrack.push([$.now(), coo]); + moveTrack.push([e._now, coo]); moveElPos = startElPos - (startCoo - coo); edge = findShadowEdge(moveElPos, min, max); @@ -1630,12 +1647,12 @@ moveElPos = edgeResistance(moveElPos, max); } if (!tail.noMove) { $el.css(getTranslate(moveElPos, options._001)); - if (!movedFLAG) { - movedFLAG = true; + if (!moved) { + moved = true; // only for mouse result.touch || MS_POINTER || $el.addClass(grabbingClass); } (options.onMove || noop).call(el, e, {pos: moveElPos, edge: edge}); @@ -1645,13 +1662,17 @@ function onEnd (result) { ////console.time('moveontouch.js onEnd'); if (controlFLAG) return; + if (!tracked) { + startTracking(result.startEvent); + } + result.touch || MS_POINTER || $el.removeClass(grabbingClass); - endTime = new Date().getTime(); + endTime = $.now(); var _backTimeIdeal = endTime - TOUCH_TIMEOUT, _backTime, _timeDiff, _timeDiffLast, @@ -1710,21 +1731,19 @@ } } time *= slowFLAG ? 10 : 1; - (options.onEnd || noop).call(el, $.extend(result, {pos: moveElPos, newPos: newPos, overPos: overPos, time: time, moved: longTouchFLAG ? snap : Math.abs(moveElPos - startElPos) > (snap ? 0 : 3)})); - ////console.timeEnd('moveontouch.js onEnd'); + (options.onEnd || noop).call(el, $.extend(result, {moved: result.moved || longTouchFLAG && snap, pos: moveElPos, newPos: newPos, overPos: overPos, time: time})); } tail = $.extend(touch(options.$wrap, { onStart: onStart, onMove: onMove, onTouchEnd: options.onTouchEnd, onEnd: onEnd, - select: options.select, - control: options.control + select: options.select }), tail); return tail; } function wheel ($el, options) { @@ -2127,19 +2146,19 @@ function getNextIndex (index) { return index < size - 1 || o_loop ? index + 1 : false; } function setStageShaftMinmaxAndSnap () { - stageShaftData.min = o_loop ? -Infinity : -getPosByIndex(size - 1, measures.w, opts.margin, repositionIndex); - stageShaftData.max = o_loop ? Infinity : -getPosByIndex(0, measures.w, opts.margin, repositionIndex); - stageShaftData.snap = measures.w + opts.margin; + stageShaftTouchTail.min = o_loop ? -Infinity : -getPosByIndex(size - 1, measures.w, opts.margin, repositionIndex); + stageShaftTouchTail.max = o_loop ? Infinity : -getPosByIndex(0, measures.w, opts.margin, repositionIndex); + stageShaftTouchTail.snap = measures.w + opts.margin; } function setNavShaftMinmax () { - navShaftData.min = Math.min(0, measures.W - $navShaft.width()); - navShaftData.max = 0; - $navShaft.toggleClass(grabClass, !(navShaftTouchTail.noMove = navShaftData.min === navShaftData.max)); + navShaftTouchTail.min = Math.min(0, measures.W - $navShaft.width()); + navShaftTouchTail.max = 0; + $navShaft.toggleClass(grabClass, !(navShaftTouchTail.noMove = navShaftTouchTail.min === navShaftTouchTail.max)); } function eachIndex (indexes, type, fn) { if (typeof indexes === 'number') { indexes = new Array(indexes); @@ -2518,14 +2537,14 @@ } function slideNavShaft (options) { var $guessNavFrame = data[options.guessIndex][navFrameKey]; if ($guessNavFrame) { - var overflowFLAG = navShaftData.min !== navShaftData.max, + var overflowFLAG = navShaftTouchTail.min !== navShaftTouchTail.max, activeNavFrameBounds = overflowFLAG && getNavFrameBounds(that.activeFrame[navFrameKey]), l = overflowFLAG && (options.keep && slideNavShaft.l ? slideNavShaft.l : minMaxLimit((options.coo || measures.w / 2) - getNavFrameBounds($guessNavFrame).c, activeNavFrameBounds.min, activeNavFrameBounds.max)), - pos = overflowFLAG && minMaxLimit(l, navShaftData.min, navShaftData.max), + pos = overflowFLAG && minMaxLimit(l, navShaftTouchTail.min, navShaftTouchTail.max), time = options.time * .9; slide($navShaft, { time: time, pos: pos || 0, @@ -2534,11 +2553,11 @@ } }); //if (time) thumbsDraw(pos); - setShadow($nav, findShadowEdge(pos, navShaftData.min, navShaftData.max)); + setShadow($nav, findShadowEdge(pos, navShaftTouchTail.min, navShaftTouchTail.max)); slideNavShaft.l = l; } } function navUpdate () { @@ -2734,11 +2753,11 @@ ////console.timeEnd('stageFramePosition'); ////console.time('updateTouchTails'); updateTouchTails('go', true); ////console.timeEnd('updateTouchTails'); ////console.time('triggerEvent'); - triggerEvent('show', { + options.reset || triggerEvent('show', { user: options.user, time: time }); ////console.timeEnd('triggerEvent'); //}, 0); @@ -2750,11 +2769,11 @@ updateFotoramaState(); loadImg(activeIndexes, 'stage'); skipReposition || stageShaftReposition(true); - triggerEvent('showend', { + options.reset || triggerEvent('showend', { user: options.user }); updateTouchTails('go', false); stageWheelUpdate(); @@ -2910,11 +2929,13 @@ height = measures.height, ratio = measures.ratio, windowHeight = $WINDOW.height() - (o_nav ? $nav.height() : 0); if (measureIsValid(width)) { - $wrap.css({width: width, minWidth: measures.minwidth, maxWidth: measures.maxwidth}); + $wrap + .addClass(wrapOnlyActiveClass) + .css({width: width, minWidth: measures.minwidth, maxWidth: measures.maxwidth}); width = measures.W = measures.w = $wrap.width(); if (opts.glimpse) { // Glimpse @@ -2935,14 +2956,13 @@ height = measures.h = Math.round(minMaxLimit(height, numberFromPercent(measures.minheight) / 100 * windowHeight || numberFromMeasure(measures.minheight), numberFromPercent(measures.maxheight) / 100 * windowHeight || numberFromMeasure(measures.maxheight))); stageShaftReposition(); $stage - .addClass(stageOnlyActiveClass) .stop() .animate({width: width, height: height}, time, function () { - $stage.removeClass(stageOnlyActiveClass); + $wrap.removeClass(wrapOnlyActiveClass); }); if (o_nav) { $nav .stop() @@ -3115,13 +3135,13 @@ } else if (!result.aborted) { onStageTap(result.startEvent, toggleControlsFLAG); } ////console.timeEnd('stageShaftTouchTail.onEnd'); }, - getPos: function () { - return -getPosByIndex(dirtyIndex, measures.w, opts.margin, repositionIndex); - }, +// getPos: function () { +// return -getPosByIndex(dirtyIndex, measures.w, opts.margin, repositionIndex); +// }, _001: true, timeLow: 1, timeHigh: 1, friction: 2, select: '.' + selectClass + ', .' + selectClass + ' *', @@ -3151,11 +3171,11 @@ pos: result.newPos, overPos: result.overPos, onEnd: onEnd }); thumbsDraw(result.newPos); - o_shadows && setShadow($nav, findShadowEdge(result.newPos, navShaftData.min, navShaftData.max)); + o_shadows && setShadow($nav, findShadowEdge(result.newPos, navShaftTouchTail.min, navShaftTouchTail.max)); } else { onEnd(); } }, timeLow: .5, @@ -3178,13 +3198,13 @@ onEnd: function (e, direction) { ////console.log('wheel $nav onEnd', direction); onTouchStart(); onTouchEnd(); var newPos = stop($navShaft) + direction * .25; - $navShaft.css(getTranslate(minMaxLimit(newPos, navShaftData.min, navShaftData.max))); - o_shadows && setShadow($nav, findShadowEdge(newPos, navShaftData.min, navShaftData.max)); - navWheelTail.prevent = {'<': newPos >= navShaftData.max, '>': newPos <= navShaftData.min}; + $navShaft.css(getTranslate(minMaxLimit(newPos, navShaftTouchTail.min, navShaftTouchTail.max))); + o_shadows && setShadow($nav, findShadowEdge(newPos, navShaftTouchTail.min, navShaftTouchTail.max)); + navWheelTail.prevent = {'<': newPos >= navShaftTouchTail.max, '>': newPos <= navShaftTouchTail.min}; clearTimeout(navWheelTail.t); navWheelTail.t = setTimeout(function () { thumbsDraw(newPos, true) }, TOUCH_TIMEOUT); thumbsDraw(newPos); @@ -3216,12 +3236,11 @@ }, { onStart: function () { onTouchStart(); stageShaftTouchTail.control = true; }, - onTouchEnd: onTouchEnd, - tail: stageShaftTouchTail + onTouchEnd: onTouchEnd }); function reset () { setData(); setOptions(); @@ -3235,25 +3254,25 @@ } activeIndex = repositionIndex = dirtyIndex = lastActiveIndex = startIndex = edgeIndex(startIndex) || 0;/*(o_rtl ? size - 1 : 0)*/; } if (size) { - ////console.log('activeIndex', activeIndex); if (changeToRtl()) return; - ////console.log('No changeToRtl, activeIndex is', activeIndex); if ($videoPlaying) { unloadVideo($videoPlaying, true); } activeIndexes = []; detachFrames(STAGE_FRAME_KEY); - that.show({index: activeIndex, time: 0}); + that.show({index: activeIndex, time: 0, reset: reset.ok}); that.resize(); } else { that.destroy(); } + + reset.ok = true; } function changeToRtl () { ////console.log('changeToRtl'); if (!changeToRtl.f === o_rtl) {