Wednesday, November 9th, 2005

SLLists: Scriptaculous Lists with PHP

Category: Library

Greg Neustaetter is a fan of the great library and decided to write a wrapper around the lists side of it.

So scriptaculous lists are really easy to use and implement…so why put together a PHP script to wrap around it all? I did this for a couple reasons (no the following list isn’t sortable!):

  • It isn’t very obvious from scriptaculous (or other similar drag-and-drop sorting libraries) how sortables can actually be used in a real application to perform a useful function.
  • I wanted a simple way to serialize the result of all this snazzy ordering into a simple PHP array with which I could update a database
  • Many people are just plain scared of JavaScript and don’t know what to do with it – I’m one of these folks too!
  • PHP is fun.

The resulting PHP class is a very simple class that makes it easy – with a couple lines of code to get a sortable list (or sortable just about anything) onto a page and to translate the result into a PHP array. I’ve got no documentation except for this sample page…so here’s a brief rundown of the features:

  • SLLists – constructor that basically sets the path to the JavaScript files
  • addList – adds a list or other element as a new sortable entity
  • printTopJS – prints the JavaScript into the head of a PHP file
  • printForm – prints an HTML form that contains the hidden inputs needed. Alternatively users can create their own forms or use the printHiddenInputs functions to put these hidden inputs in existing forms
  • printBottomJS – prints the JavaScript that should go right before the closing body tag
  • getOrderArray – returns an array with items and their order after being passed an input with the serialzed scriptaculous list

Download SSLLists


Posted by Dion Almaer at 8:27 am
Comment here

3 rating from 7 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.