Archive for the ‘Tools’ Category

jQuery Reverse Order plugin

Thursday, May 22nd, 2008

Ever want to reverse the order of a group of DOM elements? Or want to give your user the option?

What is this?

jQuery Reverse Order uses jQuery to reverse the order of DOM elements on your page.

How Do I Use It?

To use jQuery Reverse Order on your site or blog, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:

Download

The file, jquery_reverseorder.zip, contains the script, an example page, and the jQuery library. Once downloaded, unzip and upload the script to a relevant location on your hosted site.

Link To The Javascript

Add a link to the jQuery library and to the javascript file in the page(s) you’d like jQuery Reverse Order implemented. Remember to adjust the path to properly point to the location of the javascript file:

 

A packed version is also included in the .zip called "jquery_reverseorder.packed.js".

Choosing which elements to reverse

Create a collection of DOM elements inside a common parent. Here’s an example:

item 1

item 2

item 3

item 4

Then add a single line of javascript, referencing the items to be reversed, to reverse the order:

$('#items .item').reverseOrder();

You could also use:

$('#items p').reverseOrder();

Examples

Here’s another example using the native unordered list as a collection:

  • item 1
  • item 2
  • item 3
  • item 4

Then add a single line of javascript to reverse the order:

$('ul li').reverseOrder();

You can see more examples and uses of jQuery Reverse Order by clicking here.

Supported Browsers

Currently, the jQuery Reverse Order script has been tested and confirmed on the following browsers:

  • Internet Explorer 6.0+
  • Mozilla Firefox 2.0+
  • Apple Safari 2.0+
  • Opera Version 9.0

Licensing

This arc90 tool is licensed under the Creative Commons Attribution-Share Alike 3.0 license.

Discuss jQuery Reverse Order

You can send feedback on jQuery Reverse Order at the arc90 blog.

SVN Notifier

Wednesday, April 2nd, 2008

If you work with Subversion on a Mac (and you should), and especially if you’ve got Growl installed, you might be interested in SVN Notifier, the first Apple Dashboard widget to come from the Arc90 lab.

Updated 4/21/2008: Patched a security hole, and other minor enhancements. Details on the blog.

Continue reading»

Flex / AS3 Library : RESTService

Tuesday, March 25th, 2008

One of the most lamented issues in the Adobe community has been Flash Player’s lack of true HTTP support. In case that issue is unfamiliar to you, here’s the rundown: Because the Flash Player VM can run in a variety of browsers and operating systems, it was deemed too complex to try and accommodate all the various permutations of how the VM should react to the potential outcome of making an HTTP request. This situation creates something called a crippled-client.

In the Flash Player’s case, it can only handle responses of type 200, not 200 series, (e.g. 201 Created, 202 Accepted, etc.), just 200. Anything other than a 200 is treated as a 500. No message is passed to the Flash Player, instead the VM throws a completely worthless IO or Stream error. Also, regardless of the success or failure of a request, there are no response headers. Yet another issue is that request headers cannot be passed on anything other than a POST. This requires that all services must support some type of crippled-client protocol, in which every request from said client is a POST, with request headers that tell the service what the client is actually attempting to do.

The solution to this problem is to communicate directly over sockets. This is fine for requests made over HTTP, but since, until recently, Flash had no support for SSL, there was no way to make requests over HTTPS. Enter as3crypto, a cryptography library that supports SSL. Using as3crypto, we’ve developed a small library that can make fully aware HTTP requests using sockets.

There is, unfortunately, a caveat. Adobe has recently decided to make it near impossible to use sockets from web delivered applications. If you’re interested in jumping through the hoops necessary to get sockets working, be sure to let us know about your solution. AIR, however, has no such restrictions on sockets and you should be able to use the RESTService component to make fully aware HTTP requests. So have it!


What is this?

The RESTService class makes fully aware HTTP service calls. Fault and Result events contain all response headers and status messages, as well as the response body.

How Do I Use It?

