Skip to content
Permalink
Browse files

Removed old repo and started afresh

  • Loading branch information...
bakedbird committed Apr 20, 2019
0 parents commit 08f3ae800f9f4ee4fa668b0ff653141277fa54bc
Showing with 183 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +21 −0 LICENSE.md
  3. +4 −0 README.md
  4. +136 −0 mauGallery.js
  5. +13 −0 package.json
  6. +8 −0 yarn.lock
@@ -0,0 +1 @@
/node_modules
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 mauGallery

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
@@ -0,0 +1,4 @@
# mau Gallery
A simple images gallery made with jQuery and bootstrap4

TODO: add description and stuff here
@@ -0,0 +1,136 @@
;(function($) {
$.fn.mauGallery = function(options) {
var options = $.extend($.fn.mauGallery.defaults, options);
var tagsCollection = [];
return this.each(function() {
$.fn.mauGallery.methods.createRowWrapper($(this));
if (options.lightBox) {
$.fn.mauGallery.methods.createLightBox($(this), options.lightboxId);
}
$.fn.mauGallery.listeners(options);

$(this).children('.gallery-item').each(function(index) {
$.fn.mauGallery.methods.responsiveImageItem($(this));
$.fn.mauGallery.methods.moveItemInRowWrapper($(this));
$.fn.mauGallery.methods.wrapItemInColumn($(this), options.columns);
var theTag = $(this).data('gallery-tag');
if (options.showTags && theTag !== undefined && tagsCollection.indexOf(theTag) === -1) {
tagsCollection.push(theTag);
}
});

if (options.showTags) {
$.fn.mauGallery.methods.showItemTags($(this), options.tagsPosition, tagsCollection);
}

$(this).fadeIn(500);
});
};
$.fn.mauGallery.defaults = {
columns: 3,
lightBox: true,
lightboxId: null,
showTags: true,
tagsPosition: 'bottom'
};
$.fn.mauGallery.listeners = function(options) {
$('.gallery-item').on('click', function() {
if (options.lightBox && $(this).prop('tagName') === 'IMG') {
$.fn.mauGallery.methods.openLightBox($(this), options.lightboxId);
} else {
return;
}
});

$('.gallery').on('click', '.nav-link', $.fn.mauGallery.methods.filterByTag);
}
$.fn.mauGallery.methods = {
createRowWrapper(element) {
if (!element.children().first().hasClass('row')) {
element.append('<div class="gallery-items-row row"></div>');
}
},
wrapItemInColumn(element, columns) {
if (columns.constructor === Number) {
element.wrap(`<div class='item-column mb-4 col-${Math.ceil(12 / columns)}'></div>`);
} else if (columns.constructor === Object){
var columnClasses = '';
if (columns.xs) {
columnClasses += ` col-${Math.ceil(12 / columns.xs)}`;
}
if (columns.sm) {
columnClasses += ` col-sm-${Math.ceil(12 / columns.sm)}`;
}
if (columns.md) {
columnClasses += ` col-md-${Math.ceil(12 / columns.md)}`;
}
if (columns.lg) {
columnClasses += ` col-lg-${Math.ceil(12 / columns.lg)}`;
}
if (columns.xl) {
columnClasses += ` col-xl-${Math.ceil(12 / columns.xl)}`;
}
element.wrap(`<div class='item-column mb-4${columnClasses}'></div>`);
} else {
console.error(`Columns should be defined as numbers or objects. ${typeof(columns)} is not supported.`);
}
},
moveItemInRowWrapper(element) {
element.appendTo('.gallery-items-row');
},
responsiveImageItem(element) {
if (element.prop('tagName') === 'IMG') {
element.addClass('img-fluid');
}
},
openLightBox(element, lightboxId) {
$(`#${lightboxId}`).find('.lightboxImage').attr('src', element.attr('src'));
$(`#${lightboxId}`).modal('toggle');
},
createLightBox(gallery, lightboxId) {
gallery.append(`<div class="modal fade" id="${(lightboxId? lightboxId: 'galleryLightbox')}" tabindex="-1" role="dialog" aria-labelledby="lightboxModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<img class="lightboxImage img-fluid" />
</div>
</div>
</div>
</div>`);
},
showItemTags(gallery, position, tags) {
var tagItems = '<li class="nav-item"><a class="nav-link active active-tag" href="#" data-images-toggle="all">all</a></li>';
$.each(tags, function(index, value) {
tagItems += `<li class="nav-item active">
<a class="nav-link" href="#" data-images-toggle="${value}">${value}</a></li>`;
});
var tagsRow = `<ul class="my-4 tags-bar nav nav-pills">${tagItems}</ul>`;

if (position === 'bottom') {
gallery.append(tagsRow);
} else if (position === 'top') {
gallery.prepend(tagsRow);
} else {
console.error(`Unknown tags position: ${position}`);
}
},
filterByTag() {
if ($(this).hasClass('active-tag')) {
return;
}
$('.active.active-tag').removeClass('active active-tag');
$(this).addClass('active-tag active');

var tag = $(this).data('images-toggle');

$('.gallery-item').each(function() {
$(this).parents('.item-column').hide();
if (tag === 'all') {
$(this).parents('.item-column').show(300);;
} else if ($(this).data('gallery-tag') === tag) {
$(this).parents('.item-column').show(300);;
}
});
}
}
})(jQuery);
@@ -0,0 +1,13 @@
{
"name": "mau-gallery",
"version": "1.0.1",
"description": "A simple images gallery built with jQuery and bootstrap4",
"main": "mauGallery.js",
"author": "Lefteris Psitopoulos <hello@bakedbird.com>",
"license": "MIT",
"private": false,
"repository": "https://github.com/bakedbird/mauGallery.git",
"dependencies": {
"jquery": "^3.4.0"
}
}
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


jquery@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/jquery/-/jquery-3.4.0.tgz#8de513fa0fa4b2c7d2e48a530e26f0596936efdf"
integrity sha512-ggRCXln9zEqv6OqAGXFEcshF5dSBvCkzj6Gm2gzuR5fWawaX8t7cxKVkkygKODrDAzKdoYw3l/e3pm3vlT4IbQ==

0 comments on commit 08f3ae8

Please sign in to comment.
You can’t perform that action at this time.