WL client API

For the native app developed using web technologies or hybrid technologies, we refer to some classes and functions that extend components such as WL.BusyIndicator, WL.Logger, and WL.SimpleDialog with the native look and feel, which is specified with respect to mobile platforms.

To enable these native components, Worklight provides some extensive libraries to implement. We will cover some WL client-side APIs to provide you with a holistic view of implementation at the development side.

WL.BusyIndicator

The WL.BusyIndicator WL extension provides a busy indicator for a mobile application. It's a modal representation of an object named WL.BusyIndicator. It provides a dynamic graphical interface for an application that is temporarily on hold for any process or seems busy. It appears natively on Android, iOS, Blackberry, and Windows phones. For every mobile environment, its implementation occurs by using JavaScript in the Busy.js file. There are some optional parameters as well.

To change the graphical appearance of the busy indicator, you can also override the defined CSS selectors: #WLbusy, #WLbusyOverlay, and #WLbusyTitle. Use the following code to do this:

varbusyIndicator = new WL.BusyIndicator('context', {text : 'Loading...'});

WL.Logger

The WL.Logger object displays log messages to the console log for every particular environment. In mobile applications, the messages are printed to a logfile provided in the mobile SDK. In web environments, the messages seem to be printed to the browser log. In desktop environments, they are printed to the applicable debug console of each environment. Refer to the details in the following section.

WL.Logger is an object that actually holds two methods. Both these methods contain one required parameter and one optional parameter.

The method for successful cases is as follows:

WL.Logger.debug("content",ex);

The method for errors is as follows:

WL.Logger.error("content",ex);

In the preceding methods, the optional parameter ex is a JavaScript exception. If the JavaScript exception is specified, the filename and line number are appended to the message.

WL.SimpleDialog

WL.SimpleDialog is a dialog object. It holds a common API for generating a dialog for the application. This dialog object shows a dialog box with buttons. Its appearance and specification is dependent on the environment. On Android, iPhone, BlackBerry, and Windows phones, it opens as a native dialog box. This dialog appears without any conflicts with the JavaScript thread.

The WL.SimpleDialog object's method for displaying the dialog contains four parameters in which three are mandatory and one is optional. The following is the code for the show method:

WL.SimpleDialog.show(title, text, buttons, options)

In the preceding code line, the buttons parameter is a JSON array on behalf of every corresponding button. Following is an example of a JSON array:

WL.SimpleDialog.show(
"Title", "Text", 
[{text: "Button1", handler: function() {WL.Logger.debug("Button 1 pressed"); }
}]
)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.247.81