/** * 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(final 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; }
/** * Sets one or more CSS properties for the set of matched elements. * By passing an empty value, that property will be removed. * Note that this is different from jQuery, where this means * that property will be reset to previous value if existed. */ public Jerry css(String propertyName, final String value) { propertyName = Format.fromCamelCase(propertyName, '-'); if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Adds the specified class(es) to each of the set of matched elements. */ public Jerry addClass(final String... classNames) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.add(className)) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }
/** * Sets one or more CSS properties for the set of matched elements. */ public Jerry css(final String... css) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); for (int i = 0; i < css.length; i += 2) { String propertyName = css[i]; propertyName = Format.fromCamelCase(propertyName, '-'); String value = css[i + 1]; if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Removes a single class, multiple classes, or all classes * from each element in the set of matched elements. */ public Jerry removeClass(final String... classNames) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.remove(className)) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }
/** * 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(final 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; }
/** * 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) { for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); for (String className : classNames) { if (classes.contains(className) == true) { classes.remove(className); } else { classes.add(className); } } String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } return this; }
/** * Sets one or more CSS properties for the set of matched elements. * By passing an empty value, that property will be removed. * Note that this is different from jQuery, where this means * that property will be reset to previous value if existed. */ public Jerry css(String propertyName, String value) { propertyName = StringUtil.fromCamelCase(propertyName, '-'); for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Removes a single class, multiple classes, or all classes * from each element in the set of matched elements. */ public Jerry removeClass(String... classNames) { for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.remove(className) == true) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }
/** * Adds the specified class(es) to each of the set of matched elements. */ public Jerry addClass(String... classNames) { for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.add(className) == true) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }
/** * Sets one or more CSS properties for the set of matched elements. */ public Jerry css(String... css) { for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); for (int i = 0; i < css.length; i += 2) { String propertyName = css[i]; propertyName = StringUtil.fromCamelCase(propertyName, '-'); String value = css[i + 1]; if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Sets one or more CSS properties for the set of matched elements. * By passing an empty value, that property will be removed. * Note that this is different from jQuery, where this means * that property will be reset to previous value if existed. */ public Jerry css(String propertyName, final String value) { propertyName = Format.fromCamelCase(propertyName, '-'); if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Removes a single class, multiple classes, or all classes * from each element in the set of matched elements. */ public Jerry removeClass(final String... classNames) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.remove(className)) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }
/** * Sets one or more CSS properties for the set of matched elements. */ public Jerry css(final String... css) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String styleAttrValue = node.getAttribute("style"); Map<String, String> styles = createPropertiesMap(styleAttrValue, ';', ':'); for (int i = 0; i < css.length; i += 2) { String propertyName = css[i]; propertyName = Format.fromCamelCase(propertyName, '-'); String value = css[i + 1]; if (value.length() == 0) { styles.remove(propertyName); } else { styles.put(propertyName, value); } } styleAttrValue = generateAttributeValue(styles, ';', ':'); node.setAttribute("style", styleAttrValue); } return this; }
/** * Adds the specified class(es) to each of the set of matched elements. */ public Jerry addClass(final String... classNames) { if (nodes.length == 0) { return this; } for (Node node : nodes) { String attrClass = node.getAttribute("class"); Set<String> classes = createPropertiesSet(attrClass, ' '); boolean wasChange = false; for (String className : classNames) { if (classes.add(className)) { wasChange = true; } } if (wasChange) { String attrValue = generateAttributeValue(classes, ' '); node.setAttribute("class", attrValue); } } return this; }