| 1 |
var WPUltimatePostGrid = WPUltimatePostGrid || {}; |
| 2 |
|
| 3 |
WPUltimatePostGrid.grids = {}; |
| 4 |
|
| 5 |
WPUltimatePostGrid.initGrid = function(container) { |
| 6 |
var grid_id = container.data('grid'); |
| 7 |
|
| 8 |
var args = { |
| 9 |
itemSelector: '.wpupg-item', |
| 10 |
transitionDuration: wpupg_public.animationSpeed, |
| 11 |
hiddenStyle: wpupg_public.animationHide, |
| 12 |
visibleStyle: wpupg_public.animationShow |
| 13 |
}; |
| 14 |
|
| 15 |
if(wpupg_public.rtl) { |
| 16 |
args.isOriginLeft = false; |
| 17 |
} |
| 18 |
|
| 19 |
var layout_mode = container.data('layout-mode'); |
| 20 |
if(layout_mode) { |
| 21 |
args.layoutMode = layout_mode; |
| 22 |
} |
| 23 |
|
| 24 |
if(layout_mode == 'masonry' && container.data('centered')) { |
| 25 |
args.masonry = { |
| 26 |
isFitWidth: true |
| 27 |
}; |
| 28 |
} |
| 29 |
|
| 30 |
container.isotope(args); |
| 31 |
|
| 32 |
container.imagesLoaded( function() { |
| 33 |
container.isotope('layout'); |
| 34 |
}); |
| 35 |
|
| 36 |
WPUltimatePostGrid.grids[grid_id] = { |
| 37 |
args: args, |
| 38 |
container: container, |
| 39 |
centered: container.data('centered'), |
| 40 |
data: window['wpupg_grid_' + container.data('grid-id')], |
| 41 |
id: container.data('grid-id'), |
| 42 |
pages: [0], |
| 43 |
page: 0, |
| 44 |
filter: '', |
| 45 |
filters: {}, |
| 46 |
filter_text: false, |
| 47 |
filter_text_search: '', |
| 48 |
filter_text_posts: [] |
| 49 |
}; |
| 50 |
|
| 51 |
WPUltimatePostGrid.checkLinks(grid_id); |
| 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 |
}); |
| 63 |
}; |
| 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 |
|
| 129 |
WPUltimatePostGrid.updatePosts = function(grid_id) { |
| 130 |
var grid = WPUltimatePostGrid.grids[grid_id]; |
| 131 |
|
| 132 |
var posts = []; |
| 133 |
|
| 134 |
grid.container.find('.wpupg-item').each(function() { |
| 135 |
var post_id = jQuery(this).data('id'); |
| 136 |
posts.push(post_id); |
| 137 |
}); |
| 138 |
|
| 139 |
WPUltimatePostGrid.grids[grid_id].posts = posts; |
| 140 |
}; |
| 141 |
|
| 142 |
WPUltimatePostGrid.filterGrid = function(grid_id) { |
| 143 |
var grid = WPUltimatePostGrid.grids[grid_id]; |
| 144 |
var filters = []; |
| 145 |
|
| 146 |
if(grid.filter_text) { |
| 147 |
grid.filter = ''; |
| 148 |
var posts = []; |
| 149 |
|
| 150 |
for(var i=0; i < grid.filter_text_posts.length; i++) { |
| 151 |
posts.push('#wpupg-container-post-' + grid.filter_text_posts[i]); |
| 152 |
} |
| 153 |
|
| 154 |
if(posts.length == 0) { |
| 155 |
posts.push('no-result'); |
| 156 |
} |
| 157 |
|
| 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 |
} |
| 165 |
|
| 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 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
|
| 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 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 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, ''); |
| 201 |
|
| 202 |
grid.filter = '.wpupg-page-' + page + ':not(' + filter_without_page + ')'; |
| 203 |
} else { |
| 204 |
grid.filter = ':not(' + grid.filter + ')'; |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
jQuery('#wpupg-grid-' + grid_id + '-empty').hide(); |
| 210 |
grid.container.isotope({ filter: grid.filter }); |
| 211 |
grid.container.trigger('wpupgFiltered'); |
| 212 |
WPUltimatePostGrid.updateDeeplink(); |
| 213 |
}; |
| 214 |
|
| 215 |
WPUltimatePostGrid.getFilterString = function(grid_id, s, attrs, k) { |
| 216 |
if(k==attrs.length) { |
| 217 |
if(WPUltimatePostGrid.grids[grid_id].filter !== '') s = ', ' + s; |
| 218 |
WPUltimatePostGrid.grids[grid_id].filter += s; |
| 219 |
} else { |
| 220 |
for(var i=0; i<attrs[k].length;i++) { |
| 221 |
WPUltimatePostGrid.getFilterString(grid_id, s+attrs[k][i], attrs, k+1); |
| 222 |
} |
| 223 |
} |
| 224 |
}; |
| 225 |
|
| 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 |
WPUltimatePostGrid.updateDeeplink = function() { |
| 237 |
var link = ''; |
| 238 |
|
| 239 |
for(var grid_id in WPUltimatePostGrid.grids) { |
| 240 |
if(WPUltimatePostGrid.grids.hasOwnProperty(grid_id)) { |
| 241 |
var grid = WPUltimatePostGrid.grids[grid_id]; |
| 242 |
var grid_link = ''; |
| 243 |
|
| 244 |
|
| 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); |
| 250 |
|
| 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 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
if(grid_link != '') { |
| 264 |
if(link != '') link += '#'; |
| 265 |
link += grid_id; |
| 266 |
link += grid_link; |
| 267 |
} |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
WPUltimatePostGrid.replaceDeeplink(link); |
| 272 |
}; |
| 273 |
|
| 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 |
WPUltimatePostGrid.restoreDeeplink = function() { |
| 335 |
var link = document.location.hash; |
| 336 |
link = link.substr(1); |
| 337 |
|
| 338 |
if(link) { |
| 339 |
// Make sure characters are not URL encoded |
| 340 |
link = link.replace('%23', '#'); |
| 341 |
link = link.replace('%7C', '|'); |
| 342 |
link = link.replace('%2B', '+'); |
| 343 |
link = link.replace('%3A', ':'); |
| 344 |
link = link.replace('%2C', ','); |
| 345 |
|
| 346 |
// Backwards compatibility |
| 347 |
link = link.replace('|', '+'); |
| 348 |
|
| 349 |
var grids = link.split('#'); |
| 350 |
|
| 351 |
for(var i=0; i < grids.length; i++) { |
| 352 |
var parts = grids[i].split('+'); |
| 353 |
var grid_id = parts[0]; |
| 354 |
|
| 355 |
for(var j=1; j < parts.length; j++) { |
| 356 |
var filter = parts[j].split(':'); |
| 357 |
|
| 358 |
if(filter[0] == 'p') { |
| 359 |
var page = parseInt(filter[1]) - 1; |
| 360 |
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 |
} else { |
| 364 |
var terms = filter[1].split(','); |
| 365 |
WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], terms); |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
}; |
| 371 |
|
| 372 |
WPUltimatePostGrid.checkLinks = function(grid_id) { |
| 373 |
var grid = WPUltimatePostGrid.grids[grid_id]; |
| 374 |
var default_link_type = grid.container.data('link-type'); |
| 375 |
var link_target = grid.container.data('link-target'); |
| 376 |
var link_rel = link_target == 'post' ? '' : ' rel="lightbox"'; |
| 377 |
|
| 378 |
if(default_link_type != 'none') { |
| 379 |
grid.container.find('.wpupg-item').each(function() { |
| 380 |
var item = jQuery(this); |
| 381 |
|
| 382 |
// Remove links from item |
| 383 |
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() { |
| 384 |
var link = jQuery(this); |
| 385 |
if(link.parents('.sharrre').length == 0) { |
| 386 |
link.replaceWith(function() { return link.contents(); }); |
| 387 |
} |
| 388 |
}); |
| 389 |
|
| 390 |
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'); |
| 392 |
|
| 393 |
var link_type = link_behaviour == '_blank' || link_behaviour == '_self' ? link_behaviour : default_link_type; |
| 394 |
|
| 395 |
// 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>'); |
| 398 |
} |
| 399 |
}); |
| 400 |
} |
| 401 |
}; |
| 402 |
|
| 403 |
WPUltimatePostGrid.updateFilter = function(container, taxonomy, terms) { |
| 404 |
var type = container.data('type'); |
| 405 |
var func = 'updateFilter' + type.charAt(0).toUpperCase() + type.slice(1); |
| 406 |
if(typeof WPUltimatePostGrid[func] == 'function') { |
| 407 |
WPUltimatePostGrid[func](container, taxonomy, terms); |
| 408 |
} |
| 409 |
}; |
| 410 |
|
| 411 |
WPUltimatePostGrid.updateFilterIsotope = function(container, taxonomy, terms) { |
| 412 |
for(var i = 0; i < terms.length; i++) { |
| 413 |
container.find('.wpupg-filter-tag-' + terms[i]).click(); |
| 414 |
} |
| 415 |
}; |
| 416 |
|
| 417 |
WPUltimatePostGrid.initFilterIsotope = function(container) { |
| 418 |
var grid_id = container.data('grid'); |
| 419 |
|
| 420 |
WPUltimatePostGrid.grids[grid_id].multiselect = container.data('multiselect'); |
| 421 |
WPUltimatePostGrid.grids[grid_id].multiselect_type = container.data('multiselect-type'); |
| 422 |
WPUltimatePostGrid.grids[grid_id].inverse = container.data('inverse'); |
| 423 |
|
| 424 |
container.find('.wpupg-filter-isotope-term').click(function() { |
| 425 |
var filter_item = jQuery(this); |
| 426 |
var taxonomy = filter_item.data('taxonomy'); |
| 427 |
var filter_all = filter_item.data('filter') == undefined; |
| 428 |
var filter_term = filter_item.data('filter'); |
| 429 |
|
| 430 |
var filters = []; |
| 431 |
|
| 432 |
if(WPUltimatePostGrid.grids[grid_id].multiselect && !filter_all) { |
| 433 |
// Make sure "All" is not selected |
| 434 |
filter_item.siblings('.wpupg-filter-tag-').removeClass('active').trigger('checkActiveFilter'); |
| 435 |
|
| 436 |
filters = WPUltimatePostGrid.grids[grid_id].filters || []; |
| 437 |
|
| 438 |
if(filters[taxonomy] == undefined) filters[taxonomy] = []; |
| 439 |
|
| 440 |
var term_index = filters[taxonomy].indexOf(filter_term); |
| 441 |
if(term_index == -1) { |
| 442 |
// Term was not select before, add |
| 443 |
filter_item.addClass('active').trigger('checkActiveFilter'); |
| 444 |
filters[taxonomy].push(filter_term); |
| 445 |
} else { |
| 446 |
// Term was already selected, remove |
| 447 |
filter_item.removeClass('active').trigger('checkActiveFilter'); |
| 448 |
filters[taxonomy].splice(term_index, 1); |
| 449 |
|
| 450 |
// Set "All" active if no terms left |
| 451 |
var nbr_terms = 0; |
| 452 |
|
| 453 |
for(var filter_taxonomy in filters) { |
| 454 |
if(filters.hasOwnProperty(filter_taxonomy)) { |
| 455 |
var filter_taxonomy_terms = filters[filter_taxonomy]; |
| 456 |
|
| 457 |
if(filter_taxonomy_terms) { |
| 458 |
nbr_terms += filter_taxonomy_terms.length; |
| 459 |
} |
| 460 |
} |
| 461 |
} |
| 462 |
|
| 463 |
if(nbr_terms == 0) { |
| 464 |
filter_item.siblings('.wpupg-filter-tag-').addClass('active').trigger('checkActiveFilter'); |
| 465 |
} |
| 466 |
} |
| 467 |
} else { |
| 468 |
filter_item.siblings('.wpupg-filter-isotope-term').removeClass('active').trigger('checkActiveFilter'); |
| 469 |
filter_item.addClass('active').trigger('checkActiveFilter'); |
| 470 |
|
| 471 |
if(!filter_all) { |
| 472 |
filters[taxonomy] = [filter_term]; |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
WPUltimatePostGrid.grids[grid_id].filters = filters; |
| 477 |
WPUltimatePostGrid.filterGrid(grid_id); |
| 478 |
}); |
| 479 |
|
| 480 |
var filter_type = container.data('filter-type'); |
| 481 |
var filter_items = container.find('.wpupg-filter-item'); |
| 482 |
|
| 483 |
if(filter_type == 'isotope') { |
| 484 |
var margin = container.data('margin-vertical') + 'px ' + container.data('margin-horizontal') + 'px'; |
| 485 |
var padding = container.data('padding-vertical') + 'px ' + container.data('padding-horizontal') + 'px'; |
| 486 |
var border = container.data('border-width') + 'px solid ' + container.data('border-color'); |
| 487 |
var background_color = container.data('background-color'); |
| 488 |
var text_color = container.data('text-color'); |
| 489 |
|
| 490 |
var active_border = container.data('border-width') + 'px solid ' + container.data('active-border-color'); |
| 491 |
var active_background_color = container.data('active-background-color'); |
| 492 |
var active_text_color = container.data('active-text-color'); |
| 493 |
|
| 494 |
var hover_border = container.data('border-width') + 'px solid ' + container.data('hover-border-color'); |
| 495 |
var hover_background_color = container.data('hover-background-color'); |
| 496 |
var hover_text_color = container.data('hover-text-color'); |
| 497 |
|
| 498 |
filter_items.each(function() { |
| 499 |
var filter_item = jQuery(this); |
| 500 |
|
| 501 |
filter_item |
| 502 |
.css('margin', margin) |
| 503 |
.css('padding', padding) |
| 504 |
.css('border', border) |
| 505 |
.css('background-color', background_color) |
| 506 |
.css('color', text_color) |
| 507 |
.hover(function() { |
| 508 |
if(!filter_item.hasClass('active')) { |
| 509 |
filter_item |
| 510 |
.css('border', hover_border) |
| 511 |
.css('background-color', hover_background_color) |
| 512 |
.css('color', hover_text_color); |
| 513 |
} |
| 514 |
}, function() { |
| 515 |
if(!filter_item.hasClass('active')) { |
| 516 |
filter_item |
| 517 |
.css('border', border) |
| 518 |
.css('background-color', background_color) |
| 519 |
.css('color', text_color); |
| 520 |
} |
| 521 |
}) |
| 522 |
.on('checkActiveFilter', function() { |
| 523 |
if(filter_item.hasClass('active')) { |
| 524 |
filter_item |
| 525 |
.css('border', active_border) |
| 526 |
.css('background-color', active_background_color) |
| 527 |
.css('color', active_text_color); |
| 528 |
} else { |
| 529 |
filter_item |
| 530 |
.css('border', border) |
| 531 |
.css('background-color', background_color) |
| 532 |
.css('color', text_color); |
| 533 |
} |
| 534 |
}).trigger('checkActiveFilter'); |
| 535 |
}); |
| 536 |
} |
| 537 |
}; |
| 538 |
|
| 539 |
WPUltimatePostGrid.updatePagination = function(container, page) { |
| 540 |
var type = container.data('type'); |
| 541 |
|
| 542 |
if(type) { |
| 543 |
var func = 'updatePagination' + type.charAt(0).toUpperCase() + type.slice(1); |
| 544 |
if(typeof WPUltimatePostGrid[func] == 'function') { |
| 545 |
WPUltimatePostGrid[func](container, page); |
| 546 |
} |
| 547 |
} |
| 548 |
}; |
| 549 |
|
| 550 |
WPUltimatePostGrid.updatePaginationPages = function(container, page) { |
| 551 |
container.find('.wpupg-page-' + page).click(); |
| 552 |
}; |
| 553 |
|
| 554 |
WPUltimatePostGrid.initPaginationPages = function(container) { |
| 555 |
var grid_id = container.data('grid'); |
| 556 |
|
| 557 |
container.find('.wpupg-pagination-term').click(function() { |
| 558 |
var pagination_item = jQuery(this); |
| 559 |
pagination_item.siblings('.wpupg-pagination-term').removeClass('active').trigger('checkActiveFilter'); |
| 560 |
|
| 561 |
var page = parseInt(pagination_item.addClass('active').trigger('checkActiveFilter').data('page')); |
| 562 |
|
| 563 |
WPUltimatePostGrid.scrollTo(WPUltimatePostGrid.grids[grid_id].container); |
| 564 |
|
| 565 |
if(WPUltimatePostGrid.grids[grid_id].pages.indexOf(page) !== -1) { |
| 566 |
WPUltimatePostGrid.grids[grid_id].page = page; |
| 567 |
WPUltimatePostGrid.filterGrid(grid_id); |
| 568 |
} else { |
| 569 |
// Get new page via AJAX |
| 570 |
var data = { |
| 571 |
action: 'wpupg_get_page', |
| 572 |
security: wpupg_public.nonce, |
| 573 |
grid: grid_id, |
| 574 |
page: page |
| 575 |
}; |
| 576 |
|
| 577 |
pagination_item.addClass('wpupg-spinner'); |
| 578 |
pagination_item.css('color', WPUltimatePostGrid.grids[grid_id].pagination_style.active_background_color); |
| 579 |
|
| 580 |
// Get recipes through AJAX |
| 581 |
jQuery.post(wpupg_public.ajax_url, data, function(html) { |
| 582 |
var posts = jQuery(html).toArray(); |
| 583 |
|
| 584 |
WPUltimatePostGrid.grids[grid_id].page = page; |
| 585 |
WPUltimatePostGrid.insertPosts(grid_id, posts); |
| 586 |
|
| 587 |
pagination_item.removeClass('wpupg-spinner'); |
| 588 |
pagination_item.css('color', WPUltimatePostGrid.grids[grid_id].pagination_style.active_text_color); |
| 589 |
|
| 590 |
WPUltimatePostGrid.grids[grid_id].pages.push(page); |
| 591 |
WPUltimatePostGrid.updatePosts(grid_id); |
| 592 |
}); |
| 593 |
} |
| 594 |
}); |
| 595 |
|
| 596 |
var pagination_items = container.find('.wpupg-pagination-term'); |
| 597 |
|
| 598 |
var margin = container.data('margin-vertical') + 'px ' + container.data('margin-horizontal') + 'px'; |
| 599 |
var padding = container.data('padding-vertical') + 'px ' + container.data('padding-horizontal') + 'px'; |
| 600 |
var border = container.data('border-width') + 'px solid ' + container.data('border-color'); |
| 601 |
var background_color = container.data('background-color'); |
| 602 |
var text_color = container.data('text-color'); |
| 603 |
|
| 604 |
var active_border = container.data('border-width') + 'px solid ' + container.data('active-border-color'); |
| 605 |
var active_background_color = container.data('active-background-color'); |
| 606 |
var active_text_color = container.data('active-text-color'); |
| 607 |
|
| 608 |
var hover_border = container.data('border-width') + 'px solid ' + container.data('hover-border-color'); |
| 609 |
var hover_background_color = container.data('hover-background-color'); |
| 610 |
var hover_text_color = container.data('hover-text-color'); |
| 611 |
|
| 612 |
WPUltimatePostGrid.grids[grid_id].pagination_style = { |
| 613 |
margin: margin, |
| 614 |
padding: padding, |
| 615 |
border: border, |
| 616 |
background_color: background_color, |
| 617 |
text_color: text_color, |
| 618 |
active_border: active_border, |
| 619 |
active_background_color: active_background_color, |
| 620 |
active_text_color: active_text_color, |
| 621 |
hover_border: hover_border, |
| 622 |
hover_background_color: hover_background_color, |
| 623 |
hover_text_color: hover_text_color |
| 624 |
} |
| 625 |
|
| 626 |
pagination_items.each(function() { |
| 627 |
var pagination_item = jQuery(this); |
| 628 |
|
| 629 |
pagination_item |
| 630 |
.css('margin', margin) |
| 631 |
.css('padding', padding) |
| 632 |
.css('border', border) |
| 633 |
.css('background-color', background_color) |
| 634 |
.css('color', text_color) |
| 635 |
.hover(function() { |
| 636 |
if(!pagination_item.hasClass('active')) { |
| 637 |
pagination_item |
| 638 |
.css('border', hover_border) |
| 639 |
.css('background-color', hover_background_color) |
| 640 |
.css('color', hover_text_color); |
| 641 |
} |
| 642 |
}, function() { |
| 643 |
if(!pagination_item.hasClass('active')) { |
| 644 |
pagination_item |
| 645 |
.css('border', border) |
| 646 |
.css('background-color', background_color) |
| 647 |
.css('color', text_color); |
| 648 |
} |
| 649 |
}) |
| 650 |
.on('checkActiveFilter', function() { |
| 651 |
if(pagination_item.hasClass('active')) { |
| 652 |
pagination_item |
| 653 |
.css('border', active_border) |
| 654 |
.css('background-color', active_background_color) |
| 655 |
.css('color', active_text_color); |
| 656 |
} else { |
| 657 |
pagination_item |
| 658 |
.css('border', border) |
| 659 |
.css('background-color', background_color) |
| 660 |
.css('color', text_color); |
| 661 |
} |
| 662 |
}).trigger('checkActiveFilter'); |
| 663 |
}); |
| 664 |
}; |
| 665 |
|
| 666 |
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 |
WPUltimatePostGrid.grids[grid_id].container.isotope('destroy'); |
| 671 |
|
| 672 |
WPUltimatePostGrid.grids[grid_id].container.append(posts); |
| 673 |
WPUltimatePostGrid.grids[grid_id].container.isotope(WPUltimatePostGrid.grids[grid_id].args); |
| 674 |
|
| 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 |
WPUltimatePostGrid.updatePosts(grid_id); |
| 680 |
WPUltimatePostGrid.checkLinks(grid_id); |
| 681 |
WPUltimatePostGrid.filterGrid(grid_id); |
| 682 |
|
| 683 |
WPUltimatePostGrid.grids[grid_id].container.imagesLoaded( function() { |
| 684 |
WPUltimatePostGrid.grids[grid_id].container.isotope('layout'); |
| 685 |
WPUltimatePostGrid.grids[grid_id].loading = false; |
| 686 |
}); |
| 687 |
}; |
| 688 |
|
| 689 |
WPUltimatePostGrid.scrollTo = function(target) { |
| 690 |
var scroll_to = target.offset().top - 50; |
| 691 |
scroll_to = scroll_to < 0 ? 0 : scroll_to; |
| 692 |
|
| 693 |
jQuery('html,body').animate({ |
| 694 |
scrollTop: scroll_to |
| 695 |
}, 500); |
| 696 |
}; |
| 697 |
|
| 698 |
jQuery(document).ready(function($) { |
| 699 |
$('.wpupg-grid').each(function() { |
| 700 |
WPUltimatePostGrid.initGrid($(this)); |
| 701 |
}); |
| 702 |
|
| 703 |
$('.wpupg-filter').each(function() { |
| 704 |
var container = $(this); |
| 705 |
var grid_id = container.data('grid'); |
| 706 |
var type = container.data('type'); |
| 707 |
|
| 708 |
WPUltimatePostGrid.grids[grid_id].filter_type = type; |
| 709 |
WPUltimatePostGrid.grids[grid_id].filter_data = window['wpupg_filter_' + WPUltimatePostGrid.grids[grid_id].id]; |
| 710 |
|
| 711 |
var func = 'initFilter' + type.charAt(0).toUpperCase() + type.slice(1); |
| 712 |
if(typeof WPUltimatePostGrid[func] == 'function') { |
| 713 |
WPUltimatePostGrid[func](container); |
| 714 |
} |
| 715 |
}); |
| 716 |
|
| 717 |
$('.wpupg-pagination').each(function() { |
| 718 |
var container = $(this); |
| 719 |
var grid_id = container.data('grid'); |
| 720 |
var type = container.data('type'); |
| 721 |
|
| 722 |
WPUltimatePostGrid.grids[grid_id].pagination_type = type; |
| 723 |
|
| 724 |
var func = 'initPagination' + type.charAt(0).toUpperCase() + type.slice(1); |
| 725 |
if(typeof WPUltimatePostGrid[func] == 'function') { |
| 726 |
WPUltimatePostGrid[func](container); |
| 727 |
} |
| 728 |
}); |
| 729 |
WPUltimatePostGrid.preFilterGrid(); |
| 730 |
WPUltimatePostGrid.restoreDeeplink(); |
| 731 |
}); |