org.spiffyui.client
Class JSUtil

java.lang.Object
  extended by org.spiffyui.client.JSUtil

public final class JSUtil
extends java.lang.Object

A set of static JavaScript utilities that provide access to functions from JQuery and some other JavaScript libraries.


Method Summary
static void addHistoryItem(HistoryCallback callback, java.lang.String id)
           Adds an item to the browser's history.
static void addHistoryItem(HistoryCallback callback, java.lang.String id, boolean bookmarkable)
           Adds an item to the browser's history.
static java.lang.String base64Decode(java.lang.String s)
          Base64 decode a string
static java.lang.String base64Encode(java.lang.String s)
          Base64 encode a string
static void bounce(java.lang.String id, int times, int speed, int distance)
          Causes the specified element to bounce the specified number of times at the specified speed.
static void bounce(java.lang.String id, int times, int speed, int distance, JSEffectCallback callback)
          Causes the specified element to bounce the specified number of times at the specified speed.
static void collapseSection(HTMLPanel panel, java.lang.String targetId, java.lang.String sectionId, boolean animate)
          Collapses a section
static void expandSection(HTMLPanel panel, java.lang.String targetId, java.lang.String sectionId, boolean animate)
          Expands a section
static java.lang.String generateUniqueId()
          Generate a probably unique ID.
static int getHeight(java.lang.String id)
           Get the height of the element with the specified ID.
static int getWidth(java.lang.String id)
           Get the width of the element with the specified ID.
static void hide(java.lang.String id)
          Hides the specified element.
static void hide(java.lang.String id, java.lang.String speed)
          Hides an element with a fade effect.
static void hide(java.lang.String id, java.lang.String speed, JSEffectCallback callback)
          Hides an element with a fade effect.
static void horizontalToggleSlide(java.lang.String id)
          Toggles the visibility of the specified element with a horizontal slide effect sliding from the left side.
static void horizontalToggleSlide(java.lang.String id, JSEffectCallback callback)
          Toggles the visibility of the specified element with a horizontal slide effect sliding from the left side.
static boolean isVisible(java.lang.String selector)
          Determines if the element(s) defined by the specified selector is visible.
static void logObjForDebug(java.lang.Object o)
          logs an object to the Firebug console for debugging purposes.
static JavaScriptObject parseJSON(java.lang.String jsonString)
           Parse the specified JSON string into a JavaScript object.
static void printError(java.lang.String msg)
          Prints an error message to the Firebug console.
static void println(java.lang.String msg)
           Prints an info message to the Firebug console, Chrome developer console, or Internet Explorer dev mode console.
static void setText(java.lang.String id, java.lang.String txt)
          Set the text for an element
static void show(java.lang.String id)
          Shows the specified element.
static void show(java.lang.String id, java.lang.String speed)
          Shows an element with a fade effect.
static void show(java.lang.String id, java.lang.String speed, JSEffectCallback callback)
          Shows an element with a fade effect.
static void slideDown(java.lang.String id, java.lang.String speed)
          Shows an element with a slide down effect.
static void slideDown(java.lang.String id, java.lang.String speed, JSEffectCallback callback)
          Shows an element with a slide down effect.
static void slideUp(java.lang.String id, java.lang.String speed)
          Hides an element with a slide up effect.
static void slideUp(java.lang.String id, java.lang.String speed, JSEffectCallback callback)
          Hides an element with a slide up effect.
static boolean toggleSection(Element target, HTMLPanel panel, java.lang.String targetId, java.lang.String sectionId)
          Toggle hiding or showing a section
static void toggleSlide(java.lang.String id, java.lang.String speed)
          Toggles the visibility of the specified element with a vertical slide effect
static void toggleSlide(java.lang.String id, java.lang.String speed, JSEffectCallback callback)
          Toggles the visibility of the specified element with a vertical slide effect
static java.lang.String trimLastDelimiter(java.lang.String s, java.lang.String delim)
          Returns a String without the last delimiter
static boolean validateEmail(java.lang.String s)
          Validate an email address entry such that both the following will pass: Allison Blake or ablake@novell.com
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addHistoryItem

public static void addHistoryItem(HistoryCallback callback,
                                  java.lang.String id)

Adds an item to the browser's history.

