intranet-pictures 2.0.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f83afa6acab98f33abb964031b20ee5e3e13a9225ff3ec4525be209c87c66f51
4
- data.tar.gz: 1c43a4f8cc550fe3900684a81e93ed0e50276ed59154f166132b1395d0748911
3
+ metadata.gz: 6e5e318561ea69bdaed8eaf38cf8d1349220835196596acc6ba65640c2deac52
4
+ data.tar.gz: ebc612ab80afffc3c9f70a3ea0b2da47467006b91854a0e7f7c05227a2c64a2d
5
5
  SHA512:
6
- metadata.gz: 9746b40dee3c630e69510789eed1d3f937f88441b7a484c0a139d90b7eacfdff63394875bc8122e9efea0583c6955fbc3da77852bb4816a1615952b3658de099
7
- data.tar.gz: 9e8d8f8903b495bb1dbbacf010cea817f11440a0475b2eb6b98dc7b6e0576ea1dd6d1583cff63f27a9f607f384d108e1a6fa8dc969d009ba43d57b3e544cccb9
6
+ metadata.gz: fc2992a96129bf8b0e8a0e79753a9833541a10b875bddc9893cf5dec74e595dcf5693fd28f5b5c4b771725fb0bb64f14ebc43efb87855959c780efa19e4a822f
7
+ data.tar.gz: 26b461521d1b71a98a37f0e1848a3cae417eb79ccc8ba19faeaafbbc94a38143fa00871e53118417923b3a9bd1326520ae57492f732fa9fcc9f7ee68b0f35a6f
@@ -240,7 +240,8 @@ module Intranet
240
240
  " viewer_close: '#{I18n.t('pictures.viewer.close')}',\n" \
241
241
  " viewer_zoom: '#{I18n.t('pictures.viewer.zoom')}',\n" \
242
242
  " viewer_previous: '#{I18n.t('pictures.viewer.previous')}',\n" \
243
- " viewer_next: '#{I18n.t('pictures.viewer.next')}' };"]
243
+ " viewer_next: '#{I18n.t('pictures.viewer.next')}',\n" \
244
+ " viewer_toggle_caption: '#{I18n.t('pictures.viewer.toggle_caption')}' };"]
244
245
  end
245
246
 
246
247
  ##########################################################################
@@ -8,7 +8,7 @@ module Intranet
8
8
  NAME = 'intranet-pictures'
9
9
 
10
10
  # The version of the gem, according to semantic versionning.
11
- VERSION = '2.0.0'
11
+ VERSION = '2.2.0'
12
12
 
13
13
  # The URL of the gem homepage.
14
14
  HOMEPAGE_URL = 'https://rubygems.org/gems/intranet-pictures'
@@ -10,6 +10,7 @@ en:
10
10
  zoom: 'Zoom'
11
11
  previous: 'Previous image'
12
12
  next: 'Next image'
13
+ toggle_caption: 'Toggle caption/info pannel'
13
14
  nav:
14
15
  event: 'Events'
15
16
  city: 'Cities'
@@ -10,6 +10,7 @@ fr:
10
10
  zoom: 'Agrandir'
11
11
  previous: 'Image précédente'
12
12
  next: 'Image suivante'
13
+ toggle_caption: 'Afficher/Masquer les détails'
13
14
  nav:
14
15
  event: 'Événements'
15
16
  city: 'Villes'
@@ -12,43 +12,141 @@ import PhotoSwipeDynamicCaption from './photoswipe/photoswipe-dynamic-caption-pl
12
12
  // Import internationalization support
13
13
  import i18n from './../i18n.js';
14
14
 
