Re: [Proto-Scripty] multiselect combo plugin

2010-02-22 Thread Guillaume Lepicard
hi,
you might want to check
http://livepipe.net/control/selectmultiple
http://scripteka.com/

On Sun, Feb 21, 2010 at 10:04 PM, termi ivan.po...@f4s.sk wrote:

 Hi!

 please, is there any multi select combo plugin for prototype
 (script.aculo.us) like


 http://www.erichynds.com/jquery/jquery-multiselect-plugin-with-themeroller-support/

 thanks!

 termi

 --
 You received this message because you are subscribed to the Google Groups
 Prototype  script.aculo.us group.
 To post to this group, send email to
 prototype-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] for...in gets a overflow if including scriptaculous and prototype ?

2010-02-22 Thread Dale

Hi

I tried a simple javascript example on the w3school (http://
www.w3schools.com/JS/js_loop_for_in.asp),  and the example works fine
if I don't include scriptaculous or prototype, but once I do I keep
getting a strange error.

Anyone know why this error/bug shows up, or have I done something very
strange in my code ?

Thanks for any help... examples below...

The normal example:
html
body

script type=text/javascript
var x;
var mycars = new Array();
mycars[0] = Saab;
mycars[1] = Volvo;
mycars[2] = BMW;

for (x in mycars)
  {
  document.write(mycars[x] + br /);
  }
/script

/body
/html
Output of this one is:
Saab
Volvo
BMW

The modified example including the library:
html
head
script src=javascript/prototype.js type=text/javascript/script
script src=javascript/scriptaculous.js type=text/javascript/
script
/head
body
script type=text/javascript
var x;
var mycars = Array();
mycars[0] = Saab;
mycars[1] = Volvo;
mycars[2] = BMW;

for (x in mycars)
{
document.write(mycars[x] + br /);
}
/script
/body
/html

Output of this one is:
Saab
Volvo
BMW
function each(iterator, context) { var index = 0; try
{ this._each(function (value) {iterator.call(context, value, index+
+);}); } catch (e) { if (e != $break) { throw e; } } return this; }
function eachSlice(number, iterator, context) { var index = - number,
slices = [], array = this.toArray(); if (number  1) { return array; }
while ((index += number)  array.length)
{ slices.push(array.slice(index, index + number)); } return
slices.collect(iterator, context); }
function all(iterator, context) { iterator = iterator || Prototype.K;
var result = true; this.each(function (value, index) {result = result
 !!iterator.call(context, value, index);if (!result) {throw
$break;}}); return result; }
function any(iterator, context) { iterator = iterator || Prototype.K;
var result = false; this.each(function (value, index) {if ((result = !!
iterator.call(context, value, index))) {throw $break;}}); return
result; }
function collect(iterator, context) { iterator = iterator ||
Prototype.K; var results = []; this.each(function (value, index)
{results.push(iterator.call(context, value, index));}); return
results; }
function detect(iterator, context) { var result; this.each(function
(value, index) {if (iterator.call(context, value, index)) {result =
value;throw $break;}}); return result; }
function findAll(iterator, context) { var results = [];
this.each(function (value, index) {if (iterator.call(context, value,
index)) {results.push(value);}}); return results; }
function findAll(iterator, context) { var results = [];
this.each(function (value, index) {if (iterator.call(context, value,
index)) {results.push(value);}}); return results; }
function grep(filter, iterator, context) { iterator = iterator ||
Prototype.K; var results = []; if (Object.isString(filter)) { filter =
new RegExp(RegExp.escape(filter)); } this.each(function (value, index)
{if (filter.match(value)) {results.push(iterator.call(context, value,
index));}}); return results; }
function include(object) { if (Object.isFunction(this.indexOf)) { if
(this.indexOf(object) != -1) { return true; } } var found = false;
this.each(function (value) {if (value == object) {found = true;throw
$break;}}); return found; }
function include(object) { if (Object.isFunction(this.indexOf)) { if
(this.indexOf(object) != -1) { return true; } } var found = false;
this.each(function (value) {if (value == object) {found = true;throw
$break;}}); return found; }
function inGroupsOf(number, fillWith) { fillWith =
Object.isUndefined(fillWith) ? null : fillWith; return
this.eachSlice(number, function (slice) {while (slice.length  number)
{slice.push(fillWith);}return slice;}); }
function inject(memo, iterator, context) { this.each(function (value,
index) {memo = iterator.call(context, memo, value, index);}); return
memo; }
function invoke(method) { var args = $A(arguments).slice(1); return
this.map(function (value) {return value[method].apply(value,
args);}); }
function max(iterator, context) { iterator = iterator || Prototype.K;
var result; this.each(function (value, index) {value =
iterator.call(context, value, index);if (result == null || value =
result) {result = value;}}); return result; }
function min(iterator, context) { iterator = iterator || Prototype.K;
var result; this.each(function (value, index) {value =
iterator.call(context, value, index);if (result == null || value 
result) {result = value;}}); return result; }
function partition(iterator, context) { iterator = iterator ||
Prototype.K; var trues = [], falses = []; this.each(function (value,
index) {(iterator.call(context, value, index) ? trues :
falses).push(value);}); return [trues, falses]; }
function pluck(property) { var results = []; this.each(function
(value) {results.push(value[property]);}); return results; }
function reject(iterator, context) { var results = [];
this.each(function (value, index) {if (!iterator.call(context, value,
index)) {results.push(value);}}); return results; }

[Proto-Scripty] Re: for...in gets a overflow if including scriptaculous and prototype ?

2010-02-22 Thread T.J. Crowder
Hi,