History items can be added at any item with any unique ID. When the user navigates the browser's history there will be a collection of items added programmatically and items representing traditional page changes. When the item added with this method is reached the callback will be called with the specified ID.

Spiffy UI uses this method to page changes in the main navigation bar to the browser's history so the user can use the browser forward and back buttons to move between pages in the application. This method is called by the MainNavBar to add page changes.

Parameters:
callback - the history callback for this item
id - the id of the item that was selected

addHistoryItem

public static void addHistoryItem(HistoryCallback callback,
                                  java.lang.String id,
                                  boolean bookmarkable)

Adds an item to the browser's history.

History items can be added at any item with any unique ID. When the user navigates the browser's history there will be a collection of items added programmatically and items representing traditional page changes. When the item added with this method is reached the callback will be called with the specified ID.

Spiffy UI uses this method to page changes in the main navigation bar to the browser's history so the user can use the browser forward and back buttons to move between pages in the application. This method is called by the MainNavBar to add page changes.

This method support bookmarking. When a history item is bookmarkable it will cause a change in the URL which can then be bookmarked by the user to return to that specific history state.

Parameters:
callback - the history callback for this item
id - the id of the item that was selected
bookmarkable - true if this history item should be bookmarkable and false otherwise

generateUniqueId

public static final java.lang.String generateUniqueId()
Generate a probably unique ID. It is based on current time.

Returns:
the unique ID as a string

slideDown

public static void slideDown(java.lang.String id,
                             java.lang.String speed)
Shows an element with a slide down effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number

slideDown

public static void slideDown(java.lang.String id,
                             java.lang.String speed,
                             JSEffectCallback callback)
Shows an element with a slide down effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number
callback - the callback called when the animation is complete

slideUp

public static void slideUp(java.lang.String id,
                           java.lang.String speed)
Hides an element with a slide up effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number

slideUp

public static void slideUp(java.lang.String id,
                           java.lang.String speed,
                           JSEffectCallback callback)
Hides an element with a slide up effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number
callback - the callback called when the animation is complete

toggleSlide

public static void toggleSlide(java.lang.String id,
                               java.lang.String speed)
Toggles the visibility of the specified element with a vertical slide effect

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number

toggleSlide

public static void toggleSlide(java.lang.String id,
                               java.lang.String speed,
                               JSEffectCallback callback)
Toggles the visibility of the specified element with a vertical slide effect

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number
callback - the callback called when the animation is complete

horizontalToggleSlide

public static void horizontalToggleSlide(java.lang.String id,
                                         JSEffectCallback callback)
Toggles the visibility of the specified element with a horizontal slide effect sliding from the left side.

Parameters:
id - the id for the element to show
callback - the callback called when the animation is complete

horizontalToggleSlide

public static void horizontalToggleSlide(java.lang.String id)
Toggles the visibility of the specified element with a horizontal slide effect sliding from the left side.

Parameters:
id - the id for the element to show

bounce

public static void bounce(java.lang.String id,
                          int times,
                          int speed,
                          int distance)
Causes the specified element to bounce the specified number of times at the specified speed.

Parameters:
id - the ID of the element to bounce
times - the number of times to bounce the element
speed - the speed of the bounce animation in milliseconds
distance - the distance in pixels to bounds the element - default is 20

bounce

public static void bounce(java.lang.String id,
                          int times,
                          int speed,
                          int distance,
                          JSEffectCallback callback)
Causes the specified element to bounce the specified number of times at the specified speed.

Parameters:
id - the ID of the element to bounce
times - the number of times to bounce the element
speed - the speed of the bounce animation in milliseconds
distance - the distance in pixels to bounds the element - default is 20
callback - the callback called when the animation is complete

hide

public static void hide(java.lang.String id,
                        java.lang.String speed)
Hides an element with a fade effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number

hide

public static void hide(java.lang.String id,
                        java.lang.String speed,
                        JSEffectCallback callback)
Hides an element with a fade effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number
callback - the callback called when the animation is complete

hide

public static void hide(java.lang.String id)
Hides the specified element.

Parameters:
id - the id for the element to show

setText

public static void setText(java.lang.String id,
                           java.lang.String txt)
Set the text for an element

Parameters:
id - the id for the element
txt - text to set for the element

show

public static void show(java.lang.String id,
                        java.lang.String speed)