To use RESTService in your Flex project, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:

Download

The file, arc90restlib.zip, contains a compiled library, the source, and ASDoc generated documentation.

Add the code to your Flex or AIR project

You can either add the compiled library, arc90restlib.swc, to your project’s library path, or include the source directly in your project.

Create a RESTService using either MXML or ActionScript.

MXML:


ActionScript:

import com.arc90.rpc.rest.RESTService;
var service:RESTService = new RESTService("http://example.url/service/");
service.contentType = RESTService.CONTENT_TYPE_XML;
service.method = RESTServiceMethod.POST;
service.resultFormat = RESTService.RESULT_FORMAT_XML;
service.request = ;
service.url = service.rootURL + "resource";
service.headers = {"x-some-header": "somevalue"};
RESTService functions just like mx.rpc.http.HTTPService, the one major difference being that it returns void when calling the send method.

In order to handle events, add event listeners to the RESTService instance.

service.addEventListener(FaultEvent.FAULT, faultHandler);
service.addEventListener(ResultEvent.RESULT, resultHandler);
service.send();
Handling Authentication

There are two ways to handle Basic HTTP Authentication.

  1. Pass an Authorization header:
    service.headers = {Authorization: "Basic "};
  2. Use the setCredentials method:
    service.setCredentials(, );

Documentation

Review the complete documentation for a full list of all properties, methods, and events exposed by RESTService.

Licensing

This arc90 tool is licensed under the Creative Commons Attribution 2.5 license.

Discuss RESTService

You can offer feedback on RESTService at the arc90 blog.

CollapsiblePanel

Monday, March 17th, 2008

The collapsible panel is a fairly simple container that pops up all over the internet. It’s great for hiding, but not losing, areas of the screen that may be unnecessary at a given moment in time. This allows the end-user to customize certain aspects of the screen to their liking.

Unfortunately, the Flex Framework doesn’t actually contain a collapsible panel. We moaned and groaned, and then built our own. Now we’re offering it to you for nothing, because, well, that’s how we roll. So, with no further ado, arc90 presents a simple solution for a simple need, CollapsiblePanel.


What is this?

A collapsible panel container that uses a mx.effects.Resize tween on collapse and expand. The developer can manipulate the appearance of the collapse button and duration of the tween. CollapsiblePanel extends the mx.containers.Panel class, so all of that class’s functionality is still available to the developer.

How Do I Use It?

To use CollapsibelPanel in your Flex project, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:

Download

The file, arc90flexlib.zip, contains a compiled library, the source, and ASDoc generated documentation.

Add the code to your Flex project

You can either add the compiled library, arc90flexlib.swc, to your project’s library path, or include the source directly in your project.

Create a CollapsiblePanel using either MXML or ActionScript.

MXML:


ActionScript:

import com.arc90.flexlib.containers.CollapsiblePanel;
var panel:CollapsiblePanel = new CollapsiblePanel();
panel.title = "Collapsible Panel";
panel.status = "This is status text.";
panel.setStyle("collapseDuration", 500);
addChild(panel);

CollapsiblePanel functions exactly like Flex’s built-in Panel class. However, there are several additions to the API.

CollapsiblePanel implements the collapsed property. This property refers to the current state of the component, collapsed or expanded. Setting the collapsed property to true will collapse the component; setting it to false will expand it.

There are also two new events:

  • minimize: Dispatched when the collapse button is clicked and the component is in its expanded state.
  • restore: Dispatched when the collapse button is clicked and the component is in its collapsed state.

Review the documentation for a complete list of all properties, methods, styles, and events exposed by CollapsiblePanel.

Example