That for..in code is incorrect, based on a misconception (a common
one). This page explains the misconception and discusses correct ways
of iterating through arrays:
http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On Feb 22, 12:13 pm, Dale daniel.lehtovi...@gmail.com wrote:
 Hi

 I tried a simple javascript example on the w3school 
 (http://www.w3schools.com/JS/js_loop_for_in.asp),  and the example works fine
 if I don't include scriptaculous or prototype, but once I do I keep
 getting a strange error.

 Anyone know why this error/bug shows up, or have I done something very
 strange in my code ?

 Thanks for any help... examples below...

 The normal example:
 html
 body

 script type=text/javascript
 var x;
 var mycars = new Array();
 mycars[0] = Saab;
 mycars[1] = Volvo;
 mycars[2] = BMW;

 for (x in mycars)
   {
   document.write(mycars[x] + br /);
   }
 /script

 /body
 /html
 Output of this one is:
 Saab
 Volvo
 BMW

 The modified example including the library:
 html
 head
 script src=javascript/prototype.js type=text/javascript/script
 script src=javascript/scriptaculous.js type=text/javascript/
 script
 /head
 body
 script type=text/javascript
 var x;
 var mycars = Array();
 mycars[0] = Saab;
 mycars[1] = Volvo;
 mycars[2] = BMW;

 for (x in mycars)
 {
 document.write(mycars[x] + br /);}

 /script
 /body
 /html

 Output of this one is:
 Saab
 Volvo
 BMW
 function each(iterator, context) { var index = 0; try
 { this._each(function (value) {iterator.call(context, value, index+
 +);}); } catch (e) { if (e != $break) { throw e; } } return this; }
 function eachSlice(number, iterator, context) { var index = - number,
 slices = [], array = this.toArray(); if (number  1) { return array; }
 while ((index += number)  array.length)
 { slices.push(array.slice(index, index + number)); } return
 slices.collect(iterator, context); }
 function all(iterator, context) { iterator = iterator || Prototype.K;
 var result = true; this.each(function (value, index) {result = result
  !!iterator.call(context, value, index);if (!result) {throw
 $break;}}); return result; }
 function any(iterator, context) { iterator = iterator || Prototype.K;
 var result = false; this.each(function (value, index) {if ((result = !!
 iterator.call(context, value, index))) {throw $break;}}); return
 result; }
 function collect(iterator, context) { iterator = iterator ||
 Prototype.K; var results = []; this.each(function (value, index)
 {results.push(iterator.call(context, value, index));}); return
 results; }
 function detect(iterator, context) { var result; this.each(function
 (value, index) {if (iterator.call(context, value, index)) {result =
 value;throw $break;}}); return result; }
 function findAll(iterator, context) { var results = [];
 this.each(function (value, index) {if (iterator.call(context, value,
 index)) {results.push(value);}}); return results; }
 function findAll(iterator, context) { var results = [];
 this.each(function (value, index) {if (iterator.call(context, value,
 index)) {results.push(value);}}); return results; }
 function grep(filter, iterator, context) { iterator = iterator ||
 Prototype.K; var results = []; if (Object.isString(filter)) { filter =
 new RegExp(RegExp.escape(filter)); } this.each(function (value, index)
 {if (filter.match(value)) {results.push(iterator.call(context, value,
 index));}}); return results; }
 function include(object) { if (Object.isFunction(this.indexOf)) { if
 (this.indexOf(object) != -1) { return true; } } var found = false;
 this.each(function (value) {if (value == object) {found = true;throw
 $break;}}); return found; }
 function include(object) { if (Object.isFunction(this.indexOf)) { if
 (this.indexOf(object) != -1) { return true; } } var found = false;
 this.each(function (value) {if (value == object) {found = true;throw
 $break;}}); return found; }
 function inGroupsOf(number, fillWith) { fillWith =
 Object.isUndefined(fillWith) ? null : fillWith; return
 this.eachSlice(number, function (slice) {while (slice.length  number)
 {slice.push(fillWith);}return slice;}); }
 function inject(memo, iterator, context) { this.each(function (value,
 index) {memo = iterator.call(context, memo, value, index);}); return
 memo; }
 function invoke(method) { var args = $A(arguments).slice(1); return
 this.map(function (value) {return value[method].apply(value,
 args);}); }
 function max(iterator, context) { iterator = iterator || Prototype.K;
 var result; this.each(function (value, index) {value =
 iterator.call(context, value, index);if (result == null || value =
 result) {result = value;}}); return result; }
 function min(iterator, context) { iterator = iterator || Prototype.K;
 var result; this.each(function (value, index) {value =
 iterator.call(context, value, index);if (result == null || value 
 result) {result = value;}}); return result; }
 function 

[Proto-Scripty] Re: for...in gets a overflow if including scriptaculous and prototype ?

2010-02-22 Thread Dale
Thanks!
That other way worked fine for me.

//Daniel

On Feb 22, 4:08 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi,

 That for..in code is incorrect, based on a misconception (a common
 one). This page explains the misconception and discusses correct ways
 of iterating through 
 arrays:http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays

 HTH,
 --
 T.J. Crowder
 Independent Software Consultant
 tj / crowder software / comwww.crowdersoftware.com

 On Feb 22, 12:13 pm, Dale daniel.lehtovi...@gmail.com wrote:

  Hi

  I tried a simple javascript example on the w3school 
  (http://www.w3schools.com/JS/js_loop_for_in.asp),  and the example works 
  fine
  if I don't include scriptaculous or prototype, but once I do I keep
  getting a strange error.

  Anyone know why this error/bug shows up, or have I done something very
  strange in my code ?

  Thanks for any help... examples below...

  The normal example:
  html
  body

  script type=text/javascript
  var x;
  var mycars = new Array();
  mycars[0] = Saab;
  mycars[1] = Volvo;
  mycars[2] = BMW;

  for (x in mycars)
    {
    document.write(mycars[x] + br /);
    }
  /script

  /body
  /html
  Output of this one is:
  Saab
  Volvo
  BMW

  The modified example including the library:
  html
  head
  script src=javascript/prototype.js type=text/javascript/script
  script src=javascript/scriptaculous.js type=text/javascript/
  script
  /head
  body
  script type=text/javascript
  var x;
  var mycars = Array();
  mycars[0] = Saab;
  mycars[1] = Volvo;
  mycars[2] = BMW;

  for (x in mycars)
  {
  document.write(mycars[x] + br /);}

  /script
  /body
  /html

  Output of this one is:
  Saab
  Volvo
  BMW
  function each(iterator, context) { var index = 0; try
  { this._each(function (value) {iterator.call(context, value, index+
  +);}); } catch (e) { if (e != $break) { throw e; } } return this; }
  function eachSlice(number, iterator, context) { var index = - number,
  slices = [], array = this.toArray(); if (number  1) { return array; }
  while ((index += number)  array.length)
  { slices.push(array.slice(index, index + number)); } return
  slices.collect(iterator, context); }
  function all(iterator, context) { iterator = iterator || Prototype.K;
  var result = true; this.each(function (value, index) {result = result
   !!iterator.call(context, value, index);if (!result) {throw
  $break;}}); return result; }
  function any(iterator, context) { iterator = iterator || Prototype.K;
  var result = false; this.each(function (value, index) {if ((result = !!
  iterator.call(context, value, index))) {throw $break;}}); return
  result; }
  function collect(iterator, context) { iterator = iterator ||
  Prototype.K; var results = []; this.each(function (value, index)
  {results.push(iterator.call(context, value, index));}); return
  results; }
  function detect(iterator, context) { var result; this.each(function
  (value, index) {if (iterator.call(context, value, index)) {result =
  value;throw $break;}}); return result; }
  function findAll(iterator, context) { var results = [];
  this.each(function (value, index) {if (iterator.call(context, value,
  index)) {results.push(value);}}); return results; }
  function findAll(iterator, context) { var results = [];
  this.each(function (value, index) {if (iterator.call(context, value,
  index)) {results.push(value);}}); return results; }
  function grep(filter, iterator, context) { iterator = iterator ||
  Prototype.K; var results = []; if (Object.isString(filter)) { filter =
  new RegExp(RegExp.escape(filter)); } this.each(function (value, index)
  {if (filter.match(value)) {results.push(iterator.call(context, value,
  index));}}); return results; }
  function include(object) { if (Object.isFunction(this.indexOf)) { if
  (this.indexOf(object) != -1) { return true; } } var found = false;
  this.each(function (value) {if (value == object) {found = true;throw
  $break;}}); return found; }
  function include(object) { if (Object.isFunction(this.indexOf)) { if
  (this.indexOf(object) != -1) { return true; } } var found = false;
  this.each(function (value) {if (value == object) {found = true;throw
  $break;}}); return found; }
  function inGroupsOf(number, fillWith) { fillWith =
  Object.isUndefined(fillWith) ? null : fillWith; return
  this.eachSlice(number, function (slice) {while (slice.length  number)
  {slice.push(fillWith);}return slice;}); }
  function inject(memo, iterator, context) { this.each(function (value,
  index) {memo = iterator.call(context, memo, value, index);}); return
  memo; }
  function invoke(method) { var args = $A(arguments).slice(1); return
  this.map(function (value) {return value[method].apply(value,
  args);}); }
  function max(iterator, context) { iterator = iterator || Prototype.K;
  var result; this.each(function (value, index) {value =
  iterator.call(context, value, index);if (result == null || value =
  result) {result = value;}}); return result; }
  function 

Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Walter Lee Davis
Hmmm. That's not a documented function. I had a look at the source,  
and I can't see how it works. It accepts a node as its only argument,  
and it doesn't seem to perform any comparison as it executes. How then  
would I get it to stick to just the one type of sibling, and how would  
I get it to stop when it ran out of similar siblings?


Thanks as always for any pointers.

Walter

On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

You'll want to leverage Prototype's nextElementSibling function.  
That function grabs element.nextSibling and traverses until it finds  
an an actual element (by checking nodeType).


You could wrap a function around that which stores the tagName of  
the first element it matches, and then continues to find  
nextElementSibling until it either returns null, or break when the  
tagName doesn't match the original tagName.


Take a look at the innards of Element.adjacent and  
Element.nextElementSibling for an idea of what I mean.


Best,
Alex

On Mon, Feb 22, 2010 at 12:00 AM, Walter Lee Davis  
wa...@wdstudio.com wrote:

I have a structure like this inside a parent DIV:

H3
P
P
H3
P
P
P
H3
P
P

And I'd like to be able to get the paragraphs between two heads, or  
between the last head and the end of the parent DIV.  
Element.adjacent('p') doesn't do what I need -- it returns all the p  
tags in the entire DIV, since everything is at the same level. If I  
get a reference to the first element following the head, how could I  
get all similar elements up to but not including the next head? I'm  
trying to find a purely structure based way to do this, rather than  
adding classnames to the elements.


Thanks,

Walter

--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.


--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Alex Wallace
I whipped up something that should
handle the task, although I'm sure this could be optimized using the
nextElementSibling. This version grabs nextSiblings() and then filters
them, but the faster way would be to iterate over the
`element.nextSibling`
and break when it encounters a different tag name (instead of finding them
all, which is bound to be slower).

But here goes:

function consecutiveSameTagSiblings(element) {
element = $(element);
var siblings = element.nextSiblings(), results = [];
if (!siblings[0]) return results;
var tagName = siblings[0].tagName.toLowerCase();
for (var i = 0, sibling; sibling = siblings[i]; ++i) {
if (sibling.tagName.toLowerCase() === tagName)
results.push(sibling);
else
break;
}
return results;
}

Best,
Alex


On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis wa...@wdstudio.comwrote:

 Hmmm. That's not a documented function. I had a look at the source, and I
 can't see how it works. It accepts a node as its only argument, and it
 doesn't seem to perform any comparison as it executes. How then would I get
 it to stick to just the one type of sibling, and how would I get it to stop
 when it ran out of similar siblings?

 Thanks as always for any pointers.

 Walter


 On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

  You'll want to leverage Prototype's nextElementSibling function. That
 function grabs element.nextSibling and traverses until it finds an an actual
 element (by checking nodeType).

 You could wrap a function around that which stores the tagName of the
 first element it matches, and then continues to find nextElementSibling
 until it either returns null, or break when the tagName doesn't match the
 original tagName.

 Take a look at the innards of Element.adjacent and
 Element.nextElementSibling for an idea of what I mean.

 Best,
 Alex

 On Mon, Feb 22, 2010 at 12:00 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 I have a structure like this inside a parent DIV:

 H3
 P
 P
 H3
 P
 P
 P
 H3
 P
 P

 And I'd like to be able to get the paragraphs between two heads, or
 between the last head and the end of the parent DIV. Element.adjacent('p')
 doesn't do what I need -- it returns all the p tags in the entire DIV, since
 everything is at the same level. If I get a reference to the first element
 following the head, how could I get all similar elements up to but not
 including the next head? I'm trying to find a purely structure based way to
 do this, rather than adding classnames to the elements.

 Thanks,

 Walter

 --
 You received this message because you are subscribed to the Google Groups
 Prototype  script.aculo.us group.
 To post to this group, send email to
 prototype-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



 --
 You received this message because you are subscribed to the Google Groups
 Prototype  script.aculo.us group.
 To post to this group, send email to
 prototype-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.


 --
 You received this message because you are subscribed to the Google Groups
 Prototype  script.aculo.us group.
 To post to this group, send email to
 prototype-scriptacul...@googlegroups.com.
 To unsubscribe from this group, send email to
 prototype-scriptaculous+unsubscr...@googlegroups.comprototype-scriptaculous%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/prototype-scriptaculous?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Walter Lee Davis
Thanks very much. I was looking in the wrong place for the  
functionality I need. You've given me the bones I need to build on.


Walter

On Feb 22, 2010, at 11:07 AM, Alex Wallace wrote:

I whipped up something that should handle the task, although I'm  
sure this could be optimized using the nextElementSibling. This  
version grabs nextSiblings() and then filters them, but the faster  
way would be to iterate over the `element.nextSibling` and break  
when it encounters a different tag name (instead of finding them  
all, which is bound to be slower).


But here goes:

function consecutiveSameTagSiblings(element) {
element = $(element);
var siblings = element.nextSiblings(), results = [];
if (!siblings[0]) return results;
var tagName = siblings[0].tagName.toLowerCase();
for (var i = 0, sibling; sibling = siblings[i]; ++i) {
if (sibling.tagName.toLowerCase() === tagName)
results.push(sibling);
else
break;
}
return results;
}

Best,
Alex


On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis  
wa...@wdstudio.com wrote:
Hmmm. That's not a documented function. I had a look at the source,  
and I can't see how it works. It accepts a node as its only  
argument, and it doesn't seem to perform any comparison as it  
executes. How then would I get it to stick to just the one type of  
sibling, and how would I get it to stop when it ran out of similar  
siblings?


Thanks as always for any pointers.

Walter


On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

You'll want to leverage Prototype's nextElementSibling function.  
That function grabs element.nextSibling and traverses until it finds  
an an actual element (by checking nodeType).


You could wrap a function around that which stores the tagName of  
the first element it matches, and then continues to find  
nextElementSibling until it either returns null, or break when the  
tagName doesn't match the original tagName.


Take a look at the innards of Element.adjacent and  
Element.nextElementSibling for an idea of what I mean.


Best,
Alex

On Mon, Feb 22, 2010 at 12:00 AM, Walter Lee Davis  
wa...@wdstudio.com wrote:

I have a structure like this inside a parent DIV:

H3
P
P
H3
P
P
P
H3
P
P

And I'd like to be able to get the paragraphs between two heads, or  
between the last head and the end of the parent DIV.  
Element.adjacent('p') doesn't do what I need -- it returns all the p  
tags in the entire DIV, since everything is at the same level. If I  
get a reference to the first element following the head, how could I  
get all similar elements up to but not including the next head? I'm  
trying to find a purely structure based way to do this, rather than  
adding classnames to the elements.


Thanks,

Walter

--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.


--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.




--
You received this message because you are subscribed to the Google  
Groups Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com 
.
To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com 
.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en 
.


--
You received this message because you are subscribed to the Google Groups Prototype 
 script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Paul Kim
Hi Walter, if you want to get all similar elements up to but not including
the next head, I would use Prototype's Element.nextSiblings() to loop
through all elements with the same tagName and break when the tagName is
different. Here is a function I created just now that would hopefully do
what you want:

function getSimilarElements(element) {
var element = $(element);
var similarElements = new Array();
for (var i=0; i element.nextSiblings().length; i++) {
if (element.tagName == element.nextSiblings()[i].tagName) {
similarElements[i] = element.nextSiblings()[i];
}
else {
break;
}
}
return similarElements;
}

Here is the entire example as well:

!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/html;charset=utf-8 /
titleDemo/title
script type=text/javascript src=
http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
/script
script type=text/javascript src=
http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js
/script
script type=text/javascript
document.observe(dom:loaded, function() {
function getSimilarElements(element) {
var element = $(element);
var similarElements = new Array();
for (var i=0; i element.nextSiblings().length; i++) {
if (element.tagName == element.nextSiblings()[i].tagName) {
similarElements[i] = element.nextSiblings()[i];
}
else {
break;
}
}
return similarElements;
}

console.log(getSimilarElements('foo'));
});
/script
style type=text/css
body {margin:0; padding:0;}
/style
/head
body
div
h3first header/h3
p id=foofirst paragraph/p
psecond paragraph/p
h3second header/h3
pthird paragraph/p
pfourth paragraph/p
pfifth paragraph/p
h3third header/h3
psixth paragraph/p
pseventh paragraph/p
/div
/body
/html


On Mon, Feb 22, 2010 at 8:22 AM, Walter Lee Davis wa...@wdstudio.comwrote:

 Thanks very much. I was looking in the wrong place for the functionality I
 need. You've given me the bones I need to build on.

 Walter


 On Feb 22, 2010, at 11:07 AM, Alex Wallace wrote:

  I whipped up something that should handle the task, although I'm sure this
 could be optimized using the nextElementSibling. This version grabs
 nextSiblings() and then filters them, but the faster way would be to iterate
 over the `element.nextSibling` and break when it encounters a different tag
 name (instead of finding them all, which is bound to be slower).

 But here goes:

function consecutiveSameTagSiblings(element) {
element = $(element);
var siblings = element.nextSiblings(), results = [];
if (!siblings[0]) return results;
var tagName = siblings[0].tagName.toLowerCase();
for (var i = 0, sibling; sibling = siblings[i]; ++i) {
if (sibling.tagName.toLowerCase() === tagName)
results.push(sibling);
else
break;
}
return results;
}

 Best,
 Alex


 On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 Hmmm. That's not a documented function. I had a look at the source, and I
 can't see how it works. It accepts a node as its only argument, and it
 doesn't seem to perform any comparison as it executes. How then would I get
 it to stick to just the one type of sibling, and how would I get it to stop
 when it ran out of similar siblings?

 Thanks as always for any pointers.

 Walter


 On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

 You'll want to leverage Prototype's nextElementSibling function. That
 function grabs element.nextSibling and traverses until it finds an an actual
 element (by checking nodeType).

 You could wrap a function around that which stores the tagName of the
 first element it matches, and then continues to find nextElementSibling
 until it either returns null, or break when the tagName doesn't match the
 original tagName.

 Take a look at the innards of Element.adjacent and
 Element.nextElementSibling for an idea of what I mean.

 Best,
 Alex

 On Mon, Feb 22, 2010 at 12:00 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 I have a structure like this inside a parent DIV:

 H3
 P
 P
 H3
 P
 P
 P
 H3
 P
 P

 And I'd like to be able to get the paragraphs between two heads, or
 between the last head and the end of the parent DIV. Element.adjacent('p')
 doesn't do what I need -- it returns all the p tags in the entire DIV, since
 everything is at the same level. If I get a reference to the first element
 following the head, how could I get all similar elements up to but not
 including the next head? I'm trying to find a purely structure based way to
 do this, 

Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Alex Wallace
Paul, one recommendation: store the results of element.nextSiblings() in a
local variable outside of the loop. DOM traversals are pretty slow.

Best,
Alex

On Mon, Feb 22, 2010 at 12:28 PM, Paul Kim kimba...@gmail.com wrote:

 Hi Walter, if you want to get all similar elements up to but not including
 the next head, I would use Prototype's Element.nextSiblings() to loop
 through all elements with the same tagName and break when the tagName is
 different. Here is a function I created just now that would hopefully do
 what you want:

 function getSimilarElements(element) {
 var element = $(element);
 var similarElements = new Array();
 for (var i=0; i element.nextSiblings().length; i++) {
 if (element.tagName == element.nextSiblings()[i].tagName) {
 similarElements[i] = element.nextSiblings()[i];
 }
 else {
 break;
 }
 }
 return similarElements;
 }

 Here is the entire example as well:

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
  http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html;charset=utf-8 /
 titleDemo/title
 script type=text/javascript src=
 http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
 /script
 script type=text/javascript src=
 http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js
 /script
 script type=text/javascript
 document.observe(dom:loaded, function() {
 function getSimilarElements(element) {
 var element = $(element);
 var similarElements = new Array();
 for (var i=0; i element.nextSiblings().length; i++) {
 if (element.tagName == element.nextSiblings()[i].tagName) {
 similarElements[i] = element.nextSiblings()[i];
 }
 else {
 break;
 }
 }
 return similarElements;
 }

 console.log(getSimilarElements('foo'));
 });
 /script
 style type=text/css
 body {margin:0; padding:0;}
 /style
 /head
 body
 div
 h3first header/h3
 p id=foofirst paragraph/p
 psecond paragraph/p
 h3second header/h3
 pthird paragraph/p
 pfourth paragraph/p
 pfifth paragraph/p
 h3third header/h3
 psixth paragraph/p
 pseventh paragraph/p
 /div
 /body
 /html



 On Mon, Feb 22, 2010 at 8:22 AM, Walter Lee Davis wa...@wdstudio.comwrote:

 Thanks very much. I was looking in the wrong place for the functionality I
 need. You've given me the bones I need to build on.

 Walter


 On Feb 22, 2010, at 11:07 AM, Alex Wallace wrote:

  I whipped up something that should handle the task, although I'm sure
 this could be optimized using the nextElementSibling. This version grabs
 nextSiblings() and then filters them, but the faster way would be to iterate
 over the `element.nextSibling` and break when it encounters a different tag
 name (instead of finding them all, which is bound to be slower).

 But here goes:

function consecutiveSameTagSiblings(element) {
element = $(element);
var siblings = element.nextSiblings(), results = [];
if (!siblings[0]) return results;
var tagName = siblings[0].tagName.toLowerCase();
for (var i = 0, sibling; sibling = siblings[i]; ++i) {
if (sibling.tagName.toLowerCase() === tagName)
results.push(sibling);
else
break;
}
return results;
}

 Best,
 Alex


 On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 Hmmm. That's not a documented function. I had a look at the source, and I
 can't see how it works. It accepts a node as its only argument, and it
 doesn't seem to perform any comparison as it executes. How then would I get
 it to stick to just the one type of sibling, and how would I get it to stop
 when it ran out of similar siblings?

 Thanks as always for any pointers.

 Walter


 On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

 You'll want to leverage Prototype's nextElementSibling function. That
 function grabs element.nextSibling and traverses until it finds an an actual
 element (by checking nodeType).

 You could wrap a function around that which stores the tagName of the
 first element it matches, and then continues to find nextElementSibling
 until it either returns null, or break when the tagName doesn't match the
 original tagName.

 Take a look at the innards of Element.adjacent and
 Element.nextElementSibling for an idea of what I mean.

 Best,
 Alex

 On Mon, Feb 22, 2010 at 12:00 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 I have a structure like this inside a parent DIV:

 H3
 P
 P
 H3
 P
 P
 P
 H3
 P
 P

 And I'd like to be able to get the paragraphs between two heads, or
 between the last head and the end of the parent DIV. Element.adjacent('p')
 doesn't do what I 

Re: [Proto-Scripty] How would I get a closer set of siblings?

2010-02-22 Thread Paul Kim
Hi Alex, thanks for the tip. I've modified the function based on your tip
and your example function:

function consecutiveSameTagSiblings(element) {
var element = $(element);
var nextSiblings = element.nextSiblings();
var similarElements = [];
similarElements.push(element);
for (var i=0; i nextSiblings.length; i++) {
if (element.tagName == nextSiblings[i].tagName) {
similarElements.push(nextSiblings[i]);
}
else {
break;
}
}
return similarElements;
}


On Mon, Feb 22, 2010 at 9:50 AM, Alex Wallace alexmlwall...@gmail.comwrote:

 Paul, one recommendation: store the results of element.nextSiblings() in a
 local variable outside of the loop. DOM traversals are pretty slow.

 Best,
 Alex


 On Mon, Feb 22, 2010 at 12:28 PM, Paul Kim kimba...@gmail.com wrote:

 Hi Walter, if you want to get all similar elements up to but not including
 the next head, I would use Prototype's Element.nextSiblings() to loop
 through all elements with the same tagName and break when the tagName is
 different. Here is a function I created just now that would hopefully do
 what you want:

 function getSimilarElements(element) {
 var element = $(element);
 var similarElements = new Array();
 for (var i=0; i element.nextSiblings().length; i++) {
 if (element.tagName == element.nextSiblings()[i].tagName) {
 similarElements[i] = element.nextSiblings()[i];
 }
 else {
 break;
 }
 }
 return similarElements;
 }

 Here is the entire example as well:

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
  http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
 html xmlns=http://www.w3.org/1999/xhtml;
 head
 meta http-equiv=Content-Type content=text/html;charset=utf-8 /
 titleDemo/title
 script type=text/javascript src=
 http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
 /script
 script type=text/javascript src=
 http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js
 /script
 script type=text/javascript
 document.observe(dom:loaded, function() {
 function getSimilarElements(element) {
 var element = $(element);
 var similarElements = new Array();
 for (var i=0; i element.nextSiblings().length; i++) {
 if (element.tagName == element.nextSiblings()[i].tagName) {
 similarElements[i] = element.nextSiblings()[i];
 }
 else {
 break;
 }
 }
 return similarElements;
 }

 console.log(getSimilarElements('foo'));
 });
 /script
 style type=text/css
 body {margin:0; padding:0;}
 /style
 /head
 body
 div
 h3first header/h3
 p id=foofirst paragraph/p
 psecond paragraph/p
 h3second header/h3
 pthird paragraph/p
 pfourth paragraph/p
 pfifth paragraph/p
 h3third header/h3
 psixth paragraph/p
 pseventh paragraph/p
 /div
 /body
 /html



 On Mon, Feb 22, 2010 at 8:22 AM, Walter Lee Davis wa...@wdstudio.comwrote:

 Thanks very much. I was looking in the wrong place for the functionality
 I need. You've given me the bones I need to build on.

 Walter


 On Feb 22, 2010, at 11:07 AM, Alex Wallace wrote:

  I whipped up something that should handle the task, although I'm sure
 this could be optimized using the nextElementSibling. This version grabs
 nextSiblings() and then filters them, but the faster way would be to 
 iterate
 over the `element.nextSibling` and break when it encounters a different tag
 name (instead of finding them all, which is bound to be slower).

 But here goes:

function consecutiveSameTagSiblings(element) {
element = $(element);
var siblings = element.nextSiblings(), results = [];
if (!siblings[0]) return results;
var tagName = siblings[0].tagName.toLowerCase();
for (var i = 0, sibling; sibling = siblings[i]; ++i) {
if (sibling.tagName.toLowerCase() === tagName)
results.push(sibling);
else
break;
}
return results;
}

 Best,
 Alex


 On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis wa...@wdstudio.com
 wrote:
 Hmmm. That's not a documented function. I had a look at the source, and
 I can't see how it works. It accepts a node as its only argument, and it
 doesn't seem to perform any comparison as it executes. How then would I get
 it to stick to just the one type of sibling, and how would I get it to stop
 when it ran out of similar siblings?

 Thanks as always for any pointers.

 Walter


 On Feb 22, 2010, at 10:29 AM, Alex Wallace wrote:

 You'll want to leverage Prototype's nextElementSibling function. That
 function grabs element.nextSibling and traverses until it finds an an 
 actual
 element (by checking nodeType).

 You 

Re: [Proto-Scripty] Re: How would I get a closer set of siblings?

2010-02-22 Thread Walter Lee Davis
The heads and the paragraphs are all at the same level, and I don't  
want all the paragraphs, just the ones between this head and the  
next head. (It's for an accordion effect.) So while  
up('div').select('p') would do exactly what you say, it would leave me  
where I started.


Thanks,

Walter

On Feb 22, 2010, at 5:46 PM, Matt Foster wrote:


This is probably too obvious to be right but if you're simply looking
for all of the paragraph tags at that level could you simply go up to
the parent and select down from there?




On Feb 22, 12:57 pm, Paul Kim kimba...@gmail.com wrote:
Hi Alex, thanks for the tip. I've modified the function based on  
your tip

and your example function:

function consecutiveSameTagSiblings(element) {
var element = $(element);
var nextSiblings = element.nextSiblings();
var similarElements = [];
similarElements.push(element);
for (var i=0; i nextSiblings.length; i++) {
if (element.tagName == nextSiblings[i].tagName) {
similarElements.push(nextSiblings[i]);
}
else {
break;
}
}
return similarElements;
}

On Mon, Feb 22, 2010 at 9:50 AM, Alex Wallace  
alexmlwall...@gmail.comwrote:




Paul, one recommendation: store the results of  
element.nextSiblings() in a

local variable outside of the loop. DOM traversals are pretty slow.



Best,
Alex


On Mon, Feb 22, 2010 at 12:28 PM, Paul Kim kimba...@gmail.com  
wrote:


Hi Walter, if you want to get all similar elements up to but not  
including
the next head, I would use Prototype's Element.nextSiblings() to  
loop
through all elements with the same tagName and break when the  
tagName is
different. Here is a function I created just now that would  
hopefully do

what you want:



function getSimilarElements(element) {
var element = $(element);
var similarElements = new Array();
for (var i=0; i element.nextSiblings().length; i++) {
if (element.tagName == element.nextSiblings()[i].tagName) {
similarElements[i] = element.nextSiblings()[i];
}
else {
break;
}
}
return similarElements;
}



Here is the entire example as well:



!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
 http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
html xmlns=http://www.w3.org/1999/xhtml;
head
meta http-equiv=Content-Type content=text/ 
html;charset=utf-8 /

titleDemo/title
script type=text/javascript src=
http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js
/script
script type=text/javascript src=
http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculou 
...

/script
script type=text/javascript
document.observe(dom:loaded, function() {
function getSimilarElements(element) {
var element = $(element);
var similarElements = new Array();
for (var i=0; i element.nextSiblings().length; i++) {
if (element.tagName == element.nextSiblings() 
[i].tagName) {

similarElements[i] = element.nextSiblings()[i];
}
else {
break;
}
}
return similarElements;
}



console.log(getSimilarElements('foo'));
});
/script
style type=text/css
body {margin:0; padding:0;}
/style
/head
body
div
h3first header/h3
p id=foofirst paragraph/p
psecond paragraph/p
h3second header/h3
pthird paragraph/p
pfourth paragraph/p
pfifth paragraph/p
h3third header/h3
psixth paragraph/p
pseventh paragraph/p
/div
/body
/html


On Mon, Feb 22, 2010 at 8:22 AM, Walter Lee Davis  
wa...@wdstudio.comwrote:


Thanks very much. I was looking in the wrong place for the  
functionality

I need. You've given me the bones I need to build on.



Walter



On Feb 22, 2010, at 11:07 AM, Alex Wallace wrote:


 I whipped up something that should handle the task, although  
I'm sure
this could be optimized using the nextElementSibling. This  
version grabs
nextSiblings() and then filters them, but the faster way would  
be to iterate
over the `element.nextSibling` and break when it encounters a  
different tag

name (instead of finding them all, which is bound to be slower).



But here goes:



   function consecutiveSameTagSiblings(element) {
   element = $(element);
   var siblings = element.nextSiblings(), results =  
[];

   if (!siblings[0]) return results;
   var tagName = siblings[0].tagName.toLowerCase();
   for (var i = 0, sibling; sibling = siblings[i]; + 
+i) {
   if (sibling.tagName.toLowerCase() ===  
tagName)

   results.push(sibling);
   else
   break;
   }
   return results;
   }



Best,
Alex


On Mon, Feb 22, 2010 at 10:38 AM, Walter Lee Davis  
wa...@wdstudio.com

wrote:
Hmmm. That's not a documented function. I had a look at the  

[Proto-Scripty] Re: for...in gets a overflow if including scriptaculous and prototype ?

2010-02-22 Thread joe t.
TJ,
i see endless warnings against using for/in. And i understand the
reasons for them, especially on arrays. But it seems like a fairly
powerful looping tool, yet no one seems to temper the warnings with
appropriate circumstances for its use. Since the JS spec disallows
creating non-enumerable properties, ARE there any good uses for this
loop method?

Thanks,
-joe t.


On Feb 22, 9:08 am, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi,

 That for..in code is incorrect, based on a misconception (a common
 one). This page explains the misconception and discusses correct ways
 of iterating through 
 arrays:http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays

 HTH,
 --
 T.J. Crowder
 Independent Software Consultant
 tj / crowder software / comwww.crowdersoftware.com

 On Feb 22, 12:13 pm, Dale daniel.lehtovi...@gmail.com wrote:

  Hi

  I tried a simple javascript example on the w3school 
  (http://www.w3schools.com/JS/js_loop_for_in.asp),  and the example works 
  fine
  if I don't include scriptaculous or prototype, but once I do I keep
  getting a strange error.

  Anyone know why this error/bug shows up, or have I done something very
  strange in my code ?

  Thanks for any help... examples below...

  The normal example:
  html
  body

  script type=text/javascript
  var x;
  var mycars = new Array();
  mycars[0] = Saab;
  mycars[1] = Volvo;
  mycars[2] = BMW;

  for (x in mycars)
    {
    document.write(mycars[x] + br /);
    }
  /script

  /body
  /html
  Output of this one is:
  Saab
  Volvo
  BMW

  The modified example including the library:
  html
  head
  script src=javascript/prototype.js type=text/javascript/script
  script src=javascript/scriptaculous.js type=text/javascript/
  script
  /head
  body
  script type=text/javascript
  var x;
  var mycars = Array();
  mycars[0] = Saab;
  mycars[1] = Volvo;
  mycars[2] = BMW;

  for (x in mycars)
  {
  document.write(mycars[x] + br /);}

  /script
  /body
  /html

  Output of this one is:
  Saab
  Volvo
  BMW
  function each(iterator, context) { var index = 0; try
  { this._each(function (value) {iterator.call(context, value, index+
  +);}); } catch (e) { if (e != $break) { throw e; } } return this; }
  function eachSlice(number, iterator, context) { var index = - number,
  slices = [], array = this.toArray(); if (number  1) { return array; }
  while ((index += number)  array.length)
  { slices.push(array.slice(index, index + number)); } return
  slices.collect(iterator, context); }
  function all(iterator, context) { iterator = iterator || Prototype.K;
  var result = true; this.each(function (value, index) {result = result
   !!iterator.call(context, value, index);if (!result) {throw
  $break;}}); return result; }
  function any(iterator, context) { iterator = iterator || Prototype.K;
  var result = false; this.each(function (value, index) {if ((result = !!
  iterator.call(context, value, index))) {throw $break;}}); return
  result; }
  function collect(iterator, context) { iterator = iterator ||
  Prototype.K; var results = []; this.each(function (value, index)
  {results.push(iterator.call(context, value, index));}); return
  results; }
  function detect(iterator, context) { var result; this.each(function
  (value, index) {if (iterator.call(context, value, index)) {result =
  value;throw $break;}}); return result; }
  function findAll(iterator, context) { var results = [];
  this.each(function (value, index) {if (iterator.call(context, value,
  index)) {results.push(value);}}); return results; }
  function findAll(iterator, context) { var results = [];
  this.each(function (value, index) {if (iterator.call(context, value,
  index)) {results.push(value);}}); return results; }
  function grep(filter, iterator, context) { iterator = iterator ||
  Prototype.K; var results = []; if (Object.isString(filter)) { filter =
  new RegExp(RegExp.escape(filter)); } this.each(function (value, index)
  {if (filter.match(value)) {results.push(iterator.call(context, value,
  index));}}); return results; }
  function include(object) { if (Object.isFunction(this.indexOf)) { if
  (this.indexOf(object) != -1) { return true; } } var found = false;
  this.each(function (value) {if (value == object) {found = true;throw
  $break;}}); return found; }
  function include(object) { if (Object.isFunction(this.indexOf)) { if
  (this.indexOf(object) != -1) { return true; } } var found = false;
  this.each(function (value) {if (value == object) {found = true;throw
  $break;}}); return found; }
  function inGroupsOf(number, fillWith) { fillWith =
  Object.isUndefined(fillWith) ? null : fillWith; return
  this.eachSlice(number, function (slice) {while (slice.length  number)
  {slice.push(fillWith);}return slice;}); }
  function inject(memo, iterator, context) { this.each(function (value,
  index) {memo = iterator.call(context, memo, value, index);}); return
  memo; }
  function invoke(method) { var args = $A(arguments).slice(1); return
  this.map(function 

[Proto-Scripty] Re: Date Picker on modal box

2010-02-22 Thread Bram Bruneel
Hi,

You might want to try to add an onShow or onUpdate callback function
in the options which constructs the datepicker.

Regards,
Bram

On Feb 22, 1:23 pm, jothis jothish...@gmail.com wrote:
 I have a pop up (prototype js ) modal box , there I can enter data.
 Here a field for enter date.
 I need to use date picker to add date.
 But the date picker not working on modal box.
 How can solve this problem.

 Thanks and regards
 Jothis

-- 
You received this message because you are subscribed to the Google Groups 
Prototype  script.aculo.us group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.



[Proto-Scripty] Re: for...in gets a overflow if including scriptaculous and prototype ?

2010-02-22 Thread T.J. Crowder
Hey Joe,

 ARE there any good uses for this
 loop method?

Absolutely, I use it all the time! Remember that as the linked article
says:

 ...`for..in` is not for iterating through the /indexes/ of an
 /array/.  `for..in` iterates through the /property names/ of an
 /object/.  Arrays are objects, and their element indexes are
 property names (array elements are really just object
 properties), but arrays can have /other/ properties as well,
 which will break your `for..in` loops if you assume they only
 loop through array indexes...

Having a tool that loops through the names of all of the properties of
the object is very useful indeed! JavaScript objects are associative
arrays (aka dictionaries, aka maps), which makes them very handy
indeed. Let's keep track of scores in a game:

var scores, name;

scores = {}; // blank object
scores['Mohammed'] = 23;
scores['Alice'] = 47;
scores['Ping'] = 14;

for (name in scores) {
display(name + :  + scores[name]);
}

That displays:

Mohammed: 23
Alice: 47
Ping: 14

(The order is not defined, at least not as of the 3rd edition spec --
I'll have to check the new 5th edition spec, but for general-purpose
use 3rd edition is still all you can [mostly] rely on for now.)

Prototype uses for..in for lots of things, including its inheritance
mechanism. It's very handy for what it actually does, but the myth
that it loops through the indexes of an array is just that, a myth.

The new ECMAScript 5th ed. spec defines a bunch of new methods on
Array that are similar to Prototype's Enumerable methods, so those are
handy if you don't mind using functions on each iteration, which is
harmless most of the time. And of course, since you're using
Prototype, you already have access to them (albeit -- for now -- with
slightly different names).

HTH,

-- T.J. :-)

On Feb 23, 3:37 am, joe t. thooke...@gmail.com wrote:
 TJ,
 i see endless warnings against using for/in. And i understand the
 reasons for them, especially on arrays. But it seems like a fairly
 powerful looping tool, yet no one seems to temper the warnings with
 appropriate circumstances for its use. Since the JS spec disallows
 creating non-enumerable properties, ARE there any good uses for this
 loop method?

 Thanks,
 -joe t.

 On Feb 22, 9:08 am, T.J. Crowder t...@crowdersoftware.com wrote:



  Hi,

  That for..in code is incorrect, based on a misconception (a common
  one). This page explains the misconception and discusses correct ways
  of iterating through 
  arrays:http://proto-scripty.wikidot.com/prototype:tip-looping-through-arrays

  HTH,
  --
  T.J. Crowder
  Independent Software Consultant
  tj / crowder software / comwww.crowdersoftware.com

  On Feb 22, 12:13 pm, Dale daniel.lehtovi...@gmail.com wrote:

   Hi

   I tried a simple javascript example on the w3school 
   (http://www.w3schools.com/JS/js_loop_for_in.asp),  and the example works 
   fine
   if I don't include scriptaculous or prototype, but once I do I keep
   getting a strange error.

   Anyone know why this error/bug shows up, or have I done something very
   strange in my code ?

   Thanks for any help... examples below...

   The normal example:
   html
   body

   script type=text/javascript
   var x;
   var mycars = new Array();
   mycars[0] = Saab;
   mycars[1] = Volvo;
   mycars[2] = BMW;

   for (x in mycars)
     {
     document.write(mycars[x] + br /);
     }
   /script

   /body
   /html
   Output of this one is:
   Saab
   Volvo
   BMW

   The modified example including the library:
   html
   head
   script src=javascript/prototype.js type=text/javascript/script
   script src=javascript/scriptaculous.js type=text/javascript/
   script
   /head
   body
   script type=text/javascript
   var x;
   var mycars = Array();
   mycars[0] = Saab;
   mycars[1] = Volvo;
   mycars[2] = BMW;

   for (x in mycars)
   {
   document.write(mycars[x] + br /);}

   /script
   /body
   /html

   Output of this one is:
   Saab
   Volvo
   BMW
   function each(iterator, context) { var index = 0; try
   { this._each(function (value) {iterator.call(context, value, index+
   +);}); } catch (e) { if (e != $break) { throw e; } } return this; }
   function eachSlice(number, iterator, context) { var index = - number,
   slices = [], array = this.toArray(); if (number  1) { return array; }
   while ((index += number)  array.length)
   { slices.push(array.slice(index, index + number)); } return
   slices.collect(iterator, context); }
   function all(iterator, context) { iterator = iterator || Prototype.K;
   var result = true; this.each(function (value, index) {result = result
!!iterator.call(context, value, index);if (!result) {throw
   $break;}}); return result; }
   function any(iterator, context) { iterator = iterator || Prototype.K;
   var result = false; this.each(function (value, index) {if ((result = !!
   iterator.call(context, value, index))) {throw $break;}}); return
   result; }
   function