PluginProbe
WP Ultimate Post Grid / 2.0
WP Ultimate Post Grid v2.0
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
← All changes | js/grid.js +49 -118 2.12.0 View file →
@@ -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,35 +227,11 @@
267 227 }
268 228 }
269 229 }
270 230
271 - if(link == '') {
272 - WPUltimatePostGrid.removeDeepLink();
273 - } else {
274 - document.location.hash = link;
275 - }
231 + document.location.hash = link;
276 232 };
277 233
278 -/**
279 - * Source: http://stackoverflow.com/questions/1397329/how-to-remove-the-hash-from-window-location-with-javascript-without-page-refresh/5298684#5298684
280 - */
281 -WPUltimatePostGrid.removeDeepLink = function() {
282 - var scrollV, scrollH, loc = window.location;
283 - if ("pushState" in history)
284 - history.pushState("", document.title, loc.pathname + loc.search);
285 - else {
286 - // Prevent scrolling by storing the page's current scroll offset
287 - scrollV = document.body.scrollTop;
288 - scrollH = document.body.scrollLeft;
289 -
290 - loc.hash = "";
291 -
292 - // Restore the scroll offset, should be flicker free
293 - document.body.scrollTop = scrollV;
294 - document.body.scrollLeft = scrollH;
295 - }
296 -}
297 -
298 234 WPUltimatePostGrid.restoreDeeplink = function() {
299 235 var link = document.location.hash;
300 236 link = link.substr(1);
301 237
@@ -321,10 +257,8 @@
321 257
322 258 if(filter[0] == 'p') {
323 259 var page = parseInt(filter[1]) - 1;
324 260 WPUltimatePostGrid.updatePagination(jQuery('#wpupg-grid-' + grid_id + '-pagination'), page);
325 - } else if(filter[0] == 's') {
326 - WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], filter[1]);
327 261 } else {
328 262 var terms = filter[1].split(',');
329 263 WPUltimatePostGrid.updateFilter(jQuery('#wpupg-grid-' + grid_id + '-filter'), filter[0], terms);
330 264 }
@@ -334,13 +268,12 @@
334 268 };
335 269
336 270 WPUltimatePostGrid.checkLinks = function(grid_id) {
337 271 var grid = WPUltimatePostGrid.grids[grid_id];
338 - var default_link_type = grid.container.data('link-type');
272 + var link_type = grid.container.data('link-type');
339 273 var link_target = grid.container.data('link-target');
340 - var link_rel = link_target == 'post' ? '' : ' rel="lightbox"';
341 274
342 - if(default_link_type != 'none') {
275 + if(link_type != 'none') {
343 276 grid.container.find('.wpupg-item').each(function() {
344 277 var item = jQuery(this);
345 278
346 279 // Remove links from item
@@ -351,15 +284,13 @@
351 284 }
352 285 });
353 286
354 287 var link = item.data('custom-link') ? item.data('custom-link') : ( link_target == 'post' ? item.data('permalink') : item.data('image') );
355 - var link_behaviour = item.data('custom-link-behaviour');
288 + var rel = link_target == 'post' ? '' : ' rel="lightbox"';
356 289
357 - var link_type = link_behaviour == '_blank' || link_behaviour == '_self' ? link_behaviour : default_link_type;
358 -
359 290 // Add link around item
360 - if (link_behaviour !== 'none' && link && item.parent('a').length == 0) {
361 - 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>');
362 293 }
363 294 });
364 295 }
365 296 };