Show:

F2 Class

Root namespace of the F2 SDK

Defined in: src\container.js:659

Methods

Name Description
_createAppConfig (
  • appConfig
)
private

Adds properties to the AppConfig object

_createAppInstance (
  • appConfigs
)
private

Instantiates each app from it's appConfig and stores that in a local private collection

_getAppConfigFromElement (
  • node
)
private

Generate an AppConfig from the element's attributes

_hasNonTextChildNodes (
  • node
)
private

Returns true if the DOM node has children that are not text nodes

_hydrateContainerConfig (
  • containerConfig
)
private

Adds properties to the ContainerConfig object to take advantage of defaults

_initContainerEvents ( ) private

Attach container Events

_isInit ( ) private

Has the container been init?

_isPlaceholderElement (
  • node
)
private

Checks if an element is a placeholder element

_validateApp (
  • appConfig
)
private

Checks if the app is valid

_validateContainerConfig ( ) private

Checks if the ContainerConfig is valid

appConfigReplacer ( )

A function to pass into F2.stringify which will prevent circular reference errors when serializing objects

extend (
  • ns
  • obj
  • overwrite
)

Creates a namespace on F2 and copies the contents of an object into that namespace optionally overwriting existing properties.

getContainerLocale ( )

Gets the current locale defined by the container

getContainerState ( )

Gets the current list of apps in the container

guid ( )

Generates a somewhat random id

inArray (
  • value
  • array
)

Search for a value within an array.

init (
  • config
)

Initializes the container. This method must be called before performing any other actions in the container.

isInit ( )

Has the container been init?

isLocal (
  • url
)

Tests a URL to see if it's on the same domain (local) or not

isNativeNode (
  • testObject
)

Utility method to determine whether or not the argument passed in is or is not a native dom node.

loadApp (
  • appConfigs
  • [appManifest]
)
private

Loads the app's html/css/javascript

loadPlaceholders (
  • parentNode
)

Automatically load apps that are already defined in the DOM. Elements will be rendered into the location of the placeholder DOM element. Any AppHandlers that are defined will be bypassed.

log (
  • Object/Method
  • [obj2]
)

A utility logging function to write messages or objects to the browser console. This is a proxy for the console API.

parse (
  • str
)

Wrapper to convert a JSON string to an object

registerApps (
  • appConfigs
  • [appManifests]
)

Begins the loading process for all apps and/or initialization process for pre-loaded apps. The app will be passed the F2.AppConfig object which will contain the app's unique instanceId within the container. If the F2.AppConfig.root property is populated the app is considered to be a pre-loaded app and will be handled accordingly. Optionally, the F2.AppManifest can be passed in and those assets will be used instead of making a request.

removeAllApps ( )

Removes all apps from the container

removeApp (
  • instanceId
)

Removes an app from the container

stringify (
  • value
  • replacer
  • space
)

Wrapper to convert an object to JSON

Note: When using F2.stringify on an F2.AppConfig object, it is recommended to pass F2.appConfigReplacer as the replacer function in order to prevent circular serialization errors.

version ( )

Function to get the F2 version number

Properties

Name Description
Apps

The apps namespace is a place for app developers to put the javascript class that is used to initialize their app. The javascript classes should be namepaced with the F2.AppConfig.appId. It is recommended that the code be placed in a closure to help keep the global namespace clean.

If the class has an 'init' function, that function will be called automatically by F2.

Methods

_createAppConfig (
  • appConfig
) private

Defined in src\container.js:38

Adds properties to the AppConfig object

Parameters:

Returns:

F2.AppConfig:

The new F2.AppConfig object, prepopulated with necessary properties


_createAppInstance (
  • appConfigs
) private

Instantiates each app from it's appConfig and stores that in a local private collection

Parameters:


_getAppConfigFromElement (
  • node
) private

Defined in src\container.js:61

Generate an AppConfig from the element's attributes

Parameters:

  • node Element

    The DOM node from which to generate the F2.AppConfig object

Returns:

F2.AppConfig:

The new F2.AppConfig object


_hasNonTextChildNodes (
  • node
) private

Returns true if the DOM node has children that are not text nodes

Parameters:

  • node Element

    The DOM node

Returns:

Bool:

True if there are non-text children


_hydrateContainerConfig (
  • containerConfig
) private

Adds properties to the ContainerConfig object to take advantage of defaults

Parameters:


_initContainerEvents ( ) private

Attach container Events


_isInit ( ) private

Has the container been init?

Returns:

Bool:

