Ajax Bestiary: A Javascript Field Guide
 
Ajax Bestiary: A Javascript Field Guide
 
 

Entries Tagged as 'jQuery'

jQuery Corners

Posted by Don Albrecht

Proto Corner

I covered the Prototype port of this plugin a while ago, but recently realized that I had neglected to cover the original version. jQuery corners is an excellent library for adding quick corner effects to your pages in a graceful and unobtrusive way.

Here are some highlights of the plugin’s capabilities:

  • A whole slew of effects is available.
  • The width and height of the adornment area can be changed to vary the effect.
  • You can apply different effects to top and bottom corners, or apply an effect to specific corners.
  • Boxes to be adorned are selected using the standard JQuery $() element selector function.
  • No special markup is required; display falls back to unadorned corners when Javascript is off.
  • You can define your own custom corner effects that the plugin will use.

Learn more about the plugin at
http://www.methvin.com/jquery/jq-corner.html

Flot 0.2 Released

Posted by Don Albrecht

Ole Larson has released a new version of Flot:
Key Changes

  • Added support for putting a background behind the default legend.
    The default is the partly transparent background color. Added
    backgroundColor and backgroundOpacity to the legend options to control
    this.
  • The ticks options can now be a callback function that takes one
    parameter, an object with the attributes min and max. The function
    should return a ticks array.
  • Added labelFormatter option in legend, useful for turning the legend
    labels into links.
  • Fixed a couple of bugs.
  • The API should now be fully documented.
  • Patch from Guy Fraser to make parts of the code smaller.
  • API changes: Moved labelMargin option to grid from x/yaxis.

Most notably, the new packaging includes the modified excanvas script in the zip download to greatly simplify deploying with IE support.

Read about it here:

http://ole-laursen.blogspot.com/2007/12/flot-02-released.html 

24 Hours with Flot

Posted by Don Albrecht

flot2.pngAlright, So Flot 0.1 has been out in the wild for just under 2 days now and it’s gotten some pretty decent traction with the Ajax blogs.  I’ve taken some time over the past 24 hours to work with the library and I have to say, It’s pretty awesome. Highlights:  

  • The presets really are excellent , simple charts are very little work.
  • The charts look great, the integrated support for shadows & alpha channels really makes them shine
  • The underlying architecture is excellent.  I’ve been able to get under the hood and add needed features without any major headaches. 
  • jQuery based

Shown: A chart created with a modified version of Flot with normal range highlighted. You can get flot at: http://code.google.com/p/flot/

Coda Slider 1.1.1 Has Landed

Posted by Don Albrecht

Coda 1.1.1

Niall Doherty just released a minor update to the powerful & sexy jQuery CodaSlider widget. The version 1.1.1 release increases the visual styling capabilities of the widget by adding more css support.

Not a major update, but the drop in nature and dramatically increased styling ability make this an obvious addition to any projects currently using the widget.

Get it at ndoherty.com:

Handling Nested Clicks with jQuery Revisited

Posted by Don Albrecht

Yesterday, I posted instructions for handling a series of nested clicks with jquery. Today I’m going to follow up that post with a more sophisticated solution to handle a corner case we discovered in testing. I will be rehashing some but not all of yesterdays solution in this tutorial, but you may want to review it.

The problem:

We have nested clickable divs created by using the jQuery $().click( function … ) function. If the user clicks on the nested div, the click event fires for the parent div as well. Since this isn’t traditional event bubbling, we aren’t able to restrict the event to the innermost div by returning false from the click function or using event.stopPropagation(); & event.cancelBubble = true;.

We handled this yesterday by the simple expedience of using a status flag to verify that a child div hasn’t already been clicked on and erasing the status flags globally when ever an element is selected. This works beautifully for most cases, unfortunately it makes it impossible to select the parent of a previously selected element.

The Solution:

We needed to build a solution that could deal with 5 cases:

  1. Target div is innermost clicked div
  2. Target div is not innermost clicked div but selection hasn’t been processed for innermost clicked div
  3. Target div is not innermost clicked div and selection has been processed for innermost clicked div
  4. Target div is innermost clicked div and parent of previously selected div
  5. Target div is child of innermost clicked div and was previously selected.

Our previous solution handled cases 1 - 3 well. We now need a fix for cases 4 & 5. We accomplish this by providing a tracking a bit more information than the selected / not selected flag. We declare a global variable clickedDivStack that maintains an array of the currently selected div & its ancestors.

First we determine if the target is the innermost div of a selected stack (none of its children have the selected flag set on them). In this case, we know we don’t have to worry about situations 4 & 5 so we simply set the div as selected. Then we reset the clickedDivStack array to contain only the target.

if (!$(target).find(".selected").size()) {
$('.selected').removeClass("elected");
$(target).addClass("selected");
clickedDivStack = [target];
return; }

