Показать сообщение отдельно
  #4 (permalink)  
Старый 05.06.2018, 09:38
Новичок на форуме
Отправить личное сообщение для spik Посмотреть профиль Найти все сообщения от spik
 
Регистрация: 05.06.2018
Сообщений: 6

Листинг кода 2
/**
			 * Check if CSS transitions are allowed (options + devicesupport)
			 */
			doCssTrans : function () {
				if ( plugin.settings.useCSS && this.supportTransition() ) {
					return true;
				}
			},

			/**
			 * Touch navigation
			 */
			gesture : function () {
		
				var $this = this,
				dist = 0,
				vid = 1,
				distX = 0,
				distY = 0,
				zoomst = 0,
				zoom = 0,
				scale = 1.0,
					distance = null,
					vDistance = null,
					vSwipe = false,
					swipMinDistance = 50,
					vSwipMinDistance = 150,
					startCoords = {},
					endCoords = {},
					bars = $( '#swipebox-caption, #swipebox-action, #art-kn-slide-close, #art-kn-slide-tel-a' ),
					slider = $( '#swipebox-slider' );
					
				bars.addClass( 'visible-bars' );
				$this.setTimeout();
	
				$( 'body' ).bind( 'touchstart', function( event ) {							
					$( this ).addClass( 'touching' );
					endCoords = event.originalEvent.targetTouches[0];
					startCoords.pageX = event.originalEvent.targetTouches[0].pageX;
					startCoords.pageY = event.originalEvent.targetTouches[0].pageY;
	
					$( '.touching' ).bind("gesturestart gesturechange gestureend", function(event){	
						event.preventDefault();
						event.stopPropagation();
			var scale = event.originalEvent.scale;
	if (scale < 1.0) {
		vid=0;
    } else if (scale > 1.0) {
		vid=0;
    } else {
		vid=1;
	}
				});
				$( '.touching' ).bind( 'touchmove',function( event ) {
						event.preventDefault();
						event.stopPropagation();
						endCoords = event.originalEvent.targetTouches[0];
						if ( plugin.settings.closeBySwipe ) {
							vDistance = endCoords.pageY - startCoords.pageY;
							if ( Math.abs( vDistance ) >= vSwipMinDistance || vSwipe ) {
								var opacity = 0.75 - Math.abs(vDistance) / slider.height();

								slider.css( { 'top': vDistance + 'px' } );
								slider.css( { 'opacity': opacity } );

								vSwipe = true;
							}
						}
						if (event.originalEvent.targetTouches[0].pageY > startCoords.pageY) {
						distY=event.originalEvent.targetTouches[0].pageY-startCoords.pageY;
						} else {
						distY=startCoords.pageY-event.originalEvent.targetTouches[0].pageY;
						}
						if (event.originalEvent.targetTouches[0].pageX > startCoords.pageX) {
						distX=event.originalEvent.targetTouches[0].pageX-startCoords.pageX;
						} else {
						distX=startCoords.pageX-event.originalEvent.targetTouches[0].pageX;
						}
					} );
				
					return false;
						
				} ).bind( 'touchend',function( event ) {
					event.preventDefault();
					event.stopPropagation();	
					if ( plugin.settings.closeBySwipe ) {
						if ( slider.css( 'opacity' ) <= 0.5) {
							var vOffset = vDistance > 0 ? slider.height() : - slider.height();
							slider.animate( { top: vOffset + 'px', 'opacity': 0 },
								300,
								function () {
									$this.closeSlide();
								} );
						} else {
							slider.animate( { top: 0, 'opacity': 1 }, 300 );
						}

						if ( vSwipe ) {
							vSwipe = false;
							return;
						}
					}
				
					distance = endCoords.pageX - startCoords.pageX;
						if (vid==1) {
					if ( distance >= swipMinDistance ) {
						
						// swipeLeft
						$this.getPrev();
					
					} else if ( distance <= - swipMinDistance ) {
						
						// swipeRight
						$this.getNext();

					} else {
						// tap
						if ( ! bars.hasClass( 'visible-bars' ) ) {
							$this.showBars();
							$this.setTimeout();
						} else {
							$this.clearTimeout();
							$this.hideBars();
						}
					}
				}
					$( '.touching' ).off( 'touchmove' ).removeClass( 'touching' );
						
				} );

			},

			/**
			 * Set timer to hide the action bars
			 */
			setTimeout: function () {
				if ( plugin.settings.hideBarsDelay > 0 ) {
					var $this = this;
					$this.clearTimeout();
					$this.timeout = window.setTimeout( function() {
							$this.hideBars();
						},
						
						plugin.settings.hideBarsDelay
					);
				}
			},
			
			/**
			 * Clear timer
			 */
			clearTimeout: function () {
				window.clearTimeout( this.timeout );
				this.timeout = null;
			},

			
			/**
			 * Show navigation and title bars
			 */
			showBars : function () {
				var bars = $( '#swipebox-caption, #swipebox-action, #art-kn-slide-close, #art-kn-slide-tel-a' );
				if ( this.doCssTrans() ) {
					bars.addClass( 'visible-bars' );
				} else {
					$( '#swipebox-caption' ).animate( { top : 0 }, 500 );
					$( '#swipebox-action' ).animate( { bottom : 0 }, 500 );
					$( '#art-kn-slide-close' ).animate( { top : 0 }, 1500 );
				$( '#art-kn-slide-tel-a' ).animate( { bottom : '-50px' }, 500 );
					setTimeout( function() {
						bars.addClass( 'visible-bars' );
					}, 1000 );
				}
			},

			/**
			 * Hide navigation and title bars
			 */
			hideBars : function () {
				var bars = $( '#swipebox-caption, #swipebox-action, #art-kn-slide-close, #art-kn-slide-tel-a' );
				if ( this.doCssTrans() ) {
					bars.removeClass( 'visible-bars' );
				} else {
					$( '#swipebox-caption' ).animate( { top : '-50px' }, 500 );
					$( '#swipebox-action' ).animate( { bottom : '-50px' }, 500 );
					$( '#art-kn-slide-close' ).animate( { top : '-50px' }, 1500 );
					$( '#art-kn-slide-tel-a' ).animate( { bottom : 0 }, 500 );
					setTimeout( function() {
						bars.removeClass( 'visible-bars' );
					}, 1000 );
				}
			},

			/**
			 * Animate navigation and top bars
			 */
			animBars : function () {
				var $this = this,
					bars = $( '#swipebox-caption, #swipebox-action, #art-kn-slide-tel-a, #art-kn-slide-close' );
					
				bars.addClass( 'visible-bars' );
				$this.setTimeout();
				
				$( '#swipebox-slider' ).click( function() {
					if ( ! bars.hasClass( 'visible-bars' ) ) {
						$this.showBars();
						//$this.setTimeout();
					} else { bars.removeClass( 'visible-bars' ); }
				} );

				$( '#swipebox-action' ).hover( function() {
					$this.showBars();
					bars.addClass( 'visible-bars' );
					$this.clearTimeout();
				
					}, function() {
						bars.removeClass( 'visible-bars' );
						$this.setTimeout();

					} );

			},

			/**
			 * Keyboard navigation
			 */
			keyboard : function () {
				var $this = this;
				$( window ).bind( 'keyup', function( event ) {
					event.preventDefault();
					event.stopPropagation();
					
					if ( event.keyCode === 37 ) {
						
						$this.getPrev();
					
					} else if ( event.keyCode === 39 ) {
						
						$this.getNext();
					
					} else if ( event.keyCode === 27 ) {
						
						$this.closeSlide();
					
					}
				} );
			},

			/**
			 * Navigation events : go to next slide, go to prevous slide and close
			 */
			actions : function () {	
	
				var $this = this,
					action = 'touchend click'; // Just detect for both event types to allow for multi-input
			
				if ( elements.length < 2 ) {
					
					$( '.slide-kn-next, .slide-kn-prev' ).hide();
					
				} else {
					$( '.slide-kn-prev' ).bind( action, function( event ) {
						event.preventDefault();
						event.stopPropagation();
						$this.getPrev();
						$this.setTimeout();
					} );
					
					$( '.slide-kn-next' ).bind( action, function( event ) {
						event.preventDefault();
						event.stopPropagation();
						$this.getNext();
						$this.setTimeout();
					} );
				}
				
				$( '.art-slide-zakrit' ).bind( action, function() {
					$this.closeSlide();
	return false;
				} );	  
	

		if ( elements.length < 2 ) {
					$( '.slide-kn-next, .slide-kn-prev' ).hide();
					
				}
				
			},
			
			/**
			 * Set current slide
			 */
			setSlide : function ( index, isFirst ) {
				isFirst = isFirst || false;
				
				var slider = $( '#swipebox-slider' );
				
				if ( this.doCssTrans() ) {
					slider.css( { left : ( -index*100 )+'%' } );
				} else {
					slider.animate( { left : ( -index*100 )+'%' } );
				}
				
				$( '#swipebox-slider .slide' ).removeClass( 'current' );
				$( '#swipebox-slider .slide' ).eq( index ).addClass( 'current' );
				this.setTitle( index );

				if ( isFirst ) {
					slider.fadeIn();
				}

				$( '#art-kn-slide-next, #art-kn-slide-prev, #swipebox-prev, #swipebox-next' ).removeClass( 'disabled' );
				
				if ( index === 0 ) {
					$( '.slide-kn-prev' ).addClass( 'disabled' );
				} else if ( index === elements.length - 1 ) {
					$( '.slide-kn-next' ).addClass( 'disabled' );
				}
			},
		
			/**
			 * Open slide
			 */
			openSlide : function ( index ) {
				$( 'html' ).addClass( 'swipebox-html' );
				if ( isTouch ) {
					$( 'html' ).addClass( 'swipebox-touch' );
				}
				$( window ).trigger( 'resize' ); // fix scroll bar visibility on desktop
				this.setSlide( index, true );	
			},
		
			/**
			 * Set a time out if the media is a video
			 */
			preloadMedia : function ( index ) {
				var $this = this,
					src = null;

				if ( elements[index] !== undefined ) {
					src = elements[index].href;
				}

				if ( ! $this.isVideo( src ) ) {
					setTimeout( function() {
						$this.openMedia( index );
					}, 1000);
				} else {
					$this.openMedia( index );
				}
			},
Ответить с цитированием