Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

images-loaded

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

images-loaded - npm Package Compare versions

Comparing version 0.1.0 to 1.0.0

dist/index.es.js

172

dist/index.js

@@ -7,90 +7,87 @@ (function (global, factory) {

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/* eslint-disable unicorn/prefer-add-event-listener */
var slice = Array.prototype.slice;
var reurl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
var slice = Array.prototype.slice;
var reurl = /url\(\s*(['"]?)(.*?)\1\s*\)/g;
var camelCase = function camelCase(name) {
return name.replace(/([a-z])-([a-z])/g, function (str, m1, m2) {
return '' + m1 + m2.toUpperCase();
});
};
var camelCase = function camelCase(name) {
return name.replace(/([a-z])-([a-z])/g, function (str, m1, m2) {
return '' + m1 + m2.toUpperCase();
});
};
var check = function check(obj) {
return new Promise(function (resolve) {
var element = obj.element,
img = obj.img,
src = obj.src;
var check = function check(obj) {
return new Promise(function (resolve) {
var element = obj.element,
img = obj.img,
src = obj.src;
if (img.complete && img.naturalWidth !== undefined) {
resolve(element);
}
if (img.complete && img.naturalWidth !== undefined) {
resolve(element);
}
var proxyImage = img;
proxyImage.onload = function () {
return resolve(element);
};
proxyImage.onerror = function () {
return resolve(element);
};
var proxyImage = img;
proxyImage.onload = function () {
return resolve(element);
};
proxyImage.onerror = function () {
return resolve(element);
};
if (src !== undefined && element.src === undefined) {
proxyImage.src = src;
if (src !== undefined && element.src === undefined) {
proxyImage.src = src;
}
});
};
function index (element, options) {
if (typeof element === 'string') {
element = document.querySelectorAll(element);
}
});
};
var index = function (element, options) {
if (typeof element === 'string') {
element = document.querySelectorAll(element);
}
var elements = element instanceof NodeList ? slice.call(element) : [].concat(element);
var elements = element instanceof NodeList ? slice.call(element) : [].concat(element);
options = Object.assign({
props: [],
attrs: []
}, options);
options = Object.assign({
props: [],
attrs: []
}, options);
var hasProps = Array.isArray(options.props) && options.props.length;
var hasAttrs = Array.isArray(options.attrs) && options.attrs.length;
var images = [];
var hasProps = Array.isArray(options.props) && options.props.length;
var hasAttrs = Array.isArray(options.attrs) && options.attrs.length;
var images = [];
elements.forEach(function (elem) {
var nodeType = elem.nodeType;
elements.forEach(function (elem) {
var nodeType = elem.nodeType;
if (!nodeType || [1, 9, 11].indexOf(nodeType) === -1) {
return;
}
if (!nodeType || [1, 9, 11].indexOf(nodeType) === -1) {
return;
}
var children = void 0;
var children = void 0;
if (hasProps || hasAttrs) {
children = elem.getElementsByTagName('*');
} else {
children = elem.getElementsByTagName('img');
}
if (hasProps || hasAttrs) {
children = elem.getElementsByTagName('*');
} else {
children = elem.getElementsByTagName('img');
}
var tags = slice.call(children);
var tags = slice.call(children);
// Add self to array
tags.unshift(elem);
// Add self to array
tags.unshift(elem);
tags.forEach(function (tag) {
if (tag instanceof HTMLImageElement) {
images.push({
element: tag,
img: tag
});
}
tags.forEach(function (tag) {
if (tag instanceof HTMLImageElement) {
images.push({
element: tag,
img: tag
});
}
if (hasProps) {
var _ret = function () {
if (hasProps) {
var style = getComputedStyle(tag);
if (!style) {
return {
v: void 0
};
return;
}

@@ -114,32 +111,29 @@

});
}();
}
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
}
if (hasAttrs) {
options.attrs.forEach(function (attr) {
if (typeof attr !== 'string') {
return;
}
if (hasAttrs) {
options.attrs.forEach(function (attr) {
if (typeof attr !== 'string') {
return;
}
var url = tag.getAttribute(attr);
var url = tag.getAttribute(attr);
if (url !== null) {
images.push({
element: tag,
img: new Image(),
src: url
});
}
});
}
if (url !== null) {
images.push({
element: tag,
img: new Image(),
src: url
});
}
});
}
});
});
});
return Promise.all(images.map(check));
};
return Promise.all(images.map(check));
}
return index;
return index;
})));
{
"name": "images-loaded",
"version": "0.1.0",
"version": "1.0.0",
"description": "Wait for images to load using promises",

@@ -16,5 +16,10 @@ "license": "MIT",

"scripts": {
"build": "rollup -c",
"test": "xo && ava"
},
"main": "dist/index.js",
"module": "dist/index.es.js",
"files": [
"dist"
],
"keywords": [

@@ -32,9 +37,9 @@ "image",

"devDependencies": {
"ava": "^0.15.2",
"babel-preset-env": "^1.1.5",
"rollup": "^0.37.2",
"rollup-plugin-babel": "^2.7.1",
"rollup-plugin-commonjs": "^6.0.1",
"rollup-plugin-node-resolve": "^2.0.0",
"xo": "^0.16.0"
"ava": "^0.25.0",
"babel-preset-env": "^1.6.1",
"rollup": "^0.57.1",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-commonjs": "^9.1.0",
"rollup-plugin-node-resolve": "^3.3.0",
"xo": "^0.20.3"
},

@@ -47,6 +52,3 @@ "babel": {

"targets": {
"browsers": [
"last 2 versions",
"> 1%"
]
"browsers": "defaults"
},

@@ -53,0 +55,0 @@ "modules": false,

@@ -18,3 +18,3 @@ # images-loaded [![Build Status](https://travis-ci.org/awcross/images-loaded.svg?branch=master)](https://travis-ci.org/awcross/images-loaded)

imagesLoaded('.container').then(() => {
imagesLoaded('.container').then(elements => {
// images are hot and ready

@@ -46,3 +46,3 @@ });

Can be passed a list of style properties to also check, e.g. `background-image`, `border-image`, etc.
Can be passed a list of DOM style camelCase properties to check. For example, `backgroundImage`, `borderImage`, etc.

@@ -54,3 +54,3 @@ ##### attrs

Can be passed a list of attributes to check, such as `poster` on a video element.
Can be passed a list of attributes to check, such as `poster` in a video tag.

@@ -57,0 +57,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc