PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
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
wp-ultimate-post-grid / assets / js / public / grid / layout.js

layout.js in WP Ultimate Post Grid 4.0.1, at assets/js/public/grid/layout.js

91 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 export default ( elemId, args ) => {
2 return {
3 forcingHeight: false,
4 forceHeight() {
5 if ( ! this.forcingHeight ) {
6 this.forcingHeight = true;
7
8 const rows = this.getVisibleItemsPerRow();
9 let changesMade = false;
10
11 for ( let row of rows ) {
12 let heights = [];
13
14 for ( let item of row ) {
15 const currentHeight = item.style.height;
16
17 // Get item heights, without height set.
18 item.style.height = '';
19 heights.push( item.offsetHeight );
20
21 // Reset to current height.
22 item.style.height = currentHeight;
23 }
24
25 const maxHeight = Math.max( ...heights );
26
27 // If an item is not the same size, resize.
28 for ( let item of row ) {
29 const itemHeight = item.offsetHeight;
30
31 if ( itemHeight !== maxHeight ) {
32 changesMade = true;
33
34 item.style.height = `${ maxHeight }px`;
35 item.animate(
36 [{ height: `${ itemHeight }px` }, { height: `${ maxHeight }px` } ],
37 300
38 );
39 }
40 }
41 }
42
43 // Wait until animations are done.
44 setTimeout(() => {
45 // Relayout if changes were made.
46 if ( changesMade ) {
47 this.layout();
48 }
49
50 this.forcingHeight = false;
51 }, 400);
52 }
53 },
54 getVisibleItemsPerRow() {
55 const visibleItems = this.isotope.getFilteredItemElements();
56
57 let currentRowTop = 0;
58 let currentRow = [];
59 let rows = [];
60
61 for ( let item of visibleItems ) {
62 if ( currentRowTop < item.offsetTop ) {
63 // Item is on a new row.
64 if ( 0 < currentRow.length ) {
65 rows.push( currentRow );
66 }
67
68 currentRow = [];
69 currentRowTop = item.offsetTop;
70 }
71
72 // Add item to current row.
73 currentRow.push( item );
74 }
75
76 // Make sure to add last row.
77 if ( 0 < currentRow.length ) {
78 rows.push( currentRow );
79 }
80
81 return rows;
82 },
83 initLayout() {
84 if ( args.hasOwnProperty( 'force_height' ) && args.force_height ) {
85 this.isotope.on( 'layoutComplete', () => {
86 this.forceHeight();
87 } );
88 }
89 },
90 }
91 };