');
divTitle.addClass('divTitle');
divTitle.text(title);
_modalDialog.append(divTitle);
}
if(alt != ''){
var divAlt = $('
');
divAlt.addClass('divAlt');
divAlt.text(alt);
$('body').append(divAlt);
}
imageWidthProc = imageWidth/$(window).width()*100;
imageHeightProc = imageHeight/$(window).height()*100;
_modalDialog.css('width',imageWidthProc+'%');
_modalDialog.css('height',imageHeightProc+'%');
//var topCon = ($(window).height() -imageHeight)/2;
//var topPrec = topCon/$(window).height()*100;
var topPrec = 0;
if(_isVisibilityScroll){
topPrec = 1;
}
else{
var topCon = ($(window).height() -imageHeight)/2;
topPrec = topCon/$(window).height()*100;
}
_modalDialog.css('top',topPrec+'%');
var isAdd = false;
_containerWidth = imageWidth;
_containerHeight = imageHeight;
}
//------------------------- Zmiana obrazka ---------------------
$.showPhoto.next = function(event){
if(isRun) return false;
isRun = true;
isAdd = false;
var nextIndex = indexAct+1;
if(nextIndex >= photosAct.length) {
nextIndex = 0;
$.showPhoto.runGoTo(0,false)
}
var nextImg = photosAct[nextIndex];
photoAct = nextImg;
indexAct = nextIndex;
if(pp_settings.showScroll) $.showPhoto.runGoTo(indexAct,false)
$.showPhoto.showImg();
return false;
}
$.showPhoto.prev = function(event){
if(isRun) return false;
isRun = true;
isAdd = false;
var nextIndex = indexAct-1;
if(nextIndex < 0) nextIndex = photosAct.length-1;
var nextImg = photosAct[nextIndex];
photoAct = nextImg;
indexAct = nextIndex;
if(pp_settings.showScroll) $.showPhoto.runGoTo(indexAct,false)
$.showPhoto.showImg();
return false;
}
$.showPhoto.runGoTo = function(indx,updateImg){
if(updateImg){
if(isRun) return false;
isRun = true;
isAdd = false;
photoAct = photosAct[indx];
indexAct = indx;
$.showPhoto.showImg();
}
_divScrollImage.find('a').removeClass('selImgScA');
_divScrollImage.find('a').eq(indx).addClass('selImgScA');
if(indx*_widthScrollImg > _divScrollContent.width()/2){
var pW = indx*_widthScrollImg - _divScrollContent.width()/2;
if((pW+_widthPage) > (_endScroll)) pW = _endScroll-_divScrollContent.width();
_divScrollImage.addClass('isRun');
_divScrollImage.css('left',-pW);
$(_divScrollImage).one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
function(event) {
_divScrollImage.removeClass('isRun');
_isTarget = false;
_runScroll = false;
});
}
if(indx == 0) _divScrollImage.css('left',0);
}
$.showPhoto.showImg = function(){
var imgPreloader = $('
![]()
');
var loaded = false;
var imgDial = _modalDialog.find('img');
var srcImg = imgDial.attr('src');
var hi = imgDial.height();
var wi = imgDial.width();
imgPreloader.one("load", function() {
widthOrgImg = this.width;
heightOrgImg = this.height;
_modalDialog.css('background','#000000 url('+srcImg+') 50% 50% no-repeat');
if(wi/widthOrgImg >= hi/heightOrgImg)
_modalDialog.css('background-size','auto 100%');
else
_modalDialog.css('background-size','100% auto');
_modalDialog.find('img').remove();
$.showPhoto.fitToViewport(this.width,this.height);
}).each(function() {
if(this.complete) $(this).load();
});
imgPreloader.attr('src',photoAct.imgOrg);
/*
imgPreloader.load(function(){
if(loaded) return;
loaded = true;
widthOrgImg = this.width;
heightOrgImg = this.height;
_modalDialog.css('background','#000000 url('+srcImg+') 50% 50% no-repeat');
if(wi/widthOrgImg >= hi/heightOrgImg)
_modalDialog.css('background-size','auto 100%');
else
_modalDialog.css('background-size','100% auto');
_modalDialog.find('img').remove();
$.showPhoto.fitToViewport(this.width,this.height);
}).each(function(){
if(this.complete){
$(this).trigger('load');
}
});
*/
imgPreloader.onerror = function(){
alert('Obraz nie może być załadowany.');
$.showPhoto.close();
};
}
//-------------------- Górne ikony ------------------------------
$.showPhoto.close = function() {
$('.divAlt').remove();
_divPlay.addClass('divPause');
autoRun = false;
clearInterval(timer);
timer = '';
_divOverlay.remove();
_divTop.remove();
_modalDialog.remove();
_arrowNext.remove();
_arrowPrev.remove();
_showPhoto = false;
isRun = false;
_isVisibilityScroll = false;
if(pp_settings.showScroll) _divScrollPhoto.remove();
//$('body').css('');
$('body').removeClass('modal-open');
}
$.showPhoto.play = function() {
if(!autoRun){
autoRun = true;
_divPlay.removeClass('divPause');
$.showPhoto.next();
timer = setInterval(function () {
$.showPhoto.next();
}, pp_settings.pauseTime);
}
else{
_divPlay.addClass('divPause');
autoRun = false;
clearInterval(timer);
timer = '';
}
}
//-------------------- RESIZE ------------------------------
$.showPhoto.resizeImg = function() {
if(!_showPhoto) return;
if(isRes) return false;
isRes = false;
_modalDialog.find('img').css('max-width','100%');
_modalDialog.find('img').css('max-height','100%');
_modalDialog.find('img').css('z-index','50');
_modalDialog.find('img').removeClass('resImg');
_modalDialog.css('z-index','101');
var v = $.showPhoto.getViewportPhoto();
//console.log(pp_settings);
if(v.width <= pp_settings.mobileWidth && _isMobile != 1) {
_isMobile = 1;
pp_settings.maxWidth = 100;
pp_settings.maxHeight = 100;
_modalDialog.css('width',pp_settings.maxWidth+'%');
_modalDialog.css('height',pp_settings.maxHeight+'%');
_modalDialog.css('max-width',pp_settings.maxWidth+'%');
_modalDialog.css('max-height',pp_settings.maxHeight+'%');
}
if(v.width > pp_settings.mobileWidth && _isMobile != 2){
_isMobile = 2;
pp_settings.maxWidth = maxOrgWidth;
pp_settings.maxHeight = maxOrgHeight;
_modalDialog.css('width',pp_settings.maxWidth+'%');
_modalDialog.css('height',pp_settings.maxHeight+'%');
_modalDialog.css('max-width',pp_settings.maxWidth+'%');
_modalDialog.css('max-height',pp_settings.maxHeight+'%');
}
var widthImg = _modalDialog.find('img').width();
var widthCont = _modalDialog.width();
var heightImg = _modalDialog.find('img').height();
var heightCont = _modalDialog.height();
_modalDialog.addClass('resModal');
if(widthCont > widthImg){
$.showPhoto.fitToResize(widthImg,heightImg);
}
else if(heightCont > heightImg){
var procHeight = heightCont/heightImg;
var widthImg = widthImg*procHeight;
$.showPhoto.fitToResize(widthImg,heightCont);
}
setTimeout(function(){_modalDialog.removeClass('resModal')}, 500);
}
$.showPhoto.fitToResize = function(width,height){
var winHeight = $(window).height();
var winHeightPrec = (winHeight*pp_settings.maxHeight)/100;
var winWidth = $(window).width();
var winWidthPrec = (winWidth*pp_settings.maxWidth)/100;
var res = false;
var imageWidth = width;
var imageHeight = height;
var isRes = false;
while (!res){
if(imageWidth > winWidthPrec){
imageWidth = winWidthPrec;
imageHeight = (height/width) * imageWidth;
}else if((imageHeight > winHeightPrec)){
imageHeight = winHeightPrec;
imageWidth = (width/height) * imageHeight;
}else{
res = true;
};
}
imageWidthProc = imageWidth/$(window).width()*100;
imageHeightProc = imageHeight/$(window).height()*100;
_modalDialog.css('width',imageWidthProc+'%');
_modalDialog.css('height',imageHeightProc+'%');
_containerWidth = imageWidth;
_containerHeight = imageHeight;
var topPrec = 0;
if(_isVisibilityScroll){
topPrec = 1;
}
else{
var topCon = ($(window).height() -imageHeight)/2;
topPrec = topCon/$(window).height()*100;
}
_modalDialog.css('top',topPrec+'%');
if(winWidthPrec > imageWidth && winHeightPrec > imageHeight){
var widthImg = _modalDialog.find('img').width();
var heightImg = _modalDialog.find('img').height();
setTimeout(function(){$.showPhoto.fitToResize(widthOrgImg,heightOrgImg)}, 500);
}
isAdd = true;
isRun = false;
}
$.showPhoto.resPhoto = function(e) {
var v = $.showPhoto.getViewportPhoto();
//if(v.width<600)
//$.showPhoto.toggleFullScreen(document.body);
if(!isRes){
//_modalDialog.find('img').unbind('tap');
_modalDialog.css('width','100%');
_modalDialog.css('height','100%');
_modalDialog.css('max-width','100%');
_modalDialog.css('max-height','100%');
_modalDialog.css('top','0');
_modalDialog.css('z-index','102');
_modalDialog.find('img').css('max-width','none');
_modalDialog.find('img').css('max-height','none');
_modalDialog.find('img').css('z-index','101');
_modalDialog.find('img').addClass('resImg');
//console.log(_isEventScroll);
//if(typeof isTouch != undefined && _isEventScroll){
if(typeof isTouch != undefined){
_modalDialog.find('img').on('swipstart',$.showPhoto.updateImgStart);
_modalDialog.find('img').on('swipemove',$.showPhoto.updateImgMove);
_modalDialog.find('img').on('swipeleft',$.showPhoto.updateEndImg);
_modalDialog.find('img').on('swiperight',$.showPhoto.updateEndImg);
_modalDialog.find('img').on('swipedown',$.showPhoto.updateEndImg);
_modalDialog.find('img').on('swipeup',$.showPhoto.updateEndImg);
}
$(_modalDialog).one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
function(event) {
//$(_modalDialog).off("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend");
var imgResA = _modalDialog.find('img');
/*
var posImgRes = imgResA.position();
_startTopImg = posImgRes.top;
_startLeftImg = posImgRes.left;
*/
var posImgRes = imgResA[0].getBoundingClientRect();
_startTopImg = posImgRes.top;
_startLeftImg = posImgRes.left;
});
_divResize.addClass('resFull');
_modalDialog.find('img').css('left',0);
_modalDialog.find('img').css('right',0);
isRes = true;
}
else{
isRes = false;
_divResize.removeClass('resFull');
_modalDialog.find('img').css('top',0);
_modalDialog.find('img').css('left',0);
_modalDialog.find('img').css('right',0);
_startTopImg = 0;
_startLeftImg = 0;
_modalDialog.find('img').off('swipstart',$.showPhoto.updateImgStart);
_modalDialog.find('img').off('swipemove',$.showPhoto.updateImgMove);
_modalDialog.find('img').off('swipeleft',$.showPhoto.updateEndImg);
_modalDialog.find('img').off('swiperight',$.showPhoto.updateEndImg);
_modalDialog.find('img').off('swipedown',$.showPhoto.updateEndImg);
_modalDialog.find('img').off('swipeup',$.showPhoto.updateEndImg);
$.showPhoto.resizeImg();
}
return false;
}
$.showPhoto.toggleFullScreen = function(elem){
if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
if (elem.requestFullScreen) {
elem.requestFullScreen();
} else if (elem.mozRequestFullScreen) {
elem.mozRequestFullScreen();
} else if (elem.webkitRequestFullScreen) {
elem.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
}
//---------------------- Obrazek drag drop ----------------------------------
$.showPhoto.updateImgStart = function(e,parameters){
if(_runPhoto) return false;
var target = e.target;
$(e.target).parent().on('dragstart',function(e){e.preventDefault()});
if((_modalDialog.find('img'))[0] == target){
_isTargetImg = true;
}
else{
$(e.target).parents().each(function(){
if(this == (_modalDialog.find('img'))[0]){
_isTargetImg = true;
return false;
}
});
}
if(_isTargetImg){
_runPhoto = true;
}
var imgResA = _modalDialog.find('img');
//var posImgResY = imgResA.position();
//var posImgResX = imgResA.offset();
var posImgRes = imgResA[0].getBoundingClientRect();
_startTopImg = posImgRes.top;
_startLeftImg = posImgRes.left;
//e.preventDefault();
//return false;
}
$.showPhoto.updateImgMove = function(e,parameters){
if(!_isTargetImg) return false;
if(!_runPhoto) return false;
_moveImg = true;
//var dist = _startScroll-parameters.distance.dX;
var distX = _startLeftImg-parameters.distance.dX;
var distY = _startTopImg-parameters.distance.dY;
_modalDialog.find('img').css('right','auto');
_modalDialog.find('img').css('left',distX);
_modalDialog.find('img').css('top',distY);
//e.preventDefault();
//return false;
}
$.showPhoto.updateEndImg = function(e,parameters){
if(!_isTargetImg) return false;
if(!_runPhoto) return false;
_startTopImg = 0;
_startLeftImg = 0;
_moveImg = false;
_runPhoto = false;
e.preventDefault();
return false;
}
//------------------------ scroll Photo ------------------------------------
$.showPhoto.addScrollPhoto = function(){
_divScrollPhoto = $('
');
_divScrollPhoto.addClass('divScrollPhoto');
var divScrollArrow = $('
');
divScrollArrow.addClass('divScrollArrow');
_divScrollContent = $('
');
_divScrollContent.addClass('divScrollContent');
_divScrollPhoto.append(divScrollArrow);
_divScrollPhoto.append(_divScrollContent);
$('body').append(_divScrollPhoto);
divScrollArrow.on('click',function(){
var bottomSc = parseInt($(this).parent().css('bottom'));
var heightSc = $(this).parent().height();
if(bottomSc == 0){
_isVisibilityScroll = false;
$(this).removeClass('selScArrow');
$(this).parent().css('bottom',-heightSc);
}
else{
_isVisibilityScroll = true;
$(this).addClass('selScArrow');
$(this).parent().css('bottom',0);
_divScrollImage.find('img').each(function(){
$(this).attr('src',$(this).data('orgImg'));
})
}
$.showPhoto.fitToResize(widthOrgImg,heightOrgImg);
})
_widthScrollImg = _divScrollContent.height();
_heightScrollImg = _divScrollContent.height();
_endScroll = photosAct.length*_widthScrollImg;
_divScrollImage = $('
');
_divScrollImage.addClass('divScrollImage');
_divScrollImage.css('width',_endScroll);
_divScrollImage.css('height',_heightScrollImg);
$(photosAct).each(function(index){
var imgScA = $('
');
imgScA.attr('href','#empty-anchor');
imgScA.addClass('imgScA');
imgScA.css('width',_widthScrollImg);
imgScA.css('height',_heightScrollImg);
if(indexAct == index){
imgScA.addClass('selImgScA');
}
imgScA.on('mouseup',function(event){
if(!_moveScroll){
autoRun = true;
_divPlay.trigger('click');
$.showPhoto.runGoTo($(this).index(),true);
//_moveScroll = false;
//event.preventDefault();
//return false;
}
})
/*
imgAddPreloader.on('mouseup',function(event){
if(!_moveImg){
autoRun = true;
_divPlay.trigger('click');
$.showPhoto.resPhoto(event);
}
});
*/
var imgOrg = this.imgOrg;
var tabPImg = imgOrg.split('/');
var reg = /image([0-9]+)x([0-9]+)/;
for(i=0;i');
imgScSpan.addClass('imgScSpan');
imgScSpan.attr('src','/images/bg_lazy_load.jpg');
imgScSpan.data('orgImg',imgOrg);
imgScA.append(imgScSpan);
_divScrollImage.append(imgScA);
})
_divScrollContent.append(_divScrollImage);
_widthScrollImage = _divScrollImage.width();
$.showPhoto.runGoTo(indexAct,false)
//console.log(_divScrollImage);
if(_widthScrollImage <= _divScrollContent.width()){
_isEventScroll = false;
_divScrollImage.addClass('noEvent');
}
if(typeof isTouch != undefined && _isEventScroll){
$(_divScrollImage).on('swipstart',$.showPhoto.updatePhotoStart);
$(_divScrollImage).on('swipemove',$.showPhoto.updatePhotoMove);
$(_divScrollImage).on('swipeleft',$.showPhoto.updatePhotoLeft);
$(_divScrollImage).on('swiperight',$.showPhoto.updatePhotoRight);
}
}
//---------------------- Scroll drag drop ----------------------------------
$.showPhoto.updatePhotoStart = function(e,parameters){
if(_runScroll) return false;
var target = e.target;
$(e.target).parent().on('dragstart',function(e){e.preventDefault()});
if(_divScrollImage[0] == target){
_isTarget = true;
}
else{
$(e.target).parents().each(function(){
if(this == _divScrollImage[0]){
_isTarget = true;
return false;
}
});
}
if(_isTarget){
_widthPage = _divScrollContent.width();
_runScroll = true;
_startScroll = parseInt(_divScrollImage.css('left'));
}
}
$.showPhoto.updatePhotoMove = function(e,parameters){
if(!_isTarget) return false;
if(!_runScroll) return false;
var dist = _startScroll-parameters.distance.dX;
var leftUl = parseInt(_divScrollImage.css('left'));
if(leftUl > _widthScrollImg) return false;
if(Math.abs(leftUl)+_widthPage > (_endScroll+_widthScrollImg)) return false;
_moveScroll = true;
_divScrollImage.css('left',_startScroll-parameters.distance.dX);
}
$.showPhoto.updatePhotoRight = function(e,parameters){
if(!_runScroll) return false;
if(!_isTarget) return false;
var leftUl = parseInt(_divScrollImage.css('left'));
var absLeftUl = Math.abs(leftUl);
var dist = Math.ceil(parameters.distance.x/_widthScrollImg);
var distPx = dist*_widthScrollImg;
var przesun = _startScroll+distPx;
if(przesun>=0) przesun = 0;
_divScrollImage.css('left',przesun);
_divScrollImage.addClass('isRun');
$(_divScrollImage).one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
function(event) {
_divScrollImage.removeClass('isRun');
_isTarget = false;
_runScroll = false;
_moveScroll = false;
});
}
$.showPhoto.updatePhotoLeft = function(e,parameters){
if(!_runScroll) return false;
if(!_isTarget) return false;
var leftUl = parseInt(_divScrollImage.css('left'));
var absLeftUl = Math.abs(leftUl);
var dist = Math.ceil(parameters.distance.x/_widthScrollImg);
var distPx = dist*_widthScrollImg;
var przesun = _startScroll-distPx;
if((absLeftUl+_widthPage) > (_endScroll)) przesun = -(_endScroll-_divScrollContent.width());
_divScrollImage.css('left',przesun);
_divScrollImage.addClass('isRun');
$(_divScrollImage).one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend",
function(event) {
_divScrollImage.removeClass('isRun');
_isTarget = false;
_runScroll = false;
_moveScroll = false;
});
}
//----------------------------------------------------------------------------
$(window).on(function(){
$(window).on('resize', function(){
$.showPhoto.resizeImg();
});
});
$.showPhoto.getViewportPhoto = function(){return{width:window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,height:window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight}};
$.showPhoto.initialize();
};
function closePhoto(){
$.showPhoto.close();
}
function _get_scroll(){
if($(window).height() <= $(document).height()) return true;
else return false;
};
})(jQuery);
$(function(){
$('.gallery').showPhoto({joinImage:true,showScroll:true,autoRun:false,pauseTime:3000});
});