Photo Browser - 图1

Photo Browser

Photo Browser is a photo browser component to display collection of photos / images. Photos can be zoomed and panned (optional).

Photo Browser uses Swiper Slider component to slide between photos.

Photo Browser App Methods

Let’s look at related App methods to work with Photo Browser:

app.photoBrowser.create(parameters)- create Photo Browser instance

  • parameters - object. Object with photo browser parameters

Method returns created Photo Browser’s instance

app.photoBrowser.destroy(el)- destroy Photo Browser instance

  • el - HTMLElement or string (with CSS Selector) or object. Photo Browser element or Photo Browser instance to destroy.

app.photoBrowser.get(el)- get Photo Browser instance by HTML element

  • el - HTMLElement or string (with CSS Selector). Photo Browser element.

Method returns Photo Browser’s instance

For example:

  1. var photoBrowser = app.photoBrowser.create({
  2. photos: [
  3. 'path/to/photo-1.jpg',
  4. 'path/to/photo-2.jpg'
  5. ],
  6. });

Photo Browser Parameters

Let’s look on list of all available Photo Browser parameters:

ParameterTypeDefaultDescription
photosarray[]Array with URLs of photos or array of objects with “url” (or “html”) and “caption” properties.
expositionbooleantrueEnable disable exposition mode when clicking on Photo Browser.
expositionHideCaptionsbooleanfalseSet to true if you also want to hide captions in exposition mode
swipeToClosebooleantrueYou can close Photo Browser with swipe up/down when this parameter is enabled
routableModalsbooleantrueWill add opened photo browser to router history which gives ability to close photo browser by going back in router history and set current route to the photo browser modal
urlstringphotos/Photo browser modal URL that will be set as a current route
viewobjectLink to initialized View instance if you want use “page” Photo Browser type or where to set routing when routableModals enabled. By default, if not specified, it will be opened in Main View.
typestringstandaloneDefine how Photo Browser should be opened. Could be standalone (will be opened as an overlay with custom transition effect), popup (will be opened as popup), page (will be injected to View and loaded as a new page).
themestringlightPhoto Browser color theme, could be light or dark
captionsThemestringCaptions color theme, could be also light or dark. By default, equal to theme parameter
navbarbooleantrueSet to false to remove Photo Browser’s Navbar
toolbarbooleantrueSet to false to remove Photo Browser’s Toolbar
backLinkTextstringCloseText on back link in Photo Browser’s navbar
navbarOfTextstring‘of’Text of “of” in photos counter: “3 of 5”
iconsColorstringOne of the default colors
swiperobjectSwiper parameters. By default equals to:
  1. swiper: {
  2. initialSlide: 0,
  3. spaceBetween: 20,
  4. speed: 300,
  5. loop: false,
  6. preloadImages: true,
  7. navigation: {
  8. nextEl: ‘.photo-browser-next’,
  9. prevEl: ‘.photo-browser-prev’,
  10. },
  11. zoom: {
  12. enabled: true,
  13. maxRatio: 3,
  14. minRatio: 1,
  15. },
  16. lazy: {
  17. enabled: true,
  18. },
  19. },
Render functions
renderNavbarfunctionFunction to render navbar, must return navbar HTML string
renderToolbarfunctionFunction to render toolbar, must return toolbar HTML string
renderCaptionfunction(caption, index)Function to render single caption, must return caption HTML string
renderObjectfunction(photo, index)Function to render photo object, must return photo object HTML string
renderLazyPhotofunction(photo, index)Function to render lazy loaded photo slide, must return slide HTML string
renderPhotofunction(photo, index)Function to render photo as a swiper slide, must return slide HTML string
renderPagefunctionFunction to render photobrowser page, must return full page HTML layout string
renderPopupfunctionFunction to render photobrowser popup, must return full popup HTML layout string
renderStandalonefunctionFunction to render photobrowser standalone modal, must return full modal HTML layout string
Events
onobjectObject with events handlers. For example:
  1. var photoBrowser = app.photoBrowser.create({
  2. on: {
  3. opened: function () {
  4. console.log(‘photo browser opened’)
  5. }
  6. }
  7. })