<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);
// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasRequestedVersion ) {
// DO NOT MODIFY THE FOLLOWING FOUR LINES
// Location visited after installation is complete if installation is required
var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
var MMredirectURL = window.location;
document.title = document.title.slice(0, 47) + " - Flash Player Installation";
var MMdoctitle = document.title;
AC_FL_RunContent(
"src", "http://www.arc90.com/_assets/flash/playerProductInstall",
"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
"width", "400",
"height", "300%",
"align", "middle",
"id", "CollapsiblePanel_Example",
"quality", "high",
"bgcolor", "#869ca7",
"name", "CollapsiblePanel_Example",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else if (hasRequestedVersion) {
// if we've detected an acceptable version
// embed the Flash Content SWF when all tests are passed
AC_FL_RunContent(
"src", "http://www.arc90.com/_assets/collapsiblepanel/example/CollapsiblePanel_Example",
"width", "400",
"height", "300",
"align", "middle",
"id", "CollapsiblePanel_Example",
"quality", "high",
"bgcolor", "#869ca7",
"name", "CollapsiblePanel_Example",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "http://www.adobe.com/go/getflashplayer"
);
} else {  // flash is too old or we can't detect the plugin
var alternateContent = 'Alternate HTML content should be placed here. '
+ 'This content requires the Adobe Flash Player. '
+ 'Get Flash';
document.write(alternateContent);  // insert non-flash content
}
// -->

Licensing

This arc90 tool is licensed under the Creative Commons Attribution 2.5 license.

Discuss CollapsiblePanel

You can offer feedback on CollapsiblePanel at the arc90 blog.

JSON Lint

Thursday, January 10th, 2008

I’ve been really getting into JSON as a transfer protocol lately. Having been recently muddled in XML, the simplicity of JSON is a welcome respite.

Despite its simplicity, I’ve still seen quite a bit of poorly formed JSON around. And I had a bit of trouble finding a simple JSON Validator / Reformatter service on the web anywhere. So I decided to create my own.

Continue reading»

jQuery MultiSelect

Wednesday, November 28th, 2007

Ever want to put a whole bunch of Select drop downs that can have multiple selections into a tight area, only to have to struggle with layout issues?  Or have to put a layered div over over a Select and realize that Microsoft Internet Explorer 6 and lower will still display the Select?  Or have you just wanted a nice a clean way to select multiple options that don’t require Shift or Control clicking?

What is this?

jQuery MultiSelect leverages the power of jQuery, providing a clean way to display a drop down and allow multiple options to be selected with just the mouse and without taking up more room that you need.

With just a single line of code, jQuery MultiSelect styles up any select with a new and simple drop down. Your page will look clean and improved and your markup barely changes. It’s a win-win-win.

How Do I Use It?

To use jQuery MultiSelect on your site or blog, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:

Download

The file, jquery_multiselect.zip, contains the script, an example page, the jQuery library, and a couple of images. Once downloaded, unzip and upload the script to a relevant location on your hosted site.

Link To The Javascript

Add a link to the javascript file in the page(s) you’d like jQuery MultiSelect implemented. Remember to adjust the path to properly point to the location of the javascript file:


Choosing which selects to stylize

Style your selects normally. Here’s an example:


Add a small amount of javascript to turn a select into a jQuery MultiSelect. An example
for styling the above select (with an id of “lang”) is provided below:


$(function()
{
$('#lang').multiSelect(
{
select_all_min: 3,
no_selection: "Please select a few items!",
selected_text: " clicked"
});
});

jQuery MultiSelect currently supports the following configuration arguments:

  • select_all_min – The minimum number of elements the select must have
    before the ‘Select All’ option is provided.

  • no_selection - The message to display when no items in the select are
    toggled.

  • selected_text - The message appended to the current number of options selected.

If no arguments are passed to jQuery MultiSelect, the default values will be used:

  • select_all_min – 6
  • no_selection - No Selection
  • selected_text - Options Selected

Examples

You can see jQuery MultiSelect in action by clicking here.

Supported Browsers

Currently, the jQuery MultiSelect script has been tested and confirmed on the following browsers:

  • Internet Explorer 6.0+
  • Mozilla Firefox 2.0+
  • Apple Safari 2.0+
  • Opera Version 9.0

Licensing

This arc90 tool is licensed under the Creative Commons Attribution 2.5 license.

Discuss jQuery MultiSelect

You can send feedback on jQuery MultiSelect at the arc90 blog.

Modular

Monday, October 8th, 2007

If you’ve been beating your head against the wall trying to get Cairngorm and Modules to work together, stop now. We’ve already knocked ourselves senseless, not that we had much sense to begin with, and, flux capacitor like, come up with a solution.


What is this?

There’s been a lot of talk about using Cairngorm with Flex’s built in Module framework, and the general consensus is that it’s just not worth the effort. Here at Arc90, we use Cairngorm extensively, and until recently, had not leveraged modules. Then we found ourselves faced with the dilemma of making Cairngorm and Modules play nice. It turns out that the solution was fairly simple, as well as lightweight: we call it Modular.

Modular makes use of some great ideas that have been floating around the Flex community for awhile:

The parent application utilizes the existing Cairngorm framework, while our modules leverage Cairngorm, supplemented by Modular.

How Do I Use It?

To use Modular in your Flex projects, just follow these simple steps:

Download The Code

Click on the icon below to download the source code:

Download

The file, modular.zip, contains a compiled library, the source, and ASDoc generated documentation.

Add the code to your Flex project

You can either add the compiled library, Modular.swc, to your project’s library path, or include the source directly in your project.

Build your application by extending the classes contained in the com.arc90.modular package.

Any events that will be broadcast by the CairngormEventDispatcher should be instances of AbstractModuleEvent or a subclass:

import com.arc90.modular.AbstractModuleEvent;
public class CairngormModuleEvent extends AbstractModuleEvent
{
...
}

Extend ModuleFrontController and add commands.

import com.arc90.modular.ModuleFrontController;
public class ModuleController extends ModuleFrontController
{
public function ModuleController()
{
addCommand("doSomethingAwesome", ModuleCommand);
}
}

Extend ModuleSequenceCommand for any commands that will be chained:

import com.arc90.modular.ModuleSequenceCommand;
public class ModuleCommand extends ModuleSequenceCommand
{
...
}

Dispatch events

Use the dispatch() method of the AbstractModuleEvent class to dispatch your events.

var event:CairngormModuleEvent = new CairngormModuleEvent("doSomethingAwesome");
event.dispatch();

or, use the CairngormEventDispatcherFactory.

CairngormEventDispatcherFactory.getDispatcher(this).dispatchEvent(new CairngormModuleEvent("doSomethingAwesome"));

Licensing

This arc90 tool is licensed under the Creative Commons Attribution 2.5 license.

Discuss Modular

You can offer feedback on Modular at the arc90 blog.

Airifier

Wednesday, September 12th, 2007

With the coolness of Adobe’s AIR technology permeating the web (and your desktop). We thought we’d help bring it to the masses. Our own Avi Flax (not Flex) got his grubby little hands on the AIR SDK and wired it to a Java web app that let’s you turn any URL into a desktop application in about ten lousy seconds. Just visit Airifier.com and go to it. Note, it does require the Adobe AIR install to be on your Mac or PC.

Continue reading»

MultiSelect

Monday, July 2nd, 2007

Ever want to put a whole bunch of Select drop downs that can have multiple selections into a tight area, only to have to struggle with layout issues?  Or have to put a layered div over over a Select and realize that Microsoft Internet Explorer 6 and lower will still display the Select?  Or have you just wanted a nice a clean way to select multiple options that don’t require Shift or Control clicking?

Continue reading»

AppCache for PHP5

Tuesday, June 19th, 2007

Speed up your apps and have a convenient application-level scope with AppCache by Chris Dary, the seventh tool from the arc90 lab.


What is this?

AppCache is an implementation of an Application scope in PHP. If you’ve ever worked with Coldfusion (or ASP), you’ll know that Application-level variables are visible to an entire group of files. They’re one level above a session scope, and one level below server level variables.

As you can probably guess, this is hugely useful for all sorts of things – things like caching data, common variables, etc.

To do this, AppCache expands upon a fantastic caching system called memcached. Memcached’s intent is to speed up web applications by alleviating database load – it was originally created to enhance the speed of LiveJournal.com.

As a caveat, if you have not used an Application scope or a caching mechanism before: This data is not persistent – it’s stored in RAM, not on disk, and will be lost if the daemon is restarted or the cache expires, and therefore you should only use it for run-time stuff, which can be recreated or retrieved every time the app starts.

Why is this better than using Memcache directly?

A few reasons:

  1. In your code, usage is very clean – as simple as $app->var;
  2. Unlike Memcache itself, you have access to the list of variables defined within your app – $app->getKeys(); returns an array of all the currently defined variables. Use isset($app->var) to determine if a variable is set.
  3. No namespace worries. A key prefix is created from whatever you name the app – so you don’t have to worry about collisions with other memcache keys.
  4. The Memcache backend is abstracted – so if you end up implementing a different backend (database, shared memory, etc), this should be very simple.

Examples

Here are a few examples of what AppCache looks like in action:

A Simple Example
<?php
require 'Application.php';
// Initialize our application
$app = new Application('Sample Application Name');
// Check if our sample value is set
if( !isset( $app->sampleValue ) )
{
// If it is not set, initialize it, with the date, so that we can
// see that it is persistent amongst requests.
$app->sampleValue = "This sample value was set on " . date('r');
}
// Print our sample value
print_r($app->sampleValue);
// To remove sampleValue from our app, we would use:
// unset($app->sampleValue);
// To flush all values from the app, we would use:
// $app->clear();
// To access $app within functions and other classes, use either
// $GLOBALS['app'] or global $app;, then $app.
?>
A More Complex Example
<?php
require 'Application.php';
// Here, we pass our Application constructor an array of values for configuration.
$app = new Application(
array(
'key'				=>	'A complex Application example',
'memcached_servers'	=>	array('127.0.0.1:11211','anotherHost.com:22122'),
'memcached_prefix'	=>	'appvar_'
)
);
// Set up a cached_page variable that will expire.
if( !isset( $app->cached_page ) )
{
$page_content = array();
$page_content['header']	= '<html><head>' .
'<title>Page cached on ' . date('r') . '</title>' .
'</head><body>' .
'<h1>This is a cached header</h1>';
$page_content['body']	= '<p>This is some cached body content ' .
'with a random number: ' . rand() . '</p>';
$page_content['footer']	= '<h5>This is a cached footer</h5>' .
'</body></html>';
// This content will expire and be regenerated every 15 seconds
$app->setWithExpire('cached_page', $page_content, 15);
}
echo $app->cached_page['header'];
echo '<h4>The date is ' . date('r') . '. This is not cached.</h4>';
echo $app->cached_page['body'];
echo $app->cached_page['footer'];
// To see a list of all keys in our app,
// and their expiration dates (if they have one), use:
// print_r($app->getKeys());
// To remove cached_page from our app, we would use:
// unset($app->cached_page);
// To flush all values from the app, we would use:
// $app->clear();
?>

Download The Code

To use AppCache on your site, download it from one of the following sources:

Source File with Examples

This is a zip file with Application.php as well as the two examples above.

Download

Raw Source File

This is just Application.php as a PHP source file.

Download

Prerequisites

To run AppCache, you need the following:

  • PHP 5. AppCache has been tested with PHP 5.2.0, but it will likely work with other versions of PHP 5 as well.
  • An instance of memcached running somewhere. You can download it at http://www.danga.com/memcached.
  • The PHP library for memcache – installed easily with PECL. In many cases it’s as simple as running pecl install memcache. More information is available at http://us2.php.net/memcache.

Licensing

This arc90 tool is licensed under the Creative Commons Attribution 3.0 license.

Discuss AppCache

You can send feedback on AppCache at the arc90 blog.