Skip to content

Commit

Permalink
Object fit fix - waiting for DOM loaded (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederan authored Jan 8, 2019
1 parent c58b450 commit 158460c
Show file tree
Hide file tree
Showing 6 changed files with 1,271 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.4.1] - 2019-01-08
* Added fix for object-fit polyfill
* Updated object-fit polyfill file to v3.2.4

## [2.4.0] - 2018-08-14
* Added object-fit polyfill [#29](https://github.com/DekodeInteraktiv/hogan-banner/pull/29).

Expand Down
2 changes: 1 addition & 1 deletion assets/js/hogan-banner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions assets/vendor/object-fit-images.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions hogan-banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Plugin URI: https://github.com/dekodeinteraktiv/hogan-banner
* GitHub Plugin URI: https://github.com/dekodeinteraktiv/hogan-banner
* Description: Banner Module for Hogan.
* Version: 2.4.0
* Version: 2.4.1
* Author: Dekode
* Author URI: https://dekode.no
* License: GPL-3.0-or-later
Expand All @@ -24,7 +24,7 @@
exit; // Exit if accessed directly.
}

define( 'HOGAN_BANNER_VERSION', '2.4.0' );
define( 'HOGAN_BANNER_VERSION', '2.4.1' );

add_action( 'plugins_loaded', __NAMESPACE__ . '\\hogan_load_textdomain' );
add_action( 'hogan/include_modules', __NAMESPACE__ . '\\hogan_register_module' );
Expand Down
16 changes: 13 additions & 3 deletions src/banner.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
const { objectFitImages } = window;
function apply_object_fit_fix() {
if ('objectFit' in document.documentElement.style === false) {
const { objectFitImages } = window;

const images = document.querySelectorAll( '.hogan-banner-image img' );
objectFitImages( images );
const images = document.querySelectorAll( '.hogan-banner-image img' );
objectFitImages( images );
}
}

if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", apply_object_fit_fix);
} else {
apply_object_fit_fix();
}
Loading

0 comments on commit 158460c

Please sign in to comment.