widget Singleton

The widget instance has several things that usefull for the application scope.

widget()

Example

//metadata.json example file
{
	"identifier": "com.metrological.app.EmptyTemplate",
	"name": "Empty App Template",
	"version": "0.0.1",
	"author": "Metrological Widgets",
	"company": "Metrological Widgets",
	"copyright": "Metrological Widgets 2014",
	"description": "A clean App structure",
	"categories": [
		"video"
	],
	"scripts": "Javascript/init.js",
	"images": {
		"about": "Images/Icon.png",
		"icon": {
			"192x192": "Images/Icon.png"
		}
	}
}

Members

author :String static constant

Author of the app as defined in the metadata.json

company :String static constant

Company that made the app as defined in the metadata.json

Copyright text as defined in the metadata.json

description :String static constant

Description of the app as defined in the metadata.json

identifier :String static constant

App identifier as defined in the metadata.json

locale :String static constant

The locale the app is currently running in.

name :String static constant

Name of the app as defined in the metadata.json

version :String static constant

Version of the app as defined in the metadata.json

active :Boolean

Defines if the application is running or not.

isDialogActive :Boolean

Defines if the application has a dialog active on the screen or not.

Methods

close()

Close down the app.

getImage(key, type) → {Element}

Get a image (as element) with the source as defined in metadata.json Get the image source string defined in the metadata of the app.

Parameters:

Name Type Argument Description
key String

Key of the image source string to retrieve.

type String optional 

Type of the image source string to retrieve.

Returns:

The image as a HTML Dom element.

getImageSource(key, type) → {String}

Get the image source string defined in the metadata of the app.

Parameters:

Name Type Argument Description
key String

Key of the image source string to retrieve.

type String optional 

Type of the image source string to retrieve.

Returns:

Image location string.

Example

widget.getImageSource('about');
//Returns: 'Images/about.png'

widget.getImageSource('icon', '192x192');
//Returns: 'Images/Icon.png'

getLocalizedString(key, args) → {String}

Translate the language key in the active language.

Parameters:

Name Type Description
key String

Translation key.

args Array

Array with the values to fill in the string. These can be parsed to certain types specified in the translation string.
The type specifier says what type the argument data should be treated as. Possible types:

  • % - a literal percent character. No argument is required.
  • b - the argument is treated as an integer, and presented as a binary number.
  • c - the argument is treated as an integer, and presented as the character with that ASCII value.
  • d - the argument is treated as an integer, and presented as a (signed) decimal number.
  • e - the argument is treated as scientific notation (e.g. 1.2e+2). The precision specifier stands for the number of digits after the decimal point.
  • E - like %e but uses uppercase letter (e.g. 1.2E+2).
  • f - the argument is treated as a float, and presented as a floating-point number.
  • F - the argument is treated as a float, and presented as a floating-point number.
  • g - shorter of %e and %f.
  • G - shorter of %E and %f.
  • o - the argument is treated as an integer, and presented as an octal number.
  • s - the argument is treated as and presented as a string.
  • u - the argument is treated as an integer, and presented as an unsigned decimal number.
  • x - the argument is treated as an integer and presented as a hexadecimal number (with lowercase letters).
  • X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

Returns:

The translated string or the key.

Example

The below code lines do the same:

widget.getLocalizedString('close_button');
$_('close_button');

//Translation string: 
//"nrMonkeys" = "There are %d monkeys in the %s.";
widget.getLocalizedString('nrMonkeys', [2, 'tree']); // Returns -> There are 2 monkeys in the tree.

getPath() → {String}

Returns:

Path of your application.

getURL() → {String}

Returns:

External path of an asset in your application.