Note that all following parameters can be used in global app parameters under photoBrowser property to set defaults for all photo browsers. For example:

  1. var app = new Framework7({
  2. photoBrowser: {
  3. type: 'popup',
  4. }
  5. });

Photos Array

When we initialize Photo Browser we need to pass array with photos/videos in photos parameter. Let’s look at different variations of this array:

  1. // If we need photo browser with just photos we may pass array with string urls:
  2. var photos = [
  3. 'image1.jpg',
  4. 'image2.jpg',
  5. 'image3.jpg',
  6. 'image4.jpg',
  7. ];
  8. //If we need to use caption for some of photos then each photo should be presented as object:
  9. var photos = [
  10. {
  11. url: 'image1.jpg',
  12. caption: 'Caption 1'
  13. },
  14. {
  15. url: 'image2.jpg',
  16. caption: 'Caption 1'
  17. },
  18. // This one will be without caption
  19. {
  20. url: 'image3.jpg',
  21. },
  22. // This one will be also without caption
  23. 'image4.jpg'
  24. ];
  25. //If we need to use videos in some slides we need to pass HTML element of video element or iframe within "html" property:
  26. var photos = [
  27. {
  28. url: 'image1.jpg',
  29. caption: 'Caption 1'
  30. },
  31. // Video element with caption
  32. {
  33. html: '<video src="video1.mp4"></video>',
  34. caption: 'Video Caption'
  35. },
  36. // This one is embedded video without caption
  37. {
  38. html: '<iframe src="..."></iframe>',
  39. },
  40. // This one will be also video without caption
  41. '<video src="video2.mp4"></video>'
  42. ];

Photo Browser Methods & Properties

After we initialize Photo Browser we have its initialized instance in variable (like photoBrowser variable in examples above) with helpful methods and properties:

Properties
photoBrowser.appLink to global app instance
photoBrowser.elPhoto Browser HTML element
photoBrowser.$elDom7 instance with Photo Browser HTML element
photoBrowser.activeIndexIndex number of currently active photo slide
photoBrowser.exposedtrue if Photo Browser in exposition mode
photoBrowser.openedtrue if Photo Browser is currently opened
photoBrowser.urlPhoto Browser URL (that was passed in url parameter)
photoBrowser.viewPhoto Browser View (that was passed in view parameter) or found parent view
photoBrowser.swiperContains initialized Swiper instance with all available Swiper methods and properties
photoBrowser.paramsObject with initialization parameters
Methods
photoBrowser.open(index)Open Photo Browser on photo with index number equal to “index” parameter. If “index” parameter is not specified, it will be opened on last closed photo.
photoBrowser.close()Close Photo Browser
photoBrowser.expositionToggle()Toggle exposition mode
photoBrowser.expositionEnable()Enable exposition mode
photoBrowser.expositionDisable()Disable exposition mode
photoBrowser.destroy()Destroy photo prowser instance
photoBrowser.on(event, handler)Add event handler
photoBrowser.once(event, handler)Add event handler that will be removed after it was fired
photoBrowser.off(event, handler)Remove event handler
photoBrowser.off(event)Remove all handlers for specified event
photoBrowser.emit(event, …args)Fire event on instance

Photo Browser Events

Photo Browser will fire the following DOM events on photo browser element and events on app and photo browser instance:

DOM Events

EventTargetDescription
photobrowser:openPhoto Browser ElementEvent will be triggered when Photo Browser starts its opening animation
photobrowser:openedPhoto Browser ElementEvent will be triggered after Photo Browser completes its opening animation
photobrowser:closePhoto Browser ElementEvent will be triggered when Photo Browser starts its closing animation
photobrowser:closedPhoto Browser ElementEvent will be triggered after Photo Browser completes its closing animation

