Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tools that change global behavior of website things, for not deal with a lot of changes for a little thing
/**
In example make all images of website content (maybe insterted trough editor)
openable trough gallery
[this work with Blueimp Gallery https://github.com/blueimp/Gallery]
*/
$(".page-content img").each(function(){
// for possibility to disable this on some elements
if (!$(this).hasClass('no-auto-gallery')) {
// create data-gallery (if there aren't an <a> tag over image, create it)
if (!$(this).parent().hasClass('blog_img') && !$(this).parent().is('a')) {
$(this).wrap("<a href='" + $(this).attr('src') + "' data-gallery></a>");
}
// add data-gallery (if there are an <a> tag over image, only add trigger)
if (!$(this).parent().hasClass('blog_img') && $(this).parent().is('a')) {
$(this).parent().attr('data-gallery', 'content-gallery');
}
}
// * .blog_img - is image that are yet a gallery image (the main image 'poster' of content) so it also wouldn't be processed
});
/**
Or make all tag <a href="mailto:... that begining with "mailto" anchor to contact form
[used with a scroll effect begin a very nice thing. of course you need to have a contact form on any page of site]
https://arturmamedov.github.io/withFront/#target-block
*/
$('a[href^="mailto"]').each(function(){
var href_mailto = this.href.replace('mailto:', '');
$(this).attr('href', '#w-email').addClass('w-scroll');
});
@arturmamedov

This comment has been minimized.

Copy link
Owner Author

arturmamedov commented Feb 24, 2020

Improved version of auto-gallery

$(".auto-gallery-content").each(function(){
        var data_gallery = $(this).data("autoGallery") ? $(this).data("autoGallery") : "gallery";

        $("img", $(this)).each(function () {
            if (!$(this).hasClass('no-auto-gallery')) {
                // create` data-gallery
                if (!$(this).parent().is('a')) {
                    $(this).wrap("<a href='" + $(this).attr('src') + "' data-gallery='"+ data_gallery +"'></a>");
                } else {
                    // add data-gallery
                    if (typeof $(this).parent('a').attr('data-gallery') == "undefined") {
                        $(this).parent().attr('data-gallery', data_gallery);
                    }
                }
            }
        });
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.