Child pages
  • Tutorial - Rich Text Inline Edit

Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This is work in progress. Please do not use as reference.

This documentation refers to the latest trunk version of the Rich Text Inline Edit code. For documentation specific earlier releases, please see Previous Versions of Tutorials

This page will walk you through an example of adding the Fluid Rich Text Inline Edit component to an HTML file. For more general information about the Inline Edit API, see Rich Text Inline Edit API.

This tutorial assumes that:

  • you are already familiar with HTML, Javascript and CSS
  • you are familiar with what the Inline Edit is and does
  • now you just want to know how to add it to your file.

Tutorial: How to Use the Inline Edit

Scenario

You've created a database to keep track of your vast collection of CDs, and you're working on a web interface for it. When viewing the details of a CD, you would like to very easily add a personal review. Prone to rambling, you know you will want to add some styling to the text so it is easier to read. This tutorial will show you how to use the Fluid Rich Text Inline Edit for this.

There are four basic steps to adding the Inline Edit to your application:

  • Step 1: Add the Markup
  • Step 2: Write the script
  • Step 3: Add the Fluid library to your HTML
  • Step 4: Apply styles

The rest of this tutorial will explain each of these steps in detail.

On This Page
Still need help?

Join the infusion-users mailing list and ask your questions there.


Step 1: Prepare your markup

Let's assume that you're working with some HTML that displays the information about a CD in your collection - something simple like this:

<h1>Album Details</h1>

<h2>Artist</h2>
Portishead

<h2>Album</h2>
Third

<h2>Year</h2>
2008

<h2>Label</h2>
Universal Music

<h2>Review</h2>
<p>After a hiatus, <strong>Portishead</strong> is back with their first studio 
album in 6 years. <em>Third</em> brings back the familiar and
the new, and none of this is best exemplified than in the track
<em>Machine Gun</em>.</p>

<p>It seems that regardless of how <strong>Portishead</strong> sounds now, the one
thing that has stayed constant is their refusal to be ordinary.</p>

In a browser window, this might look something like this:

Unable to render embedded object: File (inline-edit-1.jpeg) not found.

The Changes

The simplest way to make many pieces of text editable requires you to do three things:

  1. mark the elements you want to be editable with the default CSS selector class, "flc-inlineEditable"
  2. wrap the actual editable text with an element * with a CSS class of "text"
  3. tell the Inline Edit about the container of these elements.

If we want to make, say, all of the album titles editable, then we could

  1. add the "flc-inlineEditable" class to those <td> elements
  2. wrap the text in those <td> elements in a <span> * with the text class
  3. place a unique ID on the <table> element.

This might look like the HTML sample to the right.

<table id="catalog-table">
  <tr>
    <th>Artist</th>
    <th>Album</th>
    <th>Year</th>
  </tr>
  <tr>
    <td>Bootsy Collins</td>
    <td class="flc-inlineEditable">
      <span class="flc-inlineEdit-text">Ultra Wave</span>
    </td>
    <td>1980</td>
  </tr>
  <tr>
    <td>New York Dolls</td>
    <td class="flc-inlineEditable">
      <span class="flc-inlineEdit-text">One Day It Will Please Us
                         To Remember Even This</span>
    </td>
    <td>2006</td>
  </tr>
  ...
</table>

That's all - these are the only changes you need to make to your HTML.

* The editable text needs to be wrapped in its own element because this element will be hidden, and replaced with an edit field, when the text is edited. If, in your HTML, you already have an element wrapping your text (for example a <p> or a <div>), you could simply add the text class to that. In this example, we can't add the class to the <td> elements because you can't just hide a table cell and replace it with an edit field, can you? That wouldn't leave you with a valid table.


Step 2: Write the script

The script needed to instantiate the Inline Edit components will look like this:

jQuery(document).ready(function () {
    fluid.inlineEdits("#catalog-table");
});

This function will look inside the element with the "catalog-table" ID (in this case, your <table> element) for anything with the flc-inlineEditable class, and convert everything it finds into an Inline Edit field.

By putting the initialization function inside the jQuery(document).ready() call, you ensure that all of your markup is ready before you try to initialize the Inline Edit components.

This script can be placed in a <script> block at the end of your document.


Step 3: Add the Fluid library to your HTML

You'll need to add the Fluid library to you HTML file. In the header of the file, link to the Javascript files with <script> tags:

<script type="text/javascript" src="infusion-1.0/InfusionAll.js"></script>

NOTE 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. This would look like this:

<script type="text/javascript" src="infusion-1.0/lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.core.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/jquery.keyboard-a11y.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/Fluid.js"></script>
<script type="text/javascript" src="infusion-1.0/components/inlineEdit/js/InlineEdit.js"></script>

But all of these individual files are not necessary to make it work - the InfusionAll.js file has everything you need.

So that's it! That's all you need to do to add the Inline Edit functionality to your table cells.

BUT: If you look at the file in a browser now, it doesn't look any different than it looked before - there's no way to tell that the album titles are editable. That's what the styles are for.


Step 4: Apply styles

The Inline Edit component can be skinned "out of the box" by including the Fluid Skinning System (FSS) CSS skin files. Just be sure to put the following in you document:

<link rel="stylesheet" type="text/css" href="framework/fss/css/fss-layout.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.hc.css" />
<link rel="stylesheet" type="text/css" href="components/inlineEdit/css/InlineEdit.css" />

and to attatch a class attribute that represents the skin you want to the components container, such as:

<div id="catalog-table" class="fl-theme-mist">
    ...
</div>

The above code would make use of the fss-theme.mist.css skin file.

If you wish to define your own styles instead, use the following information:

The Inline Edit adds classes to the display text element that can be used to style the element to let users know that the text is editable - that is, to make the functionality 'discoverable.' These classes are applied at various 'interesting moments,' for example when the cursor hovers over the editable text, or when Tab key is used to move focus to the text.

Important note

The visual appearance of the styles in the example below are just that: examples. You are free to create whatever styles you like. The important thing to understand is

  • what the interesting moments are, and
  • what the names of the styles for those moments are

The styles that are applied by the Inline Edit, and the 'interesting moments' they are used for, are:

Style: "fl-inlineEdit-invitation"
When: mouse hover and keyboard focus
Why: so that users can know that the text is editable

Sample style:

.fl-inlineEdit-invitation {
   background-color: #FFECB3 !important;
   border: 1px solid #CCC !important;
}

Style: "fl-inlineEdit-focus"
When: keyboard focus on the text
Why: so that users know that focus is on the text, and that they can press Enter to start editing

Sample style:

.fl-inlineEdit-focus {
    border: 2px solid #777777;
}

If we add a stylesheet with these styles, the table will look like this when the mouse hovers over the album titles:

Unknown macro: {center}

Unable to render embedded object: File (inline-edit-2.jpeg) not found.


  • No labels