Next, we check for case 4 & 5 by comparing the target to the contents of the clickedDivStack Array. If the length of the array is greater than 1 & the target is already in the array, we know that this was an attempt to click on the parent of a previously selected element & the current target is the innermost div of the new selection. We can then process this as a new innermost selection and return.

for (var i = 1; i < selecteddiv.length; i++) {
if (selecteddiv[i] == target) {
$('.selected').removeClass("elected");
$(target).addClass("selected");
clickedDivStack = [target];
return; }}

If the target is not a new innermost selection, it must be a parent div. Since we need to track parent divs, we add it to the array of parent divs.

clickedDivStack = [target];
return;

It’s a bit more complex, but the perfomance is excellent and it smoothly handles the click selection of divs, even coping with nested elements in all corner cases found.

Handling Nested Clicks With jQuery.

Posted by Don Albrecht

Alright, so here’s the problem. I need to apply the ability to select any div inside an ajax app. Including divs nested inside other nestable divs. ex.

<div id="outer" class="clickable">
<div id="inner" class="clickable"></div>
</div>

In jQuery, if I simply call $('.clickable').click(...); I wind up with a click event that fires twice when inner is clicked. Once with target inner and once with target outer. Since I only care about the inner most div selected, I need some way to ignore the click event on the outer div.

I achieve this by assigning an attribute to the currently selected div. In the case of my most recent project, I was able to piggyback on a class change, but any attribute would do.

Step 1: Determine if this is the innermost selected div

There are two possible scenarios for any target div. It is either the innermost clicked div or it isn’t. If it isn’t the innermost div it will either already have a child div with a set “selected” attribute or it won’t. If it has a selected child div, we escape.

if ($(target).find(".selected").size() ) { return; }

Otherwise, we remove all elements with set selected attributes and set the selected attribute for the target div.

$('.selected').removeClass( "selected");
$(target).addClass( "selected" );

Note: If the containing div was the first processed, we don’t have a problem because we will clean up the current selection when the function is called on the innermost div.

The system is working like a charm for me in my current project.  If anyone knows a more efficient way to do it, please share it in the comments below.

Smart Area: A Lightweight Resizing Text Area Plugin for jQuery

Posted by Don Albrecht

Here’s a quick and dirty little jQuery plugin to create text areas that automatically resize.

I based it off of Richard McMahon’s Prototype Version

jQuery.fn.smartArea = function (){

return this.each(function() {
if (!jQuery(this).is("textarea")) {
return false;
}

jQuery(this).click( function(){
jQuery.SA.resizeArea( this ); } )
.keyup( function(){
jQuery.SA.resizeArea( this ); } );
return this;

});

}

jQuery.SA = {
resizeArea : function ( t ) {

var lines = t.value.split('\n') || [];
var newRows = lines.length;
var oldRows = t.rows;
for (var i = 0; i < lines.length; i++)
{ var line = lines[i]; if (line.length >= t.cols) newRows += Math.floor(line.length / t.cols);
}
if (newRows > t.rows) t.rows = newRows;
if (newRows < t.rows) t.rows = Math.max(1, newRows);

}
}

New Version of Layout Tool Posted

Posted by Don Albrecht

It’s up,  I’ve posted a new version of the Blueprint Layout tool to:

 http://www.ajaxbestiary.com/Labs/BLT2/index.htm

You can view my earlier post to see what’s new and different with this version:

http://www.ajaxbestiary.com/2007/11/13/blueprint-layout-tool-progress/ 

Please post any feedback you might have below.

Blueprint Layout Tool Progress

Posted by Don Albrecht

Blueprint Layout Tool 0.2

I’ve been working on a new version of the blueprint layout tool over the past few days.  In order to build a foundation for the eventual goal of a wysiwyg, drag & drop editor with semantic markup  I’ve needed to refactor the code & change several behaviors.

Current Status 

  • Updated entire engine to Blueprint 0.6
  • Ported application from YUI to jQuery
  • Implemented multi-select capabilities
  • Replaced  nested sorting of elements with explicit group & ungroup functionality
  • Added functionality to set & remove “.last” class on columns
  • Added Ghosting to sort functionality.

Going forward:

I hope to have the new version posted some time tonight.  I hope to assimilate any major bug fixes & the blueprint grid generator into the next release.  Then I’ll be working on semantify integration.

A Lightweight Rich Text Editor in jQuery

Posted by Don Albrecht

jQuery RTE

As excellent as Xinha, YUI RTE, Tiny MCE, FCK & the other heavyweight Rich Text Widgets are, they can be massive overkill for many projects Weighing in at only 7k (uncompressed). This jQuery Editor is an incredibly light weight and responsive alternative to the big guns for most projects.

Features:

  • Stylesheet based formatting
  • Image support
  • Link Support
  • Strong, emphasis
  • Bulleted list
  • Source view

Supported Browsers

  • IE6+
  • Safari 3+
  • Firefox
  • Opera

Check it out online here:

http://batiste.dosimple.ch/blog/posts/2007-09-11-1/rich-text-editor-jquery.html