| @@ -7,14 +7,10 @@ | ||
| 7 | 7 | |
| 8 | 8 | var args = { |
| 9 | 9 | itemSelector: '.wpupg-item', |
| 10 | 10 | transitionDuration: wpupg_public.animationSpeed, |
| 11 | - hiddenStyle: { | |
| 12 | - opacity: 0 | |
| 13 | - }, | |
| 14 | - visibleStyle: { | |
| 15 | - opacity: 1 | |
| 16 | - } | |
| 11 | + hiddenStyle: wpupg_public.animationHide, | |
| 12 | + visibleStyle: wpupg_public.animationShow | |
| 17 | 13 | }; |
| 18 | 14 | |
| 19 | 15 | if(wpupg_public.rtl) { |
| 20 | 16 | args.isOriginLeft = false; |
| @@ -30,15 +26,16 @@ | ||
| 30 | 26 | isFitWidth: true |
| 31 | 27 | }; |
| 32 | 28 | } |
| 33 | 29 | |
| 34 | - container.isotope(args); | |
| 30 | + container.isotopewpupg(args); | |
| 35 | 31 | |
| 36 | 32 | container.imagesLoaded( function() { |
| 37 | - container.isotope('layout'); | |
| 33 | + container.isotopewpupg('layout'); | |
| 38 | 34 | }); |
| 39 | 35 | |
| 40 | 36 | WPUltimatePostGrid.grids[grid_id] = { |
| 37 | + args: args, | |
| 41 | 38 | container: container, |
| 42 | 39 | centered: container.data('centered'), |
| 43 | 40 | data: window['wpupg_grid_' + container.data('grid-id')], |
| 44 | 41 | id: container.data('grid-id'), |
| @@ -43,15 +40,93 @@ | ||
| 43 | 40 | data: window['wpupg_grid_' + container.data('grid-id')], |
| 44 | 41 | id: container.data('grid-id'), |
| 45 | 42 | pages: [0], |
| 46 | 43 | page: 0, |
| 47 | - filters: {} | |
| 44 | + filter: '', | |
| 45 | + filters: {}, | |
| 46 | + filter_text: false, | |
| 47 | + filter_text_search: '', | |
| 48 | + filter_text_posts: [] | |
| 48 | 49 | }; |
| 49 | 50 | |
| 50 | 51 | WPUltimatePostGrid.checkLinks(grid_id); |
| 51 | 52 | WPUltimatePostGrid.updatePosts(grid_id); |
| 53 | + | |
| 54 | + jQuery(container).on('hover', '.wpupg-item', function(e) { | |
| 55 | + var hovering = e.type == 'mouseenter'; | |
| 56 | + WPUltimatePostGrid.hoverGridItem(jQuery(this), hovering); | |
| 57 | + }); | |
| 58 | + | |
| 59 | + // Check for empty grid | |
| 60 | + container.on('arrangeComplete', function() { | |
| 61 | + WPUltimatePostGrid.checkEmpty(container); | |
| 62 | + }); | |
| 52 | 63 | }; |
| 53 | 64 | |
| 65 | +WPUltimatePostGrid.hoverGridItem = function(grid_item, hovering) { | |
| 66 | + if(hovering) { | |
| 67 | + grid_item.addClass('wpupg-hovering'); | |
| 68 | + | |
| 69 | + grid_item.find('.wpupg-show-on-hover').each(function() { | |
| 70 | + var item = jQuery(this), | |
| 71 | + effect = item.data('hover-in'), | |
| 72 | + duration = parseInt(item.data('hover-in-duration')); | |
| 73 | + | |
| 74 | + if(effect == 'fade') { | |
| 75 | + item.fadeIn(duration); | |
| 76 | + } else if(effect == 'slide') { | |
| 77 | + item.slideDown(duration); | |
| 78 | + } else { | |
| 79 | + item.show(); | |
| 80 | + } | |
| 81 | + }); | |
| 82 | + | |
| 83 | + grid_item.find('.wpupg-hide-on-hover').each(function() { | |
| 84 | + var item = jQuery(this), | |
| 85 | + effect = item.data('hover-out'), | |
| 86 | + duration = parseInt(item.data('hover-out-duration')); | |
| 87 | + | |
| 88 | + if(effect == 'fade') { | |
| 89 | + item.fadeOut(duration); | |
| 90 | + } else if(effect == 'slide') { | |
| 91 | + item.slideUp(duration); | |
| 92 | + } else { | |
| 93 | + item.hide(); | |
| 94 | + } | |
| 95 | + }); | |
| 96 | + } else { | |
| 97 | + grid_item.removeClass('wpupg-hovering'); | |
| 98 | + | |
| 99 | + grid_item.find('.wpupg-show-on-hover').each(function() { | |
| 100 | + var item = jQuery(this), | |
| 101 | + effect = item.data('hover-out'), | |
| 102 | + duration = parseInt(item.data('hover-out-duration')); | |
| 103 | + | |
| 104 | + if(effect == 'fade') { | |
| 105 | + item.fadeOut(duration); | |
| 106 | + } else if(effect == 'slide') { | |
| 107 | + item.slideUp(duration); | |
| 108 | + } else { | |
| 109 | + item.hide(); | |
| 110 | + } | |
| 111 | + }); | |
| 112 | + | |
| 113 | + grid_item.find('.wpupg-hide-on-hover').each(function() { | |
| 114 | + var item = jQuery(this), | |
| 115 | + effect = item.data('hover-in'), | |
| 116 | + duration = parseInt(item.data('hover-in-duration')); | |
| 117 | + | |
| 118 | + if(effect == 'fade') { | |
| 119 | + item.fadeIn(duration); | |
| 120 | + } else if(effect == 'slide') { | |
| 121 | + item.slideDown(duration); | |
| 122 | + } else { | |
| 123 | + item.show(); | |
| 124 | + } | |
| 125 | + }); | |
| 126 | + } | |
| 127 | +}; | |
| 128 | + | |
| 54 | 129 | WPUltimatePostGrid.updatePosts = function(grid_id) { |
| 55 | 130 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 56 | 131 | |
| 57 | 132 | var posts = []; |
| @@ -67,44 +142,74 @@ | ||
| 67 | 142 | WPUltimatePostGrid.filterGrid = function(grid_id) { |
| 68 | 143 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 69 | 144 | var filters = []; |
| 70 | 145 | |
| 71 | - // Page filter | |
| 72 | - if(grid.pagination_type == 'pages') { | |
| 73 | - var page = grid.page || 0; | |
| 74 | - filters.push(['.wpupg-page-' + page]); | |
| 75 | - } | |
| 146 | + if(grid.filter_text) { | |
| 147 | + grid.filter = ''; | |
| 148 | + var posts = []; | |
| 76 | 149 | |
| 77 | - // Taxonomy filters | |
| 78 | - for(var taxonomy in grid.filters) { | |
| 79 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 80 | - var taxonomy_filters = grid.filters[taxonomy]; | |
| 150 | + for(var i=0; i < grid.filter_text_posts.length; i++) { | |
| 151 | + posts.push('#wpupg-container-post-' + grid.filter_text_posts[i]); | |
| 152 | + posts.push('#wpurp-container-recipe-' + grid.filter_text_posts[i]); | |
| 153 | + } | |
| 81 | 154 | |
| 82 | - var match_one_filters = []; | |
| 83 | - var match_all_filter = ''; | |
| 155 | + if(posts.length == 0) { | |
| 156 | + posts.push('no-result'); | |
| 157 | + } | |
| 84 | 158 | |
| 85 | - if(taxonomy_filters) { | |
| 86 | - for(var i = 0; i < taxonomy_filters.length; i++) { | |
| 87 | - if(grid.multiselect_type == 'match_one') { | |
| 88 | - match_one_filters.push('.wpupg-tax-' + taxonomy + '-' + taxonomy_filters[i]); | |
| 89 | - } else { | |
| 90 | - match_all_filter += '.wpupg-tax-' + taxonomy + '-' + taxonomy_filters[i]; | |
| 159 | + WPUltimatePostGrid.getFilterString(grid_id, '', [posts], 0); | |
| 160 | + } else { | |
| 161 | + // Page filter | |
| 162 | + if(grid.pagination_type == 'pages') { | |
| 163 | + var page = grid.page || 0; | |
| 164 | + filters.push(['.wpupg-page-' + page]); | |
| 165 | + } | |
| 166 | + | |
| 167 | + // Taxonomy filters | |
| 168 | + for(var taxonomy in grid.filters) { | |
| 169 | + if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 170 | + var taxonomy_filters = grid.filters[taxonomy]; | |
| 171 | + | |
| 172 | + var match_one_filters = []; | |
| 173 | + var match_all_filter = ''; | |
| 174 | + var filter = ''; | |
| 175 | + | |
| 176 | + if(taxonomy_filters) { | |
| 177 | + for(var i = 0; i < taxonomy_filters.length; i++) { | |
| 178 | + filter = '.wpupg-tax-' + taxonomy + '-' + taxonomy_filters[i]; | |
| 179 | + | |
| 180 | + if(grid.multiselect_type == 'match_one') { | |
| 181 | + match_one_filters.push(filter); | |
| 182 | + } else { | |
| 183 | + match_all_filter += filter; | |
| 184 | + } | |
| 91 | 185 | } |
| 92 | 186 | } |
| 187 | + | |
| 188 | + if(grid.multiselect_type == 'match_one') { | |
| 189 | + if(match_one_filters.length > 0) filters.push(match_one_filters); | |
| 190 | + } else { | |
| 191 | + if(match_all_filter !== '') filters.push([match_all_filter]); | |
| 192 | + } | |
| 93 | 193 | } |
| 194 | + } | |
| 94 | 195 | |
| 95 | - if(grid.multiselect_type == 'match_one') { | |
| 96 | - if(match_one_filters.length > 0) filters.push(match_one_filters); | |
| 196 | + grid.filter = ''; | |
| 197 | + WPUltimatePostGrid.getFilterString(grid_id, '', filters, 0); | |
| 198 | + if(grid.inverse) { | |
| 199 | + if(grid.pagination_type == 'pages') { | |
| 200 | + var page = grid.page || 0; | |
| 201 | + var filter_without_page = grid.filter.replace('.wpupg-page-' + page, ''); | |
| 202 | + | |
| 203 | + grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; | |
| 97 | 204 | } else { |
| 98 | - if(match_all_filter !== '') filters.push([match_all_filter]); | |
| 205 | + grid.filter = ':not(' + grid.filter + ')'; | |
| 99 | 206 | } |
| 100 | 207 | } |
| 101 | 208 | } |
| 102 | 209 | |
| 103 | - grid.filter = ''; | |
| 104 | - WPUltimatePostGrid.getFilterString(grid_id, '', filters, 0); | |
| 105 | - | |
| 106 | - grid.container.isotope({ filter: grid.filter }); | |
| 210 | + jQuery('#wpupg-grid-' + grid_id + '-empty').hide(); | |
| 211 | + grid.container.isotopewpupg({ filter: grid.filter }); | |
| 107 | 212 | grid.container.trigger('wpupgFiltered'); |
| 108 | 213 | WPUltimatePostGrid.updateDeeplink(); |
| 109 | 214 | }; |
| 110 | 215 | |
| @@ -118,8 +223,18 @@ | ||
| 118 | 223 | } |
| 119 | 224 | } |
| 120 | 225 | }; |
| 121 | 226 | |
| 227 | +WPUltimatePostGrid.checkEmpty = function(container) { | |
| 228 | + var grid_id = container.data('grid'), | |
| 229 | + filter = WPUltimatePostGrid.grids[grid_id].filter, | |
| 230 | + visible_items = container.find(filter); | |
| 231 | + | |
| 232 | + if(filter !== '' && visible_items.length == 0) { | |
| 233 | + jQuery('#wpupg-grid-' + grid_id + '-empty').slideDown(300); | |
| 234 | + } | |
| 235 | +}; | |
| 236 | + | |
| 122 | 237 | WPUltimatePostGrid.updateDeeplink = function() { |
| 123 | 238 | var link = ''; |
| 124 | 239 | |
| 125 | 240 | for(var grid_id in WPUltimatePostGrid.grids) { |
| @@ -126,18 +241,23 @@ | ||
| 126 | 241 | if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { |
| 127 | 242 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 128 | 243 | var grid_link = ''; |
| 129 | 244 | |
| 130 | - // Page filter | |
| 131 | - if(grid.page != 0) grid_link += '|p:' + (grid.page+1); | |
| 132 | 245 | |
| 133 | - // Taxonomy filters | |
| 134 | - for(var taxonomy in grid.filters) { | |
| 135 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 136 | - var taxonomy_filter = grid.filters[taxonomy]; | |
| 246 | + if(grid.filter_text) { | |
| 247 | + grid_link += '+s:' + grid.filter_text_search; | |
| 248 | + } else { | |
| 249 | + // Page filter | |
| 250 | + if(grid.page != 0) grid_link += '+p:' + (grid.page+1); | |
| 137 | 251 | |
| 138 | - if(taxonomy_filter.length > 0) { | |
| 139 | - grid_link += '|' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 252 | + // Taxonomy filters | |
| 253 | + for(var taxonomy in grid.filters) { | |
| 254 | + if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 255 | + var taxonomy_filter = grid.filters[taxonomy]; | |
| 256 | + | |
| 257 | + if(taxonomy_filter.length > 0) { | |
| 258 | + grid_link += '+' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 259 | + } | |
| 140 | 260 | } |
| 141 | 261 | } |
| 142 | 262 | } |
| 143 | 263 | |
| @@ -148,27 +268,90 @@ | ||
| 148 | 268 | } |
| 149 | 269 | } |
| 150 | 270 | } |
| 151 | 271 | |
| 152 | - if(link == '') link = '*'; | |
| 153 | - document.location.hash = link; | |
| 272 | + WPUltimatePostGrid.replaceDeeplink(link); | |
| 154 | 273 | }; |
| 155 | 274 | |
| 275 | +/** | |
| 276 | + * Source: http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh/5298684#5298684 | |
| 277 | + */ | |
| 278 | +WPUltimatePostGrid.replaceDeeplink = function(link) { | |
| 279 | + var scrollV, scrollH, loc = window.location; | |
| 280 | + if ("replaceState" in history) { | |
| 281 | + var hash = link == '' ? '' : '#' + link; | |
| 282 | + history.replaceState("", document.title, loc.pathname + hash + loc.search); | |
| 283 | + } else { | |
| 284 | + // Prevent scrolling by storing the page's current scroll offset | |
| 285 | + scrollV = document.documentElement.scrollTop || document.body.scrollTop; | |
| 286 | + scrollH = document.documentElement.scrollLeft || document.body.scrollLeft; | |
| 287 | + | |
| 288 | + loc.hash = link; | |
| 289 | + | |
| 290 | + // Restore the scroll offset, should be flicker free | |
| 291 | + document.documentElement.scrollTop = document.body.scrollTop = scrollV; | |
| 292 | + document.documentElement.scrollLeft = document.body.scrollLeft = scrollH; | |
| 293 | + } | |
| 294 | +}; | |
| 295 | + | |
| 296 | +WPUltimatePostGrid.preFilterGrid = function() { | |
| 297 | + var link = document.location.hash; | |
| 298 | + link = link.substr(1); | |
| 299 | + | |
| 300 | + if(!link) { | |
| 301 | + var link = ''; | |
| 302 | + | |
| 303 | + for(var grid_id in WPUltimatePostGrid.grids) { | |
| 304 | + if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { | |
| 305 | + var grid = WPUltimatePostGrid.grids[grid_id]; | |
| 306 | + var grid_link = ''; | |
| 307 | + | |
| 308 | + if(grid.filter_data) { | |
| 309 | + var pre_filter = grid.filter_data['pre_filter']; | |
| 310 | + | |
| 311 | + // Taxonomy filters | |
| 312 | + for(var taxonomy in pre_filter) { | |
| 313 | + if(pre_filter.hasOwnProperty(taxonomy)) { | |
| 314 | + var taxonomy_filter = pre_filter[taxonomy]; | |
| 315 | + | |
| 316 | + if(taxonomy_filter.length > 0) { | |
| 317 | + grid_link += '+' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 318 | + } | |
| 319 | + } | |
| 320 | + } | |
| 321 | + } | |
| 322 | + | |
| 323 | + if(grid_link != '') { | |
| 324 | + if(link != '') link += '#'; | |
| 325 | + link += grid_id; | |
| 326 | + link += grid_link; | |
| 327 | + } | |
| 328 | + } | |
| 329 | + } | |
| 330 | + | |
| 331 | + WPUltimatePostGrid.replaceDeeplink(link); | |
| 332 | + } | |
| 333 | +}; | |
| 334 | + | |
| 156 | 335 | WPUltimatePostGrid.restoreDeeplink = function() { |
| 157 | 336 | var link = document.location.hash; |
| 158 | 337 | link = link.substr(1); |
| 159 | 338 | |
| 160 | - if(link && link != '*') { | |
| 339 | + if(link) { | |
| 161 | 340 | // Make sure characters are not URL encoded |
| 162 | 341 | link = link.replace('%23', '#'); |
| 163 | 342 | link = link.replace('%7C', '|'); |
| 343 | + link = link.replace('%2B', '+'); | |
| 164 | 344 | link = link.replace('%3A', ':'); |
| 165 | 345 | link = link.replace('%2C', ','); |
| 166 | 346 | |
| 347 | + // Backwards compatibility | |
| 348 | + link = link.replace('|', '+'); | |
| 349 | + | |
| 167 | 350 | var grids = link.split('#'); |
| 168 | 351 | |
| 169 | 352 | for(var i=0; i < grids.length; i++) { |
| 170 | - var parts = grids[i].split('|'); | |
| 353 | + var parts = grids[i].split('+'); | |
| 171 | 354 | var grid_id = parts[0]; |
| 172 | 355 | |
| 173 | 356 | for(var j=1; j < parts.length; j++) { |
| 174 | 357 | var filter = parts[j].split(':'); |
| @@ -175,11 +358,13 @@ | ||
| 175 | 358 | |
| 176 | 359 | if(filter[0] == 'p') { |
| 177 | 360 | var page = parseInt(filter[1]) - 1; |
| 178 | 361 | WPUltimatePostGrid.updatePagination(jQuery('#wpupg-grid-' + grid_id + '-pagination'), page); |
| 362 | + } else if(filter[0] == 's') { | |
| 363 | + WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], 'text', filter[1]); | |
| 179 | 364 | } else { |
| 180 | 365 | var terms = filter[1].split(','); |
| 181 | - WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], terms); | |
| 366 | + WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], 'terms', terms); | |
| 182 | 367 | } |
| 183 | 368 | } |
| 184 | 369 | } |
| 185 | 370 | } |
| @@ -186,17 +371,18 @@ | ||
| 186 | 371 | }; |
| 187 | 372 | |
| 188 | 373 | WPUltimatePostGrid.checkLinks = function(grid_id) { |
| 189 | 374 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 190 | - var link_type = grid.container.data('link-type'); | |
| 375 | + var default_link_type = grid.container.data('link-type'); | |
| 191 | 376 | var link_target = grid.container.data('link-target'); |
| 377 | + var link_rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 192 | 378 | |
| 193 | - if(link_type != 'none') { | |
| 379 | + if(default_link_type != 'none') { | |
| 194 | 380 | grid.container.find('.wpupg-item').each(function() { |
| 195 | 381 | var item = jQuery(this); |
| 196 | 382 | |
| 197 | 383 | // Remove links from item |
| 198 | - item.find('a:not(.wpupg-keep-link, .wpurp-recipe-favorite, .wpurp-recipe-add-to-shopping-list, .wpurp-recipe-print-button, .wpurp-recipe-grid-link)').each(function() { | |
| 384 | + item.find('a:not(.wpupg-keep-link, .wpurp-recipe-favorite, .wpurp-recipe-add-to-shopping-list, .wpurp-recipe-add-to-meal-plan, .wpurp-recipe-print-button, .wpurp-recipe-grid-link)').each(function() { | |
| 199 | 385 | var link = jQuery(this); |
| 200 | 386 | if(link.parents('.sharrre').length == 0) { |
| 201 | 387 | link.replaceWith(function() { return link.contents(); }); |
| 202 | 388 | } |
| @@ -202,27 +388,29 @@ | ||
| 202 | 388 | } |
| 203 | 389 | }); |
| 204 | 390 | |
| 205 | 391 | var link = item.data('custom-link') ? item.data('custom-link') : ( link_target == 'post' ? item.data('permalink') : item.data('image') ); |
| 206 | - var rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 392 | + var link_behaviour = item.data('custom-link-behaviour'); | |
| 207 | 393 | |
| 394 | + var link_type = link_behaviour == '_blank' || link_behaviour == '_self' ? link_behaviour : default_link_type; | |
| 395 | + | |
| 208 | 396 | // Add link around item |
| 209 | - if (link && item.parent('a').length == 0) { | |
| 210 | - item.wrap('<a href="' + link + '" target="' + link_type + '"' + rel + '></a>'); | |
| 397 | + if (link_behaviour !== 'none' && link && item.parent('a').length == 0) { | |
| 398 | + item.wrap('<a href="' + link + '" target="' + link_type + '"' + link_rel + ' class="' + wpupg_public.link_class + '"></a>'); | |
| 211 | 399 | } |
| 212 | 400 | }); |
| 213 | 401 | } |
| 214 | 402 | }; |
| 215 | 403 | |
| 216 | -WPUltimatePostGrid.updateFilter = function(container, taxonomy, terms) { | |
| 217 | - var type = container.data('type'); | |
| 218 | - var func = 'updateFilter' + type.charAt(0).toUpperCase() + type.slice(1); | |
| 404 | +WPUltimatePostGrid.updateFilter = function(container, taxonomy, type, terms) { | |
| 405 | + var filter_type = container.data('type'); | |
| 406 | + var func = 'updateFilter' + filter_type.charAt(0).toUpperCase() + filter_type.slice(1); | |
| 219 | 407 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 220 | - WPUltimatePostGrid[func](container, taxonomy, terms); | |
| 408 | + WPUltimatePostGrid[func](container, taxonomy, type, terms); | |
| 221 | 409 | } |
| 222 | 410 | }; |
| 223 | 411 | |
| 224 | -WPUltimatePostGrid.updateFilterIsotope = function(container, taxonomy, terms) { | |
| 412 | +WPUltimatePostGrid.updateFilterIsotope = function(container, taxonomy, type, terms) { | |
| 225 | 413 | for(var i = 0; i < terms.length; i++) { |
| 226 | 414 | container.find('.wpupg-filter-tag-' + terms[i]).click(); |
| 227 | 415 | } |
| 228 | 416 | }; |
| @@ -231,8 +419,9 @@ | ||
| 231 | 419 | var grid_id = container.data('grid'); |
| 232 | 420 | |
| 233 | 421 | WPUltimatePostGrid.grids[grid_id].multiselect = container.data('multiselect'); |
| 234 | 422 | WPUltimatePostGrid.grids[grid_id].multiselect_type = container.data('multiselect-type'); |
| 423 | + WPUltimatePostGrid.grids[grid_id].inverse = container.data('inverse'); | |
| 235 | 424 | |
| 236 | 425 | container.find('.wpupg-filter-isotope-term').click(function() { |
| 237 | 426 | var filter_item = jQuery(this); |
| 238 | 427 | var taxonomy = filter_item.data('taxonomy'); |
| @@ -291,9 +480,9 @@ | ||
| 291 | 480 | |
| 292 | 481 | var filter_type = container.data('filter-type'); |
| 293 | 482 | var filter_items = container.find('.wpupg-filter-item'); |
| 294 | 483 | |
| 295 | - if(filter_type == 'isotope') { | |
| 484 | + if(filter_type == 'isotope' || filter_type == 'text_isotope') { | |
| 296 | 485 | var margin = container.data('margin-vertical') + 'px ' + container.data('margin-horizontal') + 'px'; |
| 297 | 486 | var padding = container.data('padding-vertical') + 'px ' + container.data('padding-horizontal') + 'px'; |
| 298 | 487 | var border = container.data('border-width') + 'px solid ' + container.data('border-color'); |
| 299 | 488 | var background_color = container.data('background-color'); |
| @@ -349,11 +538,14 @@ | ||
| 349 | 538 | }; |
| 350 | 539 | |
| 351 | 540 | WPUltimatePostGrid.updatePagination = function(container, page) { |
| 352 | 541 | var type = container.data('type'); |
| 353 | - var func = 'updatePagination' + type.charAt(0).toUpperCase() + type.slice(1); | |
| 354 | - if(typeof WPUltimatePostGrid[func] == 'function') { | |
| 355 | - WPUltimatePostGrid[func](container, page); | |
| 542 | + | |
| 543 | + if(type) { | |
| 544 | + var func = 'updatePagination' + type.charAt(0).toUpperCase() + type.slice(1); | |
| 545 | + if(typeof WPUltimatePostGrid[func] == 'function') { | |
| 546 | + WPUltimatePostGrid[func](container, page); | |
| 547 | + } | |
| 356 | 548 | } |
| 357 | 549 | }; |
| 358 | 550 | |
| 359 | 551 | WPUltimatePostGrid.updatePaginationPages = function(container, page) { |
| @@ -368,8 +560,10 @@ | ||
| 368 | 560 | pagination_item.siblings('.wpupg-pagination-term').removeClass('active').trigger('checkActiveFilter'); |
| 369 | 561 | |
| 370 | 562 | var page = parseInt(pagination_item.addClass('active').trigger('checkActiveFilter').data('page')); |
| 371 | 563 | |
| 564 | + WPUltimatePostGrid.scrollTo(WPUltimatePostGrid.grids[grid_id].container); | |
| 565 | + | |
| 372 | 566 | if(WPUltimatePostGrid.grids[grid_id].pages.indexOf(page) !== -1) { |
| 373 | 567 | WPUltimatePostGrid.grids[grid_id].page = page; |
| 374 | 568 | WPUltimatePostGrid.filterGrid(grid_id); |
| 375 | 569 | } else { |
| @@ -386,17 +580,12 @@ | ||
| 386 | 580 | |
| 387 | 581 | // Get recipes through AJAX |
| 388 | 582 | jQuery.post(wpupg_public.ajax_url, data, function(html) { |
| 389 | 583 | var posts = jQuery(html).toArray(); |
| 390 | - WPUltimatePostGrid.grids[grid_id].container.isotope('insert', posts); | |
| 584 | + | |
| 391 | 585 | WPUltimatePostGrid.grids[grid_id].page = page; |
| 392 | - WPUltimatePostGrid.filterGrid(grid_id); | |
| 393 | - WPUltimatePostGrid.checkLinks(grid_id); | |
| 586 | + WPUltimatePostGrid.insertPosts(grid_id, posts); | |
| 394 | 587 | |
| 395 | - WPUltimatePostGrid.grids[grid_id].container.imagesLoaded( function() { | |
| 396 | - WPUltimatePostGrid.grids[grid_id].container.isotope('layout'); | |
| 397 | - }); | |
| 398 | - | |
| 399 | 588 | pagination_item.removeClass('wpupg-spinner'); |
| 400 | 589 | pagination_item.css('color', WPUltimatePostGrid.grids[grid_id].pagination_style.active_text_color); |
| 401 | 590 | |
| 402 | 591 | WPUltimatePostGrid.grids[grid_id].pages.push(page); |
| @@ -474,8 +663,40 @@ | ||
| 474 | 663 | }).trigger('checkActiveFilter'); |
| 475 | 664 | }); |
| 476 | 665 | }; |
| 477 | 666 | |
| 667 | +WPUltimatePostGrid.insertPosts = function(grid_id, posts) { | |
| 668 | + var scrollV = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0, | |
| 669 | + scrollH = document.documentElement.scrollLeft || document.body.scrollLeft; | |
| 670 | + | |
| 671 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg('destroy'); | |
| 672 | + | |
| 673 | + WPUltimatePostGrid.grids[grid_id].container.append(posts); | |
| 674 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg(WPUltimatePostGrid.grids[grid_id].args); | |
| 675 | + | |
| 676 | + // Restore the scroll offset, should be flicker free | |
| 677 | + jQuery(window).scrollTop(scrollV); | |
| 678 | + document.documentElement.scrollLeft = document.body.scrollLeft = scrollH; | |
| 679 | + | |
| 680 | + WPUltimatePostGrid.updatePosts(grid_id); | |
| 681 | + WPUltimatePostGrid.checkLinks(grid_id); | |
| 682 | + WPUltimatePostGrid.filterGrid(grid_id); | |
| 683 | + | |
| 684 | + WPUltimatePostGrid.grids[grid_id].container.imagesLoaded( function() { | |
| 685 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg('layout'); | |
| 686 | + WPUltimatePostGrid.grids[grid_id].loading = false; | |
| 687 | + }); | |
| 688 | +}; | |
| 689 | + | |
| 690 | +WPUltimatePostGrid.scrollTo = function(target) { | |
| 691 | + var scroll_to = target.offset().top - 50; | |
| 692 | + scroll_to = scroll_to < 0 ? 0 : scroll_to; | |
| 693 | + | |
| 694 | + jQuery('html,body').animate({ | |
| 695 | + scrollTop: scroll_to | |
| 696 | + }, 500); | |
| 697 | +}; | |
| 698 | + | |
| 478 | 699 | jQuery(document).ready(function($) { |
| 479 | 700 | $('.wpupg-grid').each(function() { |
| 480 | 701 | WPUltimatePostGrid.initGrid($(this)); |
| 481 | 702 | }); |
| @@ -485,8 +706,9 @@ | ||
| 485 | 706 | var grid_id = container.data('grid'); |
| 486 | 707 | var type = container.data('type'); |
| 487 | 708 | |
| 488 | 709 | WPUltimatePostGrid.grids[grid_id].filter_type = type; |
| 710 | + WPUltimatePostGrid.grids[grid_id].filter_data = window['wpupg_filter_' + WPUltimatePostGrid.grids[grid_id].id]; | |
| 489 | 711 | |
| 490 | 712 | var func = 'initFilter' + type.charAt(0).toUpperCase() + type.slice(1); |
| 491 | 713 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 492 | 714 | WPUltimatePostGrid[func](container); |
| @@ -504,6 +726,7 @@ | ||
| 504 | 726 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 505 | 727 | WPUltimatePostGrid[func](container); |
| 506 | 728 | } |
| 507 | 729 | }); |
| 730 | + WPUltimatePostGrid.preFilterGrid(); | |
| 508 | 731 | WPUltimatePostGrid.restoreDeeplink(); |
| 509 | 732 | }); |