1(function() { 2 var $ = jQuery; 3 var attrs = []; 4 5 // Easy function to check if a user is logged in 6 // That way we can easily hide/toggle the wpadminbar when 7 // a slideshow image is opened. 8 function is_user_logged_in(){ 9 if($('#wpadminbar').length){ 10 return true; 11 } 12 } 13 14 // bit to store whether the sticky nav was visible 15 var sticky_nav_was_visible = false; 16 17 // the sticky nav selector 18 var sticky_nav_selector = '.sticky-nav-holder'; 19 20 // If the Largo sticky nav is visible, hide the sticky nav, 21 // and remember that it was visible 22 function maybeHideStickyNav() { 23 $nav = $(sticky_nav_selector); 24 25 // Largo uses the 'show' clas rather than jQuery .show()/.hide() 26 if ($nav.hasClass('show')) { 27 $nav.removeClass('show').hide(); 28 sticky_nav_was_visible = true; 29 } 30 } 31 32 // If the Largo sticky nav was once visible, unhide it 33 // otherwise, don't unhide it. 34 function maybeShowStickyNav() { 35 if (sticky_nav_was_visible) { 36 $(sticky_nav_selector).addClass('show').show(); 37 sticky_nav_was_visible = false; 38 } 39 } 40 41 // prevent page scrolling while modal is open 42 function bodyStopScroll() { 43 $('html, body').css({ 44 overflow: 'hidden', 45 height: '100%' 46 }); 47 } 48 49 // allow page scrolling again 50 function bodyStartScroll() { 51 $('html, body').css({ 52 overflow: 'auto', 53 height: 'auto' 54 }); 55 } 56 57 function createSlider($gallery, slide_num){ 58 59 var post_id = $gallery.attr('id'), 60 post_id_clean = post_id.replace('slides-', ''), 61 slick_opts = { 62 adaptiveHeight: true, 63 lazyLoad: 'progressive', 64 dots: true, 65 prevArrow: '<a class="slick-previous slick-navigation" href="#" title="Previous">Previous</a>', 66 nextArrow: '<a class="slick-next slick-navigation" href="#" title="Next">Next</a>', 67 initialSlide: slide_num 68 }; 69 70 // Make the slider 71 $gallery.slick(slick_opts); 72 73 // If the slider is full size, allow the user to click to advance 74 if ($gallery.hasClass('navis-full')){ 75 $gallery.find('.slick-slide').click(function(){ 76 $('.slick-next').trigger('click'); 77 }); 78 } 79 80 // Distinguish between click or drag (drag >100ms) 81 var valid_click = true; 82 var delay = 100; 83 84 // Sets the flag to false 85 var drag = function(){ 86 valid_click = false; 87 } 88 89 var $target = $($gallery.find('img')); 90 91 // mousedown, a global variable is set to the timeout function 92 $target.mousedown( function(){ 93 cancel_click = setTimeout( drag, delay ); 94 }) 95 96 // mouseup, the timeout for drag is cancelled 97 $target.mouseup( function(e){ 98 clearTimeout( cancel_click ); 99 100 if(valid_click){ 101 var $slider = $(e.target.closest('.navis-slideshow')); 102 expandSlider($slider); 103 } 104 105 valid_click = true; 106 }) 107 } 108 109 function createGallery($gallery, slide_num){ 110 111 // Prep each image in the gallery 112 // When the parent is clicked, create a slider 113 $gallery.find('img').each(function(){ 114 var $this = $(this); 115 var src = $this.data('lazy'); 116 var $parent = $this.parent(); 117 118 $parent.prepend('<div style="background-image:url(' + src + ');"></div>'); 119 $parent.click(function(){ 120 var $this = $(this); 121 if ($this.closest('.largo-img-grid').length > 0){ 122 $gallery.addClass('navis-slideshow').removeClass('largo-img-grid').addClass('navis-full'); 123 // The parent index lets the slider know which image to show first 124 createSlider($gallery, $parent.index()); 125 addCloseX($gallery); 126 } 127 }); 128 }); 129 130 131 //$gallery.slick(slick_opts); 132 } 133 134 function addCloseX($slider){ 135 $slider.prepend('<span class="navis-before">X</span>'); 136 $('.navis-before').click(function(){ 137 closeFull($slider); 138 }); 139 } 140 141 // Full-width function for small slideshows 142 function expandSlider($slider){ 143 var full = 'navis-full'; 144 145 maybeHideStickyNav(); 146 bodyStopScroll(); 147 148 if (!$slider.hasClass(full)){ 149 $slider.addClass(full); 150 $slider.slick('setPosition'); 151 152 addCloseX($slider); 153 } 154
155 // Without the timeout, the full-width slider will advance beyond the first slide... 156 // ...because it thinks the click to expand is also the click to advance. 157 setTimeout(function(){ 158 $slider.find('.slick-slide').click(function(){ 159 $('.slick-next').trigger('click'); 160 }); 161 },1000); 162 }; 163 164 function closeSingle(gallery, attrs){ 165 $('.navis-before').remove(); // Removes close (X) button 166 167 if (gallery.hasClass('navis-single') && attrs){ 168 var img = gallery.find('img'); 169 170 attrs.forEach( function(attr, index, attrs) { 171 if ( typeof attr === 'undefined' ) { 172 attrs[index] = null; 173 } 174 }); 175 // Reset attributes 176 img.attr('sizes', attrs[0]); 177 img.attr('width', attrs[1]); 178 img.attr('height', attrs[2]); 179 gallery.attr('style', attrs[3]); 180 } 181 182 $('.navis-single').removeClass('navis-full navis-slideshow navis-single'); // Removes navis classes 183 184 bodyStartScroll(); 185 maybeShowStickyNav(); 186 } 187 188 function closeFull($slider){ 189 $('.navis-before').remove(); // Removes close (X) button 190 $('.navis-full').removeClass('navis-full'); 191 192 // Check if the slider belongs to a single image or a gallery/slideshow/grid (true is for gallery) 193 if($slider.hasClass('slick-slider')){ 194 $slider.slick('setPosition'); 195 196 // Check if the slider belongs to a gallery or a grid (true is for grid) 197 if (!$slider.hasClass('none-up')){ 198 $slider.slick('unslick'); 199 $slider.removeClass('navis-slideshow').addClass('largo-img-grid'); 200 201 202 // Reconfigure grid view 203 var $parent = $slider.find('>div'); 204 $parent.click(function(){ 205 var $this = $(this); 206 if ($this.closest('.largo-img-grid').length > 0){ 207 $slider.addClass('navis-slideshow').removeClass('largo-img-grid').addClass('navis-full'); 208 createSlider($slider, $this.index()); 209 addCloseX($slider); 210 } 211 212 }); 213 } 214 } 215 // Unbind the click event so that small slideshows don't break 216 $slider.find('.slick-slide').unbind('click'); 217 218 // Return images to original sizes 219 closeSingle($slider, attrs); 220 } 221 222 $(document).ready(function() { 223 // For single images, loop through each image on the page 224 $('article.post img').each(function() { 225 226 // If this is not already a slideshow 227 var img = $(this); 228 if ( img[0].hasAttribute('src') ){ 229 230 // When an image is clicked, add classes to the parent element to open the lightbox view 231 img.click(function(){ 232 var gallery = img.parent(); 233 234 bodyStopScroll(); 235 236 // Hide floating social buttons when lightbox view is opened, since 237 // the stacking order allows the social buttons to be on top of the lightbox 238 $('#floating-social-buttons').hide(); 239 240 // If our gallery parent `wp-block-columns` has the `alignfull` class, 241 // let's add our `no-transform` class so our full image works as expected. 242 if(gallery.parent('alignfull') ){ 243 $(gallery).closest('.alignfull').addClass('no-transform'); 244 } 245 246 // If a user is logged in, let's hide the admin menu. 247 // That way it doesn't overlap the image. 248 if(is_user_logged_in()){ 249 $('#wpadminbar').hide(); 250 } 251 252 maybeHideStickyNav(); 253 254 // If the image isn't linked 255 if (gallery[0].localName !== "a" && gallery.find('.navis-before').length == 0){ 256 gallery.addClass('navis-slideshow navis-single navis-full'); 257 258 // Add the close (X) button 259 gallery.prepend('<span class=\"navis-before\">X</span>'); 260 261 // Save original attribute values, for use in closeSingle(); 262 // order is important 263 attrs = [ 264 img.attr('sizes'), 265 img.attr('width'), 266 img.attr('height'), 267 gallery.attr('style') 268 ]; 269 270 // Adjust styles so images can expand to full width 271 gallery.css('max-width','100%'); 272 img.removeAttr('width height sizes'); 273 274 // Close the lightbox when the close (X) button is clicked 275 $('.navis-single .navis-before').click(function(){ 276 closeSingle(gallery, attrs); 277 278 // If the gallery parent had `alignfull` class when we opened the lightbox, 279 // let's remove our `no-transform` supporter class 280 if(gallery.parent('alignfull')){ 281 $(gallery).closest('.alignfull').removeClass('no-transform'); 282 } 283 284 // If a user is logged in, we can go ahead and 285 // restore the admin menu when the lightbox is closed. 286 if(is_user_logged_in()){ 287 $('#wpadminbar').show(); 288 } 289 290 maybeShowStickyNav(); 291 292 }); 293 } 294 }); 295 296 } 297 }); 298 299 // For each gallery, convert to a grid if necessary
300 $('.navis-slideshow').each(function() { 301 var $gallery = $(this); 302 var slide_num = 0; 303 304 // 'none-up' is the slideshow setting (0 columns) 305 if ($gallery.hasClass('none-up')){ 306 var post_id = $gallery.attr('id'), 307 post_id_clean = post_id.replace('slides-', ''); 308 309 // Check for permalink 310 if (window.location.hash) { 311 var search = new RegExp(post_id_clean, 'g'); 312 313 if (search.test(window.location.hash.replace('#', ''))) { 314 var fragment = window.location.hash.replace(/^\#.*\//, '', 'gmi'), 315 slideNum = parseInt(fragment); 316 317 if (!isNaN(slideNum)) 318 slide_num = slideNum - 1; 319 } 320 } 321 // Create a slider for the gallery 322 createSlider($gallery, slide_num); 323 } else { 324 // If this gallery should have a grid layout, add the largo grid class 325 $gallery.removeClass('navis-slideshow').addClass('largo-img-grid'); 326 createGallery($gallery, slide_num); 327 } 328 }); 329 }); 330 331 $(document).keyup(function(e) { 332 var $slider = $('.navis-full'); 333 334 if (e.keyCode == 27) { // escape 335 if ($slider.length > 0) { 336 closeFull($slider); 337 338 // If our slider's parent has `alignfull` class, 339 // we'll want to remove our `no-transform` class to restore our transform properties 340 // so `alignfull` looks correct 341 if($slider.parent('alignfull')){ 342 $slider.closest('.alignfull').removeClass('no-transform'); 343 } 344 345 // If a user is logged in, we can go ahead and 346 // restore the admin menu when the lightbox is closed. 347 if(is_user_logged_in()){ 348 $('#wpadminbar').show(); 349 } 350 351 } 352 } 353 }); 354})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.