| @@ -26,12 +26,12 @@ | ||
| 26 | 26 | isFitWidth: true |
| 27 | 27 | }; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - container.isotope(args); | |
| 30 | + container.isotopewpupg(args); | |
| 31 | 31 | |
| 32 | 32 | container.imagesLoaded( function() { |
| 33 | - container.isotope('layout'); | |
| 33 | + container.isotopewpupg('layout'); | |
| 34 | 34 | }); |
| 35 | 35 | |
| 36 | 36 | WPUltimatePostGrid.grids[grid_id] = { |
| 37 | 37 | args: args, |
| @@ -40,9 +40,13 @@ | ||
| 40 | 40 | data: window['wpupg_grid_' + container.data('grid-id')], |
| 41 | 41 | id: container.data('grid-id'), |
| 42 | 42 | pages: [0], |
| 43 | 43 | page: 0, |
| 44 | - filters: {} | |
| 44 | + filter: '', | |
| 45 | + filters: {}, | |
| 46 | + filter_text: false, | |
| 47 | + filter_text_search: '', | |
| 48 | + filter_text_posts: [] | |
| 45 | 49 | }; |
| 46 | 50 | |
| 47 | 51 | WPUltimatePostGrid.checkLinks(grid_id); |
| 48 | 52 | WPUltimatePostGrid.updatePosts(grid_id); |
| @@ -50,8 +54,13 @@ | ||
| 50 | 54 | jQuery(container).on('hover', '.wpupg-item', function(e) { |
| 51 | 55 | var hovering = e.type == 'mouseenter'; |
| 52 | 56 | WPUltimatePostGrid.hoverGridItem(jQuery(this), hovering); |
| 53 | 57 | }); |
| 58 | + | |
| 59 | + // Check for empty grid | |
| 60 | + container.on('arrangeComplete', function() { | |
| 61 | + WPUltimatePostGrid.checkEmpty(container); | |
| 62 | + }); | |
| 54 | 63 | }; |
| 55 | 64 | |
| 56 | 65 | WPUltimatePostGrid.hoverGridItem = function(grid_item, hovering) { |
| 57 | 66 | if(hovering) { |
| @@ -133,57 +142,74 @@ | ||
| 133 | 142 | WPUltimatePostGrid.filterGrid = function(grid_id) { |
| 134 | 143 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 135 | 144 | var filters = []; |
| 136 | 145 | |
| 137 | - // Page filter | |
| 138 | - if(grid.pagination_type == 'pages') { | |
| 139 | - var page = grid.page || 0; | |
| 140 | - filters.push(['.wpupg-page-' + page]); | |
| 141 | - } | |
| 146 | + if(grid.filter_text) { | |
| 147 | + grid.filter = ''; | |
| 148 | + var posts = []; | |
| 142 | 149 | |
| 143 | - // Taxonomy filters | |
| 144 | - for(var taxonomy in grid.filters) { | |
| 145 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 146 | - 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 | + } | |
| 147 | 154 | |
| 148 | - var match_one_filters = []; | |
| 149 | - var match_all_filter = ''; | |
| 150 | - var filter = ''; | |
| 155 | + if(posts.length == 0) { | |
| 156 | + posts.push('no-result'); | |
| 157 | + } | |
| 151 | 158 | |
| 152 | - if(taxonomy_filters) { | |
| 153 | - for(var i = 0; i < taxonomy_filters.length; i++) { | |
| 154 | - 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 | + } | |
| 155 | 166 | |
| 156 | - if(grid.multiselect_type == 'match_one') { | |
| 157 | - match_one_filters.push(filter); | |
| 158 | - } else { | |
| 159 | - match_all_filter += filter; | |
| 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 | + } | |
| 160 | 185 | } |
| 161 | 186 | } |
| 162 | - } | |
| 163 | 187 | |
| 164 | - if(grid.multiselect_type == 'match_one') { | |
| 165 | - if(match_one_filters.length > 0) filters.push(match_one_filters); | |
| 166 | - } else { | |
| 167 | - if(match_all_filter !== '') filters.push([match_all_filter]); | |
| 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 | + } | |
| 168 | 193 | } |
| 169 | 194 | } |
| 170 | - } | |
| 171 | 195 | |
| 172 | - grid.filter = ''; | |
| 173 | - WPUltimatePostGrid.getFilterString(grid_id, '', filters, 0); | |
| 174 | - if(grid.inverse) { | |
| 175 | - if(grid.pagination_type == 'pages') { | |
| 176 | - var page = grid.page || 0; | |
| 177 | - var filter_without_page = grid.filter.replace('.wpupg-page-' + page, ''); | |
| 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, ''); | |
| 178 | 202 | |
| 179 | - grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; | |
| 180 | - } else { | |
| 181 | - grid.filter = ':not(' + grid.filter + ')'; | |
| 203 | + grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; | |
| 204 | + } else { | |
| 205 | + grid.filter = ':not(' + grid.filter + ')'; | |
| 206 | + } | |
| 182 | 207 | } |
| 183 | 208 | } |
| 184 | 209 | |
| 185 | - grid.container.isotope({ filter: grid.filter }); | |
| 210 | + jQuery('#wpupg-grid-' + grid_id + '-empty').hide(); | |
| 211 | + grid.container.isotopewpupg({ filter: grid.filter }); | |
| 186 | 212 | grid.container.trigger('wpupgFiltered'); |
| 187 | 213 | WPUltimatePostGrid.updateDeeplink(); |
| 188 | 214 | }; |
| 189 | 215 | |
| @@ -197,8 +223,18 @@ | ||
| 197 | 223 | } |
| 198 | 224 | } |
| 199 | 225 | }; |
| 200 | 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 | + | |
| 201 | 237 | WPUltimatePostGrid.updateDeeplink = function() { |
| 202 | 238 | var link = ''; |
| 203 | 239 | |
| 204 | 240 | for(var grid_id in WPUltimatePostGrid.grids) { |
| @@ -205,18 +241,23 @@ | ||
| 205 | 241 | if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { |
| 206 | 242 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 207 | 243 | var grid_link = ''; |
| 208 | 244 | |
| 209 | - // Page filter | |
| 210 | - if(grid.page != 0) grid_link += '+p:' + (grid.page+1); | |
| 211 | 245 | |
| 212 | - // Taxonomy filters | |
| 213 | - for(var taxonomy in grid.filters) { | |
| 214 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 215 | - 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); | |
| 216 | 251 | |
| 217 | - if(taxonomy_filter.length > 0) { | |
| 218 | - 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 | + } | |
| 219 | 260 | } |
| 220 | 261 | } |
| 221 | 262 | } |
| 222 | 263 | |
| @@ -227,11 +268,71 @@ | ||
| 227 | 268 | } |
| 228 | 269 | } |
| 229 | 270 | } |
| 230 | 271 | |
| 231 | - document.location.hash = link; | |
| 272 | + WPUltimatePostGrid.replaceDeeplink(link); | |
| 232 | 273 | }; |
| 233 | 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 | + | |
| 234 | 335 | WPUltimatePostGrid.restoreDeeplink = function() { |
| 235 | 336 | var link = document.location.hash; |
| 236 | 337 | link = link.substr(1); |
| 237 | 338 | |
| @@ -257,11 +358,13 @@ | ||
| 257 | 358 | |
| 258 | 359 | if(filter[0] == 'p') { |
| 259 | 360 | var page = parseInt(filter[1]) - 1; |
| 260 | 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]); | |
| 261 | 364 | } else { |
| 262 | 365 | var terms = filter[1].split(','); |
| 263 | - WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], terms); | |
| 366 | + WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], 'terms', terms); | |
| 264 | 367 | } |
| 265 | 368 | } |
| 266 | 369 | } |
| 267 | 370 | } |
| @@ -268,12 +371,13 @@ | ||
| 268 | 371 | }; |
| 269 | 372 | |
| 270 | 373 | WPUltimatePostGrid.checkLinks = function(grid_id) { |
| 271 | 374 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 272 | - var link_type = grid.container.data('link-type'); | |
| 375 | + var default_link_type = grid.container.data('link-type'); | |
| 273 | 376 | var link_target = grid.container.data('link-target'); |
| 377 | + var link_rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 274 | 378 | |
| 275 | - if(link_type != 'none') { | |
| 379 | + if(default_link_type != 'none') { | |
| 276 | 380 | grid.container.find('.wpupg-item').each(function() { |
| 277 | 381 | var item = jQuery(this); |
| 278 | 382 | |
| 279 | 383 | // Remove links from item |
| @@ -284,27 +388,29 @@ | ||
| 284 | 388 | } |
| 285 | 389 | }); |
| 286 | 390 | |
| 287 | 391 | var link = item.data('custom-link') ? item.data('custom-link') : ( link_target == 'post' ? item.data('permalink') : item.data('image') ); |
| 288 | - var rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 392 | + var link_behaviour = item.data('custom-link-behaviour'); | |
| 289 | 393 | |
| 394 | + var link_type = link_behaviour == '_blank' || link_behaviour == '_self' ? link_behaviour : default_link_type; | |
| 395 | + | |
| 290 | 396 | // Add link around item |
| 291 | - if (link && item.parent('a').length == 0) { | |
| 292 | - item.wrap('<a href="' + link + '" target="' + link_type + '"' + rel + ' class="' + wpupg_public.link_class + '"></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>'); | |
| 293 | 399 | } |
| 294 | 400 | }); |
| 295 | 401 | } |
| 296 | 402 | }; |
| 297 | 403 | |
| 298 | -WPUltimatePostGrid.updateFilter = function(container, taxonomy, terms) { | |
| 299 | - var type = container.data('type'); | |
| 300 | - 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); | |
| 301 | 407 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 302 | - WPUltimatePostGrid[func](container, taxonomy, terms); | |
| 408 | + WPUltimatePostGrid[func](container, taxonomy, type, terms); | |
| 303 | 409 | } |
| 304 | 410 | }; |
| 305 | 411 | |
| 306 | -WPUltimatePostGrid.updateFilterIsotope = function(container, taxonomy, terms) { | |
| 412 | +WPUltimatePostGrid.updateFilterIsotope = function(container, taxonomy, type, terms) { | |
| 307 | 413 | for(var i = 0; i < terms.length; i++) { |
| 308 | 414 | container.find('.wpupg-filter-tag-' + terms[i]).click(); |
| 309 | 415 | } |
| 310 | 416 | }; |
| @@ -374,9 +480,9 @@ | ||
| 374 | 480 | |
| 375 | 481 | var filter_type = container.data('filter-type'); |
| 376 | 482 | var filter_items = container.find('.wpupg-filter-item'); |
| 377 | 483 | |
| 378 | - if(filter_type == 'isotope') { | |
| 484 | + if(filter_type == 'isotope' || filter_type == 'text_isotope') { | |
| 379 | 485 | var margin = container.data('margin-vertical') + 'px ' + container.data('margin-horizontal') + 'px'; |
| 380 | 486 | var padding = container.data('padding-vertical') + 'px ' + container.data('padding-horizontal') + 'px'; |
| 381 | 487 | var border = container.data('border-width') + 'px solid ' + container.data('border-color'); |
| 382 | 488 | var background_color = container.data('background-color'); |
| @@ -558,19 +664,26 @@ | ||
| 558 | 664 | }); |
| 559 | 665 | }; |
| 560 | 666 | |
| 561 | 667 | WPUltimatePostGrid.insertPosts = function(grid_id, posts) { |
| 562 | - WPUltimatePostGrid.grids[grid_id].container.isotope('destroy'); | |
| 668 | + var scrollV = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0, | |
| 669 | + scrollH = document.documentElement.scrollLeft || document.body.scrollLeft; | |
| 563 | 670 | |
| 671 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg('destroy'); | |
| 672 | + | |
| 564 | 673 | WPUltimatePostGrid.grids[grid_id].container.append(posts); |
| 565 | - WPUltimatePostGrid.grids[grid_id].container.isotope(WPUltimatePostGrid.grids[grid_id].args); | |
| 674 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg(WPUltimatePostGrid.grids[grid_id].args); | |
| 566 | 675 | |
| 676 | + // Restore the scroll offset, should be flicker free | |
| 677 | + jQuery(window).scrollTop(scrollV); | |
| 678 | + document.documentElement.scrollLeft = document.body.scrollLeft = scrollH; | |
| 679 | + | |
| 567 | 680 | WPUltimatePostGrid.updatePosts(grid_id); |
| 568 | 681 | WPUltimatePostGrid.checkLinks(grid_id); |
| 569 | 682 | WPUltimatePostGrid.filterGrid(grid_id); |
| 570 | 683 | |
| 571 | 684 | WPUltimatePostGrid.grids[grid_id].container.imagesLoaded( function() { |
| 572 | - WPUltimatePostGrid.grids[grid_id].container.isotope('layout'); | |
| 685 | + WPUltimatePostGrid.grids[grid_id].container.isotopewpupg('layout'); | |
| 573 | 686 | WPUltimatePostGrid.grids[grid_id].loading = false; |
| 574 | 687 | }); |
| 575 | 688 | }; |
| 576 | 689 | |
| @@ -593,8 +706,9 @@ | ||
| 593 | 706 | var grid_id = container.data('grid'); |
| 594 | 707 | var type = container.data('type'); |
| 595 | 708 | |
| 596 | 709 | WPUltimatePostGrid.grids[grid_id].filter_type = type; |
| 710 | + WPUltimatePostGrid.grids[grid_id].filter_data = window['wpupg_filter_' + WPUltimatePostGrid.grids[grid_id].id]; | |
| 597 | 711 | |
| 598 | 712 | var func = 'initFilter' + type.charAt(0).toUpperCase() + type.slice(1); |
| 599 | 713 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 600 | 714 | WPUltimatePostGrid[func](container); |
| @@ -612,6 +726,7 @@ | ||
| 612 | 726 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 613 | 727 | WPUltimatePostGrid[func](container); |
| 614 | 728 | } |
| 615 | 729 | }); |
| 730 | + WPUltimatePostGrid.preFilterGrid(); | |
| 616 | 731 | WPUltimatePostGrid.restoreDeeplink(); |
| 617 | 732 | }); |