Namespace: App

Cocoon. App

This namespace represents different methods to control your application.

Example

// Example 1: Closes the application
Cocoon.App.exit();
// Example 2: Opens a given URL
Cocoon.App.openURL("http://www.ludei.com");
// Example 3: Fired when the application is suspended
Cocoon.App.on("suspended", function(){
 ...
});

Methods

<static> exit()

Forces the app to finish.

Example
Cocoon.App.exit();

<static> forward(code) → {string}

Makes a forward call of some javascript code to be executed in a different environment (i.e. from Canvas+ the WebView and viceversa). It waits until the code is executed and the result of it is returned === synchronous.

Parameters:
Name Type Description
code string

Some JavaScript code in a string to be forwarded and executed in a different JavaScript environment (i.e. from Canvas+ to the WebView and viceversa).

Returns:

The result of the execution of the passed JavaScript code in the different JavaScript environment.

Type
string
Example
Cocoon.App.forward("alert('Ludei!');");

<static> forwardAsync(javaScriptCode, callback)

Makes a forward call of some javascript code to be executed in a different environment (i.e. from Canvas+ to the WebView and viceversa). It is asyncrhonous so it does not wait until the code is executed and the result of it is returned. Instead, it calls a callback function when the execution has finished to pass the result.

Parameters:
Name Type Argument Description
javaScriptCode string

Some JavaScript code in a string to be forwarded and executed in a different JavaScript environment (i.e. from Canvas+ to the WebView and viceversa).

callback function <optional>

A function callback (optional) that will be called when the passed JavaScript code is executed in a different thread to pass the result of the execution in the different JavaScript environment.

Example
Cocoon.App.forwardAsync("alert('Ludei!');", function(){
...
});

<static> hideTheWebView()

Hides the webview.

Example
Cocoon.App.hideTheWebView();

<static> load(path, storageType)

Allows to load a new JavaScript/HTML5 resource that can be loaded either locally (inside the platform/device storage) or using a remote URL.

Parameters:
Name Type Argument Description
path string

A path to a resource stored in the platform or in a URL to a remote resource.

storageType Cocoon.App.StorageType <optional>

If the path argument represents a locally stored resource, the developer can specify the storage where it is stored. If no value is passes, the Cocoon.App.StorageType.APP_STORAGE value is used by default.

Example
Cocoon.App.load("index.html");

<static> loadInTheWebView(path, storageType)

Loads a resource in the WebView environment from the Cocoon environment.

Parameters:
Name Type Argument Description
path string

The path to the resource. It can be a remote URL or a path to a local file.

storageType Cocoon.App.StorageType <optional>

An optional parameter to specify at which storage in the device the file path is stored. By default, APP_STORAGE is used.

Example
Cocoon.App.WebView.on("load", {
  success : function(){
    Cocoon.App.showTheWebView();
  },
  error : function(){
    console.log("Cannot show the Webview for some reason :/");
    console.log(JSON.stringify(arguments));
  }
});
Cocoon.App.loadInTheWebView("wv.html");

<static> openURL(url)

Opens a given URL using a system service that is able to open it. For example, open a HTTP URL using the system WebBrowser.

Parameters:
Name Type Description
url string

The URL to be opened by a system service.

Example
Cocoon.App.openURL("http://www.ludei.com");

<static> pause()

Pauses the Cocoon JavaScript execution loop. The callback function does not receive any parameter.

Example
Cocoon.App.pause();

<static> reload()

Reloads the last loaded path in the current context.

Example
Cocoon.App.reload();

<static> reloadWebView()

Reloads the last loaded path in the WebView context.

Example
Cocoon.App.reloadWebView();

<static> resume()

Resumes the Cocoon JavaScript execution loop.

Example
Cocoon.App.resume();

<static> showTheWebView(x, y, width, height)

Shows the webview.

Parameters:
Name Type Description
x number

The top lef x coordinate of the rectangle where the webview will be shown.

y number

The top lef y coordinate of the rectangle where the webview will be shown.

width number

The width of the rectangle where the webview will be shown.

height number

The height of the rectangle where the webview will be shown.

Example
Cocoon.App.showTheWebView(0 , 0 , window.innerWidth * window.devicePixelRatio, window.innerHeight * window.devicePixelRatio);

Events

On application activated

Allows to listen to events called when the application is activated. The callback function does not receive any parameter.

Example
Cocoon.App.on("activated", function(){
 ...
});

On application suspended

Allows to listen to events called when the application is suspended. The callback function does not receive any parameter.

Example
Cocoon.App.on("suspended", function(){
 ...
});

On application suspending

Allows to listen to events called when the application is suspending. The callback function does not receive any parameter.

Example
Cocoon.App.on("suspending", function(){
 ...
});

On memory warning

Allows to listen to memory warning notifications from the system It is strongly recommended that you implement this method and free up as much memory as possible by disposing of cached data objects, images on canvases that can be recreated.

Example
Cocoon.App.on("memorywarning", function(){
 ...
});

Members

<static> StorageType

Properties:
Name Type Description
Cocoon.App.StorageType string

The base object

Properties
Name Type Description
APP_STORAGE string

The application storage

INTERNAL_STORAGE string

Internal Storage

EXTERNAL_STORAGE string

External Storage

TEMPORARY_STORAGE string

Temporary Storage

Atomic Plugins - JavaScript Documentation by Ludei, DocStrap Copyright © 2012-2013
The contributors to the JSDoc3 and DocStrap projects.