True if the container has been init


_isPlaceholderElement (
  • node
) private

Checks if an element is a placeholder element

Parameters:

  • node Element

    The DOM element to check

Returns:

Bool:

True if the element is a placeholder


_validateApp (
  • appConfig
) private

Checks if the app is valid

Parameters:

Returns:

Bool:

True if the app is valid


_validateContainerConfig ( ) private

Checks if the ContainerConfig is valid

Returns:

Bool:

True if the config is valid


appConfigReplacer ( )

A function to pass into F2.stringify which will prevent circular reference errors when serializing objects


extend (
  • ns
  • obj
  • overwrite
)

Creates a namespace on F2 and copies the contents of an object into that namespace optionally overwriting existing properties.

Parameters:

  • ns String

    The namespace to create. Pass a falsy value to add properties to the F2 namespace directly.

  • obj Object

    The object to copy into the namespace.

  • overwrite Bool

    True if object properties should be overwritten

Returns:

Object:

The created object


getContainerLocale ( )

Gets the current locale defined by the container

Returns:

String:

IETF-defined standard language tag


getContainerState ( )

Gets the current list of apps in the container

Returns:

Array:

An array of objects containing the appId


guid ( )

Generates a somewhat random id

Returns:

String:

A random id


inArray (
  • value
  • array
)

Defined in src\container.js:17

Search for a value within an array.

Parameters:

  • value Object

    The value to search for

  • array Array

    The array to search

Returns:

Int:

index of the value in the array, -1 if value not found


init (
  • config
)

Initializes the container. This method must be called before performing any other actions in the container.

Parameters:


isInit ( )

Has the container been init?

Returns:

Bool:

True if the container has been init


isLocal (
  • url
)

Tests a URL to see if it's on the same domain (local) or not

Parameters:

  • url URL to test

Returns:

Bool:

Whether the URL is local or not


isNativeNode (
  • testObject
)

Defined in src\utils\dom.js:1

Utility method to determine whether or not the argument passed in is or is not a native dom node.

Parameters:

  • testObject Object

    The object you want to check as native dom node.

Returns:

Bool:

Returns true if the object passed is a native dom node.


loadApp (
  • appConfigs
  • [appManifest]
) private

Loads the app's html/css/javascript

Parameters:


loadPlaceholders (
  • parentNode
)

Automatically load apps that are already defined in the DOM. Elements will be rendered into the location of the placeholder DOM element. Any AppHandlers that are defined will be bypassed.

Parameters:

  • parentNode Element

    The element to search for placeholder apps


log (
  • Object/Method
  • [obj2]
)

A utility logging function to write messages or objects to the browser console. This is a proxy for the console API.

Parameters:

  • Object/Method Object | String

    An object to be logged or a console API method name, such as warn or error. All of the console method names are detailed in the Chrome docs.

  • [obj2] Object optional multiple

    An object to be logged

Example:

    //Pass any object (string, int, array, object, bool) to .log()
	                                        F2.log('foo');
	                                        F2.log(myArray);
	                                        //Use a console method name as the first argument.
	                                        F2.log('error', err);
	                                        F2.log('info', 'The session ID is ' + sessionId);
	                                    

Some code derived from HTML5 Boilerplate console plugin


parse (
  • str
)

Wrapper to convert a JSON string to an object

Parameters:

  • str String

    The JSON string to convert

Returns:

Object:

The parsed object


registerApps (
  • appConfigs
  • [appManifests]
)

Begins the loading process for all apps and/or initialization process for pre-loaded apps. The app will be passed the F2.AppConfig object which will contain the app's unique instanceId within the container. If the F2.AppConfig.root property is populated the app is considered to be a pre-loaded app and will be handled accordingly. Optionally, the F2.AppManifest can be passed in and those assets will be used instead of making a request.

Parameters:

  • appConfigs Array

    An array of F2.AppConfig objects

  • [appManifests] Array optional

    An array of F2.AppManifest objects. This array must be the same length as the apps array that is objects. This array must be the same length as the apps array that is passed in. This can be useful if apps are loaded on the server-side and passed down to the client.

Example:

Traditional App requests.

// Traditional f2 app configs
	                                    var arConfigs = [
	                                        {
	                                            appId: 'com_externaldomain_example_app',
	                                            context: {},
	                                            manifestUrl: 'http://www.externaldomain.com/F2/AppManifest'
	                                        },
	                                        {
	                                            appId: 'com_externaldomain_example_app',
	                                            context: {},
	                                            manifestUrl: 'http://www.externaldomain.com/F2/AppManifest'
	                                        },
	                                        {
	                                            appId: 'com_externaldomain_example_app2',
	                                            context: {},
	                                            manifestUrl: 'http://www.externaldomain.com/F2/AppManifest'
	                                        }
	                                    ];
	                                    
	                                    F2.init();
	                                    F2.registerApps(arConfigs);

