Skip to content

Commit 100d74f

Browse files
kaljakmarcj
authored andcommitted
1 parent adefff4 commit 100d74f

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/ElementQueries.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@
180180
else allQueries[mode][property][value] += ','+selector;
181181
}
182182

183-
function getQuery() {
183+
function getQuery(container) {
184184
var query;
185-
if (document.querySelectorAll) query = document.querySelectorAll.bind(document);
185+
if (document.querySelectorAll) query = (container) ? container.querySelectorAll.bind(container) : document.querySelectorAll.bind(document);
186186
if (!query && 'undefined' !== typeof $$) query = $$;
187187
if (!query && 'undefined' !== typeof jQuery) query = jQuery;
188188

@@ -196,14 +196,14 @@
196196
/**
197197
* Start the magic. Go through all collected rules (readRules()) and attach the resize-listener.
198198
*/
199-
function findElementQueriesElements() {
200-
var query = getQuery();
199+
function findElementQueriesElements(container) {
200+
var query = getQuery(container);
201201

202202
for (var mode in allQueries) if (allQueries.hasOwnProperty(mode)) {
203203

204204
for (var property in allQueries[mode]) if (allQueries[mode].hasOwnProperty(property)) {
205205
for (var value in allQueries[mode][property]) if (allQueries[mode][property].hasOwnProperty(value)) {
206-
var elements = query(allQueries[mode][property][value]);
206+
var elements = query(allQueries[mode][property][value], container);
207207
for (var i = 0, j = elements.length; i < j; i++) {
208208
setupElement(elements[i], {
209209
mode: mode,
@@ -407,6 +407,15 @@
407407
findResponsiveImages();
408408
};
409409

410+
/**
411+
* Go through all collected rules (readRules()) and attach the resize-listener.
412+
*
413+
* @param {HTMLElement} container only elements of the container are considered (document.body if not set)
414+
*/
415+
this.findElementQueriesElements = function(container) {
416+
findElementQueriesElements(container);
417+
};
418+
410419
/**
411420
*
412421
* @param {Boolean} withTracking allows and requires you to use detach, since we store internally all used elements
@@ -500,6 +509,10 @@
500509
else window.onload = callback;
501510
};
502511

512+
ElementQueries.findElementQueriesElements = function(container) {
513+
ElementQueries.instance.findElementQueriesElements(container);
514+
};
515+
503516
ElementQueries.listen = function() {
504517
domLoaded(ElementQueries.init);
505518
};

0 commit comments

Comments
 (0)