/* * Plugin for stretching images and video on fullscreen *Version: 2.0; *Author: Smart; */ (function($){ $.fn.tmMultimediaGallery = function(o){ return this.each(function(){ var object = $(this), data = object.data('tmMultimediaGallery'), getObject = { startIndex: 0, // initial postion for gallery showOnInit: true, // show gallery after init autoPlayState: false, // on/off autoplay autoPlayTime: 4, // autoplay timeout alignIMG:"center", // align of image alignMode: 'fill', // mode of align 'fill' or 'fit' mouseMove: false, // use mouse move actions for images controlDisplay: false, // on/off controls display hideControlsOnClick: true, // hide controls on click or on tap event paginationDisplay: true, // on/off pagination display animationSpeed:'0.7', // speed of animation mobile: false, // if mobile resizableContainer: false, // change the size of the container on the size of the window galleryOpenClass: 'galleryOpen', // class, that adds to body when gallery is open container: '.galleryContainer', // container of gallery (window or other DOM element) imageHolder: '.imageHolder', // imageHolder selector pagination: '.inner', // pagination selector paginationItem: '.item', // pagination item outerPagination: false, // outer pagination description: '.galleryDescription', // description selector descriptionActiveClass: '.active', // active class for current description item descriptionShowClass: '.show', // show class for description holder outerNavigation: false, // outer navigation next: '.nextButton', // next button selector prev: '.prevButton', // prev button selector play: '.playButton', // play button selector pause: '.pauseButton', // pause button selector spinner: '.imgSpinner', // prev button selector backClass: '.backImg', // back class frontClass: '.frontImg', // front class animationClass: 'flip', // class for main animation animationClassSub: 'scale', // class for secondary animation noAnimationClass: '.animationDisable', // class for quick image changing onShowActions: function(){}, // actions when gallery is active onHideActions: function(){}, // actions when gallery is not active, onBeforeChange: function(){}, // actions before change image onAfterChange: function(){}, // actions after change image onShowControls: function(){}, // actions shows controls of gallery onHideControls: function(){}, // actions hide controls of gallery // constructor of plugin constructor: function (params) { if (object.length) { getObject.container = object.parents(getObject.container); getObject.imageHolder = $(getObject.imageHolder, getObject.container); if (!getObject.outerPagination) { getObject.pagination = $(getObject.pagination, getObject.container); } else { getObject.pagination = $(getObject.pagination); } getObject.description = $(getObject.description, getObject.container); getObject.descriptionActiveClass = getObject.descriptionActiveClass.substr(1); getObject.descriptionShowClass = getObject.descriptionShowClass.substr(1); if (!getObject.outerNavigation) { getObject.next = $(getObject.next, getObject.container); getObject.prev = $(getObject.prev, getObject.container); } else { getObject.next = $(getObject.next); getObject.prev = $(getObject.prev); } getObject.play = $(getObject.play, getObject.container); getObject.pause = $(getObject.pause, getObject.container); getObject.spinner = $(getObject.spinner); getObject.noAnimationClass = getObject.noAnimationClass.substr(1); var image = $("img", getObject.imageHolder), video = $("video", getObject.imageHolder), imageSRCLink = $(getObject.paginationItem + " a", getObject.pagination.eq(0)), description = $("li", getObject.description), imageDeltaX, imageDeltaY, prevImg = -1, currImg = -1, allImg = imageSRCLink.length, loadComplete = true, autoPlayTimer, dragDirection = 1, doc = $(document), win = $(window), body = $('body'), galleryActive = false, showControls = false, mouseDrag = false, mouseDown = false, msie9 = Boolean(navigator.userAgent.match(/MSIE ([9]+)\./)); getObject.startIndex = (getObject.startIndex < allImg) ? getObject.startIndex : 0; init(); } function init(){ msie9&&getObject.imageHolder.addClass('ie9'); getObject.autoPlayTime*=1000; getObject.animationSpeed = getObject.animationSpeed.replace(",", "."); getObject.spinner.removeClass('spinnerShow'); object.css({"position":"absolute", width:"100%", height:"100%", "z-index":"0"}); getObject.imageHolder.css({"position":"absolute", width:"100%", height:"100%", "z-index":0, "top":0}); if (!$(getObject.frontClass, getObject.imageHolder).length) image.wrap('
'); if (!$(getObject.backClass, getObject.imageHolder).length) getObject.imageHolder.append(''); setTimeout(function() { getObject.imageHolder.removeClass('flip90'); object.css('zIndex','0'); }, 1000); if (getObject.autoPlayState){ autoPlayHandler(); } getObject.mouseMove && init_mouse_move(); window.orientation==undefined?usedDevice = "desktop":usedDevice = "fixedOptions"; if(usedDevice != "desktop"){ window.addEventListener("orientationchange", function(){ resizeImageHandler(); }, true); } win.resize(resizeImageHandler); object.on('resize', resizeImageHandler); resizeImageHandler(); if ((!getObject.controlDisplay) || (allImg <= 1)){ getObject.next.css({display:"none"}); getObject.prev.css({display:"none"}); }else{ getObject.next.css({display:"block"}); getObject.prev.css({display:"block"}); } getObject.next.on("click", clickNext); getObject.prev.on("click", clickPrev); var id = 0; if(getObject.paginationDisplay){ $(getObject.pagination) .find(getObject.paginationItem + " a") .on('mousedown', function(){ mouseDown = true; }) .on('mouseup',function(){ clearTimeout(id); id = setTimeout(function(){ mouseDown = false; }, 10); }) .on('mousemove', function(){ mouseDrag = mouseDown; }) .on('click', clickPagination); }else{ getObject.pagination.css({display:"none"}); } // object listeners object .on('showGallery', function(e, d){ reset(); body.addClass(getObject.galleryOpenClass); if (!galleryActive){ !getObject.mobile&&videoInit(); } getObject.onShowActions(); galleryActive = true; descriptionChange(); descriptionToggle(true); resizeImageHandler(); doc.on('keydown', keyboardEvent); object.on('goTo', goTo); if (!d) { d = getObject.startIndex.toString(); } object.trigger('goTo', d); }) .on('hideGallery',function(e){ getObject.onHideActions(); body.removeClass(getObject.galleryOpenClass); videoStop(); getObject.imageHolder .removeClass('videoInside') .off('click') .children('div').removeClass('videoShow') getObject.autoPlayState = false; descriptionToggle(false); galleryActive = false; doc.off('keydown', keyboardEvent); object.off('goTo', goTo); resetCounters(); }) .on('setGalleryActivity', function(e, d){ if (d) { if (d === 'true') { galleryActive = true; } else if (d === 'false') { galleryActive = false; } } }) .on('showControls', function(e){ showControls = true; getObject.onShowControls(); }) .on('hideControls', function(e){ showControls = false; getObject.onHideControls(); }) .on('toggleControls', function(e, d){ if (d) { if (d === 'true') { object.trigger('showControls'); } else if (d === 'false') { object.trigger('hideControls'); } } }) .on('click', function(){ if (getObject.hideControlsOnClick) object.trigger('toggleControls', (showControls=!showControls).toString()); }) if ($.fn.swipe) { object .swipe({ swipeLeft:function(event, direction, distance, duration, fingerCount) { galleryActive && clickNext(); }, swipeRight:function(event, direction, distance, duration, fingerCount) { galleryActive && clickPrev(); } }); } if (getObject.showOnInit) { object.trigger('showGallery'); } else { reset(); } } // keyboard listeners function keyboardEvent(e){ if (galleryActive) { if (e.keyCode == 37) { clickPrev(); } else if (e.keyCode == 39) { clickNext(); } } } // reset couters and remove active class from pagination function resetCounters(){ currImg = prevImg = -1; $(getObject.paginationItem, getObject.pagination).removeClass('active'); } // reset actions function reset () { var img = $(getObject.imageHolder).find(getObject.frontClass + ' img, '+getObject.backClass + ' img'); img.length && img.attr('src', '').css('visibility', 'hidden'); resetCounters(); } // mouse move actions function init_mouse_move(){ /* mouse move actions */ var currTop = 0; if (!getObject.mobile) { getObject.imageHolder .on('mousemove', function(e){ if (!galleryActive) { return false; } currTop = e.pageY * ($('.frontImg>img, .backImg>img').height()-win.height()) / win.height(); $('.frontImg, .backImg', getObject.imageHolder).stop().animate({'scrollTop': currTop}, 1500); }); /* end mouse move */ } else { if ($.fn.swipe) { getObject.imageHolder .find('.frontImg, .backImg') .swipe({ swipe:function(event, direction, distance, duration, fingerCount) { if (direction == 'down') { currTop -= distance; } else if (direction == 'up'){ currTop += distance; } var h = $('.frontImg>img, .backImg>img').height(); currTop = (currTop > h) ? h : currTop; currTop = (currTop < 0) ? 0 : currTop; $('.frontImg, .backImg', getObject.imageHolder).stop().animate({'scrollTop': currTop}, 1500); } }); } } } // function for go to element (number - parameter d) function goTo(e, d, q){ if (d){ d = parseInt(d); if (getObject.pagination && getObject.pagination.find('a') && getObject.pagination.find('a').eq(d)) { getObject.pagination.find('a').eq(d).trigger('click', q); } } } // show / hide description holder function descriptionToggle(value){ if (value){ getObject.description.addClass(getObject.descriptionShowClass); } else { getObject.description.removeClass(getObject.descriptionShowClass); } } // change description function descriptionChange(){ description .stop(true) .removeClass(getObject.descriptionActiveClass) .eq(currImg) .addClass(getObject.descriptionActiveClass).end(); descriptionResize(); // .delay(500).queue(descriptionResize); } function descriptionResize(){ getObject.description.css('height', description.eq(currImg).outerHeight(true)); } // next listener function clickNext(e){ if(loadComplete){ getObject.autoPlayState = false; prevImg = currImg; currImg++; if(currImg>allImg-1){ currImg = 0; } dragDirection=1; changeImageHandler(); } return false; } // prev listener function clickPrev(e){ if(loadComplete){ getObject.autoPlayState = false; prevImg = currImg; currImg--; if(currImg<0){ currImg = allImg-1; } dragDirection=-1; changeImageHandler(); } return false; } // pagination listener function clickPagination(e, d){ if (!mouseDrag) { var index = $(this).parents(getObject.paginationItem).index(); if((index !== currImg) && loadComplete){ if (!galleryActive) { object.trigger('showGallery'); } prevImg = currImg; currImg = index; clearTimeout(autoPlayTimer); getObject.autoPlayState = false; dragDirection = prevImg