use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Element method closest.
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public static Element closest(final Context context, final Scriptable thisObj, final Object[] args, final Function function) {
if (!(thisObj instanceof Element)) {
throw ScriptRuntime.typeError("Illegal invocation");
}
final String selectorString = (String) args[0];
try {
final DomNode domNode = ((Element) thisObj).getDomNodeOrNull();
if (domNode == null) {
return null;
}
final DomElement elem = domNode.closest(selectorString);
if (elem == null) {
return null;
}
return elem.getScriptableObject();
} catch (final CSSException e) {
throw ScriptRuntime.constructError("SyntaxError", "An invalid or illegal selector was specified (selector: '" + selectorString + "' error: " + e.getMessage() + ").");
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class FontFaceSet method load.
/**
* @param font a font specification using the CSS value syntax, e.g. "italic bold 16px Roboto"
* @param text limit the font faces to those whose Unicode range contains at least one
* of the characters in text. This does not check for individual glyph coverage.
* @return a Promise of an Array of FontFace loaded. The promise is fulfilled
* when all the fonts are loaded; it is rejected if one of the fonts failed to load.
*/
@JsxFunction
public Object load(final String font, final String text) {
final Scriptable scope = ScriptableObject.getTopLevelScope(this);
final LambdaConstructor ctor = (LambdaConstructor) getProperty(scope, "Promise");
final LambdaFunction resolve = (LambdaFunction) getProperty(ctor, "resolve");
return resolve.call(Context.getCurrentContext(), this, ctor, new Object[] { "" });
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class URLSearchParams method set.
/**
* The set() method of the URLSearchParams interface sets the value associated with a
* given search parameter to the given value. If there were several matching values,
* this method deletes the others. If the search parameter doesn't exist, this method
* creates it.
*
* @param name The name of the parameter to set.
* @param value The value of the parameter to set.
*/
@JsxFunction
public void set(final String name, final String value) {
final List<NameValuePair> splitted = splitQuery();
boolean change = true;
final ListIterator<NameValuePair> iter = splitted.listIterator();
while (iter.hasNext()) {
final NameValuePair entry = iter.next();
if (entry.getName().equals(name)) {
if (change) {
iter.set(new NameValuePair(name, value));
change = false;
} else {
iter.remove();
}
}
}
if (change) {
splitted.add(new NameValuePair(name, value));
}
try {
url_.setSearch(splitted);
} catch (final MalformedURLException e) {
LOG.error(e.getMessage(), e);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method scrollBy.
/**
* Scrolls the window content the specified distance.
* @param x the horizontal distance to scroll by
* @param y the vertical distance to scroll by
*/
@JsxFunction
public void scrollBy(final int x, final int y) {
final HTMLElement body = document_.getBody();
if (body != null) {
body.setScrollLeft(body.getScrollLeft() + x);
body.setScrollTop(body.getScrollTop() + y);
final Event event = new Event(body, Event.TYPE_SCROLL);
body.fireEvent(event);
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCollectionFrames method showModalDialog.
/**
* Creates a modal dialog box that displays the specified HTML document.
* @param url the URL of the document to load and display
* @param arguments object to be made available via <tt>window.dialogArguments</tt> in the dialog window
* @param features string that specifies the window ornaments for the dialog window
* @return the value of the {@code returnValue} property as set by the modal dialog's window
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536759.aspx">MSDN Documentation</a>
* @see <a href="https://developer.mozilla.org/en/DOM/window.showModalDialog">Mozilla Documentation</a>
*/
@JsxFunction(IE)
public Object showModalDialog(final String url, final Object arguments, final String features) {
final WebWindow webWindow = getWebWindow();
final WebClient client = webWindow.getWebClient();
try {
final URL completeUrl = ((HtmlPage) getDomNodeOrDie()).getFullyQualifiedUrl(url);
final DialogWindow dialog = client.openDialogWindow(completeUrl, webWindow, arguments);
// TODO: Theoretically, we shouldn't return until the dialog window has been close()'ed...
// But we have to return so that the window can be close()'ed...
// Maybe we can use Rhino's continuation support to save state and restart when
// the dialog window is close()'ed? Would only work in interpreted mode, though.
final ScriptableObject jsDialog = dialog.getScriptableObject();
return jsDialog.get("returnValue", jsDialog);
} catch (final IOException e) {
throw Context.throwAsScriptRuntimeEx(e);
}
}
Aggregations