15
- function convertDate(iso8601_date) {
16
- const d = new Date(iso8601_date);
17
- const str = d.toLocaleDateString() + ' ' + d.toLocaleTimeString().replace(/(\d{2}):(\d{2}):(\d{2})/, '$1h$2');
18
- return str;
15
+ class PhotoSwipePictureGallery {
16
+ constructor(items) {
17
+ // Create PhotoSwipe Lightbox
18
+ const lightboxOptions = {
19
+ dataSource: items,
20
+ pswpModule: PhotoSwipe,
21
+ bgOpacity: 0.95,
22
+ closeOnVerticalDrag: false,
23
+ closeTitle: i18n.viewer_close + ' (Esc)',
24
+ zoomTitle: i18n.viewer_zoom + ' (z)',
25
+ arrowPrevTitle: i18n.viewer_previous,
26
+ arrowNextTitle: i18n.viewer_next,
27
+ };
28
+ this.lightbox = new PhotoSwipeLightbox(lightboxOptions);
29
+
30
+ // Initialize caption plugin
31
+ const captionPluginOptions = {
32
+ type: 'below',
33
+ mobileLayoutBreakpoint: 800,
34
+ captionContent: (slide) => {
35
+ return this._captionContent(slide)
36
+ },
37
+ };
38
+ this.captionPlugin = new PhotoSwipeDynamicCaption(this.lightbox, captionPluginOptions);
39
+
40
+ // Add custom 'Info' button, see https://photoswipe.com/v5/docs/adding-custom-buttons/
41
+ // Info menu button
42
+ const infoButton = {
43
+ name: 'info',
44
+ title: i18n.viewer_toggle_caption,
45
+ order: 15, // Insert button between zoom & close buttons
46
+ isButton: true,
47
+ html: {
48
+ isCustomSVG: true,
49
+ inner: '<path d="M7 16a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" id="pswp__icn-info"/>'
50
+ + '<path fill="currentColor" d="M17 15h-2v6h2z"/>'
51
+ + '<path fill="currentColor" d="M17 11h-2v2h2z"/>',
52
+ outlineID: 'pswp__icn-info',
53
+ },
54
+ onClick: (ev, el, pswp) => {
55
+ this._toggleInfoPannel(ev, el, pswp);
56
+ },
57
+ };
58
+ this.lightbox.on('uiRegister', () => {
59
+ this.lightbox.pswp.ui.registerElement(infoButton);
60
+ });
61
+
62
+ this.lightbox.on('calcSlideSize', (e) => {
63
+ /* When using mobile layout for caption, hide the Info button since the caption is fixed
64
+ * at the bottom. */
65
+ if (this.captionPlugin.useMobileLayout()) {
66
+ document.querySelector('.pswp__button--info').style.display = 'none';
67
+ } else {
68
+ document.querySelector('.pswp__button--info').style.display = '';
69
+ }
70
+ });
71
+ }
72
+
73
+ // Open gallery at the given slide index (starting at 0)
74
+ open(index) {
75
+ this.lightbox.init();
76
+ this.lightbox.loadAndOpen(index);
77
+ }
78
+
79
+ // Switch between regular caption (below image) and info pannel (aside)
80
+ _toggleInfoPannel(ev, el, pswp) {
81
+ if (this.captionPlugin.options.type === 'below') {
82
+ this.captionPlugin.options.type = 'aside';
83
+ } else if (this.captionPlugin.options.type === 'aside') {
84
+ this.captionPlugin.options.type = 'below';
85
+ }
86
+ /* Force updating size of all PhotoSwipe elements. This will trigger the 'calcSlideSize' event
87
+ * on each loaded slide, causing update of the caption text (see handler above). */
88
+ this.lightbox.pswp.updateSize(true);
89
+ }
90
+
91
+ _convertDate(iso8601_date) {
92
+ const d = new Date(iso8601_date);
93
+ const str = d.toLocaleDateString() + ' ' + d.toLocaleTimeString().replace(/(\d{2}):(\d{2}):(\d{2})/, '$1h$2');
94
+ return str;
95
+ }
96
+
97
+ // Get caption content, according to current image & caption layout
98
+ _captionContent(slide) {
99
+ const slideTitle = slide.data.title;
100
+ const slideDateTime = this._convertDate(slide.data.datetime, true);
101
+
102
+ if (this.captionPlugin.options.type === 'aside' && !this.captionPlugin.useMobileLayout()) {
103
+ var caption = '<strong>' + slideTitle + '</strong><hr />' +
104
+ '<p class="pswp__caption__exif pswp__caption__exif_datetime">' + slideDateTime + '</p>';
105
+ if (slide.data.artist) {
106
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_author">' + slide.data.artist + '</p>';
107
+ }
108
+ if (slide.data.event) {
109
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_event">' + slide.data.event + '</p>';
110
+ }
111
+ if (slide.data.city || slide.data.region) {
112
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_location">';
113
+ if (slide.data.city) { caption += slide.data.city; }
114
+ if (slide.data.city && slide.data.region) { caption += ', '; }
115
+ if (slide.data.region) { caption += slide.data.region; }
116
+ caption += '</p>';
117
+ }
118
+ if (slide.data.model) {
119
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_camera">' + slide.data.model + '</p>';
120
+ }
121
+ if (slide.data.focallength) {
122
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_focal">' + slide.data.focallength + '</p>';
123
+ }
124
+ if (slide.data.fnumber) {
125
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_fstop">' + slide.data.fnumber + '</p>';
126
+ }
127
+ if (slide.data.exposure) {
128
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_shutter">' + slide.data.exposure + '</p>';
129
+ }
130
+ if (slide.data.isospeed) {
131
+ caption += '<p class="pswp__caption__exif pswp__caption__exif_iso">' + 'ISO ' + slide.data.isospeed + '</p>';
132
+ }
133
+ return caption;
134
+ } else {
135
+ return '<strong>' + slideDateTime + '</strong> &mdash; ' + slideTitle;
136
+ }
137
+ }
19
138
  }
20
139
 
21
140
  function createImageGallery(json) {
22
141
  var items = [];
23
142
  for (let i = 0; i < json.length; i++) {
24
- const imageUrl = 'api/picture?id=' + json[i].id;
25
- const imageTitle = '<strong>' + convertDate(json[i].datetime, true) + '</strong> &mdash; ' + json[i].title;
26
- items.push({ src: imageUrl, width: json[i].width, height: json[i].height, title: imageTitle});
143
+ var imageData = json[i];
144
+ imageData.src = 'api/picture?id=' + json[i].id; // Add 'src' field required by PhotoSwipe
145
+ items.push(imageData);
27
146
  }
28
147
 
29
- // Create PhotoSwipe Lightbox
30
- const lightboxOptions = {
31
- dataSource: items,
32
- pswpModule: PhotoSwipe,
33
- bgOpacity: 0.95,
34
- closeOnVerticalDrag: false,
35
- closeTitle: i18n.viewer_close + ' (Esc)',
36
- zoomTitle: i18n.viewer_zoom + ' (z)',
37
- arrowPrevTitle: i18n.viewer_previous,
38
- arrowNextTitle: i18n.viewer_next,
39
- };
40
- const lightbox = new PhotoSwipeLightbox(lightboxOptions);
41
-
42
- // Initialize caption plugin
43
- const captionPluginOptions = {
44
- type: 'below',
45
- captionContent: (slide) => { return slide.data.title || ''; }
46
- };
47
- const captionPlugin = new PhotoSwipeDynamicCaption(lightbox, captionPluginOptions);
48
-
49
- // Open gallery
50
- lightbox.init();
51
- lightbox.loadAndOpen(0); // start at first slide
148
+ const gallery = new PhotoSwipePictureGallery(items);
149
+ gallery.open(0); // start at first slide
52
150
  }
53
151
 
54
152
  // Export this function so that it may be called from HTML
@@ -39,9 +39,14 @@
39
39
 
40
40
  .pswp__dynamic-caption--mobile {
41
41
  width: 100%;
42
- top: auto;
43
- right: 0;
44
- bottom: 0;
45
42
  background: rgba(0,0,0,0.5);
46
43
  padding: 10px 15px;
44
+
45
+ right: 0;
46
+ bottom: 0;
47
+
48
+ /* override styles that were set via JS.
49
+ as they interfere with size measurement */
50
+ top: auto !important;
51
+ left: 0 !important;
47
52
  }