App and Photo Browser Instance Events

Photo Browser instance emits events on both self instance and app instance. App instance events has same names prefixed with photoBrowser.

EventTargetDescription
swipeToClosephotoBrowserEvent will be fired when user close photo browser with swipe up/down.
tapphotoBrowserSwiper event. Event will be fired when user click/tap on Swiper. Receives ‘touchend’ event as an arguments.
clickphotoBrowserSwiper event. Event will be fired when user click/tap on Swiper after 300ms delay. Receives ‘touchend’ event as an arguments.
doubleTapphotoBrowserSwiper event. Event will be fired when user double tap on Swiper’s container. Receives ‘touchend’ event as an arguments
slideChangephotoBrowserSwiper event. Event will be fired when currently active slide is changed
transitionStartphotoBrowserSwiper event. Event will be fired in the beginning of transition.
transitionEndphotoBrowserSwiper event. Event will be fired after transition.
slideChangeTransitionStartphotoBrowserSwiper event. Event will be fired in the beginning of animation to other slide (next or previous).
slideChangeTransitionEndphotoBrowserSwiper event. Event will be fired after animation to other slide (next or previous).
lazyImageLoadphotoBrowserSwiper event. Event will be fired in the beginning of lazy loading of image
lazyImageReadyphotoBrowserSwiper event. Event will be fired when lazy loading image will be loaded
touchStartphotoBrowserSwiper event. Event will be fired when user touch Swiper. Receives ‘touchstart’ event as an arguments.
touchMoveOppositephotoBrowserSwiper event. Event will be fired when user touch and move finger over Swiper in direction opposite to direction parameter. Receives ‘touchmove’ event as an arguments.
touchEndphotoBrowserSwiper event. Event will be fired when user release Swiper. Receives ‘touchend’ event as an arguments.
openphotoBrowserEvent will be triggered when Photo Browser starts its opening animation. As an argument event handler receives photoBrowser instance
photoBrowserOpenapp
openedphotoBrowserEvent will be triggered after Photo Browser completes its opening animation. As an argument event handler receives photoBrowser instance
photoBrowserOpenedapp
closephotoBrowserEvent will be triggered when Photo Browser starts its closing animation. As an argument event handler receives photoBrowser instance
photoBrowserCloseapp
closedphotoBrowserEvent will be triggered after Photo Browser completes its closing animation. As an argument event handler receives photoBrowser instance
photoBrowserClosedapp
beforeDestroyphotoBrowserEvent will be triggered right before Photo Browser instance will be destroyed. As an argument event handler receives photoBrowser instance
photoBrowserBeforeDestroyapp

