Package org.opencms.gwt.client.util
Class CmsJsUtil
java.lang.Object
org.opencms.gwt.client.util.CmsJsUtil
A class containing generic Javascript utility methods.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
callNamedFunctionWithString
(String name, String param) Calls a named global function (i.e.static void
callNamedFunctionWithString2
(String name, String param1, String param2) Calls a named global function (i.e.static void
callWithString
(com.google.gwt.core.client.JavaScriptObject func, String param) Calls a JS function with a string parameter.static void
Closes the browser window.static com.google.gwt.user.client.Command
convertCallbackToCommand
(com.google.gwt.core.client.JavaScriptObject func) Creates a Command object which calls the given native JS function.static void
fillStringMapFromJsObject
(com.google.gwt.core.client.JavaScriptObject jso, Map<String, String> map) Iterates over attributes of a Javascript object and copies them to a string map.static void
forceLoadUri
(String uri) Opens the given URI in the current browser window, ensuring that a request to the server is triggered.static com.google.gwt.core.client.JavaScriptObject
getAttribute
(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads an attribute from a Javascript object.static String
getAttributeString
(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads a string-valued attribute from a Javascript object.static String
getLocalStorage
(String key) static com.google.gwt.core.client.JavaScriptObject
Gets the current window as a Javascript object.static com.google.gwt.core.client.JsArrayString
newArray()
Creates an empty Javascript string array.static com.google.gwt.core.client.JavaScriptObject
Creates a JavaScript object from a JSON string.static void
setAttribute
(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue) Sets an attribute of the given Javascript object to a new value.static com.google.gwt.core.client.JavaScriptObject
static com.google.gwt.user.client.rpc.AsyncCallback<String>
wrapCallback
(com.google.gwt.core.client.JavaScriptObject func) Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.
-
Method Details
-
callNamedFunctionWithString
Calls a named global function (i.e. a function-valued attribute of window) with a string argument.- Parameters:
name
- the function nameparam
- the function parameter
-
callNamedFunctionWithString2
Calls a named global function (i.e. a function-valued attribute of window) with a string argument.- Parameters:
name
- the function nameparam1
- a function parameterparam2
- a function parameter
-
callWithString
Calls a JS function with a string parameter.- Parameters:
func
- the Javascript functionparam
- the string parameter
-
closeWindow
Closes the browser window. -
convertCallbackToCommand
public static com.google.gwt.user.client.Command convertCallbackToCommand(com.google.gwt.core.client.JavaScriptObject func) Creates a Command object which calls the given native JS function.- Parameters:
func
- a Javascript function- Returns:
- a Command object which calls the native function
-
fillStringMapFromJsObject
public static void fillStringMapFromJsObject(com.google.gwt.core.client.JavaScriptObject jso, Map<String, String> map) Iterates over attributes of a Javascript object and copies them to a string map.Converts all values to strings.
- Parameters:
jso
- the Javascript objectmap
- the map to fill
-
forceLoadUri
Opens the given URI in the current browser window, ensuring that a request to the server is triggered.- Parameters:
uri
- the URI to open
-
getAttribute
public static com.google.gwt.core.client.JavaScriptObject getAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads an attribute from a Javascript object.- Parameters:
jso
- the Javascript objectattr
- the name of the attribute- Returns:
- the value of the attribute
-
getAttributeString
public static String getAttributeString(com.google.gwt.core.client.JavaScriptObject jso, String attr) Reads a string-valued attribute from a Javascript object.- Parameters:
jso
- the Javascript objectattr
- the name of the attribute- Returns:
- the value of the attribute
-
getLocalStorage
-
getWindow
Gets the current window as a Javascript object.- Returns:
- the current window
-
newArray
Creates an empty Javascript string array.- Returns:
- the new array
-
parseJSON
Creates a JavaScript object from a JSON string.- Parameters:
json
- the JSON string- Returns:
- the JavaScript object parsed from the JSON string
-
setAttribute
public static void setAttribute(com.google.gwt.core.client.JavaScriptObject jso, String attr, com.google.gwt.core.client.JavaScriptObject newValue) Sets an attribute of the given Javascript object to a new value.- Parameters:
jso
- the object to modifyattr
- the attribute to setnewValue
- the new attribute value
-
toJavaScriptObject
-
wrapCallback
public static com.google.gwt.user.client.rpc.AsyncCallback<String> wrapCallback(com.google.gwt.core.client.JavaScriptObject func) Wraps a native JavaScript callback taking a string argument into an AsyncCallback so that it can easily be called from GWT Java code.- Parameters:
func
- the function to wrap- Returns:
- the AsyncCallback wrapper
-