F2 Class
Root namespace of the F2 SDK
src\container.js:659
Methods
Name | Description |
---|---|
_createAppConfig
(
|
Adds properties to the AppConfig object |
_createAppInstance
(
|
Instantiates each app from it's appConfig and stores that in a local private collection |
_getAppConfigFromElement
(
|
Generate an AppConfig from the element's attributes |
_hasNonTextChildNodes
(
|
Returns true if the DOM node has children that are not text nodes |
_hydrateContainerConfig
(
|
Adds properties to the ContainerConfig object to take advantage of defaults |
_initContainerEvents ( ) private | Attach container Events |
_isInit ( ) private | Has the container been init? |
_isPlaceholderElement
(
|
Checks if an element is a placeholder element |
_validateApp
(
|
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
(
|
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
(
|
Search for a value within an array. |
init
(
|
Initializes the container. This method must be called before performing any other actions in the container. |
isInit ( ) | Has the container been init? |
isLocal
(
|
Tests a URL to see if it's on the same domain (local) or not |
isNativeNode
(
|
Utility method to determine whether or not the argument passed in is or is not a native dom node. |
loadApp
(
|
Loads the app's html/css/javascript |
loadPlaceholders
(
|
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
(
|
A utility logging function to write messages or objects to the browser console. This is a proxy for the |
parse
(
|
Wrapper to convert a JSON string to an object |
registerApps
(
|
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
(
|
Removes an app from the container |
stringify
(
|
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
Adds properties to the AppConfig object
Parameters:
-
appConfig
F2.AppConfigThe F2.AppConfig object
Returns:
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:
-
appConfigs
ArrayAn array of F2.AppConfig objects
_getAppConfigFromElement
(
-
node
)
private
Generate an AppConfig from the element's attributes
Parameters:
-
node
ElementThe DOM node from which to generate the F2.AppConfig object
Returns:
The new F2.AppConfig object
_hasNonTextChildNodes
(
-
node
)
private
Returns true if the DOM node has children that are not text nodes
Parameters:
-
node
ElementThe DOM node
Returns:
True if there are non-text children
_hydrateContainerConfig
(
-
containerConfig
)
private
Adds properties to the ContainerConfig object to take advantage of defaults
Parameters:
-
containerConfig
F2.ContainerConfigThe F2.ContainerConfig object
_initContainerEvents ( ) private
Attach container Events
_isInit ( ) private
Has the container been init?
Returns:
True if the container has been init
_isPlaceholderElement
(
-
node
)
private
Checks if an element is a placeholder element
Parameters:
-
node
ElementThe DOM element to check
Returns:
True if the element is a placeholder
_validateApp
(
-
appConfig
)
private
Checks if the app is valid
Parameters:
-
appConfig
F2.AppConfigThe F2.AppConfig object
Returns:
True if the app is valid
_validateContainerConfig ( ) private
Checks if the ContainerConfig is valid
Returns:
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
StringThe namespace to create. Pass a falsy value to add properties to the F2 namespace directly.
-
obj
ObjectThe object to copy into the namespace.
-
overwrite
BoolTrue if object properties should be overwritten
Returns:
The created object
getContainerLocale ( )
Gets the current locale defined by the container
Returns:
IETF-defined standard language tag
getContainerState ( )
Gets the current list of apps in the container
Returns:
An array of objects containing the appId
guid ( )
Generates a somewhat random id
Returns:
A random id
inArray
(
-
value
-
array
)
Search for a value within an array.
Parameters:
-
value
ObjectThe value to search for
-
array
ArrayThe array to search
Returns:
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:
-
config
F2.ContainerConfigThe configuration object
isInit ( )
Has the container been init?
Returns:
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:
Whether the URL is local or not
isNativeNode
(
-
testObject
)
Utility method to determine whether or not the argument passed in is or is not a native dom node.
Parameters:
-
testObject
ObjectThe object you want to check as native dom node.
Returns:
Returns true if the object passed is a native dom node.
loadApp
(
-
appConfigs
-
[appManifest]
)
private
Loads the app's html/css/javascript
Parameters:
-
appConfigs
ArrayAn array of F2.AppConfig objects
-
[appManifest]
F2.AppManifest optionalThe AppManifest object
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
ElementThe 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 | StringAn object to be logged or a
console
API method name, such aswarn
orerror
. All of the console method names are detailed in the Chrome docs. -
[obj2]
Object optional multipleAn 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
StringThe JSON string to convert
Returns:
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
ArrayAn array of F2.AppConfig objects
-
[appManifests]
Array optionalAn 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
StringThe 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
ObjectThe object to convert
-
replacer
Function | ArrayAn optional parameter that determines how object values are stringified for objects. It can be a function or an array of strings.
-
space
Int | StringAn 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:
The JSON string
version ( )
Function to get the F2 version number
Returns:
F2 version number
Properties
Apps Object
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
}
};
};