
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-layout.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-text.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-hc.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-hci.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-mist.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-rust.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-coal.css" />
<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-theme-slate.css" />
<link rel="stylesheet" type="text/css" href="components/uiOptions/css/UIOptions.css" />
<link rel="stylesheet" type="text/css" href="components/uiOptions/css/Slider.css" />
<script type="text/javascript" src="InfusionAll.js"></script>
<script type="text/javascript" src="myInit.js"></script>
{code}
{color:red}NOTE{color} that the {{InfusionAll.js}} file is minified - all of the whitespace has been removed, so it isn't really human-readable. If you're using the source distribution and you want to be able to debug the code, you'll want to include each of the required files individually. Instead of including InfusionAll.js you would include this:
{include:UI Options Dependencies}
But all of these individual files are not necessary to make it work - the {{InfusionAll.js}} file has everything you need.
If you now load your {{home.html}} file in a browser you will see the sample content.
----
{anchor: step3}
h2. Step 3: Write the script to create a UI Enhancer
You'll need to create a file, say {{myInit.js}}, to contain your initialization script.
UI Options depends upon UI Enhancer and requires that a UI Enhancer is already on the page. So the first thing we will do is write a function to initialize the UI Enhancer.
When initializing the UI Enhancer it is important that we set the defaults that we want our site to display with, otherwise the default appearance of our site may be altered by the UI Enhancer. The defaults are set using the FSS and numeric and boolean values. See the [UI Enhancer API] for details about the [defaultSiteSettings|UI Enhancer API#Options] options. In this example, our site is based on the FSS theme 'mist', and uses bold, underlined links as the defaults.
The UI Enhancer has a [Table of Contents |Table of Contents API] subcomponent that has its own options. One of its options is an URL from which the template for a table of contents will be loaded. You will likely need to override the default URL as is done below.
{code:javascript}
(function ($, fluid) {
//initialize the UI Enhancer
var initUIEnhancer = function () {
var enhancerOpts = {
defaultSiteSettings: {
theme: "mist",
linksBold: true,
linksUnderline: true
},
tableOfContents: {
options: {
templateUrl: "components/tableOfContents/html/TableOfContents.html"
}
}
};
return fluid.uiEnhancer(document, enhancerOpts);
};
})(jQuery, fluid);
{code}
We still need to call our initialization function but we must ensure the document is ready. This is accomplished in the document ready block below.
{code:javascript}
(function ($, fluid) {
//initialize the UI Enhancer
var initUIEnhancer = function () {
var enhancerOpts = {
defaultSiteSettings: {
theme: "mist",
linksBold: true,
linksUnderline: true
},
tableOfContents: {
options: {
templateUrl: "components/tableOfContents/html/TableOfContents.html"
}
}
};
return fluid.uiEnhancer(document, enhancerOpts);
};
//as soon as web document is loaded, initialize the UI Enhancer
$(document).ready( function () {
initUIEnhancer();
});
})(jQuery, fluid);
{code}
If you reload the {{home.html}} page, you will see that the default styles have been applied.
----
{anchor: step4}
h2. Step 4: Write the script to create a UI Options
Now create an initialization function for the UI Options component. The first parameter to the {{fluid.uiOptions}} is the container DOM element {{uiOptions}}, which can be found on the UI Options template. The second parameter is our default options for the UIOptions component - we need to specify the URL to content for the preview pane.
{code:javascript}
//initialize UI Options component
var initUIOptions = function () {
return fluid.uiOptions(".uiOptions");
};
{code}
Currently you need to load the UI Options template yourself although this will be fixed in [FLUID-2616|http://issues.fluidproject.org/browse/FLUID-2616]. Use jQuery to [load|http://docs.jquery.com/Ajax/load] the section of the template that is required - the form with the {{uiOptions}} class on it. The template is loaded into the DOM node identified by #myUIOptions in {{home.html}}. Use [jQuery to find this node|http://docs.jquery.com/Core/jQuery#expressioncontext].
{code:javascript}
//load the UI Options component
var loadUIOptions = function () {
var urlSelector = "components/uiOptions/html/UIOptions.html .uiOptions";
uiOptionsNode.load(urlSelector, initUIOptions);
};
{code}
Don't forget to define {{uiOptionsNode}} and call {{loadUIOptions}} in your document ready block. You should also declare {{uiOptionsNode}} at the beginning so its available to other functions. When you are finished your code will look something like this:
{code:javascript}
(function ($, fluid) {
var uiOptionsNode;
//initialize the UI Enhancer
var initUIEnhancer = function () {
var enhancerOpts = {
defaultSiteSettings: {
theme: "mist",
linksBold: true,
linksUnderline: true
},
tableOfContents: {
options: {
templateUrl: "components/tableOfContents/html/TableOfContents.html"
}
}
};
return fluid.uiEnhancer(document, enhancerOpts);
};
//initialize UI Options component
var initUIOptions = function () {
return fluid.uiOptions(".uiOptions");
};
//load the UI Options component
var loadUIOptions = function () {
var urlSelector = "components/uiOptions/html/UIOptions.html .uiOptions";
uiOptionsNode.load(urlSelector, initUIOptions);
};
//as soon as web document is loaded, initialize the UI Enhancer
$(document).ready(function () {
//use JQuery to find the dom node represented by myUIOptionsSelector
uiOptionsNode = $("#myUIOptions"); //selector in which to load ui options
initUIEnhancer();
loadUIOptions();
});
})(jQuery, fluid);
{code}
Reloading the {{home.html}} file will show the UI Options component on the page. Note that the preview window has not loaded.
----
{anchor: step5}
h2. Step 5: Create the preview
h3. Using the default preview
The preview for UI Options is displayed within an IFrame. There is a default preview file that ships with Fluid Infusion - if you want to use this preview, simply copy {{components/uiOptions/UIOptionsPreview.html}} into the same directory as {{home.html}} and it will be loaded into the IFrame. Note that for the preview to work it will need access to the CSS files that are linked to in the head of the {{UIOptionsPreview.html}} file. Ensure that these have the correct paths.
Another option, instead of copying the default file to another directory, is to specify any file as an option called "previewTemplateUrl". Options are sent as the second parameter when calling the UIOptions component, so setting the preview template url would work like this:
{code:javascript}
//initialize UI Options component
var initUIOptions = function () {
var options = {
previewTemplateUrl: "components/uiOptions/html/UIOptionsPreview.html"
};
return fluid.uiOptions(".uiOptions", options);
};
{code}
h3. Guidelines for building a custom preview
It is more likely that you will want the preview to contain something that better reflects your site. For a preview to be an accurate portrayal of how UI Options can alter your site, it's important to use a variety of different markup tags. Don't just take a paragraph of plain text from one page as your preview - rather, try to include headings, links, form controls, graphics, lists, and tables for a more complete site preview.
Create a file with sample content called "mypreview.html" in the same directory as home.html. Alter your UI Options initialization function as follows to implement your preview:
{code:javascript}
//initialize UI Options component
var initUIOptions = function () {
var options = {
previewTemplateUrl: "mypreview.html"
};
return fluid.uiOptions(".uiOptions", options);
};
{code}
If you reload your {{home.html}} page now, you will see the preview and be able to use the controls in the UI Options component. The UI Enhancer will remember your saved settings and apply them the next time you load this page. By default, the UI Enhancer uses a cookie to store your settings.
----
{anchor: step6}
h2. Step 6 (Optional): Use an accordian to simplify the interface
The UI Options interface can get be quite busy given all the setting controls. To simplify the interface you may want to use an accordian to hide and show parts of the UI Options form. We will use jQuery accordian plugin. If you are not using the {{InfusionAll.js}} file, you will need to load the {{ui.accordian.js}} file in the head of the {{home.html}} file.
{code:html}
<script type="text/javascript" src="lib/jquery/ui/js/ui.accordion.js"></script>