Examples

  1. <div class="page-content">
  2. <div class="block-title">Light Theme</div>
  3. <div class="block row">
  4. <div class="col-33"><a href="#" class="button pb-standalone">Standalone</a></div>
  5. <div class="col-33"><a href="#" class="button pb-popup">Popup</a></div>
  6. <div class="col-33"><a href="#" class="button pb-page">Page</a></div>
  7. </div>
  8. <div class="block-title">Dark Theme</div>
  9. <div class="block row">
  10. <div class="col-50"><a href="#" class="button pb-standalone-dark">Standalone</a></div>
  11. <div class="col-50"><a href="#" class="button pb-popup-dark">Popup</a></div>
  12. </div>
  13. </div>
  1. var app = new Framework7();
  2. var $$ = Dom7;
  3. /*=== Default standalone ===*/
  4. var myPhotoBrowserStandalone = app.photoBrowser.create({
  5. photos : [
  6. 'http://lorempixel.com/1024/1024/sports/1/',
  7. 'http://lorempixel.com/1024/1024/sports/2/',
  8. 'http://lorempixel.com/1024/1024/sports/3/',
  9. ]
  10. });
  11. //Open photo browser on click
  12. $$('.pb-standalone').on('click', function () {
  13. myPhotoBrowserStandalone.open();
  14. });
  15. /*=== Popup ===*/
  16. var myPhotoBrowserPopup = app.photoBrowser.create({
  17. photos : [
  18. 'http://lorempixel.com/1024/1024/sports/1/',
  19. 'http://lorempixel.com/1024/1024/sports/2/',
  20. 'http://lorempixel.com/1024/1024/sports/3/',
  21. ],
  22. type: 'popup'
  23. });
  24. $$('.pb-popup').on('click', function () {
  25. myPhotoBrowserPopup.open();
  26. });
  27. /*=== As Page ===*/
  28. var myPhotoBrowserPage = app.photoBrowser.create({
  29. photos : [
  30. 'http://lorempixel.com/1024/1024/sports/1/',
  31. 'http://lorempixel.com/1024/1024/sports/2/',
  32. 'http://lorempixel.com/1024/1024/sports/3/',
  33. ],
  34. type: 'page',
  35. backLinkText: 'Back'
  36. });
  37. $$('.pb-page').on('click', function () {
  38. myPhotoBrowserPage.open();
  39. });
  40. /*=== Standalone Dark ===*/
  41. var myPhotoBrowserDark = app.photoBrowser.create({
  42. photos : [
  43. 'http://lorempixel.com/1024/1024/sports/1/',
  44. 'http://lorempixel.com/1024/1024/sports/2/',
  45. 'http://lorempixel.com/1024/1024/sports/3/',
  46. ],
  47. theme: 'dark'
  48. });
  49. $$('.pb-standalone-dark').on('click', function () {
  50. myPhotoBrowserDark.open();
  51. });
  52. /*=== Popup Dark ===*/
  53. var myPhotoBrowserPopupDark = app.photoBrowser.create({
  54. photos : [
  55. 'http://lorempixel.com/1024/1024/sports/1/',
  56. 'http://lorempixel.com/1024/1024/sports/2/',
  57. 'http://lorempixel.com/1024/1024/sports/3/',
  58. ],
  59. theme: 'dark',
  60. type: 'popup'
  61. });
  62. $$('.pb-popup-dark').on('click', function () {
  63. myPhotoBrowserPopupDark.open();
  64. });
  65. /*=== With Captions ===*/
  66. var myPhotoBrowserPopupDark = app.photoBrowser.create({
  67. photos : [
  68. {
  69. url: 'http://lorempixel.com/1024/1024/sports/1/',
  70. caption: 'Caption 1 Text'
  71. },
  72. {
  73. url: 'http://lorempixel.com/1024/1024/sports/2/',
  74. caption: 'Second Caption Text'
  75. },
  76. // This one without caption
  77. {
  78. url: 'http://lorempixel.com/1024/1024/sports/3/',
  79. },
  80. ],
  81. theme: 'dark',
  82. type: 'standalone'
  83. });
  84. $$('.pb-standalone-captions').on('click', function () {
  85. myPhotoBrowserPopupDark.open();
  86. });
  87. /*=== With Video ===*/
  88. var myPhotoBrowserPopupDark = app.photoBrowser.create({
  89. photos : [
  90. {
  91. html: '<iframe src="//www.youtube.com/embed/lmc21V-zBq0" frameborder="0" allowfullscreen></iframe>',
  92. caption: 'Woodkid - Run Boy Run (Official HD Video)'
  93. },
  94. {
  95. url: 'http://lorempixel.com/1024/1024/sports/2/',
  96. caption: 'Second Caption Text'
  97. },
  98. {
  99. url: 'http://lorempixel.com/1024/1024/sports/3/',
  100. },
  101. ],
  102. theme: 'dark',
  103. type: 'standalone'
  104. });
  105. $$('.pb-standalone-video').on('click', function () {
  106. myPhotoBrowserPopupDark.open();
  107. });