Class NativeJS
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
NativeJS()
Private default constructor to ensure non-instantiability. -
Method Summary
Modifier and TypeMethodDescriptionstatic final void
addFullscreenChangeHandler
(String eventname, FullscreenChangeHandler handler) JSNI method: Add a fullscreen change handler.static void
JSNI method: Display javascript alert panel - use sparingly.static String
JSNI method: decoding of base-64 encoded string.static String
JSNI method: base-64 encoding of string.static AbstractGraph.MyContext2d
createSVGContext
(int width, int height) JSNI method: Create a SVG context for exporting the view.static final boolean
ePubReaderHasFeature
(String feature) JSNI method: test if ePub reader supportsfeature
.static void
JSNI method: Exit fullscreen mode.static void
JSNI method: encourage browser to downloaddataURL
as a file namedfilename
.static void
JSNI method: Export the SVG context.static final void
JSNI method: focus onelement
.static String
JSNI method: Determine name of the fullscreen change event in current web browser.static final int
JSNI method: return the pixel ratio of the current device.static final String
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) Note: nonlinear content in Apple Books on iOS does not report as an ePub reading system (at least on the iPad).static final Element
JSNI method: Gets fullscreen element if in fullscreen mode ornull
if not in fullscreen or fullscreen not supported by web browser.static final void
handleDnD
(JavaScriptObject dataTransfer, EvoLudoWeb gui) JSNI method: the HTML5 File API enables reading of files.static final boolean
hasFocus()
JSNI method: Check if document has focus.static final boolean
hasKeys()
JSNI method: Check if execution environment supports keyboard events.static final boolean
hasMouse()
JSNI method: Check if execution environment supports mouse events.static final boolean
hasTouch()
JSNI method: Check if execution environment supports touch events.static final boolean
isElementActive
(Element element) JSNI method: check ifelement
is active.static final boolean
isEPub()
JSNI method: Check if graph is displayed in an ePub reading system.static final boolean
JSNI method: Check if the document is in fullscreen mode.static boolean
JSNI method: Check if fullscreen mode is supported.static final boolean
isValidDnD
(JavaScriptObject dataTransfer) JSNI method: check whether a single plist files was dropped.static boolean
JSNI method: check whether WebGL and hence 3D graphics are supported.static final boolean
isXML()
JSNI method: Test whether loaded from an XHTML document.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 void
removeFullscreenChangeHandler
(String eventname, FullscreenChangeHandler handler) JSNI method: Remove the fullscreen change handler.static void
requestFullscreen
(Element ele) JSNI method: Request fullscreen mode for the elementele
.static final void
JSNI 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 - use sparingly.- Parameters:
msg
- the message to display
-
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 ifelement
is active.- Parameters:
element
- the element to check- Returns:
true
ifelement
is 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:
true
if 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 thecanvas
objects of the data views.- Returns:
- the pixel ratio of device
-
isFullscreenSupported
public static boolean isFullscreenSupported()JSNI method: Check if fullscreen mode is supported.- Returns:
true
if 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:
true
if the document is in fullscreen mode
-
getFullscreenElement
JSNI method: Gets fullscreen element if in fullscreen mode ornull
if 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
fullscreenchange
andwebkitfullscreenchange
but with slightly different behaviour (neither identical to Safari).fullscreenchange
at 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
null
if 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
canvas
is supported- Returns:
true
if 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
onDrop
handler cannot be read using GWT routines.- Parameters:
dataTransfer
- list of dropped file(s)- Returns:
true
if 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.js
script 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 downloaddataURL
as 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:
true
if XML document
-
isEPub
public static final boolean isEPub()JSNI method: Check if graph is displayed in an ePub reading system.- Returns:
true
if 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
null
if 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:
true
if feature supported- See Also:
-
hasKeys
public static final boolean hasKeys()JSNI method: Check if execution environment supports keyboard events.- Returns:
true
if keyboard events are supported
-
hasMouse
public static final boolean hasMouse()JSNI method: Check if execution environment supports mouse events.- Returns:
true
if mouse events are supported
-
hasTouch
public static final boolean hasTouch()JSNI method: Check if execution environment supports touch events.- Returns:
true
if touch events are supported
-