Flickr Gallery
Image grid & gallery using the flickr RESTful API.
HTML
<section id="gallery">
<span class="gallery-slider__close"></span>
<span class="gallery-nav gallery-nav-left"></span>
<div class="gallery-stage">
<div class="gallery-slides"></div>
</div>
<span class="gallery-nav gallery-nav-right"></span>
</section>
CSS
* {
box-sizing: border-box;
}
#gallery {
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
position: relative;
}
#gallery:not(.open) .gallery-slider__close {
display: none;
}
.gallery-slider__close {
position: absolute;
right: 0.25em;
top: 0.25em;
}
.gallery-slider__close:before {
content: '\00D7';
font-size: 20px;
font-weight: bold;
}
#gallery:not(.open) .gallery-nav {
display: none;
}
.gallery-slider__close,
.gallery-nav {
cursor: pointer;
}
.gallery-nav-left,
.gallery-nav-right {
border-bottom: 10px solid transparent;
border-top: 10px solid transparent;
}
.gallery-nav-left {
border-right: 10px solid black;
}
.gallery-nav-right {
border-left: 10px solid black;
}
.gallery-stage {
overflow: hidden;
}
#gallery.open .gallery-stage {
flex: 1;
}
.gallery-slides {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}
#gallery.open .gallery-slides {
-webkit-flex-flow: row nowrap;
-ms-flex-flow: row nowrap;
flex-flow: row nowrap;
-webkit-transition: -webkit-transform 0.2s ease-in-out;
transition: transform 0.2s ease-in-out;
}
.gallery-slide {
-webkit-box-flex: 1;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
/* IE bug */
flex: 1 1 auto;
/* IE bug */
margin: 0;
min-width: 0;
/* ffx bug */
padding: 1em;
width: 50%;
/* IE bug */
}
#gallery:not(.open) .gallery-slide {
cursor: pointer;
}
.gallery-slide__image {
max-width: 100%;
}
.gallery-slide__title {
font-family: Arial, sans-serif;
font-weight: bold;
}
Babel + JSX
var apiKey = 'b3ecbf6e93be1a9ca7d0b2db228fda05';
var ViewModel = function(container, selectors) {
this._model = [];
this._queue = [];
this._selectors = selectors;
this.$ = container;
this.close$ = this.$.getElementsByClassName(selectors.close)[0];
this.navs$ = {
left: this.$.getElementsByClassName(selectors.navLeft)[0],
right: this.$.getElementsByClassName(selectors.navRight)[0]
};
this.slides$ = this.$.getElementsByClassName(selectors.slides)[0];
this.$.addEventListener('open', this._handleOpenEvent.bind(this));
this.$.addEventListener('close', this._handleCloseEvent.bind(this));
this.close$.addEventListener('click', this._handleCloseBtnClick.bind(this));
this.navs$.left.addEventListener('click', this._handleNavLeftClick.bind(this));
this.navs$.right.addEventListener('click', this._handleNavRightClick.bind(this));
};
ViewModel.prototype.add = function addToQueue(input) {
if (Array.isArray(input)) {
this._queue.push(...input);
} else {
this._queue.push(input);
}
return this._queue;
};
ViewModel.prototype.flush = function flushQueue() {
this._model = this._queue.slice();
this._queue.length = 0;
this._updateView();
return this._model;
};
ViewModel.prototype.generatePhotoUrl = function generatePhotoUrl(photo) {
return `https://farm${photo.farm}.staticflickr.com/${photo.server}/${photo.id}_${photo.secret}_z.jpg`;
};
ViewModel.prototype._computeSlideOffset = function computeSlideOffset() {
const activeIndex = this._getActiveSlideIndex();
const yOffset = 100 / this.slides$.children.length * activeIndex;
this.slides$.style.transform = `translateX(-${yOffset}%)`;
};
ViewModel.prototype._getActiveSlideIndex = function getActiveSlideIndex() {
const activeSlide = this.slides$.getElementsByClassName(this._selectors.active)[0];
return Array.prototype.indexOf.call(this.slides$.children, activeSlide);
};
ViewModel.prototype._handleCloseEvent = function handleCloseEvent() {
...