Content
The content widget supports the modularizing of content and code by breaking it into separate files which can be loaded either at load time or dynamically based on a message.
Demo
Source Code (Example)
<div id="content" control="content[src=assets/content1.html, lazy=false, args={name:'Neil Patrick Harris'}]"> </div>
Source Code (assets/content1.html)
<h5>Hello World!</h5> <p> My name is #{name}! </p>
Script Example
In this sample, a content widget with the name of 'myContent' is created with some initial properties; The source of the content, a boolean value representing the loading instruction, and an object of name value pairs which will be used to supplant the tokens in the content file.
Create the control…
App.createControl( 'myContent', 'content', { 'src':'myFile.html', lazy:false, args:'{name:"judy"}' }, function() { } );
Get the handle to an instance of the control…
App.getControl('myContent','content',function() { alert('foo'); });
Options
The content widget is made up of a container div and a single level of divs within that container which will constitute it's rows when it is rendered. The control tag on the div indicates what kind of widget the div will become. The widget identity can accept the following initial parameters…
Initial options supported by the widget.
| Option | Description | Default | Type |
|---|---|---|---|
| src | The source for the content file to load. | null | String |
| args | Used to replace text in the content file. | null | String |
| lazy | Indicates whether the content file should be lazy loaded. | false | Bool |
| onload | Fire this message when content file is loaded. | null | String |
| onfetch | Fire this message when content file is fetched but before being loaded. | null | String |
Actions/JavaScript API
Functions either accept a single argument such as an integer or a string, otherwise they accept a one dimensional object literal. Any function that can be called as an action accepts the same parameters but in the action parameter format.
| Function | Action | Description |
|---|---|---|
| load(obj) | render | Loads the content from a specified url. If this function is called as an action, the url is retrieved from the message that invoked it or as a parameter. |
| execute(obj) | execute | Refreshes the content using the initial settings, and any additional that are specified from a either a message or an object. |