| @@ -40,13 +40,9 @@ | ||
| 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 | - filter: '', | |
| 45 | - filters: {}, | |
| 46 | - filter_text: false, | |
| 47 | - filter_text_search: '', | |
| 48 | - filter_text_posts: [] | |
| 44 | + filters: {} | |
| 49 | 45 | }; |
| 50 | 46 | |
| 51 | 47 | WPUltimatePostGrid.checkLinks(grid_id); |
| 52 | 48 | WPUltimatePostGrid.updatePosts(grid_id); |
| @@ -54,13 +50,8 @@ | ||
| 54 | 50 | jQuery(container).on('hover', '.wpupg-item', function(e) { |
| 55 | 51 | var hovering = e.type == 'mouseenter'; |
| 56 | 52 | WPUltimatePostGrid.hoverGridItem(jQuery(this), hovering); |
| 57 | 53 | }); |
| 58 | - | |
| 59 | - // Check for empty grid | |
| 60 | - container.on('arrangeComplete', function() { | |
| 61 | - WPUltimatePostGrid.checkEmpty(container); | |
| 62 | - }); | |
| 63 | 54 | }; |
| 64 | 55 | |
| 65 | 56 | WPUltimatePostGrid.hoverGridItem = function(grid_item, hovering) { |
| 66 | 57 | if(hovering) { |
| @@ -142,72 +133,56 @@ | ||
| 142 | 133 | WPUltimatePostGrid.filterGrid = function(grid_id) { |
| 143 | 134 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 144 | 135 | var filters = []; |
| 145 | 136 | |
| 146 | - if(grid.filter_text) { | |
| 147 | - grid.filter = ''; | |
| 148 | - var posts = []; | |
| 137 | + // Page filter | |
| 138 | + if(grid.pagination_type == 'pages') { | |
| 139 | + var page = grid.page || 0; | |
| 140 | + filters.push(['.wpupg-page-' + page]); | |
| 141 | + } | |
| 149 | 142 | |
| 150 | - for(var i=0; i < grid.filter_text_posts.length; i++) { | |
| 151 | - posts.push('#wpupg-container-post-' + grid.filter_text_posts[i]); | |
| 152 | - } | |
| 143 | + // Taxonomy filters | |
| 144 | + for(var taxonomy in grid.filters) { | |
| 145 | + if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 146 | + var taxonomy_filters = grid.filters[taxonomy]; | |
| 153 | 147 | |
| 154 | - if(posts.length == 0) { | |
| 155 | - posts.push('no-result'); | |
| 156 | - } | |
| 148 | + var match_one_filters = []; | |
| 149 | + var match_all_filter = ''; | |
| 150 | + var filter = ''; | |
| 157 | 151 | |
| 158 | - WPUltimatePostGrid.getFilterString(grid_id, '', [posts], 0); | |
| 159 | - } else { | |
| 160 | - // Page filter | |
| 161 | - if(grid.pagination_type == 'pages') { | |
| 162 | - var page = grid.page || 0; | |
| 163 | - filters.push(['.wpupg-page-' + page]); | |
| 164 | - } | |
| 152 | + if(taxonomy_filters) { | |
| 153 | + for(var i = 0; i < taxonomy_filters.length; i++) { | |
| 154 | + filter = '.wpupg-tax-' + taxonomy + '-' + taxonomy_filters[i]; | |
| 165 | 155 | |
| 166 | - // Taxonomy filters | |
| 167 | - for(var taxonomy in grid.filters) { | |
| 168 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 169 | - var taxonomy_filters = grid.filters[taxonomy]; | |
| 170 | - | |
| 171 | - var match_one_filters = []; | |
| 172 | - var match_all_filter = ''; | |
| 173 | - var filter = ''; | |
| 174 | - | |
| 175 | - if(taxonomy_filters) { | |
| 176 | - for(var i = 0; i < taxonomy_filters.length; i++) { | |
| 177 | - filter = '.wpupg-tax-' + taxonomy + '-' + taxonomy_filters[i]; | |
| 178 | - | |
| 179 | - if(grid.multiselect_type == 'match_one') { | |
| 180 | - match_one_filters.push(filter); | |
| 181 | - } else { | |
| 182 | - match_all_filter += filter; | |
| 183 | - } | |
| 156 | + if(grid.multiselect_type == 'match_one') { | |
| 157 | + match_one_filters.push(filter); | |
| 158 | + } else { | |
| 159 | + match_all_filter += filter; | |
| 184 | 160 | } |
| 185 | 161 | } |
| 162 | + } | |
| 186 | 163 | |
| 187 | - if(grid.multiselect_type == 'match_one') { | |
| 188 | - if(match_one_filters.length > 0) filters.push(match_one_filters); | |
| 189 | - } else { | |
| 190 | - if(match_all_filter !== '') filters.push([match_all_filter]); | |
| 191 | - } | |
| 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]); | |
| 192 | 168 | } |
| 193 | 169 | } |
| 170 | + } | |
| 194 | 171 | |
| 195 | - grid.filter = ''; | |
| 196 | - WPUltimatePostGrid.getFilterString(grid_id, '', filters, 0); | |
| 197 | - if(grid.inverse) { | |
| 198 | - if(grid.pagination_type == 'pages') { | |
| 199 | - var page = grid.page || 0; | |
| 200 | - var filter_without_page = grid.filter.replace('.wpupg-page-' + page, ''); | |
| 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, ''); | |
| 201 | 178 | |
| 202 | - grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; | |
| 203 | - } else { | |
| 204 | - grid.filter = ':not(' + grid.filter + ')'; | |
| 205 | - } | |
| 179 | + grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; | |
| 180 | + } else { | |
| 181 | + grid.filter = ':not(' + grid.filter + ')'; | |
| 206 | 182 | } |
| 207 | 183 | } |
| 208 | 184 | |
| 209 | - jQuery('#wpupg-grid-' + grid_id + '-empty').hide(); | |
| 210 | 185 | grid.container.isotope({ filter: grid.filter }); |
| 211 | 186 | grid.container.trigger('wpupgFiltered'); |
| 212 | 187 | WPUltimatePostGrid.updateDeeplink(); |
| 213 | 188 | }; |
| @@ -222,18 +197,8 @@ | ||
| 222 | 197 | } |
| 223 | 198 | } |
| 224 | 199 | }; |
| 225 | 200 | |
| 226 | -WPUltimatePostGrid.checkEmpty = function(container) { | |
| 227 | - var grid_id = container.data('grid'), | |
| 228 | - filter = WPUltimatePostGrid.grids[grid_id].filter, | |
| 229 | - visible_items = container.find(filter); | |
| 230 | - | |
| 231 | - if(filter !== '' && visible_items.length == 0) { | |
| 232 | - jQuery('#wpupg-grid-' + grid_id + '-empty').slideDown(300); | |
| 233 | - } | |
| 234 | -}; | |
| 235 | - | |
| 236 | 201 | WPUltimatePostGrid.updateDeeplink = function() { |
| 237 | 202 | var link = ''; |
| 238 | 203 | |
| 239 | 204 | for(var grid_id in WPUltimatePostGrid.grids) { |
| @@ -240,23 +205,18 @@ | ||
| 240 | 205 | if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { |
| 241 | 206 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 242 | 207 | var grid_link = ''; |
| 243 | 208 | |
| 209 | + // Page filter | |
| 210 | + if(grid.page != 0) grid_link += '+p:' + (grid.page+1); | |
| 244 | 211 | |
| 245 | - if(grid.filter_text) { | |
| 246 | - grid_link += '+s:' + grid.filter_text_search; | |
| 247 | - } else { | |
| 248 | - // Page filter | |
| 249 | - if(grid.page != 0) grid_link += '+p:' + (grid.page+1); | |
| 212 | + // Taxonomy filters | |
| 213 | + for(var taxonomy in grid.filters) { | |
| 214 | + if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 215 | + var taxonomy_filter = grid.filters[taxonomy]; | |
| 250 | 216 | |
| 251 | - // Taxonomy filters | |
| 252 | - for(var taxonomy in grid.filters) { | |
| 253 | - if(grid.filters.hasOwnProperty(taxonomy)) { | |
| 254 | - var taxonomy_filter = grid.filters[taxonomy]; | |
| 255 | - | |
| 256 | - if(taxonomy_filter.length > 0) { | |
| 257 | - grid_link += '+' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 258 | - } | |
| 217 | + if(taxonomy_filter.length > 0) { | |
| 218 | + grid_link += '+' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 259 | 219 | } |
| 260 | 220 | } |
| 261 | 221 | } |
| 262 | 222 | |
| @@ -267,71 +227,11 @@ | ||
| 267 | 227 | } |
| 268 | 228 | } |
| 269 | 229 | } |
| 270 | 230 | |
| 271 | - WPUltimatePostGrid.replaceDeeplink(link); | |
| 231 | + document.location.hash = link; | |
| 272 | 232 | }; |
| 273 | 233 | |
| 274 | -/** | |
| 275 | - * Source: http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh/5298684#5298684 | |
| 276 | - */ | |
| 277 | -WPUltimatePostGrid.replaceDeeplink = function(link) { | |
| 278 | - var scrollV, scrollH, loc = window.location; | |
| 279 | - if ("replaceState" in history) { | |
| 280 | - var hash = link == '' ? '' : '#' + link; | |
| 281 | - history.replaceState("", document.title, loc.pathname + hash + loc.search); | |
| 282 | - } else { | |
| 283 | - // Prevent scrolling by storing the page's current scroll offset | |
| 284 | - scrollV = document.documentElement.scrollTop || document.body.scrollTop; | |
| 285 | - scrollH = document.documentElement.scrollLeft || document.body.scrollLeft; | |
| 286 | - | |
| 287 | - loc.hash = link; | |
| 288 | - | |
| 289 | - // Restore the scroll offset, should be flicker free | |
| 290 | - document.documentElement.scrollTop = document.body.scrollTop = scrollV; | |
| 291 | - document.documentElement.scrollLeft = document.body.scrollLeft = scrollH; | |
| 292 | - } | |
| 293 | -}; | |
| 294 | - | |
| 295 | -WPUltimatePostGrid.preFilterGrid = function() { | |
| 296 | - var link = document.location.hash; | |
| 297 | - link = link.substr(1); | |
| 298 | - | |
| 299 | - if(!link) { | |
| 300 | - var link = ''; | |
| 301 | - | |
| 302 | - for(var grid_id in WPUltimatePostGrid.grids) { | |
| 303 | - if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { | |
| 304 | - var grid = WPUltimatePostGrid.grids[grid_id]; | |
| 305 | - var grid_link = ''; | |
| 306 | - | |
| 307 | - if(grid.filter_data) { | |
| 308 | - var pre_filter = grid.filter_data['pre_filter']; | |
| 309 | - | |
| 310 | - // Taxonomy filters | |
| 311 | - for(var taxonomy in pre_filter) { | |
| 312 | - if(pre_filter.hasOwnProperty(taxonomy)) { | |
| 313 | - var taxonomy_filter = pre_filter[taxonomy]; | |
| 314 | - | |
| 315 | - if(taxonomy_filter.length > 0) { | |
| 316 | - grid_link += '+' + taxonomy + ':' + taxonomy_filter.join(','); | |
| 317 | - } | |
| 318 | - } | |
| 319 | - } | |
| 320 | - } | |
| 321 | - | |
| 322 | - if(grid_link != '') { | |
| 323 | - if(link != '') link += '#'; | |
| 324 | - link += grid_id; | |
| 325 | - link += grid_link; | |
| 326 | - } | |
| 327 | - } | |
| 328 | - } | |
| 329 | - | |
| 330 | - WPUltimatePostGrid.replaceDeeplink(link); | |
| 331 | - } | |
| 332 | -}; | |
| 333 | - | |
| 334 | 234 | WPUltimatePostGrid.restoreDeeplink = function() { |
| 335 | 235 | var link = document.location.hash; |
| 336 | 236 | link = link.substr(1); |
| 337 | 237 | |
| @@ -357,10 +257,8 @@ | ||
| 357 | 257 | |
| 358 | 258 | if(filter[0] == 'p') { |
| 359 | 259 | var page = parseInt(filter[1]) - 1; |
| 360 | 260 | WPUltimatePostGrid.updatePagination(jQuery('#wpupg-grid-' + grid_id + '-pagination'), page); |
| 361 | - } else if(filter[0] == 's') { | |
| 362 | - WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], filter[1]); | |
| 363 | 261 | } else { |
| 364 | 262 | var terms = filter[1].split(','); |
| 365 | 263 | WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], terms); |
| 366 | 264 | } |
| @@ -370,13 +268,12 @@ | ||
| 370 | 268 | }; |
| 371 | 269 | |
| 372 | 270 | WPUltimatePostGrid.checkLinks = function(grid_id) { |
| 373 | 271 | var grid = WPUltimatePostGrid.grids[grid_id]; |
| 374 | - var default_link_type = grid.container.data('link-type'); | |
| 272 | + var link_type = grid.container.data('link-type'); | |
| 375 | 273 | var link_target = grid.container.data('link-target'); |
| 376 | - var link_rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 377 | 274 | |
| 378 | - if(default_link_type != 'none') { | |
| 275 | + if(link_type != 'none') { | |
| 379 | 276 | grid.container.find('.wpupg-item').each(function() { |
| 380 | 277 | var item = jQuery(this); |
| 381 | 278 | |
| 382 | 279 | // Remove links from item |
| @@ -387,15 +284,13 @@ | ||
| 387 | 284 | } |
| 388 | 285 | }); |
| 389 | 286 | |
| 390 | 287 | var link = item.data('custom-link') ? item.data('custom-link') : ( link_target == 'post' ? item.data('permalink') : item.data('image') ); |
| 391 | - var link_behaviour = item.data('custom-link-behaviour'); | |
| 288 | + var rel = link_target == 'post' ? '' : ' rel="lightbox"'; | |
| 392 | 289 | |
| 393 | - var link_type = link_behaviour == '_blank' || link_behaviour == '_self' ? link_behaviour : default_link_type; | |
| 394 | - | |
| 395 | 290 | // Add link around item |
| 396 | - if (link_behaviour !== 'none' && link && item.parent('a').length == 0) { | |
| 397 | - item.wrap('<a href="' + link + '" target="' + link_type + '"' + link_rel + ' class="' + wpupg_public.link_class + '"></a>'); | |
| 291 | + if (link && item.parent('a').length == 0) { | |
| 292 | + item.wrap('<a href="' + link + '" target="' + link_type + '"' + rel + ' class="' + wpupg_public.link_class + '"></a>'); | |
| 398 | 293 | } |
| 399 | 294 | }); |
| 400 | 295 | } |
| 401 | 296 | }; |
| @@ -479,9 +374,9 @@ | ||
| 479 | 374 | |
| 480 | 375 | var filter_type = container.data('filter-type'); |
| 481 | 376 | var filter_items = container.find('.wpupg-filter-item'); |
| 482 | 377 | |
| 483 | - if(filter_type == 'isotope' || filter_type == 'text_isotope') { | |
| 378 | + if(filter_type == 'isotope') { | |
| 484 | 379 | var margin = container.data('margin-vertical') + 'px ' + container.data('margin-horizontal') + 'px'; |
| 485 | 380 | var padding = container.data('padding-vertical') + 'px ' + container.data('padding-horizontal') + 'px'; |
| 486 | 381 | var border = container.data('border-width') + 'px solid ' + container.data('border-color'); |
| 487 | 382 | var background_color = container.data('background-color'); |
| @@ -663,20 +558,13 @@ | ||
| 663 | 558 | }); |
| 664 | 559 | }; |
| 665 | 560 | |
| 666 | 561 | WPUltimatePostGrid.insertPosts = function(grid_id, posts) { |
| 667 | - var scrollV = document.documentElement.scrollTop || document.body.scrollTop, | |
| 668 | - scrollH = document.documentElement.scrollLeft || document.body.scrollLeft; | |
| 669 | - | |
| 670 | 562 | WPUltimatePostGrid.grids[grid_id].container.isotope('destroy'); |
| 671 | 563 | |
| 672 | 564 | WPUltimatePostGrid.grids[grid_id].container.append(posts); |
| 673 | 565 | WPUltimatePostGrid.grids[grid_id].container.isotope(WPUltimatePostGrid.grids[grid_id].args); |
| 674 | 566 | |
| 675 | - // Restore the scroll offset, should be flicker free | |
| 676 | - document.documentElement.scrollTop = document.body.scrollTop = scrollV; | |
| 677 | - document.documentElement.scrollLeft = document.body.scrollLeft = scrollH; | |
| 678 | - | |
| 679 | 567 | WPUltimatePostGrid.updatePosts(grid_id); |
| 680 | 568 | WPUltimatePostGrid.checkLinks(grid_id); |
| 681 | 569 | WPUltimatePostGrid.filterGrid(grid_id); |
| 682 | 570 | |
| @@ -705,9 +593,8 @@ | ||
| 705 | 593 | var grid_id = container.data('grid'); |
| 706 | 594 | var type = container.data('type'); |
| 707 | 595 | |
| 708 | 596 | WPUltimatePostGrid.grids[grid_id].filter_type = type; |
| 709 | - WPUltimatePostGrid.grids[grid_id].filter_data = window['wpupg_filter_' + WPUltimatePostGrid.grids[grid_id].id]; | |
| 710 | 597 | |
| 711 | 598 | var func = 'initFilter' + type.charAt(0).toUpperCase() + type.slice(1); |
| 712 | 599 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 713 | 600 | WPUltimatePostGrid[func](container); |
| @@ -725,7 +612,6 @@ | ||
| 725 | 612 | if(typeof WPUltimatePostGrid[func] == 'function') { |
| 726 | 613 | WPUltimatePostGrid[func](container); |
| 727 | 614 | } |
| 728 | 615 | }); |
| 729 | - WPUltimatePostGrid.preFilterGrid(); | |
| 730 | 616 | WPUltimatePostGrid.restoreDeeplink(); |
| 731 | 617 | }); |