1(function ($) { 2 "use strict"; 3 var $isotope_div = $('.isotope-gallery'); 4 var selected_filter = $isotope_div.data('selected-category'); 5 var display_cats = $isotope_div.data('display-categories'); 6 var filter_value = '*'; 7 var video_categories = []; 8 if (selected_filter && display_cats) { 9 filter_value = '.' + selected_filter; 10 } 11 12 var stdVideoGridSettings = { 13 layoutMode: 'fitRows', 14 itemSelector: '.grid-item', 15 filter: filter_value, 16 percentPosition: true, 17 }; 18 19 if (typeof window.UMGGR_Video_Grid_Isotope_Option != "undefined") { 20 var mergedVideoGridSettings = {...stdVideoGridSettings, ...window.UMGGR_Video_Grid_Isotope_Option}; 21 } else { 22 var mergedVideoGridSettings = stdVideoGridSettings; 23 } 24 25 UMGGR_Video_Shortcode.players = []; 26 UMGGR_Video_Shortcode.setplayer = { 27 initYtVideo: function (container, videoId) { 28 29 if (typeof (YT) == 'undefined' || typeof (YT.Player) == 'undefined') { 30 window.onYouTubeIframeAPIReady = function () { 31 UMGGR_Video_Shortcode.set = true; 32 UMGGR_Video_Shortcode.setplayer.setVideoPlayer(container, videoId); 33 }; 34 35 $.getScript('//www.youtube.com/iframe_api', function(){ 36 if (UMGGR_Video_Shortcode.set == false){ 37 UMGGR_Video_Shortcode.set = true; 38 UMGGR_Video_Shortcode.setplayer.setVideoPlayer(container, videoId); 39 } 40 }); 41 } else 42 { 43 UMGGR_Video_Shortcode.setplayer.setVideoPlayer(container, videoId); 44 } 45 }, 46 47 setVideoPlayer: function (container, videoId) { 48 var ytplayer = new YT.Player(container, { 49 videoId: videoId, 50 host: UMGGR_Video_Shortcode.ytPlayerHost, 51 //width: 356, 52 //height: 200, 53 }); 54 var ytplayerContainer = {player: ytplayer, container: container} 55 UMGGR_Video_Shortcode.players.push(ytplayerContainer); 56 } 57 }; 58 59 var $grid = $isotope_div.isotope(mergedVideoGridSettings), 60 $items = $grid.find('.grid-item'); 61 62 // call equalHeights script on arrangeComplete 63 $grid.on( 'arrangeComplete', function( event, filteredItems ) { 64 var maxHeight = 0; 65 66 $("#related-video-container .umg-gr-display-layout-grid .isotope-gallery.multi .isotope-gallery-item a .slide-content.color-palette-item .slide-snippet").each(function(){ 67 var thisH = $(this).height(); 68 if (thisH > maxHeight) { maxHeight = thisH; } 69 }); 70 71 $("#related-video-container .umg-gr-display-layout-grid .isotope-gallery.multi .isotope-gallery-item a .slide-content.color-palette-item .slide-snippet").height(maxHeight); 72 }); 73 74 function closeSlideMenu() { 75 /*Slide Menu Filter Close*/ 76 let peekabooHeight = $('.slide-menu-gr-peakaboo').height() ? $('.slide-menu-gr-peakaboo').height() : 0 77 var peakHeight = peekabooHeight + 5; 78 TweenMax.to($('.slide-menu-gr-peakaboo'), 0.2, {y: -peakHeight, delay: 0.3}); 79 $('.slide-menu-gr-filter-toggle').removeClass('open'); 80 } 81 82 function countVideosPerCategory(categoryName) { 83 if (categoryName == 'all') { 84 var numberCategoryitems = $('.isotope-gallery-item.grid-item').length; 85 } else { 86 var numberCategoryitems = $('.isotope-gallery-item.grid-item.' + categoryName).length; 87 } 88 if (numberCategoryitems == 1) { 89 $('.isotope-gallery-item.grid-item.' + categoryName).addClass('grid-item--single'); 90 } 91 } 92 93 /** 94 * Read a page's GET URL variables and return them as an associative array. 95 * example url: http://www.example.com/?me=myValue&name2=SomeOtherValue 96 * This code will return: { "me" : "myValue", "name2" : "SomeOtherValue" } 97 * yo can call it as: var me = getUrlVars()["me"]; 98 */ 99 function getUrlVars() { 100 var vars = [], hash; 101 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 102 for (var i = 0; i < hashes.length; i++) { 103 hash = hashes[i].split('='); 104 vars.push(hash[0]); 105 vars[hash[0]] = (hash[1]) ? hash[1] : true; 106 } 107 return vars; 108 } 109 110 function isShowAllVideosOn() { 111 if (getUrlVars()["all"]) { 112 $('.grid-item--single').removeClass('grid-item--single'); 113 countVideosPerCategory('all'); 114 $('.grid').isotope({filter: '*'}); 115 $('.slide-menu-gr-filter-toggle').html('all videos'); 116 } 117 } 118 119 function calculateSlideHeights() { 120 if (filter_value == '*' && UMGGR_Video_Shortcode.dynamicCaptionHeight) { 121 UMGGR_Video_Shortcode.heightTracker = { 122 image: 0, 123 caption: 0, 124 }; 125 $('.isotope-gallery-item.grid-item').find('.slide-image').each(function() { 126 if ($(this).outerHeight() > UMGGR_Video_Shortcode.heightTracker.image) { 127 UMGGR_Video_Shortcode.heightTracker.image = $(this).outerHeight(); 128 } 129 }); 130 $('.isotope-gallery-item.grid-item').find('.slide-image').each(function() { 131 $(this).css('height', UMGGR_Video_Shortcode.heightTracker.image); 132 }); 133 $('.isotope-gallery-item.grid-item').find('.slide-snippet').each(function() { 134 if ($(this).outerHeight() > UMGGR_Video_Shortcode.heightTracker.caption) { 135 UMGGR_Video_Shortcode.heightTracker.caption = $(this).outerHeight(); 136 } 137 }); 138 $('.isotope-gallery-item.grid-item').find('.slide-snippet').each(function() { 139 $(this).css('height', UMGGR_Video_Shortcode.heightTracker.caption); 140 }); 141 142 $($grid).isotope( 'reloadItems' ).isotope(); 143 } 144 } 145 146 $(document).ready(function () { 147 148 //Load more news 149 $('a[data-video-load-more]').on('click', function(e) { 150 e.preventDefault(); 151 152 var loadMoreAnchor = $(this); 153 154 var currentOffset = $(this).attr('data-offset'); 155 var perPage = $(this).attr('data-load-num'); 156 157 var tileTemplate = $('.isotope-gallery-item.grid-item:last').clone(); 158 159 //add loading icon to the button 160 $(loadMoreAnchor).addClass('-is-loading'); 161 162 let posts = {}; 163 $.ajax({ 164 type: "GET", 165 url: UMGGR_Video_Shortcode.wpjsonurl + '/wp/v2/umggr-video?_embed', 166 data: { 167 'per_page' : perPage, 168 'offset': currentOffset 169 }, 170 success: function (response) { 171 posts = response; 172 }, 173 }).then( ( posts ) => { 174 175 if(typeof posts !== 'undefined' && posts.length) { 176 //loop through retrived posts and render using tile template 177 for(var i in posts) { 178 var post = posts[i]; 179 180 var tile = tileTemplate.clone().attr('data-post-id', post.id).hide(); 181 182 // get a list of all classes so we can get the num-per-row class in use 183 var classList = tile.attr("class"); 184 185 // Create class array by splitting class list str
185ing 186 var classArr = classList.split(/\s+/); 187 188 var setLayoutClass = classArr[classArr.length-1]; 189 190 // strip out any curren taxonomy classes from the tile 191 tile.removeAttr('class'); 192 tile.attr('class', ''); 193 tile.addClass('isotope-gallery-item').addClass('grid-item'); 194 195 if(typeof post._embedded !== 'undefined') { 196 var getTerms = post._embedded['wp:term']['0']; 197 for(var tmpIdx = 0 ; tmpIdx<getTerms.length ; tmpIdx++){ 198 tile.addClass(getTerms[tmpIdx].slug); 199 } 200 } 201 202 tile.addClass(setLayoutClass); 203 204 //update link taking into account the click-action 205 if (UMGGR_Video_Shortcode.clickAction === 'post') { 206 tile.find('a').attr('href', post.link); 207 } else { 208 var tmpYTURL = replaceUrlParam(tile.find('a').attr('href'), 'v', post['umggr-youtube-id']); 209 tile.find('a').attr('href', tmpYTURL); 210 } 211 212 //update title 213 tile.find('h2.caption').html(post.title.rendered); 214 215 //update the description 216 tile.find('.yt-description').empty().html(post['umggr-video-description']); 217 218 //update the date 219 tile.find('.yt-published').empty().html(post['umggr-video-date']); 220 221 //update the image 222 tile.find('.slide-image img').attr('src', post['umggr-video-thumb']); 223 224 //add new tile before the Load More button 225 $grid.isotope( 'insert', tile ); 226 227 $grid.one( 'arrangeComplete', function() { 228 setTimeout(function(){$grid.isotope('layout');}, 100); 229 }); 230 231 //remove loading icon from the button 232 $(loadMoreAnchor).removeClass('-is-loading'); 233 } 234 } else { 235 //no posts left 236 } 237 238 return posts; 239 240 }); 241 242 //calculate new offset 243 var newOffset = parseInt(currentOffset) + parseInt(perPage); 244 245 //check if there are any more posts, if not then hide the load more button 246 posts = {}; 247 $.ajax({ 248 type: "GET", 249 url: UMGGR_Video_Shortcode.wpjsonurl + '/wp/v2/umggr-video', 250 data: { 251 'per_page' : perPage, 252 'offset': newOffset 253 }, 254 success: function (response) { 255 posts = response; 256 }, 257 }).then( ( posts ) => { 258 if(typeof posts === 'undefined' || posts.length === 0) { 259 loadMoreAnchor.hide(); 260 } else { 261 loadMoreAnchor.attr('data-offset', parseInt(currentOffset) + parseInt(perPage)); 262 } 263 }); 264 265 return false; 266 }); 267 268 //Video gallery rollovers 269 $('html').on('mouseenter', '.isotope-gallery-item a:not(.-always)', function () { 270 TweenMax.to($(this).find('.slide-image img'), 0.3, {scale: 1.2}); 271 TweenMax.to($(this).find('.slide-overlay'), 0.3, {opacity: 0.8}); 272 TweenMax.to($(this).find('.slide-snippet'), 0.3, {opacity: 1}); 273 TweenMax.fromTo($(this).find('.icon'), 0.3, {rotation: -20}, {rotation: 0}); 274 }); 275 $('html').on('mouseleave', '.isotope-gallery-item a:not(.-always)', function () { 276 TweenMax.to($(this).find('.slide-image img'), 0.3, {scale: 1}); 277 TweenMax.to($(this).find('.slide-overlay'), 0.3, {opacity: 0}); 278 TweenMax.to($(this).find('.slide-snippet'), 0.3, {opacity: 0.8}); 279 TweenMax.to($(this).find('.icon'), 0.3, {rotation: -20}); 280 }); 281 if (UMGGR_Video_Shortcode.setSingleWidth) { 282 countVideosPerCategory('featured'); 283 } 284 /*Slide Menu Filter Grid*/ 285 $('.filter-btn').click(function () { 286 var filter = $(this).data('filter'); 287 288 // clear any single items that have been set previously 289 $('.grid-item--single').removeClass('grid-item--single'); 290 if (UMGGR_Video_Shortcode.setSingleWidth) { 291 countVideosPerCategory(filter); 292 } 293 294 // switch this out for system generated from values on videos. 295 if (filter === 'all') { 296 $('.grid').isotope({filter: '*'}); 297 } else { 298 $('.grid').isotope({filter: '.' + filter}); 299 } 300 closeSlideMenu(); 301 $('.slide-menu-gr-filter-toggle').html($(this).html()); 302 303 return false;
304 }); 305 306 $(document).on('beforeShow.fb', function () { 307 closeSlideMenu() 308 }); 309 // check if page filter is meant to show all videos 310 isShowAllVideosOn(); 311 }); 312 $(window).load(function () { 313 //Init Isotope grid without the pre-layout state flashing up + we get a transition animation 314 $grid.addClass('show-items'); 315 $grid.isotope('revealItemElements', $items); 316 317 // set correct class name to section when item total is less than items-per-row 318 // this is to prevent blank space on the listing and full fill the available space 319 if (UMGGR_Video_Shortcode.setSingleWidth) { 320 switch ($items.length) { 321 case 3 : 322 $grid.closest('section').find('.four-per-row').each(function () { 323 $(this).removeClass('four-per-row').addClass('three-per-row'); 324 }); 325 break; 326 case 2 : 327 $grid.closest('section').find('.four-per-row').each(function () { 328 $(this).removeClass('four-per-row').addClass('two-per-row'); 329 }); 330 $grid.closest('section').find('.three-per-row').each(function () { 331 $(this).removeClass('three-per-row').addClass('two-per-row'); 332 }); 333 break; 334 case 1 : 335 $grid.closest('section').find('.four-per-row').each(function () { 336 $(this).removeClass('four-per-row').addClass('one-per-row'); 337 }); 338 $grid.closest('section').find('.three-per-row').each(function () { 339 $(this).removeClass('three-per-row').addClass('one-per-row'); 340 }); 341 $grid.closest('section').find('.two-per-row').each(function () { 342 $(this).removeClass('two-per-row').addClass('one-per-row'); 343 }); 344 break; 345 } 346 } 347 $grid.isotope(); 348 349 calculateSlideHeights(); 350 351 //Fancybox video lightbox 352 $grid.on( 'arrangeComplete', function() { 353 if (UMGGR_Video_Shortcode.disable_cookies) { 354 $('[data-fancybox]').fancybox({ 355 baseClass: "fancy-video", 356 media: { 357 youtube: { 358 url: "//www.youtube-nocookie.com/embed/$4" 359 } 360 } 361 }); 362 } else { 363 $('[data-fancybox]').fancybox({ 364 baseClass: "fancy-video" 365 }); 366 } 367 } ); 368 }); 369 370 if ($('#umggr-featured-video').length && $('#umggr-featured-video').data('yt-id')) { 371 UMGGR_Video_Shortcode.setplayer.initYtVideo('umggr-featured-video', $('#umggr-featured-video').data('yt-id')); 372 } 373 374 $(window).resize(function () { 375 calculateSlideHeights(); 376 }) 377 378 function replaceUrlParam(url, paramName, paramValue) 379 { 380 if (paramValue == null) { 381 paramValue = ''; 382 } 383 var pattern = new RegExp('\\b('+paramName+'=).*?(&|#|$)'); 384 if (url.search(pattern)>=0) { 385 return url.replace(pattern,'$1' + paramValue + '$2'); 386 } 387 url = url.replace(/[?#]$/,''); 388 return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue; 389 } 390 391})(jQuery);// JavaScript Document
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.