first commit
This commit is contained in:
1043
web/common/static/photoswipe/js/core.js
Normal file
1043
web/common/static/photoswipe/js/core.js
Normal file
File diff suppressed because it is too large
Load Diff
170
web/common/static/photoswipe/js/desktop-zoom.js
Normal file
170
web/common/static/photoswipe/js/desktop-zoom.js
Normal file
@@ -0,0 +1,170 @@
|
||||
/**
|
||||
*
|
||||
* desktop-zoom.js:
|
||||
*
|
||||
* - Binds mousewheel event for paning zoomed image.
|
||||
* - Manages "dragging", "zoomed-in", "zoom-out" classes.
|
||||
* (which are used for cursors and zoom icon)
|
||||
* - Adds toggleDesktopZoom function.
|
||||
*
|
||||
*/
|
||||
|
||||
var _wheelDelta;
|
||||
|
||||
_registerModule('DesktopZoom', {
|
||||
|
||||
publicMethods: {
|
||||
|
||||
initDesktopZoom: function() {
|
||||
|
||||
if(_oldIE) {
|
||||
// no zoom for old IE (<=8)
|
||||
return;
|
||||
}
|
||||
|
||||
if(_likelyTouchDevice) {
|
||||
// if detected hardware touch support, we wait until mouse is used,
|
||||
// and only then apply desktop-zoom features
|
||||
_listen('mouseUsed', function() {
|
||||
self.setupDesktopZoom();
|
||||
});
|
||||
} else {
|
||||
self.setupDesktopZoom(true);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
setupDesktopZoom: function(onInit) {
|
||||
|
||||
_wheelDelta = {};
|
||||
|
||||
var events = 'wheel mousewheel DOMMouseScroll';
|
||||
|
||||
_listen('bindEvents', function() {
|
||||
framework.bind(template, events, self.handleMouseWheel);
|
||||
});
|
||||
|
||||
_listen('unbindEvents', function() {
|
||||
if(_wheelDelta) {
|
||||
framework.unbind(template, events, self.handleMouseWheel);
|
||||
}
|
||||
});
|
||||
|
||||
self.mouseZoomedIn = false;
|
||||
|
||||
var hasDraggingClass,
|
||||
updateZoomable = function() {
|
||||
if(self.mouseZoomedIn) {
|
||||
framework.removeClass(template, 'pswp--zoomed-in');
|
||||
self.mouseZoomedIn = false;
|
||||
}
|
||||
if(_currZoomLevel < 1) {
|
||||
framework.addClass(template, 'pswp--zoom-allowed');
|
||||
} else {
|
||||
framework.removeClass(template, 'pswp--zoom-allowed');
|
||||
}
|
||||
removeDraggingClass();
|
||||
},
|
||||
removeDraggingClass = function() {
|
||||
if(hasDraggingClass) {
|
||||
framework.removeClass(template, 'pswp--dragging');
|
||||
hasDraggingClass = false;
|
||||
}
|
||||
};
|
||||
|
||||
_listen('resize' , updateZoomable);
|
||||
_listen('afterChange' , updateZoomable);
|
||||
_listen('pointerDown', function() {
|
||||
if(self.mouseZoomedIn) {
|
||||
hasDraggingClass = true;
|
||||
framework.addClass(template, 'pswp--dragging');
|
||||
}
|
||||
});
|
||||
_listen('pointerUp', removeDraggingClass);
|
||||
|
||||
if(!onInit) {
|
||||
updateZoomable();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
handleMouseWheel: function(e) {
|
||||
|
||||
if(_currZoomLevel <= self.currItem.fitRatio) {
|
||||
if( _options.modal ) {
|
||||
|
||||
if (!_options.closeOnScroll || _numAnimations || _isDragging) {
|
||||
e.preventDefault();
|
||||
} else if(_transformKey && Math.abs(e.deltaY) > 2) {
|
||||
// close PhotoSwipe
|
||||
// if browser supports transforms & scroll changed enough
|
||||
_closedByScroll = true;
|
||||
self.close();
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// allow just one event to fire
|
||||
e.stopPropagation();
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Events/wheel
|
||||
_wheelDelta.x = 0;
|
||||
|
||||
if('deltaX' in e) {
|
||||
if(e.deltaMode === 1 /* DOM_DELTA_LINE */) {
|
||||
// 18 - average line height
|
||||
_wheelDelta.x = e.deltaX * 18;
|
||||
_wheelDelta.y = e.deltaY * 18;
|
||||
} else {
|
||||
_wheelDelta.x = e.deltaX;
|
||||
_wheelDelta.y = e.deltaY;
|
||||
}
|
||||
} else if('wheelDelta' in e) {
|
||||
if(e.wheelDeltaX) {
|
||||
_wheelDelta.x = -0.16 * e.wheelDeltaX;
|
||||
}
|
||||
if(e.wheelDeltaY) {
|
||||
_wheelDelta.y = -0.16 * e.wheelDeltaY;
|
||||
} else {
|
||||
_wheelDelta.y = -0.16 * e.wheelDelta;
|
||||
}
|
||||
} else if('detail' in e) {
|
||||
_wheelDelta.y = e.detail;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
_calculatePanBounds(_currZoomLevel, true);
|
||||
|
||||
var newPanX = _panOffset.x - _wheelDelta.x,
|
||||
newPanY = _panOffset.y - _wheelDelta.y;
|
||||
|
||||
// only prevent scrolling in nonmodal mode when not at edges
|
||||
if (_options.modal ||
|
||||
(
|
||||
newPanX <= _currPanBounds.min.x && newPanX >= _currPanBounds.max.x &&
|
||||
newPanY <= _currPanBounds.min.y && newPanY >= _currPanBounds.max.y
|
||||
) ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
// TODO: use rAF instead of mousewheel?
|
||||
self.panTo(newPanX, newPanY);
|
||||
},
|
||||
|
||||
toggleDesktopZoom: function(centerPoint) {
|
||||
centerPoint = centerPoint || {x:_viewportSize.x/2 + _offset.x, y:_viewportSize.y/2 + _offset.y };
|
||||
|
||||
var doubleTapZoomLevel = _options.getDoubleTapZoom(true, self.currItem);
|
||||
var zoomOut = _currZoomLevel === doubleTapZoomLevel;
|
||||
|
||||
self.mouseZoomedIn = !zoomOut;
|
||||
|
||||
self.zoomTo(zoomOut ? self.currItem.initialZoomLevel : doubleTapZoomLevel, centerPoint, 333);
|
||||
framework[ (!zoomOut ? 'add' : 'remove') + 'Class'](template, 'pswp--zoomed-in');
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
277
web/common/static/photoswipe/js/framework-bridge.js
Normal file
277
web/common/static/photoswipe/js/framework-bridge.js
Normal file
@@ -0,0 +1,277 @@
|
||||
/**
|
||||
*
|
||||
* Set of generic functions used by gallery.
|
||||
*
|
||||
* You're free to modify anything here as long as functionality is kept.
|
||||
*
|
||||
*/
|
||||
var framework = {
|
||||
features: null,
|
||||
bind: function(target, type, listener, unbind) {
|
||||
var methodName = (unbind ? 'remove' : 'add') + 'EventListener';
|
||||
type = type.split(' ');
|
||||
for(var i = 0; i < type.length; i++) {
|
||||
if(type[i]) {
|
||||
target[methodName]( type[i], listener, false);
|
||||
}
|
||||
}
|
||||
},
|
||||
isArray: function(obj) {
|
||||
return (obj instanceof Array);
|
||||
},
|
||||
createEl: function(classes, tag) {
|
||||
var el = document.createElement(tag || 'div');
|
||||
if(classes) {
|
||||
el.className = classes;
|
||||
}
|
||||
return el;
|
||||
},
|
||||
getScrollY: function() {
|
||||
var yOffset = window.pageYOffset;
|
||||
return yOffset !== undefined ? yOffset : document.documentElement.scrollTop;
|
||||
},
|
||||
unbind: function(target, type, listener) {
|
||||
framework.bind(target,type,listener,true);
|
||||
},
|
||||
removeClass: function(el, className) {
|
||||
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
|
||||
el.className = el.className.replace(reg, ' ').replace(/^\s\s*/, '').replace(/\s\s*$/, '');
|
||||
},
|
||||
addClass: function(el, className) {
|
||||
if( !framework.hasClass(el,className) ) {
|
||||
el.className += (el.className ? ' ' : '') + className;
|
||||
}
|
||||
},
|
||||
hasClass: function(el, className) {
|
||||
return el.className && new RegExp('(^|\\s)' + className + '(\\s|$)').test(el.className);
|
||||
},
|
||||
getChildByClass: function(parentEl, childClassName) {
|
||||
var node = parentEl.firstChild;
|
||||
while(node) {
|
||||
if( framework.hasClass(node, childClassName) ) {
|
||||
return node;
|
||||
}
|
||||
node = node.nextSibling;
|
||||
}
|
||||
},
|
||||
arraySearch: function(array, value, key) {
|
||||
var i = array.length;
|
||||
while(i--) {
|
||||
if(array[i][key] === value) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
},
|
||||
extend: function(o1, o2, preventOverwrite) {
|
||||
for (var prop in o2) {
|
||||
if (o2.hasOwnProperty(prop)) {
|
||||
if(preventOverwrite && o1.hasOwnProperty(prop)) {
|
||||
continue;
|
||||
}
|
||||
o1[prop] = o2[prop];
|
||||
}
|
||||
}
|
||||
},
|
||||
easing: {
|
||||
sine: {
|
||||
out: function(k) {
|
||||
return Math.sin(k * (Math.PI / 2));
|
||||
},
|
||||
inOut: function(k) {
|
||||
return - (Math.cos(Math.PI * k) - 1) / 2;
|
||||
}
|
||||
},
|
||||
cubic: {
|
||||
out: function(k) {
|
||||
return --k * k * k + 1;
|
||||
}
|
||||
}
|
||||
/*
|
||||
elastic: {
|
||||
out: function ( k ) {
|
||||
|
||||
var s, a = 0.1, p = 0.4;
|
||||
if ( k === 0 ) return 0;
|
||||
if ( k === 1 ) return 1;
|
||||
if ( !a || a < 1 ) { a = 1; s = p / 4; }
|
||||
else s = p * Math.asin( 1 / a ) / ( 2 * Math.PI );
|
||||
return ( a * Math.pow( 2, - 10 * k) * Math.sin( ( k - s ) * ( 2 * Math.PI ) / p ) + 1 );
|
||||
|
||||
},
|
||||
},
|
||||
back: {
|
||||
out: function ( k ) {
|
||||
var s = 1.70158;
|
||||
return --k * k * ( ( s + 1 ) * k + s ) + 1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {object}
|
||||
*
|
||||
* {
|
||||
* raf : request animation frame function
|
||||
* caf : cancel animation frame function
|
||||
* transfrom : transform property key (with vendor), or null if not supported
|
||||
* oldIE : IE8 or below
|
||||
* }
|
||||
*
|
||||
*/
|
||||
detectFeatures: function() {
|
||||
if(framework.features) {
|
||||
return framework.features;
|
||||
}
|
||||
var helperEl = framework.createEl(),
|
||||
helperStyle = helperEl.style,
|
||||
vendor = '',
|
||||
features = {};
|
||||
|
||||
// IE8 and below
|
||||
features.oldIE = document.all && !document.addEventListener;
|
||||
|
||||
features.touch = 'ontouchstart' in window;
|
||||
|
||||
if(window.requestAnimationFrame) {
|
||||
features.raf = window.requestAnimationFrame;
|
||||
features.caf = window.cancelAnimationFrame;
|
||||
}
|
||||
|
||||
features.pointerEvent = !!(window.PointerEvent) || navigator.msPointerEnabled;
|
||||
|
||||
// fix false-positive detection of old Android in new IE
|
||||
// (IE11 ua string contains "Android 4.0")
|
||||
|
||||
if(!features.pointerEvent) {
|
||||
|
||||
var ua = navigator.userAgent;
|
||||
|
||||
// Detect if device is iPhone or iPod and if it's older than iOS 8
|
||||
// http://stackoverflow.com/a/14223920
|
||||
//
|
||||
// This detection is made because of buggy top/bottom toolbars
|
||||
// that don't trigger window.resize event.
|
||||
// For more info refer to _isFixedPosition variable in core.js
|
||||
|
||||
if (/iP(hone|od)/.test(navigator.platform)) {
|
||||
var v = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
|
||||
if(v && v.length > 0) {
|
||||
v = parseInt(v[1], 10);
|
||||
if(v >= 1 && v < 8 ) {
|
||||
features.isOldIOSPhone = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Detect old Android (before KitKat)
|
||||
// due to bugs related to position:fixed
|
||||
// http://stackoverflow.com/questions/7184573/pick-up-the-android-version-in-the-browser-by-javascript
|
||||
|
||||
var match = ua.match(/Android\s([0-9\.]*)/);
|
||||
var androidversion = match ? match[1] : 0;
|
||||
androidversion = parseFloat(androidversion);
|
||||
if(androidversion >= 1 ) {
|
||||
if(androidversion < 4.4) {
|
||||
features.isOldAndroid = true; // for fixed position bug & performance
|
||||
}
|
||||
features.androidVersion = androidversion; // for touchend bug
|
||||
}
|
||||
features.isMobileOpera = /opera mini|opera mobi/i.test(ua);
|
||||
|
||||
// p.s. yes, yes, UA sniffing is bad, propose your solution for above bugs.
|
||||
}
|
||||
|
||||
var styleChecks = ['transform', 'perspective', 'animationName'],
|
||||
vendors = ['', 'webkit','Moz','ms','O'],
|
||||
styleCheckItem,
|
||||
styleName;
|
||||
|
||||
for(var i = 0; i < 4; i++) {
|
||||
vendor = vendors[i];
|
||||
|
||||
for(var a = 0; a < 3; a++) {
|
||||
styleCheckItem = styleChecks[a];
|
||||
|
||||
// uppercase first letter of property name, if vendor is present
|
||||
styleName = vendor + (vendor ?
|
||||
styleCheckItem.charAt(0).toUpperCase() + styleCheckItem.slice(1) :
|
||||
styleCheckItem);
|
||||
|
||||
if(!features[styleCheckItem] && styleName in helperStyle ) {
|
||||
features[styleCheckItem] = styleName;
|
||||
}
|
||||
}
|
||||
|
||||
if(vendor && !features.raf) {
|
||||
vendor = vendor.toLowerCase();
|
||||
features.raf = window[vendor+'RequestAnimationFrame'];
|
||||
if(features.raf) {
|
||||
features.caf = window[vendor+'CancelAnimationFrame'] ||
|
||||
window[vendor+'CancelRequestAnimationFrame'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!features.raf) {
|
||||
var lastTime = 0;
|
||||
features.raf = function(fn) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max(0, 16 - (currTime - lastTime));
|
||||
var id = window.setTimeout(function() { fn(currTime + timeToCall); }, timeToCall);
|
||||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
features.caf = function(id) { clearTimeout(id); };
|
||||
}
|
||||
|
||||
// Detect SVG support
|
||||
features.svg = !!document.createElementNS &&
|
||||
!!document.createElementNS('http://www.w3.org/2000/svg', 'svg').createSVGRect;
|
||||
|
||||
framework.features = features;
|
||||
|
||||
return features;
|
||||
}
|
||||
};
|
||||
|
||||
framework.detectFeatures();
|
||||
|
||||
// Override addEventListener for old versions of IE
|
||||
if(framework.features.oldIE) {
|
||||
|
||||
framework.bind = function(target, type, listener, unbind) {
|
||||
|
||||
type = type.split(' ');
|
||||
|
||||
var methodName = (unbind ? 'detach' : 'attach') + 'Event',
|
||||
evName,
|
||||
_handleEv = function() {
|
||||
listener.handleEvent.call(listener);
|
||||
};
|
||||
|
||||
for(var i = 0; i < type.length; i++) {
|
||||
evName = type[i];
|
||||
if(evName) {
|
||||
|
||||
if(typeof listener === 'object' && listener.handleEvent) {
|
||||
if(!unbind) {
|
||||
listener['oldIE' + evName] = _handleEv;
|
||||
} else {
|
||||
if(!listener['oldIE' + evName]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
target[methodName]( 'on' + evName, listener['oldIE' + evName]);
|
||||
} else {
|
||||
target[methodName]( 'on' + evName, listener);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
1155
web/common/static/photoswipe/js/gestures.js
Normal file
1155
web/common/static/photoswipe/js/gestures.js
Normal file
File diff suppressed because it is too large
Load Diff
283
web/common/static/photoswipe/js/history.js
Normal file
283
web/common/static/photoswipe/js/history.js
Normal file
@@ -0,0 +1,283 @@
|
||||
/**
|
||||
*
|
||||
* history.js:
|
||||
*
|
||||
* - Back button to close gallery.
|
||||
*
|
||||
* - Unique URL for each slide: example.com/&pid=1&gid=3
|
||||
* (where PID is picture index, and GID and gallery index)
|
||||
*
|
||||
* - Switch URL when slides change.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
var _historyDefaultOptions = {
|
||||
history: true,
|
||||
galleryUID: 1
|
||||
};
|
||||
|
||||
var _historyUpdateTimeout,
|
||||
_hashChangeTimeout,
|
||||
_hashAnimCheckTimeout,
|
||||
_hashChangedByScript,
|
||||
_hashChangedByHistory,
|
||||
_hashReseted,
|
||||
_initialHash,
|
||||
_historyChanged,
|
||||
_closedFromURL,
|
||||
_urlChangedOnce,
|
||||
_windowLoc,
|
||||
|
||||
_supportsPushState,
|
||||
|
||||
_getHash = function() {
|
||||
return _windowLoc.hash.substring(1);
|
||||
},
|
||||
_cleanHistoryTimeouts = function() {
|
||||
|
||||
if(_historyUpdateTimeout) {
|
||||
clearTimeout(_historyUpdateTimeout);
|
||||
}
|
||||
|
||||
if(_hashAnimCheckTimeout) {
|
||||
clearTimeout(_hashAnimCheckTimeout);
|
||||
}
|
||||
},
|
||||
|
||||
// pid - Picture index
|
||||
// gid - Gallery index
|
||||
_parseItemIndexFromURL = function() {
|
||||
var hash = _getHash(),
|
||||
params = {};
|
||||
|
||||
if(hash.length < 5) { // pid=1
|
||||
return params;
|
||||
}
|
||||
|
||||
var i, vars = hash.split('&');
|
||||
for (i = 0; i < vars.length; i++) {
|
||||
if(!vars[i]) {
|
||||
continue;
|
||||
}
|
||||
var pair = vars[i].split('=');
|
||||
if(pair.length < 2) {
|
||||
continue;
|
||||
}
|
||||
params[pair[0]] = pair[1];
|
||||
}
|
||||
if(_options.galleryPIDs) {
|
||||
// detect custom pid in hash and search for it among the items collection
|
||||
var searchfor = params.pid;
|
||||
params.pid = 0; // if custom pid cannot be found, fallback to the first item
|
||||
for(i = 0; i < _items.length; i++) {
|
||||
if(_items[i].pid === searchfor) {
|
||||
params.pid = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
params.pid = parseInt(params.pid,10)-1;
|
||||
}
|
||||
if( params.pid < 0 ) {
|
||||
params.pid = 0;
|
||||
}
|
||||
return params;
|
||||
},
|
||||
_updateHash = function() {
|
||||
|
||||
if(_hashAnimCheckTimeout) {
|
||||
clearTimeout(_hashAnimCheckTimeout);
|
||||
}
|
||||
|
||||
|
||||
if(_numAnimations || _isDragging) {
|
||||
// changing browser URL forces layout/paint in some browsers, which causes noticable lag during animation
|
||||
// that's why we update hash only when no animations running
|
||||
_hashAnimCheckTimeout = setTimeout(_updateHash, 500);
|
||||
return;
|
||||
}
|
||||
|
||||
if(_hashChangedByScript) {
|
||||
clearTimeout(_hashChangeTimeout);
|
||||
} else {
|
||||
_hashChangedByScript = true;
|
||||
}
|
||||
|
||||
|
||||
var pid = (_currentItemIndex + 1);
|
||||
var item = _getItemAt( _currentItemIndex );
|
||||
if(item.hasOwnProperty('pid')) {
|
||||
// carry forward any custom pid assigned to the item
|
||||
pid = item.pid;
|
||||
}
|
||||
var newHash = _initialHash + '&' + 'gid=' + _options.galleryUID + '&' + 'pid=' + pid;
|
||||
|
||||
if(!_historyChanged) {
|
||||
if(_windowLoc.hash.indexOf(newHash) === -1) {
|
||||
_urlChangedOnce = true;
|
||||
}
|
||||
// first time - add new hisory record, then just replace
|
||||
}
|
||||
|
||||
var newURL = _windowLoc.href.split('#')[0] + '#' + newHash;
|
||||
|
||||
if( _supportsPushState ) {
|
||||
|
||||
if('#' + newHash !== window.location.hash) {
|
||||
history[_historyChanged ? 'replaceState' : 'pushState']('', document.title, newURL);
|
||||
}
|
||||
|
||||
} else {
|
||||
if(_historyChanged) {
|
||||
_windowLoc.replace( newURL );
|
||||
} else {
|
||||
_windowLoc.hash = newHash;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
_historyChanged = true;
|
||||
_hashChangeTimeout = setTimeout(function() {
|
||||
_hashChangedByScript = false;
|
||||
}, 60);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
_registerModule('History', {
|
||||
|
||||
|
||||
|
||||
publicMethods: {
|
||||
initHistory: function() {
|
||||
|
||||
framework.extend(_options, _historyDefaultOptions, true);
|
||||
|
||||
if( !_options.history ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_windowLoc = window.location;
|
||||
_urlChangedOnce = false;
|
||||
_closedFromURL = false;
|
||||
_historyChanged = false;
|
||||
_initialHash = _getHash();
|
||||
_supportsPushState = ('pushState' in history);
|
||||
|
||||
|
||||
if(_initialHash.indexOf('gid=') > -1) {
|
||||
_initialHash = _initialHash.split('&gid=')[0];
|
||||
_initialHash = _initialHash.split('?gid=')[0];
|
||||
}
|
||||
|
||||
|
||||
_listen('afterChange', self.updateURL);
|
||||
_listen('unbindEvents', function() {
|
||||
framework.unbind(window, 'hashchange', self.onHashChange);
|
||||
});
|
||||
|
||||
|
||||
var returnToOriginal = function() {
|
||||
_hashReseted = true;
|
||||
if(!_closedFromURL) {
|
||||
|
||||
if(_urlChangedOnce) {
|
||||
history.back();
|
||||
} else {
|
||||
|
||||
if(_initialHash) {
|
||||
_windowLoc.hash = _initialHash;
|
||||
} else {
|
||||
if (_supportsPushState) {
|
||||
|
||||
// remove hash from url without refreshing it or scrolling to top
|
||||
history.pushState('', document.title, _windowLoc.pathname + _windowLoc.search );
|
||||
} else {
|
||||
_windowLoc.hash = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_cleanHistoryTimeouts();
|
||||
};
|
||||
|
||||
|
||||
_listen('unbindEvents', function() {
|
||||
if(_closedByScroll) {
|
||||
// if PhotoSwipe is closed by scroll, we go "back" before the closing animation starts
|
||||
// this is done to keep the scroll position
|
||||
returnToOriginal();
|
||||
}
|
||||
});
|
||||
_listen('destroy', function() {
|
||||
if(!_hashReseted) {
|
||||
returnToOriginal();
|
||||
}
|
||||
});
|
||||
_listen('firstUpdate', function() {
|
||||
_currentItemIndex = _parseItemIndexFromURL().pid;
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
var index = _initialHash.indexOf('pid=');
|
||||
if(index > -1) {
|
||||
_initialHash = _initialHash.substring(0, index);
|
||||
if(_initialHash.slice(-1) === '&') {
|
||||
_initialHash = _initialHash.slice(0, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
if(_isOpen) { // hasn't destroyed yet
|
||||
framework.bind(window, 'hashchange', self.onHashChange);
|
||||
}
|
||||
}, 40);
|
||||
|
||||
},
|
||||
onHashChange: function() {
|
||||
|
||||
if(_getHash() === _initialHash) {
|
||||
|
||||
_closedFromURL = true;
|
||||
self.close();
|
||||
return;
|
||||
}
|
||||
if(!_hashChangedByScript) {
|
||||
|
||||
_hashChangedByHistory = true;
|
||||
self.goTo( _parseItemIndexFromURL().pid );
|
||||
_hashChangedByHistory = false;
|
||||
}
|
||||
|
||||
},
|
||||
updateURL: function() {
|
||||
|
||||
// Delay the update of URL, to avoid lag during transition,
|
||||
// and to not to trigger actions like "refresh page sound" or "blinking favicon" to often
|
||||
|
||||
_cleanHistoryTimeouts();
|
||||
|
||||
|
||||
if(_hashChangedByHistory) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_historyChanged) {
|
||||
_updateHash(); // first time
|
||||
} else {
|
||||
_historyUpdateTimeout = setTimeout(_updateHash, 800);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
493
web/common/static/photoswipe/js/items-controller.js
Normal file
493
web/common/static/photoswipe/js/items-controller.js
Normal file
@@ -0,0 +1,493 @@
|
||||
/**
|
||||
*
|
||||
* Controller manages gallery items, their dimensions, and their content.
|
||||
*
|
||||
*/
|
||||
|
||||
var _items,
|
||||
_tempPanAreaSize = {},
|
||||
_imagesToAppendPool = [],
|
||||
_initialContentSet,
|
||||
_initialZoomRunning,
|
||||
_controllerDefaultOptions = {
|
||||
index: 0,
|
||||
errorMsg: '<div class="pswp__error-msg"><a href="%url%" target="_blank">The image</a> could not be loaded.</div>',
|
||||
forceProgressiveLoading: false, // TODO
|
||||
preload: [1,1],
|
||||
getNumItemsFn: function() {
|
||||
return _items.length;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var _getItemAt,
|
||||
_getNumItems,
|
||||
_initialIsLoop,
|
||||
_getZeroBounds = function() {
|
||||
return {
|
||||
center:{x:0,y:0},
|
||||
max:{x:0,y:0},
|
||||
min:{x:0,y:0}
|
||||
};
|
||||
},
|
||||
_calculateSingleItemPanBounds = function(item, realPanElementW, realPanElementH ) {
|
||||
var bounds = item.bounds;
|
||||
|
||||
// position of element when it's centered
|
||||
bounds.center.x = Math.round((_tempPanAreaSize.x - realPanElementW) / 2);
|
||||
bounds.center.y = Math.round((_tempPanAreaSize.y - realPanElementH) / 2) + item.vGap.top;
|
||||
|
||||
// maximum pan position
|
||||
bounds.max.x = (realPanElementW > _tempPanAreaSize.x) ?
|
||||
Math.round(_tempPanAreaSize.x - realPanElementW) :
|
||||
bounds.center.x;
|
||||
|
||||
bounds.max.y = (realPanElementH > _tempPanAreaSize.y) ?
|
||||
Math.round(_tempPanAreaSize.y - realPanElementH) + item.vGap.top :
|
||||
bounds.center.y;
|
||||
|
||||
// minimum pan position
|
||||
bounds.min.x = (realPanElementW > _tempPanAreaSize.x) ? 0 : bounds.center.x;
|
||||
bounds.min.y = (realPanElementH > _tempPanAreaSize.y) ? item.vGap.top : bounds.center.y;
|
||||
},
|
||||
_calculateItemSize = function(item, viewportSize, zoomLevel) {
|
||||
|
||||
if (item.src && !item.loadError) {
|
||||
var isInitial = !zoomLevel;
|
||||
|
||||
if(isInitial) {
|
||||
if(!item.vGap) {
|
||||
item.vGap = {top:0,bottom:0};
|
||||
}
|
||||
// allows overriding vertical margin for individual items
|
||||
_shout('parseVerticalMargin', item);
|
||||
}
|
||||
|
||||
|
||||
_tempPanAreaSize.x = viewportSize.x;
|
||||
_tempPanAreaSize.y = viewportSize.y - item.vGap.top - item.vGap.bottom;
|
||||
|
||||
if (isInitial) {
|
||||
var hRatio = _tempPanAreaSize.x / item.w;
|
||||
var vRatio = _tempPanAreaSize.y / item.h;
|
||||
|
||||
item.fitRatio = hRatio < vRatio ? hRatio : vRatio;
|
||||
//item.fillRatio = hRatio > vRatio ? hRatio : vRatio;
|
||||
|
||||
var scaleMode = _options.scaleMode;
|
||||
|
||||
if (scaleMode === 'orig') {
|
||||
zoomLevel = 1;
|
||||
} else if (scaleMode === 'fit') {
|
||||
zoomLevel = item.fitRatio;
|
||||
}
|
||||
|
||||
if (zoomLevel > 1) {
|
||||
zoomLevel = 1;
|
||||
}
|
||||
|
||||
item.initialZoomLevel = zoomLevel;
|
||||
|
||||
if(!item.bounds) {
|
||||
// reuse bounds object
|
||||
item.bounds = _getZeroBounds();
|
||||
}
|
||||
}
|
||||
|
||||
if(!zoomLevel) {
|
||||
return;
|
||||
}
|
||||
|
||||
_calculateSingleItemPanBounds(item, item.w * zoomLevel, item.h * zoomLevel);
|
||||
|
||||
if (isInitial && zoomLevel === item.initialZoomLevel) {
|
||||
item.initialPosition = item.bounds.center;
|
||||
}
|
||||
|
||||
return item.bounds;
|
||||
} else {
|
||||
item.w = item.h = 0;
|
||||
item.initialZoomLevel = item.fitRatio = 1;
|
||||
item.bounds = _getZeroBounds();
|
||||
item.initialPosition = item.bounds.center;
|
||||
|
||||
// if it's not image, we return zero bounds (content is not zoomable)
|
||||
return item.bounds;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
_appendImage = function(index, item, baseDiv, img, preventAnimation, keepPlaceholder) {
|
||||
|
||||
|
||||
if(item.loadError) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(img) {
|
||||
|
||||
item.imageAppended = true;
|
||||
_setImageSize(item, img, (item === self.currItem && _renderMaxResolution) );
|
||||
|
||||
baseDiv.appendChild(img);
|
||||
|
||||
if(keepPlaceholder) {
|
||||
setTimeout(function() {
|
||||
if(item && item.loaded && item.placeholder) {
|
||||
item.placeholder.style.display = 'none';
|
||||
item.placeholder = null;
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
_preloadImage = function(item) {
|
||||
item.loading = true;
|
||||
item.loaded = false;
|
||||
var img = item.img = framework.createEl('pswp__img', 'img');
|
||||
var onComplete = function() {
|
||||
item.loading = false;
|
||||
item.loaded = true;
|
||||
|
||||
if(item.loadComplete) {
|
||||
item.loadComplete(item);
|
||||
} else {
|
||||
item.img = null; // no need to store image object
|
||||
}
|
||||
img.onload = img.onerror = null;
|
||||
img = null;
|
||||
};
|
||||
img.onload = onComplete;
|
||||
img.onerror = function() {
|
||||
item.loadError = true;
|
||||
onComplete();
|
||||
};
|
||||
|
||||
img.src = item.src;// + '?a=' + Math.random();
|
||||
|
||||
return img;
|
||||
},
|
||||
_checkForError = function(item, cleanUp) {
|
||||
if(item.src && item.loadError && item.container) {
|
||||
|
||||
if(cleanUp) {
|
||||
item.container.innerHTML = '';
|
||||
}
|
||||
|
||||
item.container.innerHTML = _options.errorMsg.replace('%url%', item.src );
|
||||
return true;
|
||||
|
||||
}
|
||||
},
|
||||
_setImageSize = function(item, img, maxRes) {
|
||||
if(!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!img) {
|
||||
img = item.container.lastChild;
|
||||
}
|
||||
|
||||
var w = maxRes ? item.w : Math.round(item.w * item.fitRatio),
|
||||
h = maxRes ? item.h : Math.round(item.h * item.fitRatio);
|
||||
|
||||
if(item.placeholder && !item.loaded) {
|
||||
item.placeholder.style.width = w + 'px';
|
||||
item.placeholder.style.height = h + 'px';
|
||||
}
|
||||
|
||||
img.style.width = w + 'px';
|
||||
img.style.height = h + 'px';
|
||||
},
|
||||
_appendImagesPool = function() {
|
||||
|
||||
if(_imagesToAppendPool.length) {
|
||||
var poolItem;
|
||||
|
||||
for(var i = 0; i < _imagesToAppendPool.length; i++) {
|
||||
poolItem = _imagesToAppendPool[i];
|
||||
if( poolItem.holder.index === poolItem.index ) {
|
||||
_appendImage(poolItem.index, poolItem.item, poolItem.baseDiv, poolItem.img, false, poolItem.clearPlaceholder);
|
||||
}
|
||||
}
|
||||
_imagesToAppendPool = [];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
_registerModule('Controller', {
|
||||
|
||||
publicMethods: {
|
||||
|
||||
lazyLoadItem: function(index) {
|
||||
index = _getLoopedId(index);
|
||||
var item = _getItemAt(index);
|
||||
|
||||
if(!item || ((item.loaded || item.loading) && !_itemsNeedUpdate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_shout('gettingData', index, item);
|
||||
|
||||
if (!item.src) {
|
||||
return;
|
||||
}
|
||||
|
||||
_preloadImage(item);
|
||||
},
|
||||
initController: function() {
|
||||
framework.extend(_options, _controllerDefaultOptions, true);
|
||||
self.items = _items = items;
|
||||
_getItemAt = self.getItemAt;
|
||||
_getNumItems = _options.getNumItemsFn; //self.getNumItems;
|
||||
|
||||
|
||||
|
||||
_initialIsLoop = _options.loop;
|
||||
if(_getNumItems() < 3) {
|
||||
_options.loop = false; // disable loop if less then 3 items
|
||||
}
|
||||
|
||||
_listen('beforeChange', function(diff) {
|
||||
|
||||
var p = _options.preload,
|
||||
isNext = diff === null ? true : (diff >= 0),
|
||||
preloadBefore = Math.min(p[0], _getNumItems() ),
|
||||
preloadAfter = Math.min(p[1], _getNumItems() ),
|
||||
i;
|
||||
|
||||
|
||||
for(i = 1; i <= (isNext ? preloadAfter : preloadBefore); i++) {
|
||||
self.lazyLoadItem(_currentItemIndex+i);
|
||||
}
|
||||
for(i = 1; i <= (isNext ? preloadBefore : preloadAfter); i++) {
|
||||
self.lazyLoadItem(_currentItemIndex-i);
|
||||
}
|
||||
});
|
||||
|
||||
_listen('initialLayout', function() {
|
||||
self.currItem.initialLayout = _options.getThumbBoundsFn && _options.getThumbBoundsFn(_currentItemIndex);
|
||||
});
|
||||
|
||||
_listen('mainScrollAnimComplete', _appendImagesPool);
|
||||
_listen('initialZoomInEnd', _appendImagesPool);
|
||||
|
||||
|
||||
|
||||
_listen('destroy', function() {
|
||||
var item;
|
||||
for(var i = 0; i < _items.length; i++) {
|
||||
item = _items[i];
|
||||
// remove reference to DOM elements, for GC
|
||||
if(item.container) {
|
||||
item.container = null;
|
||||
}
|
||||
if(item.placeholder) {
|
||||
item.placeholder = null;
|
||||
}
|
||||
if(item.img) {
|
||||
item.img = null;
|
||||
}
|
||||
if(item.preloader) {
|
||||
item.preloader = null;
|
||||
}
|
||||
if(item.loadError) {
|
||||
item.loaded = item.loadError = false;
|
||||
}
|
||||
}
|
||||
_imagesToAppendPool = null;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
getItemAt: function(index) {
|
||||
if (index >= 0) {
|
||||
return _items[index] !== undefined ? _items[index] : false;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
allowProgressiveImg: function() {
|
||||
// 1. Progressive image loading isn't working on webkit/blink
|
||||
// when hw-acceleration (e.g. translateZ) is applied to IMG element.
|
||||
// That's why in PhotoSwipe parent element gets zoom transform, not image itself.
|
||||
//
|
||||
// 2. Progressive image loading sometimes blinks in webkit/blink when applying animation to parent element.
|
||||
// That's why it's disabled on touch devices (mainly because of swipe transition)
|
||||
//
|
||||
// 3. Progressive image loading sometimes doesn't work in IE (up to 11).
|
||||
|
||||
// Don't allow progressive loading on non-large touch devices
|
||||
return _options.forceProgressiveLoading || !_likelyTouchDevice || _options.mouseUsed || screen.width > 1200;
|
||||
// 1200 - to eliminate touch devices with large screen (like Chromebook Pixel)
|
||||
},
|
||||
|
||||
setContent: function(holder, index) {
|
||||
|
||||
if(_options.loop) {
|
||||
index = _getLoopedId(index);
|
||||
}
|
||||
|
||||
var prevItem = self.getItemAt(holder.index);
|
||||
if(prevItem) {
|
||||
prevItem.container = null;
|
||||
}
|
||||
|
||||
var item = self.getItemAt(index),
|
||||
img;
|
||||
|
||||
if(!item) {
|
||||
holder.el.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
// allow to override data
|
||||
_shout('gettingData', index, item);
|
||||
|
||||
holder.index = index;
|
||||
holder.item = item;
|
||||
|
||||
// base container DIV is created only once for each of 3 holders
|
||||
var baseDiv = item.container = framework.createEl('pswp__zoom-wrap');
|
||||
|
||||
|
||||
|
||||
if(!item.src && item.html) {
|
||||
if(item.html.tagName) {
|
||||
baseDiv.appendChild(item.html);
|
||||
} else {
|
||||
baseDiv.innerHTML = item.html;
|
||||
}
|
||||
}
|
||||
|
||||
_checkForError(item);
|
||||
|
||||
_calculateItemSize(item, _viewportSize);
|
||||
|
||||
if(item.src && !item.loadError && !item.loaded) {
|
||||
|
||||
item.loadComplete = function(item) {
|
||||
|
||||
// gallery closed before image finished loading
|
||||
if(!_isOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
// check if holder hasn't changed while image was loading
|
||||
if(holder && holder.index === index ) {
|
||||
if( _checkForError(item, true) ) {
|
||||
item.loadComplete = item.img = null;
|
||||
_calculateItemSize(item, _viewportSize);
|
||||
_applyZoomPanToItem(item);
|
||||
|
||||
if(holder.index === _currentItemIndex) {
|
||||
// recalculate dimensions
|
||||
self.updateCurrZoomItem();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if( !item.imageAppended ) {
|
||||
if(_features.transform && (_mainScrollAnimating || _initialZoomRunning) ) {
|
||||
_imagesToAppendPool.push({
|
||||
item:item,
|
||||
baseDiv:baseDiv,
|
||||
img:item.img,
|
||||
index:index,
|
||||
holder:holder,
|
||||
clearPlaceholder:true
|
||||
});
|
||||
} else {
|
||||
_appendImage(index, item, baseDiv, item.img, _mainScrollAnimating || _initialZoomRunning, true);
|
||||
}
|
||||
} else {
|
||||
// remove preloader & mini-img
|
||||
if(!_initialZoomRunning && item.placeholder) {
|
||||
item.placeholder.style.display = 'none';
|
||||
item.placeholder = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.loadComplete = null;
|
||||
item.img = null; // no need to store image element after it's added
|
||||
|
||||
_shout('imageLoadComplete', index, item);
|
||||
};
|
||||
|
||||
if(framework.features.transform) {
|
||||
|
||||
var placeholderClassName = 'pswp__img pswp__img--placeholder';
|
||||
placeholderClassName += (item.msrc ? '' : ' pswp__img--placeholder--blank');
|
||||
|
||||
var placeholder = framework.createEl(placeholderClassName, item.msrc ? 'img' : '');
|
||||
if(item.msrc) {
|
||||
placeholder.src = item.msrc;
|
||||
}
|
||||
|
||||
_setImageSize(item, placeholder);
|
||||
|
||||
baseDiv.appendChild(placeholder);
|
||||
item.placeholder = placeholder;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(!item.loading) {
|
||||
_preloadImage(item);
|
||||
}
|
||||
|
||||
|
||||
if( self.allowProgressiveImg() ) {
|
||||
// just append image
|
||||
if(!_initialContentSet && _features.transform) {
|
||||
_imagesToAppendPool.push({
|
||||
item:item,
|
||||
baseDiv:baseDiv,
|
||||
img:item.img,
|
||||
index:index,
|
||||
holder:holder
|
||||
});
|
||||
} else {
|
||||
_appendImage(index, item, baseDiv, item.img, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
} else if(item.src && !item.loadError) {
|
||||
// image object is created every time, due to bugs of image loading & delay when switching images
|
||||
img = framework.createEl('pswp__img', 'img');
|
||||
img.style.opacity = 1;
|
||||
img.src = item.src;
|
||||
_setImageSize(item, img);
|
||||
_appendImage(index, item, baseDiv, img, true);
|
||||
}
|
||||
|
||||
|
||||
if(!_initialContentSet && index === _currentItemIndex) {
|
||||
_currZoomElementStyle = baseDiv.style;
|
||||
_showOrHide(item, (img ||item.img) );
|
||||
} else {
|
||||
_applyZoomPanToItem(item);
|
||||
}
|
||||
|
||||
holder.el.innerHTML = '';
|
||||
holder.el.appendChild(baseDiv);
|
||||
},
|
||||
|
||||
cleanSlide: function( item ) {
|
||||
if(item.img ) {
|
||||
item.img.onload = item.img.onerror = null;
|
||||
}
|
||||
item.loaded = item.loading = item.img = item.imageAppended = false;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
181
web/common/static/photoswipe/js/show-hide-transition.js
Normal file
181
web/common/static/photoswipe/js/show-hide-transition.js
Normal file
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* show-hide-transition.js:
|
||||
*
|
||||
* Manages initial opening or closing transition.
|
||||
*
|
||||
* If you're not planning to use transition for gallery at all,
|
||||
* you may set options hideAnimationDuration and showAnimationDuration to 0,
|
||||
* and just delete startAnimation function.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
var _showOrHideTimeout,
|
||||
_showOrHide = function(item, img, out, completeFn) {
|
||||
|
||||
if(_showOrHideTimeout) {
|
||||
clearTimeout(_showOrHideTimeout);
|
||||
}
|
||||
|
||||
_initialZoomRunning = true;
|
||||
_initialContentSet = true;
|
||||
|
||||
// dimensions of small thumbnail {x:,y:,w:}.
|
||||
// Height is optional, as calculated based on large image.
|
||||
var thumbBounds;
|
||||
if(item.initialLayout) {
|
||||
thumbBounds = item.initialLayout;
|
||||
item.initialLayout = null;
|
||||
} else {
|
||||
thumbBounds = _options.getThumbBoundsFn && _options.getThumbBoundsFn(_currentItemIndex);
|
||||
}
|
||||
|
||||
var duration = out ? _options.hideAnimationDuration : _options.showAnimationDuration;
|
||||
|
||||
var onComplete = function() {
|
||||
_stopAnimation('initialZoom');
|
||||
if(!out) {
|
||||
_applyBgOpacity(1);
|
||||
if(img) {
|
||||
img.style.display = 'block';
|
||||
}
|
||||
framework.addClass(template, 'pswp--animated-in');
|
||||
_shout('initialZoom' + (out ? 'OutEnd' : 'InEnd'));
|
||||
} else {
|
||||
self.template.removeAttribute('style');
|
||||
self.bg.removeAttribute('style');
|
||||
}
|
||||
|
||||
if(completeFn) {
|
||||
completeFn();
|
||||
}
|
||||
_initialZoomRunning = false;
|
||||
};
|
||||
|
||||
// if bounds aren't provided, just open gallery without animation
|
||||
if(!duration || !thumbBounds || thumbBounds.x === undefined) {
|
||||
|
||||
_shout('initialZoom' + (out ? 'Out' : 'In') );
|
||||
|
||||
_currZoomLevel = item.initialZoomLevel;
|
||||
_equalizePoints(_panOffset, item.initialPosition );
|
||||
_applyCurrentZoomPan();
|
||||
|
||||
template.style.opacity = out ? 0 : 1;
|
||||
_applyBgOpacity(1);
|
||||
|
||||
if(duration) {
|
||||
setTimeout(function() {
|
||||
onComplete();
|
||||
}, duration);
|
||||
} else {
|
||||
onComplete();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var startAnimation = function() {
|
||||
var closeWithRaf = _closedByScroll,
|
||||
fadeEverything = !self.currItem.src || self.currItem.loadError || _options.showHideOpacity;
|
||||
|
||||
// apply hw-acceleration to image
|
||||
if(item.miniImg) {
|
||||
item.miniImg.style.webkitBackfaceVisibility = 'hidden';
|
||||
}
|
||||
|
||||
if(!out) {
|
||||
_currZoomLevel = thumbBounds.w / item.w;
|
||||
_panOffset.x = thumbBounds.x;
|
||||
_panOffset.y = thumbBounds.y - _initalWindowScrollY;
|
||||
|
||||
self[fadeEverything ? 'template' : 'bg'].style.opacity = 0.001;
|
||||
_applyCurrentZoomPan();
|
||||
}
|
||||
|
||||
_registerStartAnimation('initialZoom');
|
||||
|
||||
if(out && !closeWithRaf) {
|
||||
framework.removeClass(template, 'pswp--animated-in');
|
||||
}
|
||||
|
||||
if(fadeEverything) {
|
||||
if(out) {
|
||||
framework[ (closeWithRaf ? 'remove' : 'add') + 'Class' ](template, 'pswp--animate_opacity');
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
framework.addClass(template, 'pswp--animate_opacity');
|
||||
}, 30);
|
||||
}
|
||||
}
|
||||
|
||||
_showOrHideTimeout = setTimeout(function() {
|
||||
|
||||
_shout('initialZoom' + (out ? 'Out' : 'In') );
|
||||
|
||||
|
||||
if(!out) {
|
||||
|
||||
// "in" animation always uses CSS transitions (instead of rAF).
|
||||
// CSS transition work faster here,
|
||||
// as developer may also want to animate other things,
|
||||
// like ui on top of sliding area, which can be animated just via CSS
|
||||
|
||||
_currZoomLevel = item.initialZoomLevel;
|
||||
_equalizePoints(_panOffset, item.initialPosition );
|
||||
_applyCurrentZoomPan();
|
||||
_applyBgOpacity(1);
|
||||
|
||||
if(fadeEverything) {
|
||||
template.style.opacity = 1;
|
||||
} else {
|
||||
_applyBgOpacity(1);
|
||||
}
|
||||
|
||||
_showOrHideTimeout = setTimeout(onComplete, duration + 20);
|
||||
} else {
|
||||
|
||||
// "out" animation uses rAF only when PhotoSwipe is closed by browser scroll, to recalculate position
|
||||
var destZoomLevel = thumbBounds.w / item.w,
|
||||
initialPanOffset = {
|
||||
x: _panOffset.x,
|
||||
y: _panOffset.y
|
||||
},
|
||||
initialZoomLevel = _currZoomLevel,
|
||||
initalBgOpacity = _bgOpacity,
|
||||
onUpdate = function(now) {
|
||||
|
||||
if(now === 1) {
|
||||
_currZoomLevel = destZoomLevel;
|
||||
_panOffset.x = thumbBounds.x;
|
||||
_panOffset.y = thumbBounds.y - _currentWindowScrollY;
|
||||
} else {
|
||||
_currZoomLevel = (destZoomLevel - initialZoomLevel) * now + initialZoomLevel;
|
||||
_panOffset.x = (thumbBounds.x - initialPanOffset.x) * now + initialPanOffset.x;
|
||||
_panOffset.y = (thumbBounds.y - _currentWindowScrollY - initialPanOffset.y) * now + initialPanOffset.y;
|
||||
}
|
||||
|
||||
_applyCurrentZoomPan();
|
||||
if(fadeEverything) {
|
||||
template.style.opacity = 1 - now;
|
||||
} else {
|
||||
_applyBgOpacity( initalBgOpacity - now * initalBgOpacity );
|
||||
}
|
||||
};
|
||||
|
||||
if(closeWithRaf) {
|
||||
_animateProp('initialZoom', 0, 1, duration, framework.easing.cubic.out, onUpdate, onComplete);
|
||||
} else {
|
||||
onUpdate(1);
|
||||
_showOrHideTimeout = setTimeout(onComplete, duration + 20);
|
||||
}
|
||||
}
|
||||
|
||||
}, out ? 25 : 90); // Main purpose of this delay is to give browser time to paint and
|
||||
// create composite layers of PhotoSwipe UI parts (background, controls, caption, arrows).
|
||||
// Which avoids lag at the beginning of scale transition.
|
||||
};
|
||||
startAnimation();
|
||||
|
||||
|
||||
};
|
||||
78
web/common/static/photoswipe/js/tap.js
Normal file
78
web/common/static/photoswipe/js/tap.js
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* tap.js:
|
||||
*
|
||||
* Displatches tap and double-tap events.
|
||||
*
|
||||
*/
|
||||
|
||||
var tapTimer,
|
||||
tapReleasePoint = {},
|
||||
_dispatchTapEvent = function(origEvent, releasePoint, pointerType) {
|
||||
var e = document.createEvent( 'CustomEvent' ),
|
||||
eDetail = {
|
||||
origEvent:origEvent,
|
||||
target:origEvent.target,
|
||||
releasePoint: releasePoint,
|
||||
pointerType:pointerType || 'touch'
|
||||
};
|
||||
|
||||
e.initCustomEvent( 'pswpTap', true, true, eDetail );
|
||||
origEvent.target.dispatchEvent(e);
|
||||
};
|
||||
|
||||
_registerModule('Tap', {
|
||||
publicMethods: {
|
||||
initTap: function() {
|
||||
_listen('firstTouchStart', self.onTapStart);
|
||||
_listen('touchRelease', self.onTapRelease);
|
||||
_listen('destroy', function() {
|
||||
tapReleasePoint = {};
|
||||
tapTimer = null;
|
||||
});
|
||||
},
|
||||
onTapStart: function(touchList) {
|
||||
if(touchList.length > 1) {
|
||||
clearTimeout(tapTimer);
|
||||
tapTimer = null;
|
||||
}
|
||||
},
|
||||
onTapRelease: function(e, releasePoint) {
|
||||
if(!releasePoint) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_moved && !_isMultitouch && !_numAnimations) {
|
||||
var p0 = releasePoint;
|
||||
if(tapTimer) {
|
||||
clearTimeout(tapTimer);
|
||||
tapTimer = null;
|
||||
|
||||
// Check if taped on the same place
|
||||
if ( _isNearbyPoints(p0, tapReleasePoint) ) {
|
||||
_shout('doubleTap', p0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(releasePoint.type === 'mouse') {
|
||||
_dispatchTapEvent(e, releasePoint, 'mouse');
|
||||
return;
|
||||
}
|
||||
|
||||
var clickedTagName = e.target.tagName.toUpperCase();
|
||||
// avoid double tap delay on buttons and elements that have class pswp__single-tap
|
||||
if(clickedTagName === 'BUTTON' || framework.hasClass(e.target, 'pswp__single-tap') ) {
|
||||
_dispatchTapEvent(e, releasePoint);
|
||||
return;
|
||||
}
|
||||
|
||||
_equalizePoints(tapReleasePoint, p0);
|
||||
|
||||
tapTimer = setTimeout(function() {
|
||||
_dispatchTapEvent(e, releasePoint);
|
||||
tapTimer = null;
|
||||
}, 300);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
858
web/common/static/photoswipe/js/ui/photoswipe-ui-default.js
Normal file
858
web/common/static/photoswipe/js/ui/photoswipe-ui-default.js
Normal file
@@ -0,0 +1,858 @@
|
||||
/**
|
||||
*
|
||||
* UI on top of main sliding area (caption, arrows, close button, etc.).
|
||||
* Built just using public methods/properties of PhotoSwipe.
|
||||
*
|
||||
*/
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.PhotoSwipeUI_Default = factory();
|
||||
}
|
||||
})(this, function () {
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
|
||||
var PhotoSwipeUI_Default =
|
||||
function(pswp, framework) {
|
||||
|
||||
var ui = this;
|
||||
var _overlayUIUpdated = false,
|
||||
_controlsVisible = true,
|
||||
_fullscrenAPI,
|
||||
_controls,
|
||||
_captionContainer,
|
||||
_fakeCaptionContainer,
|
||||
_indexIndicator,
|
||||
_shareButton,
|
||||
_shareModal,
|
||||
_shareModalHidden = true,
|
||||
_initalCloseOnScrollValue,
|
||||
_isIdle,
|
||||
_listen,
|
||||
|
||||
_loadingIndicator,
|
||||
_loadingIndicatorHidden,
|
||||
_loadingIndicatorTimeout,
|
||||
|
||||
_galleryHasOneSlide,
|
||||
|
||||
_options,
|
||||
_defaultUIOptions = {
|
||||
barsSize: {top:44, bottom:'auto'},
|
||||
closeElClasses: ['item', 'caption', 'zoom-wrap', 'ui', 'top-bar'],
|
||||
timeToIdle: 4000,
|
||||
timeToIdleOutside: 1000,
|
||||
loadingIndicatorDelay: 1000, // 2s
|
||||
|
||||
addCaptionHTMLFn: function(item, captionEl /*, isFake */) {
|
||||
if(!item.title) {
|
||||
captionEl.children[0].innerHTML = '';
|
||||
return false;
|
||||
}
|
||||
captionEl.children[0].innerHTML = item.title;
|
||||
return true;
|
||||
},
|
||||
|
||||
closeEl:true,
|
||||
captionEl: true,
|
||||
fullscreenEl: true,
|
||||
zoomEl: true,
|
||||
shareEl: true,
|
||||
counterEl: true,
|
||||
arrowEl: true,
|
||||
preloaderEl: true,
|
||||
|
||||
tapToClose: false,
|
||||
tapToToggleControls: true,
|
||||
|
||||
clickToCloseNonZoomable: true,
|
||||
|
||||
shareButtons: [
|
||||
{id:'facebook', label:'Share on Facebook', url:'https://www.facebook.com/sharer/sharer.php?u={{url}}'},
|
||||
{id:'twitter', label:'Tweet', url:'https://twitter.com/intent/tweet?text={{text}}&url={{url}}'},
|
||||
{id:'pinterest', label:'Pin it', url:'http://www.pinterest.com/pin/create/button/'+
|
||||
'?url={{url}}&media={{image_url}}&description={{text}}'},
|
||||
{id:'download', label:'Download image', url:'{{raw_image_url}}', download:true}
|
||||
],
|
||||
getImageURLForShare: function( /* shareButtonData */ ) {
|
||||
return pswp.currItem.src || '';
|
||||
},
|
||||
getPageURLForShare: function( /* shareButtonData */ ) {
|
||||
return window.location.href;
|
||||
},
|
||||
getTextForShare: function( /* shareButtonData */ ) {
|
||||
return pswp.currItem.title || '';
|
||||
},
|
||||
|
||||
indexIndicatorSep: ' / ',
|
||||
fitControlsWidth: 1200
|
||||
|
||||
},
|
||||
_blockControlsTap,
|
||||
_blockControlsTapTimeout;
|
||||
|
||||
|
||||
|
||||
var _onControlsTap = function(e) {
|
||||
if(_blockControlsTap) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
e = e || window.event;
|
||||
|
||||
if(_options.timeToIdle && _options.mouseUsed && !_isIdle) {
|
||||
// reset idle timer
|
||||
_onIdleMouseMove();
|
||||
}
|
||||
|
||||
|
||||
var target = e.target || e.srcElement,
|
||||
uiElement,
|
||||
clickedClass = target.getAttribute('class') || '',
|
||||
found;
|
||||
|
||||
for(var i = 0; i < _uiElements.length; i++) {
|
||||
uiElement = _uiElements[i];
|
||||
if(uiElement.onTap && clickedClass.indexOf('pswp__' + uiElement.name ) > -1 ) {
|
||||
uiElement.onTap();
|
||||
found = true;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(found) {
|
||||
if(e.stopPropagation) {
|
||||
e.stopPropagation();
|
||||
}
|
||||
_blockControlsTap = true;
|
||||
|
||||
// Some versions of Android don't prevent ghost click event
|
||||
// when preventDefault() was called on touchstart and/or touchend.
|
||||
//
|
||||
// This happens on v4.3, 4.2, 4.1,
|
||||
// older versions strangely work correctly,
|
||||
// but just in case we add delay on all of them)
|
||||
var tapDelay = framework.features.isOldAndroid ? 600 : 30;
|
||||
_blockControlsTapTimeout = setTimeout(function() {
|
||||
_blockControlsTap = false;
|
||||
}, tapDelay);
|
||||
}
|
||||
|
||||
},
|
||||
_fitControlsInViewport = function() {
|
||||
return !pswp.likelyTouchDevice || _options.mouseUsed || screen.width > _options.fitControlsWidth;
|
||||
},
|
||||
_togglePswpClass = function(el, cName, add) {
|
||||
framework[ (add ? 'add' : 'remove') + 'Class' ](el, 'pswp__' + cName);
|
||||
},
|
||||
|
||||
// add class when there is just one item in the gallery
|
||||
// (by default it hides left/right arrows and 1ofX counter)
|
||||
_countNumItems = function() {
|
||||
var hasOneSlide = (_options.getNumItemsFn() === 1);
|
||||
|
||||
if(hasOneSlide !== _galleryHasOneSlide) {
|
||||
_togglePswpClass(_controls, 'ui--one-slide', hasOneSlide);
|
||||
_galleryHasOneSlide = hasOneSlide;
|
||||
}
|
||||
},
|
||||
_toggleShareModalClass = function() {
|
||||
_togglePswpClass(_shareModal, 'share-modal--hidden', _shareModalHidden);
|
||||
},
|
||||
_toggleShareModal = function() {
|
||||
|
||||
_shareModalHidden = !_shareModalHidden;
|
||||
|
||||
|
||||
if(!_shareModalHidden) {
|
||||
_toggleShareModalClass();
|
||||
setTimeout(function() {
|
||||
if(!_shareModalHidden) {
|
||||
framework.addClass(_shareModal, 'pswp__share-modal--fade-in');
|
||||
}
|
||||
}, 30);
|
||||
} else {
|
||||
framework.removeClass(_shareModal, 'pswp__share-modal--fade-in');
|
||||
setTimeout(function() {
|
||||
if(_shareModalHidden) {
|
||||
_toggleShareModalClass();
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
|
||||
if(!_shareModalHidden) {
|
||||
_updateShareURLs();
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_openWindowPopup = function(e) {
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement;
|
||||
|
||||
pswp.shout('shareLinkClick', e, target);
|
||||
|
||||
if(!target.href) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( target.hasAttribute('download') ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
window.open(target.href, 'pswp_share', 'scrollbars=yes,resizable=yes,toolbar=no,'+
|
||||
'location=yes,width=550,height=420,top=100,left=' +
|
||||
(window.screen ? Math.round(screen.width / 2 - 275) : 100) );
|
||||
|
||||
if(!_shareModalHidden) {
|
||||
_toggleShareModal();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
_updateShareURLs = function() {
|
||||
var shareButtonOut = '',
|
||||
shareButtonData,
|
||||
shareURL,
|
||||
image_url,
|
||||
page_url,
|
||||
share_text;
|
||||
|
||||
for(var i = 0; i < _options.shareButtons.length; i++) {
|
||||
shareButtonData = _options.shareButtons[i];
|
||||
|
||||
image_url = _options.getImageURLForShare(shareButtonData);
|
||||
page_url = _options.getPageURLForShare(shareButtonData);
|
||||
share_text = _options.getTextForShare(shareButtonData);
|
||||
|
||||
shareURL = shareButtonData.url.replace('{{url}}', encodeURIComponent(page_url) )
|
||||
.replace('{{image_url}}', encodeURIComponent(image_url) )
|
||||
.replace('{{raw_image_url}}', image_url )
|
||||
.replace('{{text}}', encodeURIComponent(share_text) );
|
||||
|
||||
shareButtonOut += '<a href="' + shareURL + '" target="_blank" '+
|
||||
'class="pswp__share--' + shareButtonData.id + '"' +
|
||||
(shareButtonData.download ? 'download' : '') + '>' +
|
||||
shareButtonData.label + '</a>';
|
||||
|
||||
if(_options.parseShareButtonOut) {
|
||||
shareButtonOut = _options.parseShareButtonOut(shareButtonData, shareButtonOut);
|
||||
}
|
||||
}
|
||||
_shareModal.children[0].innerHTML = shareButtonOut;
|
||||
_shareModal.children[0].onclick = _openWindowPopup;
|
||||
|
||||
},
|
||||
_hasCloseClass = function(target) {
|
||||
for(var i = 0; i < _options.closeElClasses.length; i++) {
|
||||
if( framework.hasClass(target, 'pswp__' + _options.closeElClasses[i]) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
},
|
||||
_idleInterval,
|
||||
_idleTimer,
|
||||
_idleIncrement = 0,
|
||||
_onIdleMouseMove = function() {
|
||||
clearTimeout(_idleTimer);
|
||||
_idleIncrement = 0;
|
||||
if(_isIdle) {
|
||||
ui.setIdle(false);
|
||||
}
|
||||
},
|
||||
_onMouseLeaveWindow = function(e) {
|
||||
e = e ? e : window.event;
|
||||
var from = e.relatedTarget || e.toElement;
|
||||
if (!from || from.nodeName === 'HTML') {
|
||||
clearTimeout(_idleTimer);
|
||||
_idleTimer = setTimeout(function() {
|
||||
ui.setIdle(true);
|
||||
}, _options.timeToIdleOutside);
|
||||
}
|
||||
},
|
||||
_setupFullscreenAPI = function() {
|
||||
if(_options.fullscreenEl && !framework.features.isOldAndroid) {
|
||||
if(!_fullscrenAPI) {
|
||||
_fullscrenAPI = ui.getFullscreenAPI();
|
||||
}
|
||||
if(_fullscrenAPI) {
|
||||
framework.bind(document, _fullscrenAPI.eventK, ui.updateFullscreen);
|
||||
ui.updateFullscreen();
|
||||
framework.addClass(pswp.template, 'pswp--supports-fs');
|
||||
} else {
|
||||
framework.removeClass(pswp.template, 'pswp--supports-fs');
|
||||
}
|
||||
}
|
||||
},
|
||||
_setupLoadingIndicator = function() {
|
||||
// Setup loading indicator
|
||||
if(_options.preloaderEl) {
|
||||
|
||||
_toggleLoadingIndicator(true);
|
||||
|
||||
_listen('beforeChange', function() {
|
||||
|
||||
clearTimeout(_loadingIndicatorTimeout);
|
||||
|
||||
// display loading indicator with delay
|
||||
_loadingIndicatorTimeout = setTimeout(function() {
|
||||
|
||||
if(pswp.currItem && pswp.currItem.loading) {
|
||||
|
||||
if( !pswp.allowProgressiveImg() || (pswp.currItem.img && !pswp.currItem.img.naturalWidth) ) {
|
||||
// show preloader if progressive loading is not enabled,
|
||||
// or image width is not defined yet (because of slow connection)
|
||||
_toggleLoadingIndicator(false);
|
||||
// items-controller.js function allowProgressiveImg
|
||||
}
|
||||
|
||||
} else {
|
||||
_toggleLoadingIndicator(true); // hide preloader
|
||||
}
|
||||
|
||||
}, _options.loadingIndicatorDelay);
|
||||
|
||||
});
|
||||
_listen('imageLoadComplete', function(index, item) {
|
||||
if(pswp.currItem === item) {
|
||||
_toggleLoadingIndicator(true);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
},
|
||||
_toggleLoadingIndicator = function(hide) {
|
||||
if( _loadingIndicatorHidden !== hide ) {
|
||||
_togglePswpClass(_loadingIndicator, 'preloader--active', !hide);
|
||||
_loadingIndicatorHidden = hide;
|
||||
}
|
||||
},
|
||||
_applyNavBarGaps = function(item) {
|
||||
var gap = item.vGap;
|
||||
|
||||
if( _fitControlsInViewport() ) {
|
||||
|
||||
var bars = _options.barsSize;
|
||||
if(_options.captionEl && bars.bottom === 'auto') {
|
||||
if(!_fakeCaptionContainer) {
|
||||
_fakeCaptionContainer = framework.createEl('pswp__caption pswp__caption--fake');
|
||||
_fakeCaptionContainer.appendChild( framework.createEl('pswp__caption__center') );
|
||||
_controls.insertBefore(_fakeCaptionContainer, _captionContainer);
|
||||
framework.addClass(_controls, 'pswp__ui--fit');
|
||||
}
|
||||
if( _options.addCaptionHTMLFn(item, _fakeCaptionContainer, true) ) {
|
||||
|
||||
var captionSize = _fakeCaptionContainer.clientHeight;
|
||||
gap.bottom = parseInt(captionSize,10) || 44;
|
||||
} else {
|
||||
gap.bottom = bars.top; // if no caption, set size of bottom gap to size of top
|
||||
}
|
||||
} else {
|
||||
gap.bottom = bars.bottom === 'auto' ? 0 : bars.bottom;
|
||||
}
|
||||
|
||||
// height of top bar is static, no need to calculate it
|
||||
gap.top = bars.top;
|
||||
} else {
|
||||
gap.top = gap.bottom = 0;
|
||||
}
|
||||
},
|
||||
_setupIdle = function() {
|
||||
// Hide controls when mouse is used
|
||||
if(_options.timeToIdle) {
|
||||
_listen('mouseUsed', function() {
|
||||
|
||||
framework.bind(document, 'mousemove', _onIdleMouseMove);
|
||||
framework.bind(document, 'mouseout', _onMouseLeaveWindow);
|
||||
|
||||
_idleInterval = setInterval(function() {
|
||||
_idleIncrement++;
|
||||
if(_idleIncrement === 2) {
|
||||
ui.setIdle(true);
|
||||
}
|
||||
}, _options.timeToIdle / 2);
|
||||
});
|
||||
}
|
||||
},
|
||||
_setupHidingControlsDuringGestures = function() {
|
||||
|
||||
// Hide controls on vertical drag
|
||||
_listen('onVerticalDrag', function(now) {
|
||||
if(_controlsVisible && now < 0.95) {
|
||||
ui.hideControls();
|
||||
} else if(!_controlsVisible && now >= 0.95) {
|
||||
ui.showControls();
|
||||
}
|
||||
});
|
||||
|
||||
// Hide controls when pinching to close
|
||||
var pinchControlsHidden;
|
||||
_listen('onPinchClose' , function(now) {
|
||||
if(_controlsVisible && now < 0.9) {
|
||||
ui.hideControls();
|
||||
pinchControlsHidden = true;
|
||||
} else if(pinchControlsHidden && !_controlsVisible && now > 0.9) {
|
||||
ui.showControls();
|
||||
}
|
||||
});
|
||||
|
||||
_listen('zoomGestureEnded', function() {
|
||||
pinchControlsHidden = false;
|
||||
if(pinchControlsHidden && !_controlsVisible) {
|
||||
ui.showControls();
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
var _uiElements = [
|
||||
{
|
||||
name: 'caption',
|
||||
option: 'captionEl',
|
||||
onInit: function(el) {
|
||||
_captionContainer = el;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'share-modal',
|
||||
option: 'shareEl',
|
||||
onInit: function(el) {
|
||||
_shareModal = el;
|
||||
},
|
||||
onTap: function() {
|
||||
_toggleShareModal();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'button--share',
|
||||
option: 'shareEl',
|
||||
onInit: function(el) {
|
||||
_shareButton = el;
|
||||
},
|
||||
onTap: function() {
|
||||
_toggleShareModal();
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'button--zoom',
|
||||
option: 'zoomEl',
|
||||
onTap: pswp.toggleDesktopZoom
|
||||
},
|
||||
{
|
||||
name: 'counter',
|
||||
option: 'counterEl',
|
||||
onInit: function(el) {
|
||||
_indexIndicator = el;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'button--close',
|
||||
option: 'closeEl',
|
||||
onTap: pswp.close
|
||||
},
|
||||
{
|
||||
name: 'button--arrow--left',
|
||||
option: 'arrowEl',
|
||||
onTap: pswp.prev
|
||||
},
|
||||
{
|
||||
name: 'button--arrow--right',
|
||||
option: 'arrowEl',
|
||||
onTap: pswp.next
|
||||
},
|
||||
{
|
||||
name: 'button--fs',
|
||||
option: 'fullscreenEl',
|
||||
onTap: function() {
|
||||
if(_fullscrenAPI.isFullscreen()) {
|
||||
_fullscrenAPI.exit();
|
||||
} else {
|
||||
_fullscrenAPI.enter();
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'preloader',
|
||||
option: 'preloaderEl',
|
||||
onInit: function(el) {
|
||||
_loadingIndicator = el;
|
||||
}
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
var _setupUIElements = function() {
|
||||
var item,
|
||||
classAttr,
|
||||
uiElement;
|
||||
|
||||
var loopThroughChildElements = function(sChildren) {
|
||||
if(!sChildren) {
|
||||
return;
|
||||
}
|
||||
|
||||
var l = sChildren.length;
|
||||
for(var i = 0; i < l; i++) {
|
||||
item = sChildren[i];
|
||||
classAttr = item.className;
|
||||
|
||||
for(var a = 0; a < _uiElements.length; a++) {
|
||||
uiElement = _uiElements[a];
|
||||
|
||||
if(classAttr.indexOf('pswp__' + uiElement.name) > -1 ) {
|
||||
|
||||
if( _options[uiElement.option] ) { // if element is not disabled from options
|
||||
|
||||
framework.removeClass(item, 'pswp__element--disabled');
|
||||
if(uiElement.onInit) {
|
||||
uiElement.onInit(item);
|
||||
}
|
||||
|
||||
//item.style.display = 'block';
|
||||
} else {
|
||||
framework.addClass(item, 'pswp__element--disabled');
|
||||
//item.style.display = 'none';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
loopThroughChildElements(_controls.children);
|
||||
|
||||
var topBar = framework.getChildByClass(_controls, 'pswp__top-bar');
|
||||
if(topBar) {
|
||||
loopThroughChildElements( topBar.children );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
ui.init = function() {
|
||||
|
||||
// extend options
|
||||
framework.extend(pswp.options, _defaultUIOptions, true);
|
||||
|
||||
// create local link for fast access
|
||||
_options = pswp.options;
|
||||
|
||||
// find pswp__ui element
|
||||
_controls = framework.getChildByClass(pswp.scrollWrap, 'pswp__ui');
|
||||
|
||||
// create local link
|
||||
_listen = pswp.listen;
|
||||
|
||||
|
||||
_setupHidingControlsDuringGestures();
|
||||
|
||||
// update controls when slides change
|
||||
_listen('beforeChange', ui.update);
|
||||
|
||||
// toggle zoom on double-tap
|
||||
_listen('doubleTap', function(point) {
|
||||
var initialZoomLevel = pswp.currItem.initialZoomLevel;
|
||||
if(pswp.getZoomLevel() !== initialZoomLevel) {
|
||||
pswp.zoomTo(initialZoomLevel, point, 333);
|
||||
} else {
|
||||
pswp.zoomTo(_options.getDoubleTapZoom(false, pswp.currItem), point, 333);
|
||||
}
|
||||
});
|
||||
|
||||
// Allow text selection in caption
|
||||
_listen('preventDragEvent', function(e, isDown, preventObj) {
|
||||
var t = e.target || e.srcElement;
|
||||
if(
|
||||
t &&
|
||||
t.getAttribute('class') && e.type.indexOf('mouse') > -1 &&
|
||||
( t.getAttribute('class').indexOf('__caption') > 0 || (/(SMALL|STRONG|EM)/i).test(t.tagName) )
|
||||
) {
|
||||
preventObj.prevent = false;
|
||||
}
|
||||
});
|
||||
|
||||
// bind events for UI
|
||||
_listen('bindEvents', function() {
|
||||
framework.bind(_controls, 'pswpTap click', _onControlsTap);
|
||||
framework.bind(pswp.scrollWrap, 'pswpTap', ui.onGlobalTap);
|
||||
|
||||
if(!pswp.likelyTouchDevice) {
|
||||
framework.bind(pswp.scrollWrap, 'mouseover', ui.onMouseOver);
|
||||
}
|
||||
});
|
||||
|
||||
// unbind events for UI
|
||||
_listen('unbindEvents', function() {
|
||||
if(!_shareModalHidden) {
|
||||
_toggleShareModal();
|
||||
}
|
||||
|
||||
if(_idleInterval) {
|
||||
clearInterval(_idleInterval);
|
||||
}
|
||||
framework.unbind(document, 'mouseout', _onMouseLeaveWindow);
|
||||
framework.unbind(document, 'mousemove', _onIdleMouseMove);
|
||||
framework.unbind(_controls, 'pswpTap click', _onControlsTap);
|
||||
framework.unbind(pswp.scrollWrap, 'pswpTap', ui.onGlobalTap);
|
||||
framework.unbind(pswp.scrollWrap, 'mouseover', ui.onMouseOver);
|
||||
|
||||
if(_fullscrenAPI) {
|
||||
framework.unbind(document, _fullscrenAPI.eventK, ui.updateFullscreen);
|
||||
if(_fullscrenAPI.isFullscreen()) {
|
||||
_options.hideAnimationDuration = 0;
|
||||
_fullscrenAPI.exit();
|
||||
}
|
||||
_fullscrenAPI = null;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// clean up things when gallery is destroyed
|
||||
_listen('destroy', function() {
|
||||
if(_options.captionEl) {
|
||||
if(_fakeCaptionContainer) {
|
||||
_controls.removeChild(_fakeCaptionContainer);
|
||||
}
|
||||
framework.removeClass(_captionContainer, 'pswp__caption--empty');
|
||||
}
|
||||
|
||||
if(_shareModal) {
|
||||
_shareModal.children[0].onclick = null;
|
||||
}
|
||||
framework.removeClass(_controls, 'pswp__ui--over-close');
|
||||
framework.addClass( _controls, 'pswp__ui--hidden');
|
||||
ui.setIdle(false);
|
||||
});
|
||||
|
||||
|
||||
if(!_options.showAnimationDuration) {
|
||||
framework.removeClass( _controls, 'pswp__ui--hidden');
|
||||
}
|
||||
_listen('initialZoomIn', function() {
|
||||
if(_options.showAnimationDuration) {
|
||||
framework.removeClass( _controls, 'pswp__ui--hidden');
|
||||
}
|
||||
});
|
||||
_listen('initialZoomOut', function() {
|
||||
framework.addClass( _controls, 'pswp__ui--hidden');
|
||||
});
|
||||
|
||||
_listen('parseVerticalMargin', _applyNavBarGaps);
|
||||
|
||||
_setupUIElements();
|
||||
|
||||
if(_options.shareEl && _shareButton && _shareModal) {
|
||||
_shareModalHidden = true;
|
||||
}
|
||||
|
||||
_countNumItems();
|
||||
|
||||
_setupIdle();
|
||||
|
||||
_setupFullscreenAPI();
|
||||
|
||||
_setupLoadingIndicator();
|
||||
};
|
||||
|
||||
ui.setIdle = function(isIdle) {
|
||||
_isIdle = isIdle;
|
||||
_togglePswpClass(_controls, 'ui--idle', isIdle);
|
||||
};
|
||||
|
||||
ui.update = function() {
|
||||
// Don't update UI if it's hidden
|
||||
if(_controlsVisible && pswp.currItem) {
|
||||
|
||||
ui.updateIndexIndicator();
|
||||
|
||||
if(_options.captionEl) {
|
||||
_options.addCaptionHTMLFn(pswp.currItem, _captionContainer);
|
||||
|
||||
_togglePswpClass(_captionContainer, 'caption--empty', !pswp.currItem.title);
|
||||
}
|
||||
|
||||
_overlayUIUpdated = true;
|
||||
|
||||
} else {
|
||||
_overlayUIUpdated = false;
|
||||
}
|
||||
|
||||
if(!_shareModalHidden) {
|
||||
_toggleShareModal();
|
||||
}
|
||||
|
||||
_countNumItems();
|
||||
};
|
||||
|
||||
ui.updateFullscreen = function(e) {
|
||||
|
||||
if(e) {
|
||||
// some browsers change window scroll position during the fullscreen
|
||||
// so PhotoSwipe updates it just in case
|
||||
setTimeout(function() {
|
||||
pswp.setScrollOffset( 0, framework.getScrollY() );
|
||||
}, 50);
|
||||
}
|
||||
|
||||
// toogle pswp--fs class on root element
|
||||
framework[ (_fullscrenAPI.isFullscreen() ? 'add' : 'remove') + 'Class' ](pswp.template, 'pswp--fs');
|
||||
};
|
||||
|
||||
ui.updateIndexIndicator = function() {
|
||||
if(_options.counterEl) {
|
||||
_indexIndicator.innerHTML = (pswp.getCurrentIndex()+1) +
|
||||
_options.indexIndicatorSep +
|
||||
_options.getNumItemsFn();
|
||||
}
|
||||
};
|
||||
|
||||
ui.onGlobalTap = function(e) {
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement;
|
||||
|
||||
if(_blockControlsTap) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(e.detail && e.detail.pointerType === 'mouse') {
|
||||
|
||||
// close gallery if clicked outside of the image
|
||||
if(_hasCloseClass(target)) {
|
||||
pswp.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if(framework.hasClass(target, 'pswp__img')) {
|
||||
if(pswp.getZoomLevel() === 1 && pswp.getZoomLevel() <= pswp.currItem.fitRatio) {
|
||||
if(_options.clickToCloseNonZoomable) {
|
||||
pswp.close();
|
||||
}
|
||||
} else {
|
||||
pswp.toggleDesktopZoom(e.detail.releasePoint);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// tap anywhere (except buttons) to toggle visibility of controls
|
||||
if(_options.tapToToggleControls) {
|
||||
if(_controlsVisible) {
|
||||
ui.hideControls();
|
||||
} else {
|
||||
ui.showControls();
|
||||
}
|
||||
}
|
||||
|
||||
// tap to close gallery
|
||||
if(_options.tapToClose && (framework.hasClass(target, 'pswp__img') || _hasCloseClass(target)) ) {
|
||||
pswp.close();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
ui.onMouseOver = function(e) {
|
||||
e = e || window.event;
|
||||
var target = e.target || e.srcElement;
|
||||
|
||||
// add class when mouse is over an element that should close the gallery
|
||||
_togglePswpClass(_controls, 'ui--over-close', _hasCloseClass(target));
|
||||
};
|
||||
|
||||
ui.hideControls = function() {
|
||||
framework.addClass(_controls,'pswp__ui--hidden');
|
||||
_controlsVisible = false;
|
||||
};
|
||||
|
||||
ui.showControls = function() {
|
||||
_controlsVisible = true;
|
||||
if(!_overlayUIUpdated) {
|
||||
ui.update();
|
||||
}
|
||||
framework.removeClass(_controls,'pswp__ui--hidden');
|
||||
};
|
||||
|
||||
ui.supportsFullscreen = function() {
|
||||
var d = document;
|
||||
return !!(d.exitFullscreen || d.mozCancelFullScreen || d.webkitExitFullscreen || d.msExitFullscreen);
|
||||
};
|
||||
|
||||
ui.getFullscreenAPI = function() {
|
||||
var dE = document.documentElement,
|
||||
api,
|
||||
tF = 'fullscreenchange';
|
||||
|
||||
if (dE.requestFullscreen) {
|
||||
api = {
|
||||
enterK: 'requestFullscreen',
|
||||
exitK: 'exitFullscreen',
|
||||
elementK: 'fullscreenElement',
|
||||
eventK: tF
|
||||
};
|
||||
|
||||
} else if(dE.mozRequestFullScreen ) {
|
||||
api = {
|
||||
enterK: 'mozRequestFullScreen',
|
||||
exitK: 'mozCancelFullScreen',
|
||||
elementK: 'mozFullScreenElement',
|
||||
eventK: 'moz' + tF
|
||||
};
|
||||
|
||||
|
||||
|
||||
} else if(dE.webkitRequestFullscreen) {
|
||||
api = {
|
||||
enterK: 'webkitRequestFullscreen',
|
||||
exitK: 'webkitExitFullscreen',
|
||||
elementK: 'webkitFullscreenElement',
|
||||
eventK: 'webkit' + tF
|
||||
};
|
||||
|
||||
} else if(dE.msRequestFullscreen) {
|
||||
api = {
|
||||
enterK: 'msRequestFullscreen',
|
||||
exitK: 'msExitFullscreen',
|
||||
elementK: 'msFullscreenElement',
|
||||
eventK: 'MSFullscreenChange'
|
||||
};
|
||||
}
|
||||
|
||||
if(api) {
|
||||
api.enter = function() {
|
||||
// disable close-on-scroll in fullscreen
|
||||
_initalCloseOnScrollValue = _options.closeOnScroll;
|
||||
_options.closeOnScroll = false;
|
||||
|
||||
if(this.enterK === 'webkitRequestFullscreen') {
|
||||
pswp.template[this.enterK]( Element.ALLOW_KEYBOARD_INPUT );
|
||||
} else {
|
||||
return pswp.template[this.enterK]();
|
||||
}
|
||||
};
|
||||
api.exit = function() {
|
||||
_options.closeOnScroll = _initalCloseOnScrollValue;
|
||||
|
||||
return document[this.exitK]();
|
||||
|
||||
};
|
||||
api.isFullscreen = function() { return document[this.elementK]; };
|
||||
}
|
||||
|
||||
return api;
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
||||
return PhotoSwipeUI_Default;
|
||||
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user