/*globals jQuery, window */ /*jslint plusplus: true, nomen: true, regexp: true, vars: true */ (function ($) { "use strict"; function Gallery (data) { this.index = data.index; this.slug = data.slug; this.url = data.url; this.title = data.title; this.$element = null; this.pictures = $.map(data.pictures, function (name) { return { src: this.url + name, title: name.replace(/[_\-]/g, ' ').split('.')[0], thumb: { src: this.url + 'thumbs/' + name } }; }.bind(this)); }; Gallery.prototype.getThumbnailUrl = function () { return this.pictures[0].thumb.src; } Gallery.prototype.getElement = function () { if (!this.$element) { this.$element = this.render().hide().insertAfter(this.index.$element); $('a', this.$element).venobox(); } return this.$element; }; Gallery.prototype.render = function () { return $('
', { 'class': 'card-columns', 'id': this.url, }).append( $.map(this.pictures, this.renderPicture.bind(this)) ); } Gallery.prototype.renderPicture = function (picture) { return $('
').append( $('', { 'class': "card img-fluid", 'href': picture.src, 'title': picture.title, 'data-gall': this.slug, }).append( $('', { 'src': picture.thumb.src, 'alt': picture.title, 'class': 'card-img-top' }) ) ); } function Galleries (options) { this.options = options || {}; this.items = []; this.$element = $(this.options.element); this.$title = $(this.options.title); this.listIndexTitle = this.$title.text(); this.$breadcrumb = $(this.options.breadcrumb); this.$backButtons = $(this.options.backButtons); this.$backButtons.on('click', function(e) { this.listIndex() e.preventDefault(); }.bind(this)); this.$element.on('click', 'a[data-gallery]', function (e) { var $card = $(e.currentTarget).closest('.card'); this.showGallery($card.data('gallery')); e.preventDefault(); }.bind(this)); }; Galleries.prototype.loadData = function () { $.ajax({ url: this.options.index, context: this, dataType: 'json', }).done(function (response) { this.items = $.map(response, function (data, slug) { return new Gallery({ index: this, slug: slug, url: this.options.url + slug + '/', title: data.title, pictures: data.pictures }); }.bind(this)); this.render(); this.listIndex(); }); }; Galleries.prototype.render = function () { this.$element.html(''); var elements = $.map(this.items, this.renderGaleryCard); this.$element.append(elements); } Galleries.prototype.renderGaleryCard = function(gallery) { var url = '#' + gallery.url; var $card = $('