Browse Source

Adds experimental support for faster touch events. This is a work-in-progress, not yet a working version!

pull/7/head
Viljami S 13 years ago
parent
commit
429bcb33a3
  1. 29
      responsiveslides.js

29
responsiveslides.js

@ -1,6 +1,7 @@
/*! ResponsiveSlides.js v1.04. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */ /*! ResponsiveSlides.js v1.04. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function ($) { (function ($) {
$.fn.responsiveSlides = function (opts) { $.fn.responsiveSlides = function (opts) {
// Settings // Settings
var settings = { var settings = {
'speed' : 4000, 'speed' : 4000,
@ -11,7 +12,9 @@
}; };
return this.each(function () { return this.each(function () {
var $this = $(this); var $this = $(this);
if (opts) { if (opts) {
$.extend(settings, opts); $.extend(settings, opts);
} }
@ -19,6 +22,10 @@
var slideshow = function () { var slideshow = function () {
var $slide = $this.find('img'), var $slide = $this.find('img'),
hasTouch = 'ontouchstart' in window,
startEvent = hasTouch ? 'touchstart' : 'mousedown',
endEvent = hasTouch ? 'touchend' : 'mouseup',
cancelEvent = hasTouch ? 'touchcancel' : 'mouseup',
namespace = settings.namespace, namespace = settings.namespace,
activeClass = namespace + '_here', activeClass = namespace + '_here',
visibleClass = namespace + '_on', visibleClass = namespace + '_on',
@ -68,6 +75,7 @@
// Auto: false // Auto: false
} else { } else {
tabMarkup = ''; tabMarkup = '';
$slide.each(function (i) { $slide.each(function (i) {
@ -78,6 +86,7 @@
'class="' + slideClassPrefix + n + '">' + n + '</a>' + 'class="' + slideClassPrefix + n + '">' + n + '</a>' +
'</li>'; '</li>';
}); });
$pagination.append(tabMarkup); $pagination.append(tabMarkup);
$this.after($pagination).find(':first-child').addClass(visibleClass); $this.after($pagination).find(':first-child').addClass(visibleClass);
@ -85,9 +94,14 @@
$('.' + tabsClass + ' a').each(function (i) { $('.' + tabsClass + ' a').each(function (i) {
var $el = $(this); var $el = $(this);
$el.click(function (e) { $el.bind('click', function (e) {
e.preventDefault(); e.preventDefault();
});
$el.bind(startEvent, function (e) {
//e.preventDefault();
// Prevent clicking if animated // Prevent clicking if animated
if ($('.' + visibleClass + ':animated').length) { if ($('.' + visibleClass + ':animated').length) {
return false; return false;
@ -102,15 +116,22 @@
}).end(); }).end();
$el.parent().addClass(activeClass); $el.parent().addClass(activeClass);
} }
}); });
}); });
} }
}; };
// Fallback to make IE6 support CSS max-width // Fallback to make IE6 support CSS max-width
var widthSupport = function () { var widthSupport = function () {
var maxwidth = parseFloat(settings.maxwidth); var maxwidth = parseFloat(settings.maxwidth);
if (opts && opts.maxwidth) { if (opts && opts.maxwidth) {
if (typeof document.body.style.maxHeight === 'undefined') { if (typeof document.body.style.maxHeight === 'undefined') {
$this.each(function () { $this.each(function () {
$this.css('width', '100%'); $this.css('width', '100%');
@ -121,16 +142,20 @@
} }
}); });
} }
} }
}; };
// Call once // Call once
slideshow(); slideshow();
widthSupport(); widthSupport();
// Call on resize // Call on resize
$(window).resize(function () { $(window).resize(function () {
widthSupport(); widthSupport();
}); });
}); });
}; };
})(jQuery); })(jQuery);
Loading…
Cancel
Save