Class NativeJS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateNativeJS()Private default constructor to ensure non-instantiability. -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidaddFullscreenChangeHandler(String eventname, FullscreenChangeHandler handler) JSNI method: Add a fullscreen change handler.static voidJSNI method: Display javascript alert panel.static StringJSNI method: decoding of base-64 encoded string.static StringJSNI method: base-64 encoding of string.static AbstractGraph.MyContext2dcreateSVGContext(int width, int height) JSNI method: Create a SVG context for exporting the view.static final booleanePubReaderHasFeature(String feature) JSNI method: test if ePub reader supportsfeature.static voidJSNI method: Exit fullscreen mode.static voidJSNI method: encourage browser to downloaddataURLas a file namedfilename.static voidJSNI method: Export the SVG context.static final voidJSNI method: focus onelement.static StringJSNI method: Determine name of the fullscreen change event in current web browser.static final intJSNI method: return the pixel ratio of the current device.static final StringJSNI method: Retrieve string identifying the ePub reading system: web browser: null iBooks: iBooks, Apple Books Adobe Digital Editions 4.5.8 (macOS): RMSDK Readium: no JS (and no display equations!) TEA Ebook 1.5.0 (macOS): no JS (and issues with MathML) calibre: calibre-desktop (supports JS and MathML but appears unstable) Note: nonlinear content in Apple Books on iOS does not report as an ePub reading system (at least on the iPad).static final ElementJSNI method: Gets fullscreen element if in fullscreen mode ornullif not in fullscreen or fullscreen not supported by web browser.static final voidhandleDnD(JavaScriptObject dataTransfer, EvoLudoWeb gui) JSNI method: the HTML5 File API enables reading of files.static final booleanhasFocus()JSNI method: Check if document has focus.static final booleanhasKeys()JSNI method: Check if execution environment supports keyboard events.static final booleanhasMouse()JSNI method: Check if execution environment supports mouse events.static final booleanhasTouch()JSNI method: Check if execution environment supports touch events.static final booleanisElementActive(Element element) JSNI method: check ifelementis active.static final booleanisEPub()JSNI method: Check if graph is displayed in an ePub reading system.static final booleanJSNI method: Check if the document is in fullscreen mode.static booleanJSNI method: Check if fullscreen mode is supported.static final booleanisValidDnD(JavaScriptObject dataTransfer) JSNI method: check whether a single plist files was dropped.static booleanJSNI method: check whether WebGL and hence 3D graphics are supported.static final booleanisXML()JSNI method: Test whether loaded from an XHTML document.static voidJSNI method: log message into JS console.querySelectorAll(String selector) JSNI method: expose convenient javascript method to obtain a list of elements in the DOM that match the selection criterionselector.static final voidremoveFullscreenChangeHandler(String eventname, FullscreenChangeHandler handler) JSNI method: Remove the fullscreen change handler.static voidrequestFullscreen(Element ele) JSNI method: Request fullscreen mode for the elementele.static final voidJSNI method: opens javascript file chooser and attempts to restore state from selected file
-
Constructor Details
-
NativeJS
private NativeJS()Private default constructor to ensure non-instantiability.
-
-
Method Details
-
alert
JSNI method: Display javascript alert panel. Very intrusive. Use for debugging only.- Parameters:
msg- the message to display
-
log
JSNI method: log message into JS console.- Parameters:
msg- the message to log
-
b64encode
JSNI method: base-64 encoding of string.- Parameters:
b- string to encode- Returns:
- encoded string
-
b64decode
JSNI method: decoding of base-64 encoded string.- Parameters:
a- string to decode- Returns:
- decoded string
-
querySelectorAll
JSNI method: expose convenient javascript method to obtain a list of elements in the DOM that match the selection criterionselector.- Parameters:
selector- the criterion for selecting elements in DOM- Returns:
- list of elements that match
selector
-
isElementActive
JSNI method: check ifelementis active.- Parameters:
element- the element to check- Returns:
trueifelementis active
-
focusOn
JSNI method: focus onelement.- Parameters:
element- the element to focus on
-
hasFocus
public static final boolean hasFocus()JSNI method: Check if document has focus. This is important to avoid showing tooltips when the browser window is not in focus.- Returns:
trueif document has focus
-
getDevicePixelRatio
public static final int getDevicePixelRatio()JSNI method: return the pixel ratio of the current device. This is intended to prevent distortions on thecanvasobjects of the data views.- Returns:
- the pixel ratio of device
-
isFullscreenSupported
public static boolean isFullscreenSupported()JSNI method: Check if fullscreen mode is supported.- Returns:
trueif fullscreen supported
-
requestFullscreen
JSNI method: Request fullscreen mode for the elementele.- Parameters:
ele- the element to request fullscreen mode for
-
isFullscreen
public static final boolean isFullscreen()JSNI method: Check if the document is in fullscreen mode.- Returns:
trueif the document is in fullscreen mode
-
getFullscreenElement
JSNI method: Gets fullscreen element if in fullscreen mode ornullif not in fullscreen or fullscreen not supported by web browser.- Returns:
- fullscreen element or
null
-
exitFullscreen
public static void exitFullscreen()JSNI method: Exit fullscreen mode. -
fullscreenChangeEventName
JSNI method: Determine name of the fullscreen change event in current web browser.Note: Chrome implements both
fullscreenchangeandwebkitfullscreenchangebut with slightly different behaviour (neither identical to Safari).fullscreenchangeat least works for a single graph and hence give it precedence. For Firefox scaling/resizing issues remain as well as for Chrome with multiple graphs.- Returns:
- web browser specific fullscreen change event name or
nullif Fullscreen API not implemented.
-
addFullscreenChangeHandler
public static final void addFullscreenChangeHandler(String eventname, FullscreenChangeHandler handler) JSNI method: Add a fullscreen change handler.- Parameters:
eventname- the name of the fullscreen change eventhandler- the handler to add- Implementation Notes:
- The JSNI routine works reasonably well with Safari but not with
all other browsers because aspects of the fullscreen API are
interpreted differently, see
fullscreenChangeEventName().
-
removeFullscreenChangeHandler
public static final void removeFullscreenChangeHandler(String eventname, FullscreenChangeHandler handler) JSNI method: Remove the fullscreen change handler.- Parameters:
eventname- the name of the fullscreen change eventhandler- the handler to add- Implementation Notes:
- The handler function needs to be specified again when removing
the listener... Because we don't know how to store the handler
returned by the JSNI method
_addFullscreenChangeHandler(String, FullscreenChangeHandler)it must be exact copy of handler specification there.
-
isWebGLSupported
public static boolean isWebGLSupported()JSNI method: check whether WebGL and hence 3D graphics are supported.Note: asssumes that
canvasis supported- Returns:
trueif WebGL is supported
-
isValidDnD
JSNI method: check whether a single plist files was dropped.Note: This check needs to be done in native javascript because the DataTransfer object returned by the
onDrophandler cannot be read using GWT routines.- Parameters:
dataTransfer- list of dropped file(s)- Returns:
trueif the dropped file looks promising and ok for further processing
-
handleDnD
JSNI method: the HTML5 File API enables reading of files. Take advantage of functionality to read contents of dropped file.Note:
isValidDnD(JavaScriptObject)should be called first to ensure that only a single 'plist' file was dropped.- Parameters:
dataTransfer- the list of dropped file(s)gui- the user interface that processes dropped file
-
restoreFromFile
JSNI method: opens javascript file chooser and attempts to restore state from selected file- Parameters:
gui- the user interface that processes the contents of selected file
-
createSVGContext
JSNI method: Create a SVG context for exporting the view.Note: Requires that the
Canvas2SVG.jsscript has been injected, e.g. using something likeScriptInjector.fromString(Resources.INSTANCE.canvas2SVG().getText()).inject();- Parameters:
width- the width of the contextheight- the height of the context- Returns:
- the SVG context
-
exportSVG
JSNI method: Export the SVG context.- Parameters:
ctx- the SVG context to export
-
export
JSNI method: encourage browser to downloaddataURLas a file namedfilename.Note:
#characters cause trouble in data URL. Escape them with%23.- Parameters:
dataURL- the file content encoded as data URLfilename- the name of the downloaded file
-
isXML
public static final boolean isXML()JSNI method: Test whether loaded from an XHTML document.Note: GWT interferes here and both
Document.get().createElement("div").getTagName()=="DIV"as well as$doc.createElement("div").tagName == "DIV"falsely (always?) returnfalse.- Returns:
trueif XML document
-
isEPub
public static final boolean isEPub()JSNI method: Check if graph is displayed in an ePub reading system.- Returns:
trueif ePub reading system.
-
getEPubReader
JSNI method: Retrieve string identifying the ePub reading system:- web browser: null
- iBooks: iBooks, Apple Books
- Adobe Digital Editions 4.5.8 (macOS): RMSDK
- Readium: no JS (and no display equations!)
- TEA Ebook 1.5.0 (macOS): no JS (and issues with MathML)
- calibre: calibre-desktop (supports JS and MathML but appears unstable)
- Returns:
- identification string of ePub reading system or
nullif no reading system or reading system unknown
-
ePubReaderHasFeature
JSNI method: test if ePub reader supportsfeature. in ePub 3 possible features are:- dom-manipulation
- Scripts MAY make structural changes to the document’s DOM (applies to spine-level scripting only).
- layout-changes
- Scripts MAY modify attributes and CSS styles that affect content layout (applies to spine-level scripting only).
- touch-events
- The device supports touch events and the Reading System passes touch events to the content.
- mouse-events
- The device supports mouse events and the Reading System passes mouse events to the content.
- keyboard-events
- The device supports keyboard events and the Reading System passes keyboard events to the content.
- spine-scripting
- Indicates whether the Reading System supports spine-level scripting (e.g., so a container-constrained script can determine whether any actions that depend on scripting support in a Top-level Content Document have any chance of success before attempting them).
- Parameters:
feature- the ePub feature to test- Returns:
trueif feature supported- See Also:
-
hasKeys
public static final boolean hasKeys()JSNI method: Check if execution environment supports keyboard events.- Returns:
trueif keyboard events are supported
-
hasMouse
public static final boolean hasMouse()JSNI method: Check if execution environment supports mouse events.- Returns:
trueif mouse events are supported
-
hasTouch
public static final boolean hasTouch()JSNI method: Check if execution environment supports touch events.- Returns:
trueif touch events are supported
-