Skip to content

Commit

Permalink
v2.5.0 - added ability to change source and destroy gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
akalicki committed Nov 25, 2013
1 parent c270a15 commit b22ce4c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ code and unneeded options.

[demo]: http://akalicki.github.io/jquery-simple-gallery/

**CURRENT VERSION: v2.4.0**
**CURRENT VERSION: v2.5.0**

## Get Started ##

Expand Down Expand Up @@ -85,7 +85,8 @@ initialization is listed below:
+ `source` (mandatory, *no default*) - a string representing the selector for
the source images used in the photo gallery. The string supplied can be
anything, so long as the selector `$(source)` will isolate all `<img>` tags
to be displayed in the gallery.
to be displayed in the gallery. A gallery's source collection can be also be
dynamically changed after instantiation.

+ `animate` (optional, *default = true*) - a boolean true/false value
representing whether to animate the slideshow. If false, the target display
Expand Down Expand Up @@ -147,6 +148,7 @@ $('#displayImage').gallery('option', 'changeTime'); // "700"
// set new values of options
$('#displayImage').gallery('option', 'easing', 'linear');
$('#displayImage').gallery('option', 'changeTime', 600);
$('#displayImage').gallery('source', '#new-thumbnails img');
```

## Advanced Use ##
Expand All @@ -165,16 +167,20 @@ the gallery.

+ `resumeAnimation` - resumes the gallery's animation after having been stopped.

+ `destroy` - destroys the gallery: removes the class added to the selected
thumbnail, fades out the target image, and stops the gallery from cycling.

All public functions are called on the gallery instance of the display image
after instantiation as follows:

```javascript
// create gallery linked to '#displayImage'
$('#displayImage').gallery({source: "#thumbnails img"});

// stop and then resume gallery animation
// stop and then resume animation, then destroy gallery
$('#displayImage').gallery("stopAnimation");
$('#displayImage').gallery("resumeAnimation");
$('#displayImage').gallery("destroy");
```

A typical usage would be to stop the gallery from animating when the user
Expand Down Expand Up @@ -207,6 +213,11 @@ method is called.
+ `galleryanimationresume` - triggered when the gallery's `resumeAnimation`
method is called.

+ `galleryoptionchange` - triggered when one of the gallery's options is
changed after instantiation.

+ `gallerydestroy` - triggered when the gallery's `destroy` method is called.

Handler functions can be bound to the gallery's events after instantiation
like so:

Expand Down Expand Up @@ -240,7 +251,9 @@ A few examples of simple ways to implement this plugin:

## Demos ##

Want to see simple-gallery.js in action? Check out some sites that currently use it! Send me a link to your implementation and I'll be happy to add it to the list.
Want to see simple-gallery.js in action? Check out some sites that currently
use it! Send me a link to your implementation and I'll be happy to add it to
the list.

+ [Columbia University Engineers Without Borders](http://morocco.cuewb.org/#bridge)
+ [Centro de Día Geriátrico](http://cdg.com.py/fotos.php)
Expand Down
47 changes: 34 additions & 13 deletions simple-gallery.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* simple-gallery.js - v2.4.0
* simple-gallery.js - v2.5.0
* Author: Alex Kalicki (https://github.com/akalicki)
*
* simple-gallery.js is a lightweight jQuery extension for quickly creating
Expand Down Expand Up @@ -36,31 +36,52 @@
"background-position": "center",
"opacity": 0
});
this.images.css("opacity", 0);

this.images.animate(
{"opacity": 1},
this.options.changeTime,
this.options.easing
);

this.images.on('click.gallery', $.proxy(this._onClick, this));
this._loadNext();
},

// reset DOM to state before gallery was invoked
_destroy: function() {
this.element.css({
"background-repeat": "repeat",
"background-position": "0% 0%",
"opacity": 1
});
this._trigger("destroy");
this.images.off('click.gallery');
$("." + this.options.selectClass).removeClass(this.options.selectClass);

window.clearTimeout(this.cycle);
this.element.stop(true);
if (this.options.showCaptions) {
$(this.options.captionTarget).stop(true);
}

this._startTransition();
var self = this;
this.element.queue(function(next) {
self.element.css({
"background-repeat": "repeat",
"background-position": "0% 0%",
"background-image": "none",
"opacity": 1
});
next();
});

this._super();
},

// allow setting of options during/after construction
_setOption: function(key, value) {
this._trigger('optionchange');
this.options[key] = value;

if (key === "source") {
this._trigger('sourcechange');
window.clearTimeout(this.cycle);
this.images.off('click.gallery');
this.images = $(this.options.source);
this.images.on('click.gallery', $.proxy(this._onClick, this));
this.nextImg = this.options.startImg;
this._changeToImg(this.nextImg);
}
},

// load the next image in cycle
Expand Down
7 changes: 4 additions & 3 deletions simple-gallery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b22ce4c

Please sign in to comment.