Pre-loaded and tradition apps mixed.

// Pre-loaded apps and traditional f2 app configs
	                                    // you can preload the same app multiple times as long as you have a unique root for each
	                                    var arConfigs = [
	                                        {
	                                            appId: 'com_mydomain_example_app',
	                                            context: {},
	                                            root: 'div#example-app-1',
	                                            manifestUrl: ''
	                                        },
	                                        {
	                                            appId: 'com_mydomain_example_app',
	                                            context: {},
	                                            root: 'div#example-app-2',
	                                            manifestUrl: ''
	                                        },
	                                        {
	                                            appId: 'com_externaldomain_example_app',
	                                            context: {},
	                                            manifestUrl: 'http://www.externaldomain.com/F2/AppManifest'
	                                        }
	                                    ];
	                                    
	                                    F2.init();
	                                    F2.registerApps(arConfigs);

Apps with predefined manifests.

// Traditional f2 app configs
	                                    var arConfigs = [
	                                        {appId: 'com_externaldomain_example_app', context: {}},
	                                        {appId: 'com_externaldomain_example_app', context: {}},
	                                        {appId: 'com_externaldomain_example_app2', context: {}}
	                                    ];
	                                    
	                                    // Pre requested manifest responses
	                                    var arManifests = [
	                                        {
	                                            apps: ['<div>Example App!</div>'],
	                                            inlineScripts: [],
	                                            scripts: ['http://www.domain.com/js/AppClass.js'],
	                                            styles: ['http://www.domain.com/css/AppStyles.css']
	                                        },
	                                        {
	                                            apps: ['<div>Example App!</div>'],
	                                            inlineScripts: [],
	                                            scripts: ['http://www.domain.com/js/AppClass.js'],
	                                            styles: ['http://www.domain.com/css/AppStyles.css']
	                                        },
	                                        {
	                                            apps: ['<div>Example App 2!</div>'],
	                                            inlineScripts: [],
	                                            scripts: ['http://www.domain.com/js/App2Class.js'],
	                                            styles: ['http://www.domain.com/css/App2Styles.css']
	                                        }
	                                    ];
	                                    
	                                    F2.init();
	                                    F2.registerApps(arConfigs, arManifests);

removeAllApps ( )

Removes all apps from the container


removeApp (
  • instanceId
)

Removes an app from the container

Parameters:

  • instanceId String

    The app's instanceId


stringify (
  • value
  • replacer
  • space
)

Wrapper to convert an object to JSON

Note: When using F2.stringify on an F2.AppConfig object, it is recommended to pass F2.appConfigReplacer as the replacer function in order to prevent circular serialization errors.

Parameters:

  • value Object

    The object to convert

  • replacer Function | Array

    An optional parameter that determines how object values are stringified for objects. It can be a function or an array of strings.

  • space Int | String

    An optional parameter that specifies the indentation of nested structures. If it is omitted, the text will be packed without extra whitespace. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\t' or ' '), it contains the characters used to indent at each level.

Returns:

String:

The JSON string


version ( )

Function to get the F2 version number

Returns:

String:

F2 version number


Properties

Apps Object

Defined in src\apps.js:1

The apps namespace is a place for app developers to put the javascript class that is used to initialize their app. The javascript classes should be namepaced with the F2.AppConfig.appId. It is recommended that the code be placed in a closure to help keep the global namespace clean.

If the class has an 'init' function, that function will be called automatically by F2.

Example:

F2.Apps["com_example_helloworld"] = (function() {
	                                        var App_Class = function(appConfig, appContent, root) {
	                                            this._app = appConfig; // the F2.AppConfig object
	                                            this._appContent = appContent // the F2.AppManifest.AppContent object
	                                            this.$root = root; // the root DOM Element that contains this app
	                                        }
	                                    
	                                        App_Class.prototype.init = function() {
	                                            // perform init actions
	                                        }
	                                    
	                                        return App_Class;
	                                    })();
F2.Apps["com_example_helloworld"] = function(appConfig, appContent, root) {
	                                       return {
	                                           init:function() {
	                                               // perform init actions
	                                           }
	                                       };
	                                    };