Skip to content

Commit

Permalink
Respect disable setting on asynchronously loaded content
Browse files Browse the repository at this point in the history
  • Loading branch information
michalsnik committed Jun 22, 2018
1 parent 88ce309 commit 676b927
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/js/aos.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ let options = {
useClassNames: false
};

// Detect not supported browsers (<=IE9)
// http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
const isBrowserNotSupported = () => document.all && !window.atob;

const initializeScroll = function initializeScroll() {
// Extend elements objects in $aosElements with their positions
$aosElements = prepare($aosElements, options);
Expand Down Expand Up @@ -74,6 +78,11 @@ const refresh = function refresh(initialize = false) {
*/
const refreshHard = function refreshHard() {
$aosElements = elements();

if (isDisabled(options.disable) || isBrowserNotSupported()) {
return disable();
}

refresh();
};

Expand Down Expand Up @@ -126,15 +135,18 @@ const init = function init(settings) {
// Create initial array with elements -> to be fullfilled later with prepare()
$aosElements = elements();

// Detect not supported browsers (<=IE9)
// http://browserhacks.com/#hack-e71d8692f65334173fee715c222cb805
const browserNotSupported = document.all && !window.atob;
/**
* Observe [aos] elements
* If something is loaded by AJAX
* it'll refresh plugin automatically
*/
observe('[data-aos]', refreshHard);

/**
* Don't init plugin if option `disable` is set
* or when browser is not supported
*/
if (isDisabled(options.disable) || browserNotSupported) {
if (isDisabled(options.disable) || isBrowserNotSupported()) {
return disable();
}

Expand Down Expand Up @@ -180,13 +192,6 @@ const init = function init(settings) {
window.addEventListener('resize', debounce(refresh, 50, true));
window.addEventListener('orientationchange', debounce(refresh, 50, true));

/**
* Observe [aos] elements
* If something is loaded by AJAX
* it'll refresh plugin automatically
*/
observe('[data-aos]', refreshHard);

return $aosElements;
};

Expand Down

0 comments on commit 676b927

Please sign in to comment.