Search in sources :

Example 81 with JsxFunction

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);
    }
}
Also used : ProxyDomNode(com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.ProxyDomNode) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomText(com.gargoylesoftware.htmlunit.html.DomText) FunctionObject(net.sourceforge.htmlunit.corejs.javascript.FunctionObject) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 82 with JsxFunction

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;
}
Also used : NamedNodeMap(com.gargoylesoftware.htmlunit.javascript.NamedNodeMap) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) Attr(com.gargoylesoftware.htmlunit.javascript.host.dom.Attr) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 83 with JsxFunction

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);
}
Also used : FunctionObject(net.sourceforge.htmlunit.corejs.javascript.FunctionObject) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 84 with JsxFunction

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);
}
Also used : DOMException(org.w3c.dom.DOMException) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 85 with JsxFunction

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;
}
Also used : NativeArrayBuffer(net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer) NativeUint8Array(net.sourceforge.htmlunit.corejs.javascript.typedarrays.NativeUint8Array) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Aggregations

JsxFunction (com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)133 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)30 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)20 ScriptableObject (net.sourceforge.htmlunit.corejs.javascript.ScriptableObject)19 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)16 URL (java.net.URL)14 IOException (java.io.IOException)11 Scriptable (net.sourceforge.htmlunit.corejs.javascript.Scriptable)11 WebClient (com.gargoylesoftware.htmlunit.WebClient)10 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)10 SimpleRange (com.gargoylesoftware.htmlunit.html.impl.SimpleRange)10 Event (com.gargoylesoftware.htmlunit.javascript.host.event.Event)10 SgmlPage (com.gargoylesoftware.htmlunit.SgmlPage)8 HtmlUnitScriptable (com.gargoylesoftware.htmlunit.javascript.HtmlUnitScriptable)8 MessageEvent (com.gargoylesoftware.htmlunit.javascript.host.event.MessageEvent)8 HTMLElement (com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement)8 NameValuePair (com.gargoylesoftware.htmlunit.util.NameValuePair)8 Range (org.w3c.dom.ranges.Range)8 HtmlAttributeChangeEvent (com.gargoylesoftware.htmlunit.html.HtmlAttributeChangeEvent)7 HtmlElement (com.gargoylesoftware.htmlunit.html.HtmlElement)7