/* * slides, a slideshow plugin for jquery * intructions: http://slidesjs.com * by: nathan searles, http://nathansearles.com * version: 1.1.6 * updated: march 23th, 2011 * * licensed under the apache license, version 2.0 (the "license"); * you may not use this file except in compliance with the license. * you may obtain a copy of the license at * * http://www.apache.org/licenses/license-2.0 * * unless required by applicable law or agreed to in writing, software * distributed under the license is distributed on an "as is" basis, * without warranties or conditions of any kind, either express or implied. * see the license for the specific language governing permissions and * limitations under the license. */ (function($) { $.fn.slides = function(g) { g = $.extend({}, $.fn.slides.option, g); return this.each(function() { $('.' + g.container, $(this)).children().wrapall('
'); var d = $(this), control = $('.slides_control', d), total = control.children().size(), width = control.children().outerwidth(), height = control.children().outerheight(), start = g.start - 1, effect = g.effect.indexof(',') < 0 ? g.effect : g.effect.replace(' ', '').split(',')[0], paginationeffect = g.effect.indexof(',') < 0 ? effect : g.effect.replace(' ', '').split(',')[1], next = 0, prev = 0, number = 0, current = 0, loaded, active, clicked, position, direction, imageparent, pausetimeout, playinterval; function animate(a, b, c) { if (!active && loaded) { active = true; g.animationstart(current + 1); switch (a) { case 'next': prev = current; next = current + 1; next = total === next ? 0 : next; position = width * 2; a = -width * 2; current = next; break; case 'prev': prev = current; next = current - 1; next = next === -1 ? total - 1 : next; position = 0; a = 0; current = next; break; case 'pagination': next = parseint(c, 10); prev = $('.' + g.paginationclass + ' li.current a', d).attr('href').match('[^#/]+$'); if (next > prev) { position = width * 2; a = -width * 2 } else { position = 0; a = 0 } current = next; break } if (b === 'fade') { if (g.crossfade) { control.children(':eq(' + next + ')', d).css({ zindex: 10 }).fadein(g.fadespeed, g.fadeeasing, function() { if (g.autoheight) { control.animate({ height: control.children(':eq(' + next + ')', d).outerheight() }, g.autoheightspeed, function() { control.children(':eq(' + prev + ')', d).css({ display: 'none', zindex: 0 }); control.children(':eq(' + next + ')', d).css({ zindex: 0 }); g.animationcomplete(next + 1); active = false }) } else { control.children(':eq(' + prev + ')', d).css({ display: 'none', zindex: 0 }); control.children(':eq(' + next + ')', d).css({ zindex: 0 }); g.animationcomplete(next + 1); active = false } }) } else { control.children(':eq(' + prev + ')', d).fadeout(g.fadespeed, g.fadeeasing, function() { if (g.autoheight) { control.animate({ height: control.children(':eq(' + next + ')', d).outerheight() }, g.autoheightspeed, function() { control.children(':eq(' + next + ')', d).fadein(g.fadespeed, g.fadeeasing) }) } else { control.children(':eq(' + next + ')', d).fadein(g.fadespeed, g.fadeeasing, function() { if ($.browser.msie) { $(this).get(0).style.removeattribute('filter') } }) } g.animationcomplete(next + 1); active = false }) } } else { control.children(':eq(' + next + ')').css({ left: position, display: 'block' }); if (g.autoheight) { control.animate({ left: a, height: control.children(':eq(' + next + ')').outerheight() }, g.slidespeed, g.slideeasing, function() { control.css({ left: -width }); control.children(':eq(' + next + ')').css({ left: width, zindex: 5 }); control.children(':eq(' + prev + ')').css({ left: width, display: 'none', zindex: 0 }); g.animationcomplete(next + 1); active = false }) } else { control.animate({ left: a }, g.slidespeed, g.slideeasing, function() { control.css({ left: -width }); control.children(':eq(' + next + ')').css({ left: width, zindex: 5 }); control.children(':eq(' + prev + ')').css({ left: width, display: 'none', zindex: 0 }); g.animationcomplete(next + 1); active = false }) } } if (g.pagination) { $('.' + g.paginationclass + ' li.current', d).removeclass('current'); $('.' + g.paginationclass + ' li:eq(' + next + ')', d).addclass('current') } } } function stop() { clearinterval(d.data('interval')) } function pause() { if (g.pause) { cleartimeout(d.data('pause')); clearinterval(d.data('interval')); pausetimeout = settimeout(function() { cleartimeout(d.data('pause')); playinterval = setinterval(function() { animate("next", effect) }, g.play); d.data('interval', playinterval) }, g.pause); d.data('pause', pausetimeout) } else { stop() } } if (total < 2) { return } if (start < 0) { start = 0 } if (start > total) { start = total - 1 } if (g.start) { current = start } if (g.randomize) { control.randomize() } $('.' + g.container, d).css({ overflow: 'hidden', position: 'relative' }); control.children().css({ position: 'absolute', top: 0, left: control.children().outerwidth(), zindex: 0, display: 'none' }); control.css({ position: 'relative', width: (width * 3), height: height, left: -width }); $('.' + g.container, d).css({ display: 'block' }); if (g.autoheight) { control.children().css({ height: 'auto' }); control.animate({ height: control.children(':eq(' + start + ')').outerheight() }, g.autoheightspeed) } if (g.preload && control.find('img').length) { $('.' + g.container, d).css({ background: 'url(' + g.preloadimage + ') no-repeat 50% 50%' }); var f = control.find('img:eq(' + start + ')').attr('src') + '?' + (new date()).gettime(); if ($('img', d).parent().attr('class') != 'slides_control') { imageparent = control.children(':eq(0)')[0].tagname.tolowercase() } else { imageparent = control.find('img:eq(' + start + ')') } control.find('img:eq(' + start + ')').attr('src', f).load(function() { control.find(imageparent + ':eq(' + start + ')').fadein(g.fadespeed, g.fadeeasing, function() { $(this).css({ zindex: 5 }); $('.' + g.container, d).css({ background: '' }); loaded = true; g.slidesloaded() }) }) } else { control.children(':eq(' + start + ')').fadein(g.fadespeed, g.fadeeasing, function() { loaded = true; g.slidesloaded() }) } if (g.bigtarget) { control.children().css({ cursor: 'pointer' }); control.children().click(function() { animate('next', effect); return false }) } if (g.hoverpause && g.play) { control.bind('mouseover', function() { stop() }); control.bind('mouseleave', function() { pause() }) } if (g.generatenextprev) { $('.' + g.container, d).after('prev'); $('.' + g.prev, d).after('next') } $('.' + g.next, d).click(function(e) { e.preventdefault(); if (g.play) { pause() } animate('next', effect) }); $('.' + g.prev, d).click(function(e) { e.preventdefault(); if (g.play) { pause() } animate('prev', effect) }); if (g.generatepagination) { d.append(''); control.children().each(function() { $('.' + g.paginationclass, d).append('
  • ' + '
  • '); number++ }) } else { $('.' + g.paginationclass + ' li a', d).each(function() { $(this).attr('href', '#' + number); number++ }) } $('.' + g.paginationclass + ' li:eq(' + start + ')', d).addclass('current'); $('.' + g.paginationclass + ' li a', d).click(function() { if (g.play) { pause() } clicked = $(this).attr('href').match('[^#/]+$'); if (current != clicked) { animate('pagination', paginationeffect, clicked) } return false }); $('a.link', d).click(function() { if (g.play) { pause() } clicked = $(this).attr('href').match('[^#/]+$') - 1; if (current != clicked) { animate('pagination', paginationeffect, clicked) } return false }); if (g.play) { playinterval = setinterval(function() { animate('next', effect) }, g.play); d.data('interval', playinterval) } }) }; $.fn.slides.option = { preload: false, preloadimage: '/img/loading.gif', container: 'slides_container', generatenextprev: false, next: 'next', prev: 'prev', pagination: true, generatepagination: true, paginationclass: 'pagination', fadespeed: 350, fadeeasing: '', slidespeed: 350, slideeasing: '', start: 1, effect: 'slide', crossfade: false, randomize: false, play: 0, pause: 0, hoverpause: false, autoheight: false, autoheightspeed: 350, bigtarget: false, animationstart: function() {}, animationcomplete: function() {}, slidesloaded: function() {} }; $.fn.randomize = function(c) { function randomizeorder() { return (math.round(math.random()) - 0.5) } return ($(this).each(function() { var $this = $(this); var $children = $this.children(); var a = $children.length; if (a > 1) { $children.hide(); var b = []; for (i = 0; i < a; i++) { b[b.length] = i } b = b.sort(randomizeorder); $.each(b, function(j, k) { var $child = $children.eq(k); var $clone = $child.clone(true); $clone.show().appendto($this); if (c !== undefined) { c($child, $clone) } $child.remove() }) } })) } })(jquery);