Skip to content

- fixed #95 #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/ElementQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@
else allQueries[mode][property][value] += ','+selector;
}

function getQuery() {
function getQuery(container) {
var query;
if (document.querySelectorAll) query = document.querySelectorAll.bind(document);
if (document.querySelectorAll) query = (container) ? container.querySelectorAll.bind(container) : document.querySelectorAll.bind(document);
if (!query && 'undefined' !== typeof $$) query = $$;
if (!query && 'undefined' !== typeof jQuery) query = jQuery;

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

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

for (var property in allQueries[mode]) if (allQueries[mode].hasOwnProperty(property)) {
for (var value in allQueries[mode][property]) if (allQueries[mode][property].hasOwnProperty(value)) {
var elements = query(allQueries[mode][property][value]);
var elements = query(allQueries[mode][property][value], container);
for (var i = 0, j = elements.length; i < j; i++) {
setupElement(elements[i], {
mode: mode,
Expand Down Expand Up @@ -407,6 +407,15 @@
findResponsiveImages();
};

/**
* Go through all collected rules (readRules()) and attach the resize-listener.
*
* @param {HTMLElement} container only elements of the container are considered (document.body if not set)
*/
this.findElementQueriesElements = function(container) {
findElementQueriesElements(container);
};

/**
*
* @param {Boolean} withTracking allows and requires you to use detach, since we store internally all used elements
Expand Down Expand Up @@ -500,6 +509,10 @@
else window.onload = callback;
};

ElementQueries.findElementQueriesElements = function(container) {
ElementQueries.instance.findElementQueriesElements(container);
};

ElementQueries.listen = function() {
domLoaded(ElementQueries.init);
};
Expand Down