Shows an element with a fade effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number

show

public static void show(java.lang.String id,
                        java.lang.String speed,
                        JSEffectCallback callback)
Shows an element with a fade effect.

Parameters:
id - the id for the element to show
speed - the speed to fade in. options are slow, normal, fast or a number
callback - the callback called when the animation is complete

show

public static void show(java.lang.String id)
Shows the specified element.

Parameters:
id - the id for the element to show

println

public static void println(java.lang.String msg)

Prints an info message to the Firebug console, Chrome developer console, or Internet Explorer dev mode console.

This method is very useful for debugging when you aren't using GWT hosted mode. The message print out to the console one item at a time and don't do anything if the console isn't available.

Parameters:
msg - the message to print

logObjForDebug

public static void logObjForDebug(java.lang.Object o)
logs an object to the Firebug console for debugging purposes. If the Firebug console is not enabled this method doesn't do anything.

Parameters:
o - the object to log to firebug console

printError

public static void printError(java.lang.String msg)
Prints an error message to the Firebug console. If the Firebug console is not enable this method doesn't do anything.

Parameters:
msg - the message to print

isVisible

public static boolean isVisible(java.lang.String selector)
Determines if the element(s) defined by the specified selector is visible. This doesn't always mean that is is on the screen, only that it would be visible if it were.

Parameters:
selector - the elements to inspect
Returns:
true if any of the selected elements are visible and false otherwise

toggleSection

public static boolean toggleSection(Element target,
                                    HTMLPanel panel,
                                    java.lang.String targetId,
                                    java.lang.String sectionId)
Toggle hiding or showing a section

Parameters:
target - - the event's onclick target
panel - - the parent HTMLPanel of the target
targetId - - the ID of the target
sectionId - - the ID of the section to toggle
Returns:
boolean true if the target does match the element with the targetId

expandSection

public static void expandSection(HTMLPanel panel,
                                 java.lang.String targetId,
                                 java.lang.String sectionId,
                                 boolean animate)
Expands a section

Parameters:
panel - - HTMLPanel holding the target
targetId - - the ID of the target
sectionId - - the ID of the section to toggle
animate - - boolean true to use slide down effect, false to just display:none

collapseSection

public static void collapseSection(HTMLPanel panel,
                                   java.lang.String targetId,
                                   java.lang.String sectionId,
                                   boolean animate)
Collapses a section

Parameters:
panel - - HTMLPanel holding the target
targetId - - the ID of the target
sectionId - - the ID of the section to toggle
animate - - boolean true to use slide down effect, false to just display:none

base64Encode

public static java.lang.String base64Encode(java.lang.String s)
Base64 encode a string

Parameters:
s - the string to encode
Returns:
the encoded string

base64Decode

public static java.lang.String base64Decode(java.lang.String s)
Base64 decode a string

Parameters:
s - the string to decode
Returns:
the decoded string

validateEmail

public static boolean validateEmail(java.lang.String s)
Validate an email address entry such that both the following will pass: Allison Blake or ablake@novell.com

Parameters:
s - - the String to test
Returns:
- true if valid

trimLastDelimiter

public static java.lang.String trimLastDelimiter(java.lang.String s,
                                                 java.lang.String delim)
Returns a String without the last delimiter

Parameters:
s - - String to trim
delim - - the delimiter
Returns:
the String without the last delimter

getHeight

public static int getHeight(java.lang.String id)

Get the height of the element with the specified ID.

This method gets the height of the specified element on the screen including padding and margins. The element must be visible and attached to the page.

Parameters:
id - the id of the element example: myElement
Returns:
the height of the element

getWidth

public static int getWidth(java.lang.String id)

Get the width of the element with the specified ID.

This method gets the width of the specified element on the screen including padding and margins. The element must be visible and attached to the page.

Parameters:
id - the id of the element example: myElement
Returns:
the width of the element

parseJSON

public static JavaScriptObject parseJSON(java.lang.String jsonString)

Parse the specified JSON string into a JavaScript object.

This method parses the specified string of well-formed JSON and returns a JavaScript object. It calls JSON.parse when it is available and calls eval only on older browsers which don't support JSON.parse.

Parameters:
jsonString - the json string to parse
Returns:
the JavaScript object representing the JSON string