elemental2 icon indicating copy to clipboard operation
elemental2 copied to clipboard

Add w3c_vibration.js

Open craigmit opened this issue 5 months ago • 0 comments

JavaScript has navigator.vibrate ( https://developer.mozilla.org/en-US/docs/Web/API/Navigator/vibrate ), however, Elemental2 doesn't have it.

It exists in the closure-compiler here: https://github.com/google/closure-compiler/blob/master/externs/browser/w3c_vibration.js

Can we pleae add it to Elemental2?

Until it's added, we need to us JSInterop:

import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public interface NavigatorVibrate {
  @JsMethod
  boolean vibrate(double milliseconds);
  @JsMethod
  boolean vibrate(double[] pattern);
}
NavigatorVibrate nav = Js.cast(DomGlobal.navigator);
nav.vibrate(80);

craigmit avatar Aug 19 '25 22:08 craigmit