1(function ($) { 2 "use strict"; 3 var $items = $('.flex-grid-gr-slide'), 4 transitionItems = new TimelineMax({delay: 0.3}); 5 6 7 var thumbImageOnLoad = function(loadedTile) { 8 loadedTile.removeClass('-is-loading'); 9 }; 10 11 12 $(document).ready(function () 13 { 14 //Load more news 15 $('a[data-news-load-more]').on('click', function(e) { 16 e.preventDefault(); 17 18 if ($(this).hasClass('-is-loading')) { 19 return; 20 } 21 22 var loadMoreAnchor = $(this); 23 24 var currentOffset = $(this).attr('data-offset'); 25 var perPage = $(this).attr('data-load-num'); 26 27 //clone last item from tiles list to use as a template 28 var tileTemplate = $('.news-tiled article:last').clone(); 29 if(!tileTemplate.length) { 30 return false; 31 } 32 33 //set default views for clone 34 tileTemplate.addClass('-is-loading'); 35 36 //remove existing background image 37 tileTemplate.find('.image-overlay').css('background-image', 'none'); 38 39 //add loading icon to the button 40 $(loadMoreAnchor).addClass('-is-loading'); 41 42 let posts = {}; 43 $.ajax({
44 type: "GET", 45 url: UMGGR_News_Shortcode.wpjsonurl + '/wp/v2/posts', 46 data: { 47 'per_page' : perPage, 48 'offset': currentOffset 49 }, 50 success: function (response) { 51 posts = response; 52 }, 53 }).then( ( posts ) => { 54 55 if(typeof posts !== 'undefined' && posts.length) { 56 //loop through retrived posts and render using tile template 57 for(var i in posts) { 58 var post = posts[i]; 59 60 var tile = tileTemplate.clone().attr('data-post-id', post.id).hide(); 61 62 //update link 63 tile.find('a.slide-image, .slide-snippet a').attr('href', post.link); 64 tile.find('a.slide-image, .slide-snippet a').attr('data-umga-internal-click', 'news'); 65 tile.find('a.slide-image, .slide-snippet a').attr('data-umga-news-headline', post.title.rendered); 66 67 //update title 68 tile.find('.slide-snippet h2').html(post.title.rendered); 69 tile.find('.slide-snippet a').attr('title', 'Read More About ' + post.title.rendered); 70 71 //add new tile before the Load More button 72 tile.insertBefore(loadMoreAnchor); 73 } 74 } else { 75 //no posts left 76 } 77 78 return posts; 79 80 } ).then( (posts) => { 81 if(typeof posts !== 'undefined' && posts.length) { 82 //loop through retrived posts and render using tile template 83 for (var i in posts) { 84 var post = posts[i]; 85 86 var updatePostAttachment = function(post) { 87 88 //fetch featured image if it's set 89 var featuredImageId = post.featured_media; 90 91 92 if(post.featured_media && post.featured_media_data) { 93 94 var tile = $('.news-tiled article[data-post-id="'+ post.id +'"]'); 95 96 //update news thumbnail image 97 var newsThumbnail = post.featured_media_data.thumbnail_src; 98 var thumbImage = new Image(); 99 thumbImage.src = newsThumbnail; 100 thumbImage.onload = thumbImageOnLoad(tile); 101 102 var newsThumbnailAltText = post.featured_media_data.alt_text ? post.featured_media_data.alt_text : post.featured_media_data.title; 103 104 tile.find('.image-overlay').css('background-image', "url('"+newsThumbnail+"')"); 105 106 //update alt tag 107 tile.find('.image-overlay span[role="img"]').attr('aria-label', newsThumbnailAltText); 108 tile.find('.slide-image').attr('title', newsThumbnailAltText); 109 } else { 110 111 var placeholder = $('.news-tiled').attr('data-placeholder'); 112 var tile = $('.news-tiled article[data-post-id="'+ post.id +'"]'); 113 114 if(placeholder.length) { 115 //if no featured image then use placeholder 116 tile.find('.image-overlay').css('background-image', "url('"+placeholder+"')"); 117 } 118 119 thumbImageOnLoad(tile); 120 121 tile.find('.image-overlay span[role="img"]').attr('aria-label', post.title.rendered); 122 tile.find('.slide-image').attr('title', post.title.rendered); 123 } 124 } 125 126 updatePostAttachment(post); 127 128 } 129 } 130 131 return posts; 132 }).then( (posts) => { 133 134 var firstTile = false; 135 136 //fade new tiles in 137 if(typeof posts !== 'undefined' && posts.length) { 138 //loop through retrived posts and render using tile template 139 for (var i in posts) { 140 var post = posts[i]; 141 var tile = $('.news-tiled article[data-post-id="'+ post.id +'"]'); 142 if(tile.length) { 143 144 //set first tile 145 if (!firstTile) { 146 firstTile = tile; 147 } 148 149 tile.fadeIn(); 150 } 151 } 152 } 153 154 //calculate new offset 155 var newOffset = parseInt(currentOffset) + parseInt(perPage); 156 157 //check if there are any more posts, if not then hide the load more button 158 posts = {}; 159 $.ajax({
160 type: "GET", 161 url: UMGGR_News_Shortcode.wpjsonurl + '/wp/v2/posts', 162 data: { 163 'per_page' : perPage, 164 'offset': newOffset 165 }, 166 success: function (response) { 167 posts = response; 168 }, 169 }).then( ( posts ) => { 170 if(typeof posts === 'undefined' || posts.length === 0) { 171 loadMoreAnchor.hide(); 172 } else { 173 loadMoreAnchor.attr('data-offset', parseInt(currentOffset) + parseInt(perPage)); 174 } 175 }); 176 177 //reload the grid 178 transitionItems.staggerTo($items, 0.3, {x: 0, opacity: 1}, 0.1); 179 180 //scroll to first new tile 181 if(firstTile && firstTile.length) { 182 TweenMax.to( 183 window, 184 1, 185 { 186 scrollTo: 187 { 188 y: firstTile, 189 offsetY: 100, 190 autoKill: false 191 } 192 } 193 ); 194 } 195 196 //add loading icon to the button 197 $(loadMoreAnchor).removeClass('-is-loading'); 198 199 }); 200 201 return false; 202 }); 203 204 //News image rollovers 205 $('.flex-grid-gr-slide').mouseenter(function () { 206 TweenMax.to($(this).find('.slide-overlay'), 0.3, {opacity: 0.5}); 207 TweenMax.to($(this).find('.image-overlay'), 0.3, {scale: 1.2}); 208 TweenMax.to($(this).find('.slide-snippet'), 0.3, {opacity: 1}); 209 TweenMax.fromTo($(this).find('.plus'), 0.3, {rotation: -20}, {rotation: 0}); 210 }); 211 $('.flex-grid-gr-slide').mouseleave(function () { 212 TweenMax.to($(this).find('.slide-overlay'), 0.3, {opacity: 0}); 213 TweenMax.to($(this).find('.image-overlay'), 0.3, {scale: 1}); 214 TweenMax.to($(this).find('.slide-snippet'), 0.3, {opacity: 0.8}); 215 TweenMax.to($(this).find('.plus'), 0.3, {rotation: -20}); 216 }); 217 $(window).load(function () { 218 //Run items transition 219 transitionItems.staggerTo($items, 0.3, {x: 0, opacity: 1}, 0.1); 220 }); 221 }); 222})(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.