object-fit-images
Advanced tools
Comparing version 2.4.0 to 2.4.1
'use strict'; | ||
var ಠ = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent image, used as accessor and replacing image | ||
var propRegex = /(object-fit|object-position)\s*:\s*([\w\s%]+)/g; | ||
var isSupported = 'object-fit' in document.documentElement.style; | ||
var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g; | ||
var supportsObjectFit = 'object-fit' in document.documentElement.style; | ||
var nativeGetAttribute = document.documentElement.getAttribute; | ||
@@ -22,2 +22,3 @@ var nativeSetAttribute = document.documentElement.setAttribute; | ||
var style = getStyle(el); | ||
console.log(el); | ||
@@ -74,3 +75,5 @@ // exit if not set | ||
(function loop() { | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=495908 | ||
if (el[ಠ].i.naturalWidth) { | ||
console.log(el[ಠ].i.naturalWidth); | ||
if (el[ಠ].i.naturalWidth > el.width || el[ಠ].i.naturalHeight > el.height) { | ||
@@ -105,4 +108,4 @@ el.style.backgroundSize = 'contain'; | ||
function watchMQ(imgs) { | ||
window.addEventListener('resize', fix.bind(null, imgs)); | ||
function watchMQ(imgs, opts) { | ||
window.addEventListener('resize', fix.bind(null, imgs, opts)); | ||
} | ||
@@ -116,3 +119,3 @@ function onInsert(e) { | ||
function hijackAttributes() { | ||
if (!isSupported) { | ||
if (!supportsObjectFit) { | ||
HTMLImageElement.prototype.getAttribute = function (name) { | ||
@@ -136,8 +139,8 @@ if (this[ಠ] && name === 'src') { | ||
function fix(imgs, opts) { | ||
if (isSupported) { | ||
return false; | ||
} | ||
var startAutoMode = !autoModeEnabled && !imgs; | ||
opts = opts || {}; | ||
imgs = imgs || 'img'; | ||
if (supportsObjectFit && !opts.skipTest) { | ||
return false; | ||
} | ||
@@ -164,8 +167,11 @@ // use imgs as a selector or just select all images | ||
if (opts.watchMQ) { | ||
watchMQ(imgs); | ||
delete opts.watchMQ; | ||
watchMQ(imgs, opts); | ||
} | ||
} | ||
fix.supportsObjectFit = supportsObjectFit; | ||
hijackAttributes(); | ||
module.exports = fix; |
var ಠ = 'data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='; // transparent image, used as accessor and replacing image | ||
var propRegex = /(object-fit|object-position)\s*:\s*([\w\s%]+)/g; | ||
var isSupported = 'object-fit' in document.documentElement.style; | ||
var propRegex = /(object-fit|object-position)\s*:\s*([-\w\s%]+)/g; | ||
var supportsObjectFit = 'object-fit' in document.documentElement.style; | ||
var nativeGetAttribute = document.documentElement.getAttribute; | ||
@@ -20,2 +20,3 @@ var nativeSetAttribute = document.documentElement.setAttribute; | ||
var style = getStyle(el); | ||
console.log(el); | ||
@@ -72,3 +73,5 @@ // exit if not set | ||
(function loop() { | ||
// https://bugs.chromium.org/p/chromium/issues/detail?id=495908 | ||
if (el[ಠ].i.naturalWidth) { | ||
console.log(el[ಠ].i.naturalWidth); | ||
if (el[ಠ].i.naturalWidth > el.width || el[ಠ].i.naturalHeight > el.height) { | ||
@@ -103,4 +106,4 @@ el.style.backgroundSize = 'contain'; | ||
function watchMQ(imgs) { | ||
window.addEventListener('resize', fix.bind(null, imgs)); | ||
function watchMQ(imgs, opts) { | ||
window.addEventListener('resize', fix.bind(null, imgs, opts)); | ||
} | ||
@@ -114,3 +117,3 @@ function onInsert(e) { | ||
function hijackAttributes() { | ||
if (!isSupported) { | ||
if (!supportsObjectFit) { | ||
HTMLImageElement.prototype.getAttribute = function (name) { | ||
@@ -134,8 +137,8 @@ if (this[ಠ] && name === 'src') { | ||
function fix(imgs, opts) { | ||
if (isSupported) { | ||
return false; | ||
} | ||
var startAutoMode = !autoModeEnabled && !imgs; | ||
opts = opts || {}; | ||
imgs = imgs || 'img'; | ||
if (supportsObjectFit && !opts.skipTest) { | ||
return false; | ||
} | ||
@@ -162,8 +165,11 @@ // use imgs as a selector or just select all images | ||
if (opts.watchMQ) { | ||
watchMQ(imgs); | ||
delete opts.watchMQ; | ||
watchMQ(imgs, opts); | ||
} | ||
} | ||
fix.supportsObjectFit = supportsObjectFit; | ||
hijackAttributes(); | ||
export default fix; |
{ | ||
"name": "object-fit-images", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "Adds support to object-fit to images on IE9, IE10, IE11, Edge and other old browsers.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -78,2 +78,5 @@ # object-fit-images | ||
objectFitImages(oneImage); | ||
// or with jQuery | ||
$('img.some-image').get().forEach(objectFitImages); | ||
``` | ||
@@ -80,0 +83,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18886
295
131