var photospageContainer = document.querySelector('article'), photospageWindowWidth = 0 ; function photosInit() { window.addEventListener('resize', photospageHandleWindowResize); photospageHandleWindowResize(); if(photospageWindowWidth > 700) { imagesLoaded(photospageContainer, function() { new Packery(photospageContainer); }); } } function photospageHandleWindowResize() { photospageWindowWidth = Math.max(document.documentElement.clientWidth || document.body.clientWidth); } photosInit();