| 1 |
// $Id: slideshow.js,v 1.8 2007/04/21 16:38:48 timcn Exp $
|
| 2 |
|
| 3 |
Drupal.imageQueue = new function() {
|
| 4 |
this.processing = false;
|
| 5 |
this.queue = [];
|
| 6 |
var obj = this;
|
| 7 |
|
| 8 |
this.add = function(url) {
|
| 9 |
this.queue.push(url);
|
| 10 |
if (!this.processing) this.process();
|
| 11 |
};
|
| 12 |
|
| 13 |
this.process = function() {
|
| 14 |
this.processing = this.queue.length > 0;
|
| 15 |
if (this.processing) {
|
| 16 |
var x = $('<img />').src(this.queue.shift()).load(function() { obj.process(); });
|
| 17 |
}
|
| 18 |
};
|
| 19 |
|
| 20 |
return this;
|
| 21 |
};
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
Drupal.slideshow = function(container) {
|
| 26 |
this.container = $(container);
|
| 27 |
this.id = container.id;
|
| 28 |
jQuery.extend(this, Drupal.settings.slideshow[this.id]);
|
| 29 |
|
| 30 |
var slideshow = this;
|
| 31 |
this.container
|
| 32 |
.find('.previous').click(function() { slideshow.previous(); return false; }).end()
|
| 33 |
.find('.next, img').click(function() { slideshow.next(); return false; }).end();
|
| 34 |
|
| 35 |
for (var i = 0; i < this.images.length; i++) {
|
| 36 |
Drupal.imageQueue.add(this.images[i].src);
|
| 37 |
}
|
| 38 |
}
|
| 39 |
|
| 40 |
Drupal.slideshow.prototype = {
|
| 41 |
previous: function() {
|
| 42 |
if (--this.current < 0) this.current = this.images.length - 1;
|
| 43 |
this.update();
|
| 44 |
},
|
| 45 |
|
| 46 |
next: function() {
|
| 47 |
if (++this.current >= this.images.length) this.current = 0;
|
| 48 |
this.update();
|
| 49 |
},
|
| 50 |
|
| 51 |
update: function() {
|
| 52 |
self.scrollTo(0, Drupal.absolutePosition(this.container[0]).y);
|
| 53 |
|
| 54 |
var current = this.images[this.current];
|
| 55 |
|
| 56 |
this.container
|
| 57 |
.find('img').src(current.src).end()
|
| 58 |
.find('.title').html(current.title).end()
|
| 59 |
.find('.current').html(this.current + 1).end()
|
| 60 |
.find('.next').href(this.link.replace('$slideshow$', 1 + (this.current + 1 >= this.images.length ? 0 : this.current + 1))).end()
|
| 61 |
.find('.previous').href(this.link.replace('$slideshow$', (this.current < 1 ? this.images.length : this.current))).end();
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
|
| 66 |
$(function() {
|
| 67 |
$('.slideshow').each(function() {
|
| 68 |
new Drupal.slideshow(this);
|
| 69 |
});
|
| 70 |
});
|