' ).text( current.data( 'title' ) ).html() ) {
$( '.jp-carousel-titleanddesc-title' ).fadeOut( 'fast' ).empty();
}
if ( captionHtml === $( '
' ).text( current.data( 'desc' ) ).html() ) {
$( '.jp-carousel-titleanddesc-desc' ).fadeOut( 'fast' ).empty();
}
caption.html( current.data( 'caption' ) ).fadeIn( 'slow' );
} else {
caption.fadeOut( 'fast' ).empty();
}
// Record pageview in WP Stats, for each new image loaded full-screen.
if ( jetpackCarouselStrings.stats ) {
new Image().src = document.location.protocol +
'//pixel.wp.com/g.gif?' +
jetpackCarouselStrings.stats +
'&post=' + encodeURIComponent( attachmentId ) +
'&rand=' + Math.random();
}
// Load the images for the next and previous slides.
$( next ).add( previous ).each( function() {
gallery.jp_carousel( 'loadFullImage', $( this ) );
});
window.location.hash = last_known_location_hash = '#jp-carousel-' + attachmentId;
},
slides : function(){
return this.find('.jp-carousel-slide');
},
slideDimensions : function(){
return {
width: $(window).width() - (screenPadding * 2),
height: Math.floor( $(window).height() / 100 * proportion - 60 )
};
},
loadSlide : function() {
return this.each(function(){
var slide = $(this);
slide.find('img')
.one('load', function(){
// set the width/height of the image if it's too big
slide
.jp_carousel('fitSlide',false);
});
});
},
bestFit : function(){
var max = gallery.jp_carousel('slideDimensions'),
orig = this.jp_carousel('originalDimensions'),
orig_ratio = orig.width / orig.height,
w_ratio = 1,
h_ratio = 1,
width, height;
if ( orig.width > max.width ) {
w_ratio = max.width / orig.width;
}
if ( orig.height > max.height ) {
h_ratio = max.height / orig.height;
}
if ( w_ratio < h_ratio ) {
width = max.width;
height = Math.floor( width / orig_ratio );
} else if ( h_ratio < w_ratio ) {
height = max.height;
width = Math.floor( height * orig_ratio );
} else {
width = orig.width;
height = orig.height;
}
return {
width: width,
height: height
};
},
fitInfo : function(/*animated*/){
var current = this.jp_carousel('selectedSlide'),
size = current.jp_carousel('bestFit');
photo_info.css({
'left' : Math.floor( (info.width() - size.width) * 0.5 ),
'width' : Math.floor( size.width )
});
return this;
},
fitMeta : function(animated){
var newInfoTop = { top: Math.floor( $(window).height() / 100 * proportion + 5 ) + 'px' };
var newLeftWidth = { width: ( info.width() - (imageMeta.width() + 80) ) + 'px' };
if (animated) {
info.animate(newInfoTop);
leftColWrapper.animate(newLeftWidth);
} else {
info.animate(newInfoTop);
leftColWrapper.css(newLeftWidth);
}
},
fitSlide : function(/*animated*/){
return this.each(function(){
var $this = $(this),
dimensions = $this.jp_carousel('bestFit'),
method = 'css',
max = gallery.jp_carousel('slideDimensions');
dimensions.left = 0;
dimensions.top = Math.floor( (max.height - dimensions.height) * 0.5 ) + 40;
$this[method](dimensions);
});
},
texturize : function(text) {
text = '' + text; // make sure we get a string. Title "1" came in as int 1, for example, which did not support .replace().
text = text.replace(/'/g, '’').replace(/'/g, '’').replace(/[\u2019]/g, '’');
text = text.replace(/"/g, '”').replace(/"/g, '”').replace(/"/g, '”').replace(/[\u201D]/g, '”');
text = text.replace(/([\w]+)=&#[\d]+;(.+?)&#[\d]+;/g, '$1="$2"'); // untexturize allowed HTML tags params double-quotes
return $.trim(text);
},
initSlides : function(items, start_index){
if ( items.length < 2 ) {
$( '.jp-carousel-next-button, .jp-carousel-previous-button' ).hide();
} else {
$( '.jp-carousel-next-button, .jp-carousel-previous-button' ).show();
}
// Calculate the new src.
items.each(function(/*i*/){
var src_item = $(this),
orig_size = src_item.data('orig-size') || '',
max = gallery.jp_carousel('slideDimensions'),
parts = orig_size.split(','),
medium_file = src_item.data('medium-file') || '',
large_file = src_item.data('large-file') || '',
src;
orig_size = {width: parseInt(parts[0], 10), height: parseInt(parts[1], 10)};
src = src_item.data('orig-file');
src = gallery.jp_carousel('selectBestImageSize', {
orig_file : src,
orig_width : orig_size.width,
orig_height : orig_size.height,
max_width : max.width,
max_height : max.height,
medium_file : medium_file,
large_file : large_file
});
// Set the final src
$(this).data( 'gallery-src', src );
});
// If the start_index is not 0 then preload the clicked image first.
if ( 0 !== start_index ) {
$('
![]()
')[0].src = $(items[start_index]).data('gallery-src');
}
var useInPageThumbnails = items.first().closest( '.tiled-gallery.type-rectangular' ).length > 0;
// create the 'slide'
items.each(function(i){
var src_item = $(this),
attachment_id = src_item.data('attachment-id') || 0,
comments_opened = src_item.data('comments-opened') || 0,
image_meta = src_item.data('image-meta') || {},
orig_size = src_item.data('orig-size') || '',
thumb_size = { width : src_item[0].naturalWidth, height : src_item[0].naturalHeight },
title = src_item.data('image-title') || '',
description = src_item.data('image-description') || '',
caption = src_item.parents('.gallery-item').find('.gallery-caption').html() || '',
src = src_item.data('gallery-src') || '',
medium_file = src_item.data('medium-file') || '',
large_file = src_item.data('large-file') || '',
orig_file = src_item.data('orig-file') || '';
var tiledCaption = src_item.parents('div.tiled-gallery-item').find('div.tiled-gallery-caption').html();
if ( tiledCaption ) {
caption = tiledCaption;
}
if ( attachment_id && orig_size.length ) {
title = gallery.jp_carousel('texturize', title);
description = gallery.jp_carousel('texturize', description);
caption = gallery.jp_carousel('texturize', caption);
// Initially, the image is a 1x1 transparent gif. The preview is shown as a background image on the slide itself.
var image = $( '
![]()
' )
.attr( 'src', 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7' )
.css( 'width', '100%' )
.css( 'height', '100%' );
var slide = $('
')
.hide()
.css({
//'position' : 'fixed',
'left' : i < start_index ? -1000 : gallery.width()
})
.append( image )
.appendTo(gallery)
.data('src', src )
.data('title', title)
.data('desc', description)
.data('caption', caption)
.data('attachment-id', attachment_id)
.data('permalink', src_item.parents('a').attr('href'))
.data('orig-size', orig_size)
.data('comments-opened', comments_opened)
.data('image-meta', image_meta)
.data('medium-file', medium_file)
.data('large-file', large_file)
.data('orig-file', orig_file)
.data('thumb-size', thumb_size)
;
if ( useInPageThumbnails ) {
// Use the image already loaded in the gallery as a preview.
slide
.data( 'preview-image', src_item.attr( 'src' ) )
.css( {
'background-image' : 'url("' + src_item.attr( 'src' ) + '")',
'background-size' : '100% 100%',
'background-position' : 'center center'
} );
}
slide.jp_carousel( 'fitSlide', false );
}
});
return this;
},
selectBestImageSize: function(args) {
if ( 'object' !== typeof args ) {
args = {};
}
if ( 'undefined' === typeof args.orig_file ) {
return '';
}
if ( 'undefined' === typeof args.orig_width || 'undefined' === typeof args.max_width ) {
return args.orig_file;
}
if ( 'undefined' === typeof args.medium_file || 'undefined' === typeof args.large_file ) {
return args.orig_file;
}
// Check if the image is being served by Photon (using a regular expression on the hostname).
var imageLinkParser = document.createElement( 'a' );
imageLinkParser.href = args.large_file;
var isPhotonUrl = ( imageLinkParser.hostname.match( /^i[\d]{1}.wp.com$/i ) != null );
var medium_size_parts = gallery.jp_carousel( 'getImageSizeParts', args.medium_file, args.orig_width, isPhotonUrl );
var large_size_parts = gallery.jp_carousel( 'getImageSizeParts', args.large_file, args.orig_width, isPhotonUrl );
var large_width = parseInt( large_size_parts[0], 10 ),
large_height = parseInt( large_size_parts[1], 10 ),
medium_width = parseInt( medium_size_parts[0], 10 ),
medium_height = parseInt( medium_size_parts[1], 10 );
// Assign max width and height.
args.orig_max_width = args.max_width;
args.orig_max_height = args.max_height;
// Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android phones = 1.5, etc)
if ( 'undefined' !== typeof window.devicePixelRatio && window.devicePixelRatio > 1 ) {
args.max_width = args.max_width * window.devicePixelRatio;
args.max_height = args.max_height * window.devicePixelRatio;
}
if ( large_width >= args.max_width || large_height >= args.max_height ) {
return args.large_file;
}
if ( medium_width >= args.max_width || medium_height >= args.max_height ) {
return args.medium_file;
}
if ( isPhotonUrl ) {
// args.orig_file doesn't point to a Photon url, so in this case we use args.large_file
// to return the photon url of the original image.
var largeFileIndex = args.large_file.lastIndexOf( '?' );
var origPhotonUrl = args.large_file;
if ( -1 !== largeFileIndex ) {
origPhotonUrl = args.large_file.substring( 0, largeFileIndex );
// If we have a really large image load a smaller version
// that is closer to the viewable size
if ( args.orig_width > args.max_width || args.orig_height > args.max_height ) {
origPhotonUrl += '?fit=' + args.orig_max_width + '%2C' + args.orig_max_height;
}
}
return origPhotonUrl;
}
return args.orig_file;
},
getImageSizeParts: function( file, orig_width, isPhotonUrl ) {
var size = isPhotonUrl ?
file.replace( /.*=([\d]+%2C[\d]+).*$/, '$1' ) :
file.replace( /.*-([\d]+x[\d]+)\..+$/, '$1' );
var size_parts = ( size !== file ) ?
( isPhotonUrl ? size.split( '%2C' ) : size.split( 'x' ) ) :
[ orig_width, 0 ];
// If one of the dimensions is set to 9999, then the actual value of that dimension can't be retrieved from the url.
// In that case, we set the value to 0.
if ( '9999' === size_parts[0] ) {
size_parts[0] = '0';
}
if ( '9999' === size_parts[1] ) {
size_parts[1] = '0';
}
return size_parts;
},
originalDimensions: function() {
var splitted = $(this).data('orig-size').split(',');
return {width: parseInt(splitted[0], 10), height: parseInt(splitted[1], 10)};
},
format: function( args ) {
if ( 'object' !== typeof args ) {
args = {};
}
if ( ! args.text || 'undefined' === typeof args.text ) {
return;
}
if ( ! args.replacements || 'undefined' === typeof args.replacements ) {
return args.text;
}
return args.text.replace(/{(\d+)}/g, function( match, number ) {
return typeof args.replacements[number] !== 'undefined' ? args.replacements[number] : match;
});
},
/**
* Returns a number in a fraction format that represents the shutter speed.
* @param Number speed
* @return String
*/
shutterSpeed: function( speed ) {
var denominator;
// round to one decimal if value > 1s by multiplying it by 10, rounding, then dividing by 10 again
if ( speed >= 1 ) {
return Math.round( speed * 10 ) / 10 + 's';
}
// If the speed is less than one, we find the denominator by inverting
// the number. Since cameras usually use rational numbers as shutter
// speeds, we should get a nice round number. Or close to one in cases
// like 1/30. So we round it.
denominator = Math.round( 1 / speed );
return '1/' + denominator + 's';
},
parseTitleDesc: function( value ) {
if ( !value.match(' ') && value.match('_') ) {
return '';
}
// Prefix list originally based on http://commons.wikimedia.org/wiki/MediaWiki:Filename-prefix-blacklist
$([
'CIMG', // Casio
'DSC_', // Nikon
'DSCF', // Fuji
'DSCN', // Nikon
'DUW', // some mobile phones
'GEDC', // GE
'IMG', // generic
'JD', // Jenoptik
'MGP', // Pentax
'PICT', // misc.
'Imagen', // misc.
'Foto', // misc.
'DSC', // misc.
'Scan', // Scanners
'SANY', // Sanyo
'SAM', // Samsung
'Screen Shot [0-9]+' // Mac screenshots
])
.each(function(key, val){
var regex = new RegExp('^' + val);
if ( regex.test(value) ) {
value = '';
return;
}
});
return value;
},
getTitleDesc: function( data ) {
var title ='', desc = '', markup = '', target;
target = $( 'div.jp-carousel-titleanddesc', 'div.jp-carousel-wrap' );
target.hide();
title = gallery.jp_carousel('parseTitleDesc', data.title) || '';
desc = gallery.jp_carousel('parseTitleDesc', data.desc) || '';
if ( title.length || desc.length ) {
// Convert from HTML to plain text (including HTML entities decode, etc)
if ( $('
').html( title ).text() === $('
').html( desc ).text() ) {
title = '';
}
markup = ( title.length ) ? '
' + title + '
' : '';
markup += ( desc.length ) ? '
' + desc + '
' : '';
target.html( markup ).fadeIn('slow');
}
$( 'div#jp-carousel-comment-form-container' ).css('margin-top', '20px');
$( 'div#jp-carousel-comments-loading' ).css('margin-top', '20px');
},
// updateExif updates the contents of the exif UL (.jp-carousel-image-exif)
updateExif: function( meta ) {
if ( !meta || 1 !== Number( jetpackCarouselStrings.display_exif ) ) {
return false;
}
var $ul = $( '
' );
$.each( meta, function( key, val ) {
if ( 0 === parseFloat(val) || !val.length || -1 === $.inArray( key, $.makeArray( jetpackCarouselStrings.meta_data ) ) ) {
return;
}
switch( key ) {
case 'focal_length':
val = val + 'mm';
break;
case 'shutter_speed':
val = gallery.jp_carousel('shutterSpeed', val);
break;
case 'aperture':
val = 'f/' + val;
break;
}
$ul.append( '
' + jetpackCarouselStrings[key] + '
' + val + '' );
});
// Update (replace) the content of the ul
$( 'div.jp-carousel-image-meta ul.jp-carousel-image-exif' ).replaceWith( $ul );
},
// updateFullSizeLink updates the contents of the jp-carousel-image-download link
updateFullSizeLink: function(current) {
if(!current || !current.data) {
return false;
}
var original,
origSize = current.data('orig-size').split(',' ),
imageLinkParser = document.createElement( 'a' );
imageLinkParser.href = current.data( 'src' ).replace( /\?.+$/, '' );
// Is this a Photon URL?
if ( imageLinkParser.hostname.match( /^i[\d]{1}.wp.com$/i ) !== null ) {
original = imageLinkParser.href;
} else {
original = current.data('orig-file').replace(/\?.+$/, '');
}
var permalink = $( '
'+gallery.jp_carousel('format', {'text': jetpackCarouselStrings.download_original, 'replacements': origSize})+'' )
.addClass( 'jp-carousel-image-download' )
.attr( 'href', original )
.attr( 'target', '_blank' );
// Update (replace) the content of the anchor
$( 'div.jp-carousel-image-meta a.jp-carousel-image-download' ).replaceWith( permalink );
},
updateMap: function( meta ) {
if ( !meta.latitude || !meta.longitude || 1 !== Number( jetpackCarouselStrings.display_geo ) ) {
return;
}
var latitude = meta.latitude,
longitude = meta.longitude,
$metabox = $( 'div.jp-carousel-image-meta', 'div.jp-carousel-wrap' ),
$mapbox = $( '
' ),
style = '&scale=2&style=feature:all|element:all|invert_lightness:true|hue:0x0077FF|saturation:-50|lightness:-5|gamma:0.91';
$mapbox
.addClass( 'jp-carousel-image-map' )
.html( '

\
\
\
\
' )
.prependTo( $metabox );
},
testCommentsOpened: function( opened ) {
if ( 1 === parseInt( opened, 10 ) ) {
$('.jp-carousel-buttons').fadeIn('fast');
commentForm.fadeIn('fast');
} else {
$('.jp-carousel-buttons').fadeOut('fast');
commentForm.fadeOut('fast');
}
},
getComments: function( args ) {
clearInterval( commentInterval );
if ( 'object' !== typeof args ) {
return;
}
if ( 'undefined' === typeof args.attachment_id || ! args.attachment_id ) {
return;
}
if ( ! args.offset || 'undefined' === typeof args.offset || args.offset < 1 ) {
args.offset = 0;
}
var comments = $('.jp-carousel-comments'),
commentsLoading = $('#jp-carousel-comments-loading').show();
if ( args.clear ) {
comments.hide().empty();
}
$.ajax({
type: 'GET',
url: jetpackCarouselStrings.ajaxurl,
dataType: 'json',
data: {
action: 'get_attachment_comments',
nonce: jetpackCarouselStrings.nonce,
id: args.attachment_id,
offset: args.offset
},
success: function(data/*, status, xhr*/) {
if ( args.clear ) {
comments.fadeOut('fast').empty();
}
$( data ).each(function(){
var comment = $('
')
.addClass('jp-carousel-comment')
.attr('id', 'jp-carousel-comment-' + this['id'])
.html(
'' +
'' +
'' +
''
);
comments.append(comment);
// Set the interval to check for a new page of comments.
clearInterval( commentInterval );
commentInterval = setInterval( function() {
if ( ( $('.jp-carousel-overlay').height() - 150 ) < $('.jp-carousel-wrap').scrollTop() + $(window).height() ) {
gallery.jp_carousel('getComments',{ attachment_id: args.attachment_id, offset: args.offset + 10, clear: false });
clearInterval( commentInterval );
}
}, 300 );
});
// Verify (late) that the user didn't repeatldy click the arrows really fast, in which case the requested
// attachment id might no longer match the current attachment id by the time we get the data back or a now
// registered infiniscroll event kicks in, so we don't ever display comments for the wrong image by mistake.
var current = $('.jp-carousel div.selected');
if ( current && current.data && current.data('attachment-id') != args.attachment_id ) { // jshint ignore:line
comments.fadeOut('fast');
comments.empty();
return;
}
// Increase the height of the background, semi-transparent overlay to match the new length of the comments list.
$('.jp-carousel-overlay').height( $(window).height() + titleAndDescription.height() + commentForm.height() + ( (comments.height() > 0) ? comments.height() : imageMeta.height() ) + 200 );
comments.show();
commentsLoading.hide();
},
error: function(xhr, status, error) {
// TODO: proper error handling
console.log( 'Comment get fail...', xhr, status, error );
comments.fadeIn('fast');
commentsLoading.fadeOut('fast');
}
});
},
postCommentError: function(args) {
if ( 'object' !== typeof args ) {
args = {};
}
if ( ! args.field || 'undefined' === typeof args.field || ! args.error || 'undefined' === typeof args.error ) {
return;
}
$('#jp-carousel-comment-post-results').slideUp('fast').html('').slideDown('fast');
$('#jp-carousel-comment-form-spinner').spin(false);
},
setCommentIframeSrc: function(attachment_id) {
var iframe = $('#jp-carousel-comment-iframe');
// Set the proper irame src for the current attachment id
if (iframe && iframe.length) {
iframe.attr('src', iframe.attr('src').replace(/(postid=)\d+/, '$1'+attachment_id) );
iframe.attr('src', iframe.attr('src').replace(/(%23.+)?$/, '%23jp-carousel-'+attachment_id) );
}
},
clearCommentTextAreaValue: function() {
var commentTextArea = $('#jp-carousel-comment-form-comment-field');
if ( commentTextArea ) {
commentTextArea.val('');
}
},
nextSlide : function () {
var slides = this.jp_carousel( 'slides' );
var selected = this.jp_carousel( 'selectedSlide' );
if ( selected.length === 0 || ( slides.length > 2 && selected.is( slides.last() ) ) ) {
return slides.first();
}
return selected.next();
},
prevSlide : function () {
var slides = this.jp_carousel( 'slides' );
var selected = this.jp_carousel( 'selectedSlide' );
if ( selected.length === 0 || ( slides.length > 2 && selected.is( slides.first() ) ) ) {
return slides.last();
}
return selected.prev();
},
loadFullImage : function ( slide ) {
var image = slide.find( 'img:first' );
if ( ! image.data( 'loaded' ) ) {
// If the width of the slide is smaller than the width of the "thumbnail" we're already using,
// don't load the full image.
image.on( 'load.jetpack', function () {
image.off( 'load.jetpack' );
$( this ).closest( '.jp-carousel-slide' ).css( 'background-image', '' );
} );
if ( ! slide.data( 'preview-image' ) || ( slide.data( 'thumb-size' ) && slide.width() > slide.data( 'thumb-size' ).width ) ) {
image.attr( 'src', image.closest( '.jp-carousel-slide' ).data( 'src' ) ).attr('itemprop', 'image');
} else {
image.attr( 'src', slide.data( 'preview-image' ) ).attr('itemprop', 'image');
}
image.data( 'loaded', 1 );
}
},
hasMultipleImages : function () {
return gallery.jp_carousel('slides').length > 1;
}
};
$.fn.jp_carousel = function(method){
// ask for the HTML of the gallery
// Method calling logic
if ( methods[method] ) {
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.open.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.jp_carousel' );
}
};
// register the event listener for starting the gallery
$( document.body ).on( 'click.jp-carousel', 'div.gallery,div.tiled-gallery, a.single-image-gallery', function(e) {
if ( ! $(this).jp_carousel( 'testForData', e.currentTarget ) ) {
return;
}
if ( $(e.target).parent().hasClass('gallery-caption') ) {
return;
}
e.preventDefault();
// Stopping propagation in case there are parent elements
// with .gallery or .tiled-gallery class
e.stopPropagation();
$(this).jp_carousel('open', {start_index: $(this).find('.gallery-item, .tiled-gallery-item').index($(e.target).parents('.gallery-item, .tiled-gallery-item'))});
});
// handle lightbox (single image gallery) for images linking to 'Attachment Page'
if ( 1 === Number( jetpackCarouselStrings.single_image_gallery ) ) {
processSingleImageGallery();
$( document.body ).on( 'post-load', function() {
processSingleImageGallery();
} );
}
// Makes carousel work on page load and when back button leads to same URL with carousel hash (ie: no actual document.ready trigger)
$( window ).on( 'hashchange.jp-carousel', function () {
var hashRegExp = /jp-carousel-(\d+)/,
matches, attachmentId, galleries, selectedThumbnail;
if ( ! window.location.hash || ! hashRegExp.test( window.location.hash ) ) {
if ( gallery && gallery.opened ) {
container.jp_carousel( 'close' );
}
return;
}
if ( ( window.location.hash === last_known_location_hash ) && gallery.opened ) {
return;
}
if ( window.location.hash && gallery && !gallery.opened && history.back) {
history.back();
return;
}
last_known_location_hash = window.location.hash;
matches = window.location.hash.match( hashRegExp );
attachmentId = parseInt( matches[1], 10 );
galleries = $( 'div.gallery, div.tiled-gallery, a.single-image-gallery' );
// Find the first thumbnail that matches the attachment ID in the location
// hash, then open the gallery that contains it.
galleries.each( function( _, galleryEl ) {
$( galleryEl ).find('img').each( function( imageIndex, imageEl ) {
if ( $( imageEl ).data( 'attachment-id' ) === parseInt( attachmentId, 10 ) ) {
selectedThumbnail = { index: imageIndex, gallery: galleryEl };
return false;
}
});
if ( selectedThumbnail ) {
$( selectedThumbnail.gallery )
.jp_carousel( 'openOrSelectSlide', selectedThumbnail.index );
return false;
}
});
});
if ( window.location.hash ) {
$( window ).trigger( 'hashchange' );
}
});
/**
* jQuery Plugin to obtain touch gestures from iPhone, iPod Touch and iPad, should also work with Android mobile phones (not tested yet!)
* Common usage: wipe images (left and right to show the previous or next image)
*
* @author Andreas Waltl, netCU Internetagentur (http://www.netcu.de)
* Version 1.1.1, modified to pass the touchmove event to the callbacks.
*/
(function($) {
$.fn.touchwipe = function(settings) {
var config = {
min_move_x: 20,
min_move_y: 20,
wipeLeft: function(/*e*/) { },
wipeRight: function(/*e*/) { },
wipeUp: function(/*e*/) { },
wipeDown: function(/*e*/) { },
preventDefaultEvents: true
};
if (settings) {
$.extend(config, settings);
}
this.each(function() {
var startX;
var startY;
var isMoving = false;
function cancelTouch() {
this.removeEventListener('touchmove', onTouchMove);
startX = null;
isMoving = false;
}
function onTouchMove(e) {
if(config.preventDefaultEvents) {
e.preventDefault();
}
if(isMoving) {
var x = e.touches[0].pageX;
var y = e.touches[0].pageY;
var dx = startX - x;
var dy = startY - y;
if(Math.abs(dx) >= config.min_move_x) {
cancelTouch();
if(dx > 0) {
config.wipeLeft(e);
} else {
config.wipeRight(e);
}
}
else if(Math.abs(dy) >= config.min_move_y) {
cancelTouch();
if(dy > 0) {
config.wipeDown(e);
} else {
config.wipeUp(e);
}
}
}
}
function onTouchStart(e)
{
if (e.touches.length === 1) {
startX = e.touches[0].pageX;
startY = e.touches[0].pageY;
isMoving = true;
this.addEventListener('touchmove', onTouchMove, false);
}
}
if ('ontouchstart' in document.documentElement) {
this.addEventListener('touchstart', onTouchStart, false);
}
});
return this;
};
})(jQuery);