Thanks for the reply Martin! col0 is an array of integers that
retrieved from a browser cookie. The page I am working on is similar
to the iGoogle page where you have movable widgets arranged in 3
columns. Widgets can be moved up and down in their column and even
between columns. I'm primarily using the Scriptaculous Sortables class
to make columns sortable with each other. Column order is saved and
restored via the Sequence and setSequence function calls and cookies.
That part was straight forward. However, I need a method to move the
widgets to the correct column div before calling setSequence. Right
now the code is repetitive, but it's just a first draft. :) Here is
the full function:

Columns are divs with id's of "col-0", "col-1", and "col-2"
Widget are divs with id's like "w_2" and "w_20" and are contained in
columns
There is one cookie per column that contains a list of integers
separated by commas, the integers correspond to the order the widgets
should appear in the column.

        function orderWidgetsByColumn() {
//these are string containing integers separated by commas
//example: 2,18,3,19,3
                var widgetListStr0 = getCookie('col-0');
                var widgetListStr1 = getCookie('col-1');
                var widgetListStr2 = getCookie('col-2');

//if all cookies are set, move all widgets to the correct column
                if( widgetListStr0.length > 0 &&
                        widgetListStr1.length > 0 &&
                        widgetListStr2.length > 0 ) {

//convert the comma delimited strings to arrays
                        var col0 = widgetListStr0.split(',');
                        var col1 = widgetListStr1.split(',');
                        var col2 = widgetListStr2.split(',');

                        var x;
                        var w_id = "";

                        //step through the first column
                        for( x in col0 ) {
                                w_id = 'w_' + col0[x];

                                //if the current item is not in col0, move it 
there
                                if( ! ($(w_id).descendantOf('col-0')) ) {
                                        
$('col-0').insert(document.getElementById(w_id));
                                }

                        }

                        //step through the second column
                        for( x in col1 ) {
                                w_id = "w_" + col0[x];

                                //if the current item is not in col0, move it 
there
                                if( ! ($(w_id).descendantOf('col-1')) ) {
                                        
$('col-1').insert(document.getElementById(w_id));
                                }
                        }

                        //step through the third column
                        for( x in col2 ) {
                                w_id = "w_" + col0[x];

                                //if the current item is not in col2, move it 
there
                                if( ! ($(w_id).descendantOf('col-2')) ) {
                                        
$('col-2').insert(document.getElementById(w_id));
                                }
                        }

                }

                return;

        }

On May 8, 5:20 am, "Martin Ström" <[EMAIL PROTECTED]> wrote:
> What is the contents of your "col0" variable?
> If it's an array you should not use the "for (x in ...)" loop but a
> traditional for (x = 0; x < y; x++) loop or Prototype's Array#each
>
> If you post how you get the col0's contents setup I'm sure we can help you.
>
> 2008/5/8 Timebomb <[EMAIL PROTECTED]>:
>
>
>
>
>
> >  I am trying to write some code using javascript and the prototype
> >  library that makes sure certain divs are contained in a column div, if
> >  they are not they get moved there. I'm getting the error "$(w_id) has
> >  no properties" when I run it. Is it possible to programmatically build
> >  a string containing a div id then use it like I need to? I'm new to
> >  prototype. Thanks in advance.
>
> >  Here is my code snippet:
>
> >  var x;
> >  var w_id = "";
>
> >  //step through the first column
> >  for( x in col0 ) {
> >         w_id = 'w_' + col0[x];
>
> >         //if the current item is not in col0, move it there
> >         if( ! ($(w_id).descendantOf('col-0')) ) {
> >                 $('col-0').insert(document.getElementById(w_id));
> >         }
>
> >  }
>
> --
> burnfield.com/martin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to