blob: b88113190ff7cbdca86dc99fa2dc91e43e369288 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
var _ = require("underscore");
exports.topLevelElement = topLevelElement;
exports.elements = elements;
exports.element = element;
function topLevelElement(tagName, attributes) {
return elements([element(tagName, attributes, {fresh: true})]);
}
function elements(elementStyles) {
return elementStyles.map(function(elementStyle) {
if (_.isString(elementStyle)) {
return element(elementStyle);
} else {
return elementStyle;
}
});
}
function element(tagName, attributes, options) {
options = options || {};
return new Element(tagName, attributes, options);
}
function Element(tagName, attributes, options) {
var tagNames = {};
if (_.isArray(tagName)) {
tagName.forEach(function(tagName) {
tagNames[tagName] = true;
});
tagName = tagName[0];
} else {
tagNames[tagName] = true;
}
this.tagName = tagName;
this.tagNames = tagNames;
this.attributes = attributes || {};
this.fresh = options.fresh;
}
Element.prototype.matchesElement = function(element) {
return this.tagNames[element.tagName] && _.isEqual(this.attributes || {}, element.attributes || {});
};
exports.empty = elements([]);
|