use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Element method insertAdjacentText.
/**
* Inserts the given text into the element at the specified location.
* @param where specifies where to insert the text, using one of the following values (case-insensitive):
* beforebegin, afterbegin, beforeend, afterend
* @param text the text to insert
*
* @see <a href="http://msdn.microsoft.com/en-us/library/ie/ms536453.aspx">MSDN</a>
*/
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public void insertAdjacentText(final String where, final String text) {
final Object[] values = getInsertAdjacentLocation(where);
final DomNode node = (DomNode) values[0];
final boolean append = ((Boolean) values[1]).booleanValue();
final DomText domText = new DomText(node.getPage(), text);
// add the new nodes
if (append) {
node.appendChild(domText);
} else {
node.insertBefore(domText);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Element method setAttributeNode.
/**
* Sets the attribute node for the specified attribute.
* @param newAtt the attribute to set
* @return the replaced attribute node, if any
*/
@JsxFunction
public Attr setAttributeNode(final Attr newAtt) {
final String name = newAtt.getName();
final NamedNodeMap nodes = getAttributes();
final Attr replacedAtt = (Attr) nodes.getNamedItemWithoutSytheticClassAttr(name);
if (replacedAtt != null) {
replacedAtt.detachFromParent();
}
final DomAttr newDomAttr = newAtt.getDomNodeOrDie();
getDomNodeOrDie().setAttributeNode(newDomAttr);
return replacedAtt;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Element method removeAttributeNode.
/**
* Removes the specified attribute.
* @param attribute the attribute to remove
*/
@JsxFunction
public void removeAttributeNode(final Attr attribute) {
final String name = attribute.getName();
final Object namespaceUri = attribute.getNamespaceURI();
if (namespaceUri instanceof String) {
removeAttributeNS((String) namespaceUri, name);
return;
}
removeAttributeNS(null, name);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Storage method setItem.
/**
* Sets the item value.
* @param key the item key
* @param data the value
*/
@JsxFunction
public void setItem(final String key, final String data) {
final long storeSize = storeSize_ + data.length();
if (storeSize > STORE_SIZE_KIMIT) {
Context.throwAsScriptRuntimeEx(new DOMException((short) 22, "QuotaExceededError: Failed to execute 'setItem' on 'Storage': " + "Setting the value of '" + key + "' exceeded the quota."));
return;
}
storeSize_ = storeSize;
store_.put(key, data);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class TextEncoder method encode.
/**
* @param toEncode the string to encode
* @return returns a Uint8Array containing the text given encoded .
*/
@JsxFunction
public NativeUint8Array encode(final Object toEncode) {
if (Undefined.isUndefined(toEncode)) {
final NativeUint8Array result = new NativeUint8Array(0);
result.setParentScope(getParentScope());
result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName()));
return result;
}
final String txt;
if (toEncode == null) {
txt = "null";
} else {
txt = Context.toString(toEncode);
}
final byte[] bytes = txt.getBytes(StandardCharsets.UTF_8);
final NativeArrayBuffer arrayBuffer = new NativeArrayBuffer(bytes.length);
System.arraycopy(bytes, 0, arrayBuffer.getBuffer(), 0, bytes.length);
final NativeUint8Array result = new NativeUint8Array(arrayBuffer, 0, bytes.length);
result.setParentScope(getParentScope());
result.setPrototype(ScriptableObject.getClassPrototype(getWindow(this), result.getClassName()));
return result;
}
Aggregations