Search in sources :

Example 21 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLElement method mergeAttributes.

/**
 * An IE-only method which copies all custom attributes from the specified source element
 * to this element.
 * @param source the source element from which to copy the custom attributes
 * @param preserveIdentity if {@code false}, the <tt>name</tt> and <tt>id</tt> attributes are not copied
 */
@JsxFunction(IE)
public void mergeAttributes(final HTMLElement source, final Object preserveIdentity) {
    final HtmlElement src = source.getDomNodeOrDie();
    final HtmlElement target = getDomNodeOrDie();
    // Merge ID and name if we aren't preserving identity.
    if (preserveIdentity instanceof Boolean && !((Boolean) preserveIdentity).booleanValue()) {
        target.setId(src.getId());
        target.setAttribute("name", src.getAttributeDirect("name"));
    }
}
Also used : HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 22 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLElement method removeNode.

/**
 * Removes this object from the document hierarchy.
 * @param removeChildren whether to remove children or no
 * @return a reference to the object that is removed
 */
@JsxFunction(IE)
public HTMLElement removeNode(final boolean removeChildren) {
    final HTMLElement parent = (HTMLElement) getParentElement();
    if (parent != null) {
        parent.removeChild(this);
        if (!removeChildren) {
            final NodeList collection = getChildNodes();
            final int length = collection.getLength();
            for (int i = 0; i < length; i++) {
                final Node object = (Node) collection.item(Integer.valueOf(0));
                parent.appendChild(object);
            }
        }
    }
    return this;
}
Also used : NodeList(com.gargoylesoftware.htmlunit.javascript.host.dom.NodeList) DomNode(com.gargoylesoftware.htmlunit.html.DomNode) Node(com.gargoylesoftware.htmlunit.javascript.host.dom.Node) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 23 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLElement method setActive.

/**
 * Sets the object as active without setting focus to the object.
 * @see <a href="http://msdn.microsoft.com/en-us/library/ms536738.aspx">MSDN documentation</a>
 */
@JsxFunction(IE)
public void setActive() {
    final Window window = getWindow();
    final HTMLDocument document = (HTMLDocument) window.getDocument();
    document.setActiveElement(this);
    if (window.getWebWindow() == window.getWebWindow().getWebClient().getCurrentWindow()) {
        final HtmlElement element = getDomNodeOrDie();
        ((HtmlPage) element.getPage()).setFocusedElement(element);
    }
}
Also used : Window(com.gargoylesoftware.htmlunit.javascript.host.Window) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) HtmlElement(com.gargoylesoftware.htmlunit.html.HtmlElement) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 24 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLMediaElement method play.

/**
 * Begins playback of the media.
 *
 * @return a {@link Promise} which is fulfilled when playback has been started,
 *         or is rejected if for any reason playback cannot be started
 */
@JsxFunction
public Object play() {
    if (getBrowserVersion().hasFeature(JS_PROMISE)) {
        final Scriptable scope = ScriptableObject.getTopLevelScope(this);
        final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
        final LambdaFunction reject = (LambdaFunction) getProperty(ctor, "reject");
        return reject.call(Context.getCurrentContext(), this, ctor, new Object[] { new DOMException("HtmlUnit does not support media play().", DOMException.NOT_FOUND_ERR) });
    }
    return Undefined.instance;
}
Also used : DOMException(com.gargoylesoftware.htmlunit.javascript.host.dom.DOMException) LambdaConstructor(net.sourceforge.htmlunit.corejs.javascript.LambdaConstructor) LambdaFunction(net.sourceforge.htmlunit.corejs.javascript.LambdaFunction) Scriptable(net.sourceforge.htmlunit.corejs.javascript.Scriptable) JsxFunction(com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction)

Example 25 with JsxFunction

use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.

the class HTMLFormElement method item.

/**
 * Retrieves a form object or an object from an elements collection.
 * @param index Integer or String that specifies the object or collection to retrieve.
 *              If this parameter is an integer, it is the zero-based index of the object.
 *              If this parameter is a string, all objects with matching name or id properties are retrieved,
 *              and a collection is returned if more than one match is made
 * @param subIndex Optional. Integer that specifies the zero-based index of the object to retrieve
 *              when a collection is returned
 * @return an object or a collection of objects if successful, or null otherwise
 */
@JsxFunction(IE)
public Object item(final Object index, final Object subIndex) {
    if (index instanceof Number) {
        return getElements().item(index);
    }
    final String name = Context.toString(index);
    final Object response = getWithPreemption(name);
    if (subIndex instanceof Number && response instanceof HTMLCollection) {
        return ((HTMLCollection) response).item(subIndex);
    }
    return response;
}
Also used : ScriptableObject(net.sourceforge.htmlunit.corejs.javascript.ScriptableObject) 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