use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method before.
/**
* Inserts content, specified by the parameter, before each
* element in the set of matched elements.
*/
public Jerry before(String html) {
if (html == null) {
html = StringPool.EMPTY;
}
final Document doc = builder.parse(html);
if (nodes.length == 0) {
return this;
}
for (Node node : nodes) {
Document workingDoc = doc.clone();
node.insertBefore(workingDoc.getChildNodes(), node);
}
return this;
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method filter.
/**
* Reduces the set of matched elements to those that pass the
* {@link JerryFunction function's} test.
*/
public Jerry filter(JerryFunction jerryFunction) {
List<Node> result = new NodeList(nodes.length);
for (int i = 0; i < nodes.length; i++) {
Node node = nodes[i];
Node parentNode = node.getParentNode();
if (parentNode == null) {
continue;
}
Jerry $this = new Jerry(this, node);
boolean accept = jerryFunction.onNode($this, i);
if (accept) {
result.add(node);
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method hasClass.
/**
* Determines whether any of the matched elements are assigned the given class.
*/
public boolean hasClass(String... classNames) {
if (nodes.length == 0) {
return false;
}
for (Node node : nodes) {
String attrClass = node.getAttribute("class");
Set<String> classes = createPropertiesSet(attrClass, ' ');
for (String className : classNames) {
if (classes.contains(className)) {
return true;
}
}
}
return false;
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method has.
/**
* Reduce the set of matched elements to those that have a descendant that
* matches the selector or DOM element.
*/
public Jerry has(String cssSelectors) {
List<Node> result = new NodeList(nodes.length);
if (nodes.length > 0) {
for (Node node : nodes) {
NodeSelector nodeSelector = createNodeSelector(node);
List<Node> selectedNodes = nodeSelector.select(cssSelectors);
if (!selectedNodes.isEmpty()) {
result.add(node);
}
}
}
return new Jerry(this, result);
}
use of jodd.lagarto.dom.Node in project jodd by oblac.
the class Jerry method toggleClass.
/**
* Adds or remove one or more classes from each element in the set of
* matched elements, depending on either the class's presence or
* the value of the switch argument.
*/
public Jerry toggleClass(String... classNames) {
if (nodes.length == 0) {
return this;
}
for (Node node : nodes) {
String attrClass = node.getAttribute("class");
Set<String> classes = createPropertiesSet(attrClass, ' ');
for (String className : classNames) {
if (classes.contains(className)) {
classes.remove(className);
} else {
classes.add(className);
}
}
String attrValue = generateAttributeValue(classes, ' ');
node.setAttribute("class", attrValue);
}
return this;
}
Aggregations