Skip to content
Open
Changes from 1 commit
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
Next Next commit
support data- custom HTML attributes
  • Loading branch information
fabasoft-michael-stedry committed May 29, 2019
commit f81e0a708eaf4e2472f4fd7eac9df37c85218b8e
20 changes: 11 additions & 9 deletions src/ElementQueries.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
this.element = element;
var key, option, elementSize, value, actualValue, attrValues, attrValue, attrName;

var attributes = ['min-width', 'min-height', 'max-width', 'max-height'];
var attributes = ['min-width', 'data-min-width', 'min-height', 'data-min-height', 'max-width', 'data-max-width', 'max-height', 'data-max-height'];

/**
* Extracts the computed width/height and sets to min/max- attribute.
Expand All @@ -133,7 +133,7 @@
value = convertToPx(this.element, option.value);

actualValue = option.property === 'width' ? elementSize.width : elementSize.height;
attrName = option.mode + '-' + option.property;
attrName = option.attrName;
attrValue = '';

if (option.mode === 'min' && actualValue >= value) {
Expand Down Expand Up @@ -185,8 +185,9 @@
* @param {String} mode min|max
* @param {String} property width|height
* @param {String} value
* @param {String} attrName
*/
function queueQuery(selector, mode, property, value) {
function queueQuery(selector, mode, property, value, attrName) {
if (typeof(allQueries[selector]) === 'undefined') {
allQueries[selector] = [];
// add animation to trigger animationstart event, so we know exactly when a element appears in the DOM
Expand All @@ -200,6 +201,7 @@
allQueries[selector].push({
mode: mode,
property: property,
attrName: attrName,
value: value
});
}
Expand Down Expand Up @@ -336,8 +338,8 @@
}
}

var regex = /,?[\s\t]*([^,\n]*?)((?:\[[\s\t]*?(?:min|max)-(?:width|height)[\s\t]*?[~$\^]?=[\s\t]*?"[^"]*?"[\s\t]*?])+)([^,\n\s\{]*)/mgi;
var attrRegex = /\[[\s\t]*?(min|max)-(width|height)[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]/mgi;
var regex = /,?[\s\t]*([^,\n]*?)((?:\[[\s\t]*?(?:data-)?(?:min|max)-(?:width|height)[\s\t]*?[~$\^]?=[\s\t]*?"[^"]*?"[\s\t]*?])+)([^,\n\s\{]*)/mgi;
var attrRegex = /\[[\s\t]*?((?:data-)?(min|max)-(width|height))[\s\t]*?[~$\^]?=[\s\t]*?"([^"]*?)"[\s\t]*?]/mgi;

/**
* @param {String} css
Expand All @@ -351,7 +353,7 @@
attrs = match[2];

while (null !== (attrMatch = attrRegex.exec(attrs))) {
queueQuery(smatch, attrMatch[1], attrMatch[2], attrMatch[3]);
queueQuery(smatch, attrMatch[2], attrMatch[3], attrMatch[4], attrMatch[1]);
}
}
}
Expand All @@ -368,16 +370,16 @@

if ('string' === typeof rules) {
rules = rules.toLowerCase();
if (-1 !== rules.indexOf('min-width') || -1 !== rules.indexOf('max-width')) {
if (-1 !== rules.indexOf('min-width') || -1 !== rules.indexOf('data-min-width') || -1 !== rules.indexOf('max-width') || -1 !== rules.indexOf('data-max-width')) {
extractQuery(rules);
}
} else {
for (var i = 0, j = rules.length; i < j; i++) {
if (1 === rules[i].type) {
selector = rules[i].selectorText || rules[i].cssText;
if (-1 !== selector.indexOf('min-height') || -1 !== selector.indexOf('max-height')) {
if (-1 !== selector.indexOf('min-height') || -1 !== selector.indexOf('data-min-height') || -1 !== selector.indexOf('max-height') || -1 !== selector.indexOf('data-max-height')) {
extractQuery(selector);
} else if (-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('max-width')) {
} else if (-1 !== selector.indexOf('min-width') || -1 !== selector.indexOf('data-min-width') || -1 !== selector.indexOf('max-width') || -1 !== selector.indexOf('data-max-width')) {
extractQuery(selector);
}
} else if (4 === rules[i].type) {
Expand Down