Archive for the “yui” Category


Users are more likely to complete your web forms if you provide a simple help system to answer common questions to complete each input. There are a couple of common techniques to provide help for individual form inputs…

  • Help text under the form inputs - often too limited in space and/or clutters the form too much to provide detailed help
  • Clickable help icons next to the form elements - can either show the help when moused over or when clicked but either way require an additional action from the user to see the help

I prefer to show a help tooltip automatically to the right of the input when an input gains the focus. Unlike normal tooltips, the tooltip remains visible as long as the input has the focus allowing the user to refer back to the tooltip as needed while entering the input. Tab through each field in the form below to see this in action…

The tooltips in the form above are implemented using YUI in a Javascript class call YFormTip. Both the formtip-example.html and the yformtip.js are available to download free of course.

None of this is rocket science but it is my $0.02 on providing context sensitive help for web forms.

Comments 2 Comments »

You can now reduce the number of HTTP requests to serve all the YUI javascript dependendices to a single HTTP request. As an example, we just updated our Web Speed Check to use a single HTTP request to load all the YUI javascript dependencies using the new YUI combo loader…

<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.5.2/build/yahoo-dom-event/yahoo-dom-event.js&2.5.2/build/animation/animation-min.js&2.5.2/build/connection/connection-min.js&2.5.2/build/element/element-beta-min.js&2.5.2/build/datasource/datasource-beta-min.js&2.5.2/build/datatable/datatable-beta-min.js"></script>

This replaced the following code…

<script src="http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/animation/animation-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/connection/connection-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/element/element-beta-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/datasource/datasource-beta-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/datatable/datatable-beta-min.js"></script>

So, we’ve reduced from making six HTTP requests to making a single HTTP request to load the YUI javascript dependencies and this reduces the total page load time. Thanks to Eric Miraglia for this tip.

Comments 5 Comments »

Overview

Show a green highlight that fades away on a table row when a new record is added by a user. Add a pulsing yellow glow to a button you want the user to press next. With this open source YPulse library and YUI, both are easy to implement.

Example

View this example code here.

While both example above pulse the background color, YPulse can oscillate any attribute. So, you might use YPulse to oscilatte the opacity to make an object flash on and off the page.

Browser Support

The YPulse library should work with all the major browsers supported by YUI but has not been tested extensively.

Usage

You will need to upload ypulse.js to your webserver and you will need something like this on you page…

<div id=”my-div”>This is the element I want to pulse.</div>

<script type=”text/javascript” src=”http://yui.yahooapis.com/2.5.2/build/yahoo-dom-event/yahoo-dom-event.js”></script>
<script type=”text/javascript” src=”http://yui.yahooapis.com/2.5.2/build/animation/animation-min.js”></script>
<script type=”text/javascript” src=”ypulse.js”></script>
<script>

var pulser = new YAHOO.squarebits.YPulse(
‘my-div’,
‘backgroundColor’,
‘#FFFFFF’,
‘#FFFF00′,
0.75,
0.10,
0.75,
0.75,
YAHOO.util.Easing.easeBoth,
YAHOO.util.Easing.easeBoth
);

Syntax

The YPulse constructor supports the following parameters…

  • elem - The DOM element or element ID to pulse (like ‘my-div’)
  • attributeName - The name of the attribute to change (like ‘backgroundColor’)
  • startingValue - The starting value of the attribute (like ‘#FFFFFF’)
  • endingValue - The name of the attribute to change (like ‘#FF0000′)
  • s2eDuration - The number of seconds for the start-end transition
  • s2eWait - The number of seconds to wait after completing the start-end transition
  • e2sDuration - The number of seconds for the end-start transition
  • e2sWait - The number of seconds to wait after completing the end-start transition
  • s2eMthod - The YAHOO easing method to use for the start-end transition
  • e2sMthod - The YAHOO easing method to use for the end-start transition

A YPulse instance object supports two methods…

  • go(repeat) - Starts the pulse and executes the pulse for the specified repeat count. If repeat is omitted, the pulse never stops. If repeat is set to 1, only the start-end transition is done. If repeat is set to 2, the start-end transition and end-start transition are done
  • stop() - Stops a running pulse

Download

You can download YPulse here: YPulse.

Comments 10 Comments »

We recently launched the Instant Website Speed Check and used the Yahoo User Interface (YUI) libraries extensively to build the client. Specifically, we used the following components from the YUI library…

  • YUI DataTable - Used to display the latency test results.
  • YUI Connection Manager - Used to execute the AJAX calls to the server to start testing and to poll for test results
  • YUI Reset/Fonts/Base/Grids CSS - Used to provide a foundation to layout the page and elements on the page consistently across browsers.

This is my second project using YUI and I’m still climbing the learning curve. This blog entry reflects the point of view of someone still learning YUI versus an expert explaning the best way to use YUI.

The YUI DataTable is a relatively complex control with lots of options. While I would use the DataTable again on a project, I often find it frustrating finding out how to accomplish simple things. For example, I had trouble figuring out how to update a cell in the table — I ended up writing the following javascript method to update a table cell…

// Updates a cell in a YUI DataTable
//   record - The instance of YAHOO.util.Record that should be updated
//   fieldName - The key name of a column in the YUI DataTable
//   value - The new value for the cell
function updateCellValue(record, fieldName, value) {
  var column = _dataTable.getColumn(fieldName);
  var cellRef = {record:record, column:column};
  var cell = _dataTable.getTdEl(cellRef);
  _dataTable.getRecordSet().updateRecordValue(record, fieldName, value);
  _dataTable.formatCell(cell.firstChild, record, column);
}

I’m guessing I jumped through some unnecessary hoops to update a cell but I really couldn’t find a better way after 30 minutes of reviewing the YUI API Documentation. Overall, I found the YUI documentation and examples to be excellent although I struggled to find a better way to update a cell in this case.

The YUI Connection Manager was quite straightforward and easy enough to implement. With the Connection Manager, you simply make a call to YAHOO.util.Connect.asyncRequest passing in GET/POST, passing in the URL, passing in a callback object with success and failure handlers, and passing in the post data. Here is the javascript method that initiates the testing…

function createInstantDataSourceSet() {
  var url = '/speed-check/index.jsp'
  var callback = {
    success: function(o) {
      var instantDataSourceSetId = o.responseText.trim();
      pollForInstantMonitorTests(instantDataSourceSetId);
    },
    failure: function(o) {
      alert('Failed: ' + o.statusText);
    }

  };
  var instantDataSourcesJson = buildInstantDataSourcesJson();
  var postData = 'step=create-instant-data-source-set';
  postData += '&instantDataSources=' + escape(instantDataSourcesJson);
  YAHOO.util.Connect.asyncRequest('POST', url, callback, postData);
}

The Connection Manager was easy enough to understand and implement — no problems there.

Regarding using the Reset/Fonts/Base/Grids CSS, this worked out extremely well as it seemed to greatly reduce the work required to tweak the UI to look consistent across the major browsers (Firefox, IE, Safari, and Opera). The client was designed in Firefox initially and then tested under IE, Safari, and Opera — there was probably just 15 minutes spent tweaking the input bar area to layout consistently across all the browsers.

Overall, we plan to continue to use YUI on future projects.

Comments 11 Comments »