Show:

F2 Class

Root namespace of the F2 SDK

Methods

Name Description
_absolutizeURI (
  • base
  • href
)
private

Abosolutizes a relative URL

_afterAppRender (
  • appConfig
  • html
)
deprecated private

Appends the app's html to the DOM

_appRender (
  • appConfig
  • html
)
deprecated private

Renders the html for an app.

_beforeAppRender (
  • appConfig
)
deprecated private

Rendering hook to allow containers to render some html prior to an app loading

_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

_initAppEvents ( ) private

Attach app events

_initContainerEvents ( ) private

Attach container Events

_isInit ( ) private

Has the container been init?

_isPlaceholderElement (
  • node
)
private

Checks if an element is a placeholder element

_onScriptLoadFailure (
  • appConfig
  • scriptInfo
)
deprecated private

Handler to inform the container that a script failed to load

_parseURI (
  • url
)
private

Parses URI

_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?

isLocalRequest (
  • url
)

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

isNativeDOMNode (
  • 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.

loadSecureApp (
  • appConfig
  • appManifest
)
private

Loads the app's html/css/javascript into an iframe

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

_absolutizeURI (
  • base
  • href
) private

Defined in sdk\src\F2.js:39

Abosolutizes a relative URL

Parameters:

  • base e.g., location.href
  • href URL to absolutize

_afterAppRender (
  • appConfig
  • html
) deprecated private

Defined in sdk\src\container.js:14

Deprecated: This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0

Appends the app's html to the DOM

Parameters:

  • appConfig F2.AppConfig

    The F2.AppConfig object

  • html String

    The string of html

Returns:

Element:

The DOM Element that contains the app


_appRender (
  • appConfig
  • html
) deprecated private

Defined in sdk\src\container.js:41

Deprecated: This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0

Renders the html for an app.

Parameters:

  • appConfig F2.AppConfig

    The F2.AppConfig object

  • html String

    The string of html


_beforeAppRender (
  • appConfig
) deprecated private

Defined in sdk\src\container.js:62

Deprecated: This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0

Rendering hook to allow containers to render some html prior to an app loading

Parameters:

Returns:

Element:

The DOM Element surrounding the app


_createAppConfig (
  • appConfig
) private

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

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:


_initAppEvents ( ) private

Attach app events


_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


_onScriptLoadFailure (
  • appConfig
  • scriptInfo
) deprecated private

Defined in sdk\src\container.js:76

Deprecated: This has been replaced with {{#crossLink "F2.AppHandlers"}}{{/crossLink}} and will be removed in v2.0

Handler to inform the container that a script failed to load

Parameters:

  • appConfig F2.AppConfig

    The F2.AppConfig object

  • scriptInfo Object

    The path of the script that failed to load or the exception info for the inline script that failed to execute


_parseURI (
  • url
) private

Defined in sdk\src\F2.js:76

Parses URI

Parameters:

  • url The URL to parse

_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 ( )

Defined in sdk\src\F2.js:102

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


extend (
  • ns
  • obj
  • overwrite
)

Defined in sdk\src\F2.js:150

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 ( )

Defined in sdk\src\F2.js:190

Generates a somewhat random id

Returns:

String:

A random id


inArray (
  • value
  • array
)

Defined in sdk\src\F2.js:202

Search for a value within an array.

Parameters:

  • value Object

    The value to search for

  • array Array

    The array to search

Returns:

Bool:

True if the item is in the array


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


isLocalRequest (
  • url
)

Defined in sdk\src\F2.js:212

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 Derived from: https://github.com/jquery/jquery/blob/master/src/ajax.js


isNativeDOMNode (
  • testObject
)

Defined in sdk\src\F2.js:256

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


loadSecureApp (
  • appConfig
  • appManifest
) private

Loads the app's html/css/javascript into an iframe

Parameters:


log (
  • Object/Method
  • [obj2]
)

Defined in sdk\src\F2.js:275

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
)

Defined in sdk\src\F2.js:331

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
)

Defined in sdk\src\F2.js:340

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 ( )

Defined in sdk\src\F2.js:361

Function to get the F2 version number

Returns:

String:

F2 version number


Properties

Apps Object

Defined in sdk\src\F2.js:114

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
       }
   };
};