var $ = jQuery.noConflict(); $(document).ready(function(){ if($('.jbmodal').length > 0){ function loadModal(newModal) { theTitle = $('.jbmodal-title'); theImg = $('.jbmodal-img > img'); theCaption = $('.jbmodal-caption'); theHTML = $('.jbmodal-HTML'); thePinit = $('.jbmodal-img > a.pinit'); newTitle = $(newModal).attr('data-jbmodal-title'); newImg = $(newModal).attr('data-jbmodal-img'); newCaption = $(newModal).attr('data-jbmodal-caption'); newHTML = $(newModal).attr('data-jbmodal-HTML'); newPinit = $(newModal).attr('data-jbmodal-pinit'); if(theTitle !== undefined && newTitle !== undefined) { $(theTitle).hide().html(newTitle).fadeIn(); } else { $(theTitle).hide(); } if(theImg !== undefined && newImg !== undefined) { $(theImg).hide().attr('src', newImg).fadeIn(); } else { $(theImg).hide(); } if(theCaption !== undefined && newCaption !== undefined) { $(theCaption).hide().html(newCaption).fadeIn(); } else { $(theCaption).hide(); } if(theHTML !== undefined && newHTML !== undefined) { $(theHTML).hide().html(newHTML).fadeIn(); } else { $(theHTML).hide(); } if(thePinit !== undefined && newPinit !== undefined) { $(thePinit).hide().attr('href', newPinit).fadeIn(); } else { $(thePinit).hide(); } $(newModal).addClass('jbmodal-trigger'); } $('.jbmodal').click(function(){ $('.jbmodal').removeClass('jbmodal-trigger'); $(this).addClass('jbmodal-trigger'); // setup the modal content jbmodal = '
'; jbmodal += '
' // check if modal trigger is part of a set jbmodal_parent = $(this).parent(); jbmodal_set_count = $(jbmodal_parent).find('.jbmodal').length; // alert(jbmodal_set_count); // variable modal content if($(this).attr('data-jbmodal-title') !== undefined) { jbmodal_title = $(this).attr('data-jbmodal-title'); jbmodal += '

'+jbmodal_title+'

'; } if($(this).attr('data-jbmodal-img') !== undefined) { jbmodal_img = $(this).attr('data-jbmodal-img'); jbmodal += '
'; // add set linking if(jbmodal_set_count > 1) { jbmodal += ''; jbmodal += ''; } if($(this).attr('data-jbmodal-pinit') !== undefined) { jbmodal_pinit = $(this).attr('data-jbmodal-pinit'); jbmodal += ''; } jbmodal += '
'; if($(this).attr('data-jbmodal-caption') !== undefined) { jbmodal_caption = $(this).attr('data-jbmodal-caption'); jbmodal += '

'+jbmodal_caption+'

'; } } if($(this).attr('data-jbmodal-HTML') !== undefined) { jbmodal_HTML = $(this).attr('data-jbmodal-HTML'); jbmodal += '
'+jbmodal_HTML+'
'; } jbmodal += '
'; jbmodal += '
'; // end modal content jbmodal += '
'; // end modal box // the modal background overlay jbmodalBG = '
'; // create and show the modal elements $('body').append(jbmodalBG); $('body').append($(jbmodal).hide().fadeIn('fast')); // close the modal $('.jbmodal-bg, .jbmodal-pos, .jbmodal-controls .fa-close').on('click', function(e) { if( e.target !== this ) { return; } else { $('.jbmodal-pos').fadeOut('fast', function() { $('.jbmodal-bg').fadeOut('fast', function() { $('.jbmodal-pos').remove(); $('.jbmodal-bg').remove(); }); }); } }); // escape the modal $(document).keyup(function(e) { if (e.keyCode == 27) { $('.jbmodal-box').fadeOut('fast', function() { $('.jbmodal-bg').fadeOut('fast', function() { $('.jbmodal-box').remove(); $('.jbmodal-bg').remove(); }); }); } }); // prev/next if(jbmodal_set_count > 1) { var targetModal = ''; // prev $('.jbmodal-prev').click(function(){ targetModal = $('.jbmodal-trigger').prevAll('.jbmodal').first(); if(!$(targetModal).length > 0){ targetModal = $('.jbmodal-trigger').parents('.gallery-wrap').find('.jbmodal').last(); } $('.jbmodal').removeClass('jbmodal-trigger'); loadModal(targetModal); }); // next $('.jbmodal-next').click(function(){ targetModal = $('.jbmodal-trigger').nextAll('.jbmodal').first(); if(!$(targetModal).length > 0){ targetModal = $('.jbmodal-trigger').parents('.gallery-wrap').find('.jbmodal').first(); } $('.jbmodal').removeClass('jbmodal-trigger'); loadModal(targetModal); }); } // prev/next (arrow keys) $(document).keyup(function(e) { if (e.keyCode == 37) { // left/prev targetModal = $('.jbmodal-trigger').prevAll('.jbmodal').first(); if(!$(targetModal).length > 0){ targetModal = $('.jbmodal-trigger').parents('.gallery-wrap').find('.jbmodal').last(); } $('.jbmodal').removeClass('jbmodal-trigger'); $(targetModal).addClass('jbmodal-trigger'); loadModal(targetModal); } }); $(document).keyup(function(e) { if (e.keyCode == 39) { // right/next targetModal = $('.jbmodal-trigger').nextAll('.jbmodal').first(); if(!$(targetModal).length > 0){ targetModal = $('.jbmodal-trigger').parents('.gallery-wrap').find('.jbmodal').first(); } $('.jbmodal').removeClass('jbmodal-trigger'); loadModal(targetModal); } }); }); // END main modal function } // END main if });