scratch – Blame information for rev 115
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | # blueimp Gallery |
2 | |||
3 | - [Demo](#demo) |
||
4 | - [Description](#description) |
||
5 | - [Setup](#setup) |
||
6 | - [Lightbox setup](#lightbox-setup) |
||
7 | - [Controls](#controls) |
||
8 | - [Carousel setup](#carousel-setup) |
||
9 | - [Keyboard shortcuts](#keyboard-shortcuts) |
||
10 | - [Options](#options) |
||
11 | - [Default options](#default-options) |
||
12 | - [Event callbacks](#event-callbacks) |
||
13 | - [Carousel options](#carousel-options) |
||
14 | - [Indicator options](#indicator-options) |
||
15 | - [Fullscreen options](#fullscreen-options) |
||
16 | - [Video options](#video-options) |
||
17 | - [Video factory options](#video-factory-options) |
||
18 | - [YouTube options](#youtube-options) |
||
19 | - [Vimeo options](#vimeo-options) |
||
20 | - [Container and element options](#container-and-element-options) |
||
21 | - [Property options](#property-options) |
||
22 | - [API](#api) |
||
23 | - [Initialization](#initialization) |
||
24 | - [API methods](#api-methods) |
||
25 | - [Videos](#videos) |
||
26 | - [HTML5 video player](#html5-video-player) |
||
27 | - [Multiple video sources](#multiple-video-sources) |
||
28 | - [YouTube](#youtube) |
||
29 | - [Vimeo](#vimeo) |
||
30 | - [Additional Gallery elements](#additional-gallery-elements) |
||
31 | - [Additional content types](#additional-content-types) |
||
32 | - [Example HTML text factory implementation](#example-html-text-factory-implementation) |
||
33 | - [jQuery plugin](#jquery-plugin) |
||
34 | - [jQuery plugin setup](#jquery-plugin-setup) |
||
35 | - [HTML5 data-attributes](#html5-data-attributes) |
||
36 | - [Container ids and link grouping](#container-ids-and-link-grouping) |
||
37 | - [Gallery object](#gallery-object) |
||
38 | - [jQuery events](#jquery-events) |
||
39 | - [Requirements](#requirements) |
||
40 | - [Browsers](#browsers) |
||
41 | - [Desktop browsers](#desktop-browsers) |
||
42 | - [Mobile browsers](#mobile-browsers) |
||
43 | - [License](#license) |
||
44 | - [Credits](#credits) |
||
45 | |||
46 | ## Demo |
||
47 | [blueimp Gallery Demo](https://blueimp.github.io/Gallery/) |
||
48 | |||
49 | ## Description |
||
50 | blueimp Gallery is a touch-enabled, responsive and customizable image and video |
||
51 | gallery, carousel and lightbox, optimized for both mobile and desktop web |
||
52 | browsers. |
||
53 | It features swipe, mouse and keyboard navigation, transition effects, slideshow |
||
54 | functionality, fullscreen support and on-demand content loading and can be |
||
55 | extended to display additional content types. |
||
56 | |||
57 | ## Setup |
||
58 | |||
59 | ### Lightbox setup |
||
60 | Copy the **css**, **img** and **js** directories to your website. |
||
61 | |||
62 | Include the Gallery stylesheet in the head section of your webpage: |
||
63 | |||
64 | ```html |
||
65 | <link rel="stylesheet" href="css/blueimp-gallery.min.css"> |
||
66 | ``` |
||
67 | |||
68 | Add the following HTML snippet with the Gallery widget to the body of your |
||
69 | webpage: |
||
70 | |||
71 | ```html |
||
72 | <!-- The Gallery as lightbox dialog, should be a child element of the document body --> |
||
73 | <div id="blueimp-gallery" class="blueimp-gallery"> |
||
74 | <div class="slides"></div> |
||
75 | <h3 class="title"></h3> |
||
76 | <a class="prev">‹</a> |
||
77 | <a class="next">›</a> |
||
78 | <a class="close">×</a> |
||
79 | <a class="play-pause"></a> |
||
80 | <ol class="indicator"></ol> |
||
81 | </div> |
||
82 | ``` |
||
83 | |||
84 | Include the Gallery script at the bottom of the body of your webpage: |
||
85 | |||
86 | ```html |
||
87 | <script src="js/blueimp-gallery.min.js"></script> |
||
88 | ``` |
||
89 | |||
90 | Create a list of links to image files, optionally with enclosed thumbnails and |
||
91 | add them to the body of your webpage, before including the Gallery script: |
||
92 | |||
93 | ```html |
||
94 | <div id="links"> |
||
95 | <a href="images/banana.jpg" title="Banana"> |
||
96 | <img src="images/thumbnails/banana.jpg" alt="Banana"> |
||
97 | </a> |
||
98 | <a href="images/apple.jpg" title="Apple"> |
||
99 | <img src="images/thumbnails/apple.jpg" alt="Apple"> |
||
100 | </a> |
||
101 | <a href="images/orange.jpg" title="Orange"> |
||
102 | <img src="images/thumbnails/orange.jpg" alt="Orange"> |
||
103 | </a> |
||
104 | </div> |
||
105 | ``` |
||
106 | |||
107 | Add the following JavaScript code after including the Gallery script, to display |
||
108 | the images in the Gallery lightbox on click of the links: |
||
109 | |||
110 | ```html |
||
111 | <script> |
||
112 | document.getElementById('links').onclick = function (event) { |
||
113 | event = event || window.event; |
||
114 | var target = event.target || event.srcElement, |
||
115 | link = target.src ? target.parentNode : target, |
||
116 | options = {index: link, event: event}, |
||
117 | links = this.getElementsByTagName('a'); |
||
118 | blueimp.Gallery(links, options); |
||
119 | }; |
||
120 | </script> |
||
121 | ``` |
||
122 | |||
123 | ### Controls |
||
124 | To initialize the Gallery with visible controls, add the CSS class |
||
125 | **blueimp-gallery-controls** to the Gallery widget: |
||
126 | |||
127 | ```html |
||
128 | <div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls"> |
||
129 | <div class="slides"></div> |
||
130 | <h3 class="title"></h3> |
||
131 | <a class="prev">‹</a> |
||
132 | <a class="next">›</a> |
||
133 | <a class="close">×</a> |
||
134 | <a class="play-pause"></a> |
||
135 | <ol class="indicator"></ol> |
||
136 | </div> |
||
137 | ``` |
||
138 | |||
139 | ### Carousel setup |
||
140 | To display the images in an inline carousel instead of a lightbox, follow the |
||
141 | [lightbox setup](#lightbox-setup) and add the CSS class |
||
142 | **blueimp-gallery-carousel** to the Gallery widget and remove the child element |
||
143 | with the **close** class, or add a new Gallery widget with a different **id** |
||
144 | to your webpage: |
||
145 | |||
146 | ```html |
||
147 | <!-- The Gallery as inline carousel, can be positioned anywhere on the page --> |
||
148 | <div id="blueimp-gallery-carousel" class="blueimp-gallery blueimp-gallery-carousel"> |
||
149 | <div class="slides"></div> |
||
150 | <h3 class="title"></h3> |
||
151 | <a class="prev">‹</a> |
||
152 | <a class="next">›</a> |
||
153 | <a class="play-pause"></a> |
||
154 | <ol class="indicator"></ol> |
||
155 | </div> |
||
156 | ``` |
||
157 | |||
158 | Add the following JavaScript code after including the Gallery script to |
||
159 | initialize the carousel: |
||
160 | |||
161 | ```html |
||
162 | <script> |
||
163 | blueimp.Gallery( |
||
164 | document.getElementById('links').getElementsByTagName('a'), |
||
165 | { |
||
166 | container: '#blueimp-gallery-carousel', |
||
167 | carousel: true |
||
168 | } |
||
169 | ); |
||
170 | </script> |
||
171 | ``` |
||
172 | |||
173 | ## Keyboard shortcuts |
||
174 | The Gallery can be controlled with the following keyboard shortcuts: |
||
175 | |||
176 | * **Return**: Toggle controls visibility. |
||
177 | * **Esc**: Close the Gallery lightbox. |
||
178 | * **Space**: Toggle the slideshow (play/pause). |
||
179 | * **Left**: Move to the previous slide. |
||
180 | * **Right**: Move to the next slide. |
||
181 | |||
182 | Please note that setting the **carousel** option to **true** disables the |
||
183 | keyboard shortcuts by default. |
||
184 | |||
185 | ## Options |
||
186 | |||
187 | ### Default options |
||
188 | The following are the default options set by the core Gallery library: |
||
189 | |||
190 | ```js |
||
191 | var options = { |
||
192 | // The Id, element or querySelector of the gallery widget: |
||
193 | container: '#blueimp-gallery', |
||
194 | // The tag name, Id, element or querySelector of the slides container: |
||
195 | slidesContainer: 'div', |
||
196 | // The tag name, Id, element or querySelector of the title element: |
||
197 | titleElement: 'h3', |
||
198 | // The class to add when the gallery is visible: |
||
199 | displayClass: 'blueimp-gallery-display', |
||
200 | // The class to add when the gallery controls are visible: |
||
201 | controlsClass: 'blueimp-gallery-controls', |
||
202 | // The class to add when the gallery only displays one element: |
||
203 | singleClass: 'blueimp-gallery-single', |
||
204 | // The class to add when the left edge has been reached: |
||
205 | leftEdgeClass: 'blueimp-gallery-left', |
||
206 | // The class to add when the right edge has been reached: |
||
207 | rightEdgeClass: 'blueimp-gallery-right', |
||
208 | // The class to add when the automatic slideshow is active: |
||
209 | playingClass: 'blueimp-gallery-playing', |
||
210 | // The class for all slides: |
||
211 | slideClass: 'slide', |
||
212 | // The slide class for loading elements: |
||
213 | slideLoadingClass: 'slide-loading', |
||
214 | // The slide class for elements that failed to load: |
||
215 | slideErrorClass: 'slide-error', |
||
216 | // The class for the content element loaded into each slide: |
||
217 | slideContentClass: 'slide-content', |
||
218 | // The class for the "toggle" control: |
||
219 | toggleClass: 'toggle', |
||
220 | // The class for the "prev" control: |
||
221 | prevClass: 'prev', |
||
222 | // The class for the "next" control: |
||
223 | nextClass: 'next', |
||
224 | // The class for the "close" control: |
||
225 | closeClass: 'close', |
||
226 | // The class for the "play-pause" toggle control: |
||
227 | playPauseClass: 'play-pause', |
||
228 | // The list object property (or data attribute) with the object type: |
||
229 | typeProperty: 'type', |
||
230 | // The list object property (or data attribute) with the object title: |
||
231 | titleProperty: 'title', |
||
232 | // The list object property (or data attribute) with the object URL: |
||
233 | urlProperty: 'href', |
||
234 | // The list object property (or data attribute) with the object srcset URL(s): |
||
235 | srcsetProperty: 'urlset', |
||
236 | // The gallery listens for transitionend events before triggering the |
||
237 | // opened and closed events, unless the following option is set to false: |
||
238 | displayTransition: true, |
||
239 | // Defines if the gallery slides are cleared from the gallery modal, |
||
240 | // or reused for the next gallery initialization: |
||
241 | clearSlides: true, |
||
242 | // Defines if images should be stretched to fill the available space, |
||
243 | // while maintaining their aspect ratio (will only be enabled for browsers |
||
244 | // supporting background-size="contain", which excludes IE < 9). |
||
245 | // Set to "cover", to make images cover all available space (requires |
||
246 | // support for background-size="cover", which excludes IE < 9): |
||
247 | stretchImages: false, |
||
248 | // Toggle the controls on pressing the Return key: |
||
249 | toggleControlsOnReturn: true, |
||
250 | // Toggle the controls on slide click: |
||
251 | toggleControlsOnSlideClick: true, |
||
252 | // Toggle the automatic slideshow interval on pressing the Space key: |
||
253 | toggleSlideshowOnSpace: true, |
||
254 | // Navigate the gallery by pressing left and right on the keyboard: |
||
255 | enableKeyboardNavigation: true, |
||
256 | // Close the gallery on pressing the ESC key: |
||
257 | closeOnEscape: true, |
||
258 | // Close the gallery when clicking on an empty slide area: |
||
259 | closeOnSlideClick: true, |
||
260 | // Close the gallery by swiping up or down: |
||
261 | closeOnSwipeUpOrDown: true, |
||
262 | // Emulate touch events on mouse-pointer devices such as desktop browsers: |
||
263 | emulateTouchEvents: true, |
||
264 | // Stop touch events from bubbling up to ancestor elements of the Gallery: |
||
265 | stopTouchEventsPropagation: false, |
||
266 | // Hide the page scrollbars: |
||
267 | hidePageScrollbars: true, |
||
268 | // Stops any touches on the container from scrolling the page: |
||
269 | disableScroll: true, |
||
270 | // Carousel mode (shortcut for carousel specific options): |
||
271 | carousel: false, |
||
272 | // Allow continuous navigation, moving from last to first |
||
273 | // and from first to last slide: |
||
274 | continuous: true, |
||
275 | // Remove elements outside of the preload range from the DOM: |
||
276 | unloadElements: true, |
||
277 | // Start with the automatic slideshow: |
||
278 | startSlideshow: false, |
||
279 | // Delay in milliseconds between slides for the automatic slideshow: |
||
280 | slideshowInterval: 5000, |
||
281 | // The starting index as integer. |
||
282 | // Can also be an object of the given list, |
||
283 | // or an equal object with the same url property: |
||
284 | index: 0, |
||
285 | // The number of elements to load around the current index: |
||
286 | preloadRange: 2, |
||
287 | // The transition speed between slide changes in milliseconds: |
||
288 | transitionSpeed: 400, |
||
289 | // The transition speed for automatic slide changes, set to an integer |
||
290 | // greater 0 to override the default transition speed: |
||
291 | slideshowTransitionSpeed: undefined, |
||
292 | // The event object for which the default action will be canceled |
||
293 | // on Gallery initialization (e.g. the click event to open the Gallery): |
||
294 | event: undefined, |
||
295 | // Callback function executed when the Gallery is initialized. |
||
296 | // Is called with the gallery instance as "this" object: |
||
297 | onopen: undefined, |
||
298 | // Callback function executed when the Gallery has been initialized |
||
299 | // and the initialization transition has been completed. |
||
300 | // Is called with the gallery instance as "this" object: |
||
301 | onopened: undefined, |
||
302 | // Callback function executed on slide change. |
||
303 | // Is called with the gallery instance as "this" object and the |
||
304 | // current index and slide as arguments: |
||
305 | onslide: undefined, |
||
306 | // Callback function executed after the slide change transition. |
||
307 | // Is called with the gallery instance as "this" object and the |
||
308 | // current index and slide as arguments: |
||
309 | onslideend: undefined, |
||
310 | // Callback function executed on slide content load. |
||
311 | // Is called with the gallery instance as "this" object and the |
||
312 | // slide index and slide element as arguments: |
||
313 | onslidecomplete: undefined, |
||
314 | // Callback function executed when the Gallery is about to be closed. |
||
315 | // Is called with the gallery instance as "this" object: |
||
316 | onclose: undefined, |
||
317 | // Callback function executed when the Gallery has been closed |
||
318 | // and the closing transition has been completed. |
||
319 | // Is called with the gallery instance as "this" object: |
||
320 | onclosed: undefined |
||
321 | }; |
||
322 | ``` |
||
323 | |||
324 | ### Event callbacks |
||
325 | Event callbacks can be set as function properties of the options object passed |
||
326 | to the Gallery initialization function: |
||
327 | |||
328 | ```js |
||
329 | var gallery = blueimp.Gallery( |
||
330 | linkList, |
||
331 | { |
||
332 | onopen: function () { |
||
333 | // Callback function executed when the Gallery is initialized. |
||
334 | }, |
||
335 | onopened: function () { |
||
336 | // Callback function executed when the Gallery has been initialized |
||
337 | // and the initialization transition has been completed. |
||
338 | }, |
||
339 | onslide: function (index, slide) { |
||
340 | // Callback function executed on slide change. |
||
341 | }, |
||
342 | onslideend: function (index, slide) { |
||
343 | // Callback function executed after the slide change transition. |
||
344 | }, |
||
345 | onslidecomplete: function (index, slide) { |
||
346 | // Callback function executed on slide content load. |
||
347 | }, |
||
348 | onclose: function () { |
||
349 | // Callback function executed when the Gallery is about to be closed. |
||
350 | }, |
||
351 | onclosed: function () { |
||
352 | // Callback function executed when the Gallery has been closed |
||
353 | // and the closing transition has been completed. |
||
354 | } |
||
355 | } |
||
356 | ); |
||
357 | ``` |
||
358 | |||
359 | ### Carousel options |
||
360 | If the **carousel** option is **true**, the following options are set to |
||
361 | different default values: |
||
362 | |||
363 | ```js |
||
364 | var carouselOptions = { |
||
365 | hidePageScrollbars: false, |
||
366 | toggleControlsOnReturn: false, |
||
367 | toggleSlideshowOnSpace: false, |
||
368 | enableKeyboardNavigation: false, |
||
369 | closeOnEscape: false, |
||
370 | closeOnSlideClick: false, |
||
371 | closeOnSwipeUpOrDown: false, |
||
372 | disableScroll: false, |
||
373 | startSlideshow: true |
||
374 | }; |
||
375 | ``` |
||
376 | |||
377 | The options object passed to the Gallery function extends the default options |
||
378 | and also those options set via **carousel** mode. |
||
379 | |||
380 | ### Indicator options |
||
381 | The following are the additional default options set for the slide position |
||
382 | indicator: |
||
383 | |||
384 | ```js |
||
385 | var indicatorOptions = { |
||
386 | // The tag name, Id, element or querySelector of the indicator container: |
||
387 | indicatorContainer: 'ol', |
||
388 | // The class for the active indicator: |
||
389 | activeIndicatorClass: 'active', |
||
390 | // The list object property (or data attribute) with the thumbnail URL, |
||
391 | // used as alternative to a thumbnail child element: |
||
392 | thumbnailProperty: 'thumbnail', |
||
393 | // Defines if the gallery indicators should display a thumbnail: |
||
394 | thumbnailIndicators: true |
||
395 | }; |
||
396 | ``` |
||
397 | |||
398 | ### Fullscreen options |
||
399 | The following are the additional default options set for the fullscreen mode: |
||
400 | |||
401 | ```js |
||
402 | var fullscreenOptions = { |
||
403 | // Defines if the gallery should open in fullscreen mode: |
||
404 | fullScreen: false |
||
405 | }; |
||
406 | ``` |
||
407 | |||
408 | ### Video options |
||
409 | |||
410 | #### Video factory options |
||
411 | The following are the additional default options set for the video factory: |
||
412 | |||
413 | ```js |
||
414 | var videoFactoryOptions = { |
||
415 | // The class for video content elements: |
||
416 | videoContentClass: 'video-content', |
||
417 | // The class for video when it is loading: |
||
418 | videoLoadingClass: 'video-loading', |
||
419 | // The class for video when it is playing: |
||
420 | videoPlayingClass: 'video-playing', |
||
421 | // The list object property (or data attribute) for the video poster URL: |
||
422 | videoPosterProperty: 'poster', |
||
423 | // The list object property (or data attribute) for the video sources array: |
||
424 | videoSourcesProperty: 'sources' |
||
425 | }; |
||
426 | ``` |
||
427 | #### YouTube options |
||
428 | Options for [YouTube](https://www.youtube.com/) videos: |
||
429 | |||
430 | ```js |
||
431 | var youTubeOptions = { |
||
432 | // The list object property (or data attribute) with the YouTube video id: |
||
433 | youTubeVideoIdProperty: 'youtube', |
||
434 | // Optional object with parameters passed to the YouTube video player: |
||
435 | // https://developers.google.com/youtube/player_parameters |
||
436 | youTubePlayerVars: undefined, |
||
437 | // Require a click on the native YouTube player for the initial playback: |
||
438 | youTubeClickToPlay: true |
||
439 | }; |
||
440 | ``` |
||
441 | |||
442 | #### Vimeo options |
||
443 | Options for [Vimeo](https://vimeo.com/) videos: |
||
444 | |||
445 | ```js |
||
446 | var vimeoOptions = { |
||
447 | // The list object property (or data attribute) with the Vimeo video id: |
||
448 | vimeoVideoIdProperty: 'vimeo', |
||
449 | // The URL for the Vimeo video player, can be extended with custom parameters: |
||
450 | // https://developer.vimeo.com/player/embedding |
||
451 | vimeoPlayerUrl: '//player.vimeo.com/video/VIDEO_ID?api=1&player_id=PLAYER_ID', |
||
452 | // The prefix for the Vimeo video player ID: |
||
453 | vimeoPlayerIdPrefix: 'vimeo-player-', |
||
454 | // Require a click on the native Vimeo player for the initial playback: |
||
455 | vimeoClickToPlay: true |
||
456 | }; |
||
457 | ``` |
||
458 | |||
459 | ### Container and element options |
||
460 | The widget **container** option can be set as id string (with "#" as prefix) or |
||
461 | element node, so the following are equivalent: |
||
462 | |||
463 | ```js |
||
464 | var options = { |
||
465 | container: '#blueimp-gallery' |
||
466 | }; |
||
467 | ``` |
||
468 | |||
469 | ```js |
||
470 | var options = { |
||
471 | container: document.getElementById('blueimp-gallery') |
||
472 | }; |
||
473 | ``` |
||
474 | |||
475 | The **slidesContainer**, **titleElement** and **indicatorContainer** options can |
||
476 | also be defined using a tag name, which selects the first tag of this kind found |
||
477 | inside of the widget container: |
||
478 | |||
479 | ```js |
||
480 | var options = { |
||
481 | slidesContainer: 'div', |
||
482 | titleElement: 'h3', |
||
483 | indicatorContainer: 'ol' |
||
484 | }; |
||
485 | ``` |
||
486 | |||
487 | It is also possible to define the container and element options with a more |
||
488 | complex |
||
489 | [querySelector](https://developer.mozilla.org/en-US/docs/Web/API/document.querySelector), |
||
490 | which is supported by IE8+ and all modern web browsers. |
||
491 | |||
492 | If the helper script is replaced with [jQuery](https://jquery.com/), |
||
493 | the container and element options can be any valid jQuery selector. |
||
494 | |||
495 | ### Property options |
||
496 | The options ending with "Property" define how the properties of each link |
||
497 | element are accessed. |
||
498 | For example, the **urlProperty** is by default set to **href**. This allows to |
||
499 | define link elements with **href** or **data-href** attributes: |
||
500 | |||
501 | ```html |
||
502 | <div id="links"> |
||
503 | <a href="images/banana.jpg">Banana</a> |
||
504 | <a data-href="images/apple.jpg">Apple</a> |
||
505 | </div> |
||
506 | ``` |
||
507 | |||
508 | If the links are passed as JavaScript array, it is also possible to define |
||
509 | nested property names, by using the native JavaScript accessor syntax for the |
||
510 | property string: |
||
511 | |||
512 | ```js |
||
513 | blueimp.Gallery( |
||
514 | [ |
||
515 | { |
||
516 | data: {urls: ['https://example.org/images/banana.jpg']} |
||
517 | }, |
||
518 | { |
||
519 | data: {urls: ['https://example.org/images/apple.jpg']} |
||
520 | } |
||
521 | ], |
||
522 | { |
||
523 | urlProperty: 'data.urls[0]' |
||
524 | } |
||
525 | ); |
||
526 | ``` |
||
527 | |||
528 | ## API |
||
529 | |||
530 | ### Initialization |
||
531 | The blueimp Gallery can be initialized by simply calling it as a function with |
||
532 | an array of links as first argument and an optional options object as second |
||
533 | argument: |
||
534 | |||
535 | ```js |
||
536 | var gallery = blueimp.Gallery(links, options); |
||
537 | ``` |
||
538 | |||
539 | The links array can be a list of URL strings or a list of objects with URL |
||
540 | properties: |
||
541 | |||
542 | ```js |
||
543 | var gallery = blueimp.Gallery([ |
||
544 | 'https://example.org/images/banana.jpg', |
||
545 | 'https://example.org/images/apple.jpg', |
||
546 | 'https://example.org/images/orange.jpg' |
||
547 | ]); |
||
548 | ``` |
||
549 | |||
550 | ```js |
||
551 | var gallery = blueimp.Gallery([ |
||
552 | { |
||
553 | title: 'Banana', |
||
554 | href: 'https://example.org/images/banana.jpg', |
||
555 | type: 'image/jpeg', |
||
556 | thumbnail: 'https://example.org/thumbnails/banana.jpg' |
||
557 | }, |
||
558 | { |
||
559 | title: 'Apple', |
||
560 | href: 'https://example.org/images/apple.jpg', |
||
561 | type: 'image/jpeg', |
||
562 | thumbnail: 'https://example.org/thumbnails/apple.jpg' |
||
563 | } |
||
564 | ]); |
||
565 | ``` |
||
566 | |||
567 | The URL property name defined by each list object can be configured via the |
||
568 | **urlProperty** option. By default, it is set to **href**, which allows to pass |
||
569 | a list of HTML link elements as first argument. |
||
570 | |||
571 | For images, the **thumbnail** property defines the URL of the image thumbnail, |
||
572 | which is used for the indicator navigation displayed at the bottom of the |
||
573 | Gallery, if the controls are visible. |
||
574 | |||
575 | The object returned by executing the Gallery function (the **gallery** variable |
||
576 | in the example code above) is a new instance of the Gallery and allows to access |
||
577 | the public [API methods](#api-methods) provided by the Gallery. |
||
578 | The Gallery initialization function returns **false** if the given list was |
||
579 | empty, the Gallery widget is missing, or the browser doesn't pass the |
||
580 | functionality test. |
||
581 | |||
582 | ### API methods |
||
583 | The Gallery object returned by executing the Gallery function provides the |
||
584 | following public API methods: |
||
585 | |||
586 | ```js |
||
587 | // Return the current slide index position: |
||
588 | var pos = gallery.getIndex(); |
||
589 | |||
590 | // Return the total number of slides: |
||
591 | var count = gallery.getNumber(); |
||
592 | |||
593 | // Move to the previous slide: |
||
594 | gallery.prev(); |
||
595 | |||
596 | // Move to the next slide: |
||
597 | gallery.next(); |
||
598 | |||
599 | // Move to the given slide index with the (optional) given duraction speed in milliseconds: |
||
600 | gallery.slide(index, duration); |
||
601 | |||
602 | // Start an automatic slideshow with the given interval in milliseconds (optional): |
||
603 | gallery.play(interval); |
||
604 | |||
605 | // Stop the automatic slideshow: |
||
606 | gallery.pause(); |
||
607 | |||
608 | // Add additional slides after Gallery initialization: |
||
609 | gallery.add(list); |
||
610 | |||
611 | // Close and deinitialize the Gallery: |
||
612 | gallery.close(); |
||
613 | ``` |
||
614 | |||
615 | ### Videos |
||
616 | |||
617 | #### HTML5 video player |
||
618 | |||
619 | The Gallery can be initialized with a list of videos instead of images, or a |
||
620 | combination of both: |
||
621 | |||
622 | ```js |
||
623 | blueimp.Gallery([ |
||
624 | { |
||
625 | title: 'Fruits', |
||
626 | href: 'https://example.org/videos/fruits.mp4', |
||
627 | type: 'video/mp4', |
||
628 | poster: 'https://example.org/images/fruits.jpg' |
||
629 | }, |
||
630 | { |
||
631 | title: 'Banana', |
||
632 | href: 'https://example.org/images/banana.jpg', |
||
633 | type: 'image/jpeg', |
||
634 | thumbnail: 'https://example.org/thumbnails/banana.jpg' |
||
635 | } |
||
636 | ]); |
||
637 | ``` |
||
638 | |||
639 | The Gallery uses the **type** property to determine the content type of the |
||
640 | object to display. |
||
641 | If the type property is empty or doesn't exist, the default type **image** is |
||
642 | assumed. |
||
643 | Objects with a video type will be displayed in a |
||
644 | [HTML5 video element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) |
||
645 | if the browser supports the video content type. |
||
646 | |||
647 | For videos, the **poster** property defines the URL of the poster image to |
||
648 | display, before the video is started. |
||
649 | |||
650 | #### Multiple video sources |
||
651 | To provide multiple video formats, the **sources** property of a list object can |
||
652 | be set to an array of objects with **href** and **type** properties for each |
||
653 | video source. The first video format in the list that the browser can play will |
||
654 | be displayed: |
||
655 | |||
656 | ```js |
||
657 | blueimp.Gallery([ |
||
658 | { |
||
659 | title: 'Fruits', |
||
660 | type: 'video/*', |
||
661 | poster: 'https://example.org/images/fruits.jpg', |
||
662 | sources: [ |
||
663 | { |
||
664 | href: 'https://example.org/videos/fruits.mp4', |
||
665 | type: 'video/mp4' |
||
666 | }, |
||
667 | { |
||
668 | href: 'https://example.org/videos/fruits.ogg', |
||
669 | type: 'video/ogg' |
||
670 | } |
||
671 | ] |
||
672 | } |
||
673 | ]); |
||
674 | ``` |
||
675 | |||
676 | It is also possible to define the video sources as data-attribute on a link |
||
677 | element in [JSON](https://developer.mozilla.org/en-US/docs/JSON) array format: |
||
678 | |||
679 | ```html |
||
680 | <div id="links"> |
||
681 | <a |
||
682 | href="https://example.org/videos/fruits.mp4" |
||
683 | title="Fruits" |
||
684 | type="video/mp4" |
||
685 | data-poster="https://example.org/images/fruits.jpg" |
||
686 | data-sources='[{"href": "https://example.org/videos/fruits.mp4", "type": "video/mp4"}, {"href": "https://example.org/videos/fruits.ogg", "type": "video/ogg"}]' |
||
687 | >Fruits</a> |
||
688 | </div> |
||
689 | ``` |
||
690 | |||
691 | #### YouTube |
||
692 | The Gallery can display [YouTube](https://www.youtube.com/) videos for Gallery |
||
693 | items with a **type** of **text/html** and a **youtube** property |
||
694 | (configurable via [YouTube options](#youtube-options)) with the YouTube |
||
695 | video-ID: |
||
696 | |||
697 | ```js |
||
698 | blueimp.Gallery([ |
||
699 | { |
||
700 | title: 'A YouYube video', |
||
701 | href: 'https://www.youtube.com/watch?v=VIDEO_ID', |
||
702 | type: 'text/html', |
||
703 | youtube: 'VIDEO_ID', |
||
704 | poster: 'https://img.youtube.com/vi/VIDEO_ID/maxresdefault.jpg' |
||
705 | }, |
||
706 | { |
||
707 | title: 'Banana', |
||
708 | href: 'https://example.org/images/banana.jpg', |
||
709 | type: 'image/jpeg', |
||
710 | thumbnail: 'https://example.org/thumbnails/banana.jpg' |
||
711 | } |
||
712 | ]); |
||
713 | ``` |
||
714 | |||
715 | If the `href` and `poster` properties are undefined, they are set automatically |
||
716 | based on the video ID. |
||
717 | |||
718 | Please note that the Gallery YouTube integration requires a browser with |
||
719 | [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage) |
||
720 | support, which excludes IE7. |
||
721 | |||
722 | #### Vimeo |
||
723 | The Gallery can display [Vimeo](https://vimeo.com/) videos for Gallery items |
||
724 | with a **type** of **text/html** and a **vimeo** property |
||
725 | (configurable via [Vimeo options](#vimeo-options)) with the Vimeo video-ID: |
||
726 | |||
727 | ```js |
||
728 | blueimp.Gallery([ |
||
729 | { |
||
730 | title: 'A Vimeo video', |
||
731 | href: 'https://vimeo.com/VIDEO_ID', |
||
732 | type: 'text/html', |
||
733 | vimeo: 'VIDEO_ID', |
||
734 | poster: 'https://secure-b.vimeocdn.com/ts/POSTER_ID.jpg' |
||
735 | }, |
||
736 | { |
||
737 | title: 'Banana', |
||
738 | href: 'https://example.org/images/banana.jpg', |
||
739 | type: 'image/jpeg', |
||
740 | thumbnail: 'https://example.org/thumbnails/banana.jpg' |
||
741 | } |
||
742 | ]); |
||
743 | ``` |
||
744 | |||
745 | If the `href` property is undefined, it is set automatically based on the |
||
746 | video ID. |
||
747 | |||
748 | Please note that the Gallery Vimeo integration requires a browser with |
||
749 | [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage) |
||
750 | support, which excludes IE7. |
||
751 | |||
752 | ### Additional Gallery elements |
||
753 | It is possible to add additional elements to the Gallery widget, e.g. a |
||
754 | description label. |
||
755 | |||
756 | First, add the desired HTML element to the Gallery widget: |
||
757 | |||
758 | ```html |
||
759 | <div id="blueimp-gallery" class="blueimp-gallery"> |
||
760 | <div class="slides"></div> |
||
761 | <h3 class="title"></h3> |
||
762 | <!-- The placeholder for the description label: --> |
||
763 | <p class="description"></p> |
||
764 | <a class="prev">‹</a> |
||
765 | <a class="next">›</a> |
||
766 | <a class="close">×</a> |
||
767 | <a class="play-pause"></a> |
||
768 | <ol class="indicator"></ol> |
||
769 | </div> |
||
770 | ``` |
||
771 | |||
772 | Next, add the desired element styles to your CSS file: |
||
773 | |||
774 | ```css |
||
775 | .blueimp-gallery > .description { |
||
776 | position: absolute; |
||
777 | top: 30px; |
||
778 | left: 15px; |
||
779 | color: #fff; |
||
780 | display: none; |
||
781 | } |
||
782 | .blueimp-gallery-controls > .description { |
||
783 | display: block; |
||
784 | } |
||
785 | ``` |
||
786 | |||
787 | Then, add the additional element information to each of your links: |
||
788 | |||
789 | ```html |
||
790 | <div id="links"> |
||
791 | <a href="images/banana.jpg" title="Banana" data-description="This is a banana.">Banana</a> |
||
792 | <a href="images/apple.jpg" title="Apple" data-description="This is an apple.">Apple</a> |
||
793 | </div> |
||
794 | ``` |
||
795 | |||
796 | Finally, initialize the Gallery with an onslide callback option, to set the |
||
797 | element content based on the information from the current link: |
||
798 | |||
799 | ```js |
||
800 | blueimp.Gallery( |
||
801 | document.getElementById('links'), |
||
802 | { |
||
803 | onslide: function (index, slide) { |
||
804 | var text = this.list[index].getAttribute('data-description'), |
||
805 | node = this.container.find('.description'); |
||
806 | node.empty(); |
||
807 | if (text) { |
||
808 | node[0].appendChild(document.createTextNode(text)); |
||
809 | } |
||
810 | } |
||
811 | } |
||
812 | ); |
||
813 | ``` |
||
814 | |||
815 | ### Additional content types |
||
816 | By extending the Gallery prototype with new factory methods, additional content |
||
817 | types can be displayed. By default, blueimp Gallery provides the |
||
818 | **imageFactory** and **videoFactory** methods for **image** and **video** |
||
819 | content types respectively. |
||
820 | |||
821 | The Gallery uses the **type** property of each content object to determine which |
||
822 | factory method to use. The **type** defines the |
||
823 | [Internet media type](https://en.wikipedia.org/wiki/Internet_media_type) of the |
||
824 | content object and is composed of two or more parts: A type, a subtype, and zero |
||
825 | or more optional parameters, e.g. **text/html; charset=UTF-8** for an HTML |
||
826 | document with UTF-8 encoding. |
||
827 | The main type (the string in front of the slash, **text** in the example above) |
||
828 | is concatenated with the string **Factory** to create the factory method name, |
||
829 | e.g. **textFactory**. |
||
830 | |||
831 | #### Example HTML text factory implementation |
||
832 | Please note that the textFactory script has to be included after the core |
||
833 | Gallery script, but before including the [YouTube](#youtube) and [Vimeo](#vimeo) |
||
834 | integration plugins, which extend the textFactory implementation to handle |
||
835 | YouTube and Vimeo video links. |
||
836 | |||
837 | Please also note that although blueimp Gallery doesn't require |
||
838 | [jQuery](https://jquery.com/), the following example uses it for convenience. |
||
839 | |||
840 | Extend the Gallery prototype with the **textFactory** method: |
||
841 | |||
842 | ```js |
||
843 | blueimp.Gallery.prototype.textFactory = function (obj, callback) { |
||
844 | var $element = $('<div>') |
||
845 | .addClass('text-content') |
||
846 | .attr('title', obj.title); |
||
847 | $.get(obj.href) |
||
848 | .done(function (result) { |
||
849 | $element.html(result); |
||
850 | callback({ |
||
851 | type: 'load', |
||
852 | target: $element[0] |
||
853 | }); |
||
854 | }) |
||
855 | .fail(function () { |
||
856 | callback({ |
||
857 | type: 'error', |
||
858 | target: $element[0] |
||
859 | }); |
||
860 | }); |
||
861 | return $element[0]; |
||
862 | }; |
||
863 | ``` |
||
864 | |||
865 | Next, add the **text-content** class to the Gallery CSS: |
||
866 | |||
867 | ```css |
||
868 | .blueimp-gallery > .slides > .slide > .text-content { |
||
869 | overflow: auto; |
||
870 | margin: 60px auto; |
||
871 | padding: 0 60px; |
||
872 | max-width: 920px; |
||
873 | text-align: left; |
||
874 | } |
||
875 | ``` |
||
876 | |||
877 | With the previous changes in place, the Gallery can now handle HTML content |
||
878 | types: |
||
879 | |||
880 | ```js |
||
881 | blueimp.Gallery([ |
||
882 | { |
||
883 | title: 'Noodle soup', |
||
884 | href: 'https://example.org/text/noodle-soup.html', |
||
885 | type: 'text/html' |
||
886 | }, |
||
887 | { |
||
888 | title: 'Tomato salad', |
||
889 | href: 'https://example.org/text/tomato-salad.html', |
||
890 | type: 'text/html' |
||
891 | } |
||
892 | ]); |
||
893 | ``` |
||
894 | |||
895 | ### jQuery plugin |
||
896 | |||
897 | #### jQuery plugin setup |
||
898 | The blueimp Gallery jQuery plugin registers a global click handler to open links |
||
899 | with **data-gallery** attribute in the Gallery lightbox. |
||
900 | |||
901 | To use it, follow the [lightbox setup](#lightbox-setup) guide, but replace the |
||
902 | minified Gallery script with the jQuery plugin version and include it after |
||
903 | including [jQuery](https://jquery.com/): |
||
904 | |||
905 | ```html |
||
906 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> |
||
907 | <script src="js/jquery.blueimp-gallery.min.js"></script> |
||
908 | ``` |
||
909 | |||
910 | Next, add the attribute **data-gallery** to your Gallery links: |
||
911 | |||
912 | ```html |
||
913 | <div id="links"> |
||
914 | <a href="images/banana.jpg" title="Banana" data-gallery> |
||
915 | <img src="images/thumbnails/banana.jpg" alt="Banana"> |
||
916 | </a> |
||
917 | <a href="images/apple.jpg" title="Apple" data-gallery> |
||
918 | <img src="images/thumbnails/apple.jpg" alt="Apple"> |
||
919 | </a> |
||
920 | <a href="images/orange.jpg" title="Orange" data-gallery> |
||
921 | <img src="images/thumbnails/orange.jpg" alt="Orange"> |
||
922 | </a> |
||
923 | </div> |
||
924 | ``` |
||
925 | |||
926 | The onclick handler from the [lightbox setup](#lightbox-setup) guide is not |
||
927 | required and can be removed. |
||
928 | |||
929 | #### HTML5 data-attributes |
||
930 | Options for the Gallery lightbox opened via the jQuery plugin can be defined as |
||
931 | [HTML5 data-attributes](https://api.jquery.com/data/#data-html5) on the Gallery |
||
932 | widget container. |
||
933 | |||
934 | The jQuery plugin also introduces the additional **filter** option, which is |
||
935 | applied to the Gallery links via |
||
936 | [jQuery's filter method](https://api.jquery.com/filter/) and allows to remove |
||
937 | duplicates from the list: |
||
938 | |||
939 | ```html |
||
940 | <div id="blueimp-gallery" class="blueimp-gallery" data-start-slideshow="true" data-filter=":even"> |
||
941 | <div class="slides"></div> |
||
942 | <h3 class="title"></h3> |
||
943 | <a class="prev">‹</a> |
||
944 | <a class="next">›</a> |
||
945 | <a class="close">×</a> |
||
946 | <a class="play-pause"></a> |
||
947 | <ol class="indicator"></ol> |
||
948 | </div> |
||
949 | ``` |
||
950 | |||
951 | This will initialize the Gallery with the option **startSlideshow** set to |
||
952 | **true**. |
||
953 | It will also filter the Gallery links so that only links with an even index |
||
954 | number will be included. |
||
955 | |||
956 | #### Container ids and link grouping |
||
957 | If the **data-gallery** attribute value is a valid id string |
||
958 | (e.g. "#blueimp-gallery"), it is used as container option. |
||
959 | Setting **data-gallery** to a non-empty string also allows to group links into |
||
960 | different sets of Gallery images: |
||
961 | |||
962 | ```html |
||
963 | <div id="fruits"> |
||
964 | <a href="images/banana.jpg" title="Banana" data-gallery="#blueimp-gallery-fruits"> |
||
965 | <img src="images/thumbnails/banana.jpg" alt="Banana"> |
||
966 | </a> |
||
967 | <a href="images/apple.jpg" title="Apple" data-gallery="#blueimp-gallery-fruits"> |
||
968 | <img src="images/thumbnails/apple.jpg" alt="Apple"> |
||
969 | </a> |
||
970 | </div> |
||
971 | <div id="vegetables"> |
||
972 | <a href="images/tomato.jpg" title="Tomato" data-gallery="#blueimp-gallery-vegetables"> |
||
973 | <img src="images/thumbnails/tomato.jpg" alt="Tomato"> |
||
974 | </a> |
||
975 | <a href="images/onion.jpg" title="Onion" data-gallery="#blueimp-gallery-vegetables"> |
||
976 | <img src="images/thumbnails/onion.jpg" alt="Onion"> |
||
977 | </a> |
||
978 | </div> |
||
979 | ``` |
||
980 | |||
981 | This will open the links with the **data-gallery** attribute |
||
982 | **#blueimp-gallery-fruits** in the Gallery widget with the id |
||
983 | **blueimp-gallery-fruits**, and the links with the **data-gallery** attribute |
||
984 | **#blueimp-gallery-vegetables** in the Gallery widget with the id |
||
985 | **blueimp-gallery-vegetables**. |
||
986 | |||
987 | #### Gallery object |
||
988 | The gallery object is stored via |
||
989 | [jQuery data storage](https://api.jquery.com/category/miscellaneous/data-storage/) |
||
990 | on the Gallery widget when the Gallery is opened and can be retrieved the |
||
991 | following way: |
||
992 | |||
993 | ```js |
||
994 | var gallery = $('#blueimp-gallery').data('gallery'); |
||
995 | ``` |
||
996 | |||
997 | This gallery object provides all methods outlined in the API methods section. |
||
998 | |||
999 | #### jQuery events |
||
1000 | The jQuery plugin triggers Gallery events on the widget container, with event |
||
1001 | names equivalent to the gallery [event callbacks](#event-callbacks): |
||
1002 | |||
1003 | ```js |
||
1004 | $('#blueimp-gallery') |
||
1005 | .on('open', function (event) { |
||
1006 | // Gallery open event handler |
||
1007 | }) |
||
1008 | .on('opened', function (event) { |
||
1009 | // Gallery opened event handler |
||
1010 | }) |
||
1011 | .on('slide', function (event, index, slide) { |
||
1012 | // Gallery slide event handler |
||
1013 | }) |
||
1014 | .on('slideend', function (event, index, slide) { |
||
1015 | // Gallery slideend event handler |
||
1016 | }) |
||
1017 | .on('slidecomplete', function (event, index, slide) { |
||
1018 | // Gallery slidecomplete event handler |
||
1019 | }) |
||
1020 | .on('close', function (event) { |
||
1021 | // Gallery close event handler |
||
1022 | }) |
||
1023 | .on('closed', function (event) { |
||
1024 | // Gallery closed event handler |
||
1025 | }); |
||
1026 | ``` |
||
1027 | |||
1028 | ## Requirements |
||
1029 | blueimp Gallery doesn't require any other libraries and can be used standalone |
||
1030 | without any dependencies. |
||
1031 | |||
1032 | You can also use the individual source files instead of the standalone minified |
||
1033 | version: |
||
1034 | |||
1035 | ```html |
||
1036 | <link rel="stylesheet" href="css/blueimp-gallery.css"> |
||
1037 | <link rel="stylesheet" href="css/blueimp-gallery-indicator.css"> |
||
1038 | <link rel="stylesheet" href="css/blueimp-gallery-video.css"> |
||
1039 | <!-- ... --> |
||
1040 | <script src="js/blueimp-helper.js"></script> |
||
1041 | <script src="js/blueimp-gallery.js"></script> |
||
1042 | <script src="js/blueimp-gallery-fullscreen.js"></script> |
||
1043 | <script src="js/blueimp-gallery-indicator.js"></script> |
||
1044 | <script src="js/blueimp-gallery-video.js"></script> |
||
1045 | <script src="js/blueimp-gallery-youtube.js"></script> |
||
1046 | <script src="js/blueimp-gallery-vimeo.js"></script> |
||
1047 | ``` |
||
1048 | |||
1049 | The helper script can be replaced by [jQuery](https://jquery.com/) v. 1.7+. |
||
1050 | The fullscreen, indicator, video, youtube and vimeo source files are optional if |
||
1051 | their functionality is not required. |
||
1052 | |||
1053 | The [jQuery plugin](#jquery-plugin) requires |
||
1054 | [jQuery](https://jquery.com/) v. 1.7+ and the basic Gallery script, while the |
||
1055 | fullscreen, indicator, video, youtube and vimeo source files are also optional: |
||
1056 | |||
1057 | ```html |
||
1058 | <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> |
||
1059 | <script src="js/blueimp-gallery.js"></script> |
||
1060 | <script src="js/blueimp-gallery-fullscreen.js"></script> |
||
1061 | <script src="js/blueimp-gallery-indicator.js"></script> |
||
1062 | <script src="js/blueimp-gallery-video.js"></script> |
||
1063 | <script src="js/blueimp-gallery-youtube.js"></script> |
||
1064 | <script src="js/blueimp-gallery-vimeo.js"></script> |
||
1065 | <script src="js/jquery.blueimp-gallery.js"></script> |
||
1066 | ``` |
||
1067 | |||
1068 | Please note that the jQuery plugin is an optional extension and not required for |
||
1069 | the Gallery functionality. |
||
1070 | |||
1071 | ## Browsers |
||
1072 | blueimp Gallery has been tested with and supports the following browsers: |
||
1073 | |||
1074 | ### Desktop browsers |
||
1075 | |||
1076 | * Google Chrome 14.0+ |
||
1077 | * Apple Safari 4.0+ |
||
1078 | * Mozilla Firefox 4.0+ |
||
1079 | * Opera 10.0+ |
||
1080 | * Microsoft Internet Explorer 7.0+ |
||
1081 | |||
1082 | ### Mobile browsers |
||
1083 | |||
1084 | * Apple Safari on iOS 6.0+ |
||
1085 | * Google Chrome on iOS 6.0+ |
||
1086 | * Google Chrome on Android 4.0+ |
||
1087 | * Default Browser on Android 2.3+ |
||
1088 | * Opera Mobile 12.0+ |
||
1089 | |||
1090 | ## License |
||
1091 | Released under the [MIT license](https://opensource.org/licenses/MIT). |
||
1092 | |||
1093 | ## Credits |
||
1094 | The swipe implementation is based on code from the |
||
1095 | [Swipe](http://swipejs.com/) library. |