use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLElement method clearAttributes.
/**
* An IE-only method which clears all custom attributes.
*/
@JsxFunction(IE)
public void clearAttributes() {
final HtmlElement node = getDomNodeOrDie();
// Remove custom attributes defined directly in HTML.
final List<String> removals = new ArrayList<>();
for (final String attributeName : node.getAttributesMap().keySet()) {
// May not be 100% correct.
if (!ScriptableObject.hasProperty(getPrototype(), attributeName)) {
removals.add(attributeName);
}
}
for (final String attributeName : removals) {
node.removeAttribute(attributeName);
}
// Remove custom attributes defined at runtime via JavaScript.
for (final Object id : getAllIds()) {
if (id instanceof Integer) {
final int i = ((Integer) id).intValue();
delete(i);
} else if (id instanceof String) {
delete((String) id);
}
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLFormElement method requestSubmit.
/**
* Submits the form by submitted using a specific submit button.
* @param submitter The submit button whose attributes describe the method
* by which the form is to be submitted. This may be either
* an <input> or <button> element whose type attribute is submit.
* If you omit the submitter parameter, the form element itself is used as the submitter.
*/
@JsxFunction({ CHROME, EDGE, FF, FF_ESR })
public void requestSubmit(final Object submitter) {
if (Undefined.isUndefined(submitter)) {
submit();
return;
}
SubmittableElement submittable = null;
if (submitter instanceof HTMLElement) {
final HTMLElement subHtmlElement = (HTMLElement) submitter;
if (subHtmlElement instanceof HTMLButtonElement) {
if ("submit".equals(((HTMLButtonElement) subHtmlElement).getType())) {
submittable = (SubmittableElement) subHtmlElement.getDomNodeOrDie();
}
} else if (subHtmlElement instanceof HTMLInputElement) {
if ("submit".equals(((HTMLInputElement) subHtmlElement).getType())) {
submittable = (SubmittableElement) subHtmlElement.getDomNodeOrDie();
}
}
if (submittable != null && subHtmlElement.getForm() != this) {
throw ScriptRuntime.typeError("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + "The specified element is not owned by this form element.");
}
}
if (submittable == null) {
throw ScriptRuntime.typeError("Failed to execute 'requestSubmit' on 'HTMLFormElement': " + "The specified element is not a submit button.");
}
this.getHtmlForm().submit(submittable);
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class Geolocation method getCurrentPosition.
/**
* Gets the current position.
* @param successCallback success callback
* @param errorCallback optional error callback
* @param options optional options
*/
@JsxFunction
public void getCurrentPosition(final Function successCallback, final Object errorCallback, final Object options) {
successHandler_ = successCallback;
final WebWindow webWindow = getWindow().getWebWindow();
if (webWindow.getWebClient().getOptions().isGeolocationEnabled()) {
final JavaScriptJob job = BackgroundJavaScriptFactory.theFactory().createJavaScriptJob(0, null, () -> doGetPosition());
webWindow.getJobManager().addJob(job, webWindow.getEnclosedPage());
}
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLCanvasElement method getContext.
/**
* Gets the context.
* @param contextId the context id
* @return Returns an object that exposes an API for drawing on the canvas,
* or null if the given context ID is not supported
*/
@JsxFunction
public Object getContext(final String contextId) {
if ("2d".equals(contextId)) {
if (context2d_ == null) {
final CanvasRenderingContext2D context = new CanvasRenderingContext2D(this);
context.setParentScope(getParentScope());
context.setPrototype(getPrototype(context.getClass()));
context2d_ = context;
}
return context2d_;
}
return null;
}
use of com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction in project htmlunit by HtmlUnit.
the class HTMLSubCollection method namedItem.
/**
* Retrieves the item or items corresponding to the specified name (checks ids, and if
* that does not work, then names).
* @param name the name or id the element or elements to return
* @return the element or elements corresponding to the specified name or id
* @see <a href="http://msdn.microsoft.com/en-us/library/ms536634.aspx">MSDN doc</a>
*/
@JsxFunction
public Object namedItem(final String name) {
final List<DomNode> elements = getElements();
final BrowserVersion browserVersion = getBrowserVersion();
if (browserVersion.hasFeature(HTMLCOLLECTION_NAMED_ITEM_ID_FIRST)) {
for (final Object next : elements) {
if (next instanceof DomElement) {
final DomElement elem = (DomElement) next;
final String id = elem.getId();
if (name.equals(id)) {
return getScriptableForElement(elem);
}
}
}
}
for (final Object next : elements) {
if (next instanceof DomElement) {
final DomElement elem = (DomElement) next;
final String nodeName = elem.getAttributeDirect("name");
if (name.equals(nodeName)) {
return getScriptableForElement(elem);
}
final String id = elem.getId();
if (name.equals(id)) {
return getScriptableForElement(elem);
}
}
}
return null;
}
Aggregations