|
1 | 1 | /*
|
2 |
| - * jQuery Image Gallery Plugin 1.0 |
3 |
| - * https://github.com/blueimp/jQuery-File-Upload |
| 2 | + * jQuery Image Gallery Plugin 1.1 |
| 3 | + * https://github.com/blueimp/jQuery-Image-Gallery |
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
6 | 6 | * https://blueimp.net
|
|
9 | 9 | * http://creativecommons.org/licenses/MIT/
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/*global jQuery, window, document */ |
| 12 | +/*global jQuery, window, document, setTimeout, clearTimeout */ |
13 | 13 |
|
14 | 14 | (function ($) {
|
15 | 15 | 'use strict';
|
16 | 16 |
|
17 | 17 | // The Image Gallery plugin makes use of jQuery's live method to attach
|
18 |
| - // a click handler for all elements that match the selector of the given |
| 18 | + // a click handler to all elements that match the selector of the given |
19 | 19 | // jQuery collection, now and in the future:
|
20 | 20 | //
|
21 |
| - // $('a[rel^=gallery]').imagegallery(); |
| 21 | + // $('a[rel=gallery]').imagegallery(); |
22 | 22 | //
|
23 | 23 | // The click handler opens the linked images in a jQuery UI dialog.
|
24 | 24 | // The options object given to the imagegallery method is passed to the
|
25 | 25 | // jQuery UI dialog initialization and allows to set any dialog options:
|
26 | 26 | //
|
27 |
| - // $('a[rel^=gallery]').imagegallery({ |
| 27 | + // $('a[rel=gallery]').imagegallery({ |
28 | 28 | // open: function (event, ui) {/* called on dialogopen */},
|
29 |
| - // title: 'Image Gallery' // Sets the dialog title |
| 29 | + // title: 'Image Gallery', // Sets the dialog title |
| 30 | + // offsetWidth: 50, // Offset of image width to viewport width |
| 31 | + // offsetHeight: 50, // Offset of image height to viewport height |
| 32 | + // slideshow: 50000, // Shows the next image after 5000 ms |
| 33 | + // canvas: true, // Displays images as canvas element |
| 34 | + // namespace: 'myimagegallery' // event handler namespace |
30 | 35 | // });
|
| 36 | + // |
| 37 | + // offsetWidth, offsetHeight, canvas, slideshow and namespace are |
| 38 | + // imagegallery specific options, while open and title are jQuery UI |
| 39 | + // dialog options. |
31 | 40 | //
|
32 | 41 | // The click event listeners can be removed by calling the imagegallery
|
33 | 42 | // method with "destroy" as first argument, using the same selector for
|
34 |
| - // the jQuery collection: |
| 43 | + // the jQuery collection and the same namespace: |
35 | 44 | //
|
36 |
| - // $('a[rel^=gallery]').imagegallery('destroy', options); |
| 45 | + // $('a[rel=gallery]').imagegallery('destroy', {namespace: 'ns'}); |
37 | 46 | //
|
38 | 47 | // To directly open an image with gallery functionality, the imagegallery
|
39 | 48 | // method can be called with "open" as first argument:
|
40 | 49 | //
|
41 |
| - // $('a[rel^=gallery]').imagegallery('open'); |
| 50 | + // $('a:last').imagegallery('open', {selector: 'a[rel=gallery]'}); |
42 | 51 | //
|
43 | 52 | // The selector for related images can be overriden with the "selector"
|
44 | 53 | // option.
|
45 |
| - // The namespace used for the click event listeners can be overriden |
46 |
| - // with the "namespace" option. |
47 | 54 |
|
48 | 55 | $.fn.imagegallery = function (options, opts) {
|
49 | 56 | opts = $.extend({
|
|
102 | 109 | // The loader is displayed until the image has loaded
|
103 | 110 | // and the dialog has been opened:
|
104 | 111 | loader = $('<div class="' + className + '-loader"></div>')
|
105 |
| - .hide().appendTo('body').fadeIn(); |
| 112 | + .hide() |
| 113 | + .appendTo($('.ui-widget-overlay:last')[0] || 'body') |
| 114 | + .fadeIn(); |
106 | 115 | options = $.extend({
|
107 | 116 | namespace: 'imagegallery',
|
108 | 117 | modal: true,
|
|
111 | 120 | height: 'auto',
|
112 | 121 | show: 'fade',
|
113 | 122 | hide: 'fade',
|
| 123 | + offsetWidth: 100, |
| 124 | + offsetHeight: 100, |
114 | 125 | title: link.title ||
|
115 | 126 | decodeURIComponent(link.href.split('/').pop()),
|
116 | 127 | dialogClass: className
|
|
178 | 189 | wheelHandler
|
179 | 190 | );
|
180 | 191 | },
|
| 192 | + slideShow, |
181 | 193 | scaledImage;
|
182 | 194 | if (e.type === 'error') {
|
183 | 195 | scaledImage = this;
|
184 | 196 | dialog.addClass('ui-state-error');
|
185 | 197 | } else {
|
186 | 198 | scaledImage = $.fn.imagegallery.scale(
|
187 | 199 | this,
|
188 |
| - $(window).width() - 100, |
189 |
| - $(window).height() - 100, |
| 200 | + $(window).width() - options.offsetWidth, |
| 201 | + $(window).height() - options.offsetHeight, |
190 | 202 | options.canvas
|
191 | 203 | );
|
192 | 204 | }
|
|
199 | 211 | ', DOMMouseScroll.' + options.namespace,
|
200 | 212 | wheelHandler
|
201 | 213 | );
|
| 214 | + if (options.slideshow) { |
| 215 | + slideShow = setTimeout(function () { |
| 216 | + dialog.click(); |
| 217 | + }, options.slideshow); |
| 218 | + } |
202 | 219 | dialog.bind({
|
203 | 220 | click: function (e) {
|
204 |
| - dialog.unbind('click').fadeOut(); |
| 221 | + clearTimeout(slideShow); |
| 222 | + dialog.unbind('click').dialog('widget').fadeOut(); |
205 | 223 | var newLink = (e.altKey && prevLink) || nextLink;
|
206 | 224 | if (newLink.href !== link.href) {
|
207 | 225 | options.callback = closeDialog;
|
| 226 | + delete options.title; |
208 | 227 | $.fn.imagegallery.open(newLink, options);
|
209 | 228 | } else {
|
210 | 229 | closeDialog();
|
|
217 | 236 | $('.ui-widget-overlay:last').click(closeDialog);
|
218 | 237 | },
|
219 | 238 | dialogclose: function () {
|
| 239 | + clearTimeout(slideShow); |
220 | 240 | $(this).remove();
|
221 | 241 | }
|
222 | 242 | }).css('cursor', 'pointer').append(
|
|
0 commit comments