# wp-ultimate-post-grid/4.0.1/assets/js/public/grid/empty.js

WP Ultimate Post Grid, version 4.0.1. 50 lines.

- Page: https://pluginprobe.com/plugins/wp-ultimate-post-grid/4.0.1/code/assets/js/public/grid/empty.js
- Raw: https://pluginprobe.com/plugins/wp-ultimate-post-grid/4.0.1/raw/assets/js/public/grid/empty.js
- Modified: 2020-01-24T07:47:12+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wp-ultimate-post-grid/4.0.1/code/assets/js/public/grid/empty.js#L10-L20`.

```javascript
import { slideDown, slideUp, slideStop } from 'slide-anim';

export default ( elemId, args ) => {
    return {
        isEmpty: false,
        hideEmpty( temporary = false ) {
            const emptyElem = document.querySelector( '#' + this.elemId + '-empty' );

            if ( emptyElem ) {
                if ( temporary ) {
                    if ( ! this.isEmpty ) {
                        emptyElem.style.visibility = 'hidden';
                    }
                } else {
                    slideStop( emptyElem );
                    slideUp( emptyElem );
                }
            }
        },
        checkEmpty() {
            const emptyElem = document.querySelector( '#' + this.elemId + '-empty' );

            if ( emptyElem ) {
                // Revert optional temporary hide.
                emptyElem.style.visibility = 'visible';

                // Check if should show or not.
                const visibleItems = this.isotope.getFilteredItemElements();

                if ( 0 === visibleItems.length && ! this.isEmpty ) {
                    slideStop( emptyElem );
                    slideDown( emptyElem );
                    this.isEmpty = true;
                } else if ( 0 < visibleItems.length && this.isEmpty ) {
                    this.hideEmpty();
                    this.isEmpty = false;
                }
            }
        },
        initEmpty() {
            this.on( 'initReady', () => {
                this.checkEmpty();
            });

            this.on( 'visibleItemsChanged', () => {
                this.checkEmpty();
            });
        }
    }
};
```
