[Proto-Scripty] Ajax request onfailure

2009-05-14 Thread ioustinos

Hi there, i would like to be able to monitor whether i get a response
or not from  request, within a certain time.
Using firebug, i can see that sometimes, the response does not come
back(request indicated with red color on firebug), or takes too long
to come back. On both those cases i would like to know so that i can
do something about it.
I have set the onFailure callback but it never got triggered.

What can i do?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] AJAX exception handling

2009-05-14 Thread Glenn Maynard

Exceptions inside AJAX handlers are sent to onException and then
swallowed.  The behavior I think most people would expect is that if
they're not using any onException handlers, exceptions should be
raised normally, not silently discarded.  That's the behavior I
want--for errors to always go to the error console, like all other
errors.  (I can see the underlying reason for this behavior--so
callbacks are guaranteed to be called, even if one of them
misbehaves.)

I can work around this with a responder:

Ajax.Responders.register({
onException: function(request, exception) {
(function() { throw exception; }).defer();
}
});

The defer() is necessary to break out of Ajax.Responders.dispatch's
exception handler, which silently eats everything.  This also has the
nice property that if multiple callbacks throw errors, the callback
chain isn't broken, but all of the errors are still shown.  It's also
not dependant on responder order; if it's registered first, later
responders still run.

I'm not sure if throwing an exception outside of the context it was
originally thrown will confuse JS debuggers.  (I don't use one; they
all destabilize FF badly for me.)

It would be nice to have this behavior by default.  I suspect most
people who use Prototype AJAX have been bitten by this, and this
workaround is a bit obscure for people to have to discover on their
own.

-- 
Glenn Maynard

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: AJAX exception handling

2009-05-14 Thread T.J. Crowder

Hi,

 swallowed.  The behavior I think most people would expect is that if
 they're not using any onException handlers, exceptions should be
 raised normally, not silently discarded.

I don't think they would, but more to the point, raised normally
*where*?  In the normal case (asynchronous requests), the code that
initiated the request has long since completed.  So unless you mean
raising exceptions to the browser (which doesn't seem like a good
idea, and can result in your script being terminated completely), I
don't see where it would get raised.  And there's no standard for a
global exception catcher, is there?  Some browsers have them, I think,
but I don't know of a standard for one.  So even if Prototype raised
the exception globally, how would you handle it?

No, having a callback for exceptions makes sense to me.  As with a
standard try/catch/finally block, your exception handling logic is
near (but not interspersed with) your mainline logic, which has proven
to be a fairly useful paradigm.  (try = request, catch = onException,
finally = onComplete)  Maybe there could be an argument for
synchronous requests to raise the exception out of the Ajax.Request
constructor, but I think it's trumped by having a uniform way of
handling exceptions for all Ajax requests (rather than different
mechanisms depending on whether you're doing a synchronous or async
request).

If you want to semi-globally handle all exceptions in Ajax requests,
as you show you can do it with a responder.  If you want to semi-
globally handle all exceptions only in your own Ajax requests (and
not, say, Autocompleter's), a factory function readily handles setting
that up on each request.

function ajaxRequest(url, options) {
options = options || {};
options.onException = options.onException || yourGlobalHandler;
return new Ajax.Request(url, options);
}
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On May 14, 3:40 am, Glenn Maynard gl...@zewt.org wrote:
 Exceptions inside AJAX handlers are sent to onException and then
 swallowed.  The behavior I think most people would expect is that if
 they're not using any onException handlers, exceptions should be
 raised normally, not silently discarded.  That's the behavior I
 want--for errors to always go to the error console, like all other
 errors.  (I can see the underlying reason for this behavior--so
 callbacks are guaranteed to be called, even if one of them
 misbehaves.)

 I can work around this with a responder:

 Ajax.Responders.register({
         onException: function(request, exception) {
                 (function() { throw exception; }).defer();
         }

 });

 The defer() is necessary to break out of Ajax.Responders.dispatch's
 exception handler, which silently eats everything.  This also has the
 nice property that if multiple callbacks throw errors, the callback
 chain isn't broken, but all of the errors are still shown.  It's also
 not dependant on responder order; if it's registered first, later
 responders still run.

 I'm not sure if throwing an exception outside of the context it was
 originally thrown will confuse JS debuggers.  (I don't use one; they
 all destabilize FF badly for me.)

 It would be nice to have this behavior by default.  I suspect most
 people who use Prototype AJAX have been bitten by this, and this
 workaround is a bit obscure for people to have to discover on their
 own.

 --
 Glenn Maynard
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Adding a input box

2009-05-14 Thread mahi

Hi

I am newbie in prototype.js, here i am trying to add the input box it
is working in IE  but not in mozilla .
pl help me ASAP...


var c =new Element('input', {'type':'text', 'id': 'var1Value' ,
'value':'var1 default value'});
$('uiElements').insert(c);

regards
mahendra varandani
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding a input box

2009-05-14 Thread rai.ashis
Hi,

you can try other way to insert like

$('uiElements').insert(input type='text' id='idName' value='anything'/);

it's the simple way as you are writing the code in js file so you can try
this one.


You can try scriptaculous builder.js also. Here is the link

http://wiki.github.com/madrobby/scriptaculous/builder


Thanks


On Thu, May 14, 2009 at 2:54 PM, mahi chiku.4...@gmail.com wrote:


 Hi

 I am newbie in prototype.js, here i am trying to add the input box it
 is working in IE  but not in mozilla .
 pl help me ASAP...


 var c =new Element('input', {'type':'text', 'id': 'var1Value' ,
 'value':'var1 default value'});
 $('uiElements').insert(c);

 regards
 mahendra varandani
 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding a input box

2009-05-14 Thread ColinFine



On May 14, 10:09 am, mahi chiku.4...@gmail.com wrote:
 Hi

 I am newbie in prototype.js, here i am trying to add the input box it
 is working in IE  but not in mozilla .
 pl help me ASAP...

 var c =new Element('input', {'type':'text', 'id': 'var1Value' ,
 'value':'var1 default value'});
 $('uiElements').insert(c);

You need to give us more information.
When you say 'not working', it might be any of:
- gives a browser error
- crashes the browser
- no visible effect
- displays the input box, but it is empty
- displays the input box, but won't let you change it
- displays the input box, but when you submit the form, it ignores the
changes you've made

and probably more possibilities I haven't thought of.

Can you see that without knowing what you mean by it, it's almost
impossible to advise you?

Also, you haven't told us what 'usElements' is.

Colin

 regards
 mahendra varandani
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread louis w

I'm not sure if include would work if an item has more then one class.

Given these classes: $A(['foo', 'bar', 'foob']);

Would match:
div class=foo whateverhi/div
div class=barhi/div

Would not match
div class=whateverHi/div
div class=foobarHi/div

I guess i am going to have to iterate the classes to check, was hoping
there was a more elegant solution.



On May 13, 11:09 pm, rai.ashis ashis@gmail.com wrote:
 Hi,

 i think you can you can use include which will return either true or false
 depending upon.

 I think this one works.

 Thanks

 On Thu, May 14, 2009 at 12:19 AM, louis w louiswa...@gmail.com wrote:

  I have an array containing a number of strings. I would like to
  continue exucuting my script only if an item has ANY/ALL of the
  strings assigned as a class name.

  $A(['foo', 'bar', 'foob']);

  Is there an elegant want to do this without having to loop through the
  items?

 --
 Ashis Rai
 Sundhara, Kathmandu, Nepal
 P.O Box No: 12434
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding a input box

2009-05-14 Thread Miguel Beltran R.

 'value':'var1 default value'});


maybe no correct closing values
chage to 'value':'var1', default:'value'});

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Adding a input box

2009-05-14 Thread mahen
Hi all

thanks  for replying..

no this is the correct value i am giving this by my own.

well ya i tried the above solutions by direct inserting the input tag as
Html but still its not working in Mozilla. Well my designer is
saying there might be somewhat issue of Design Css as the positioning of
that container div he is working on it might it workss..

again thanks for reply and if you found any relative spolutions pl let me
know.


Mahendra Varandani
Software Engineer
IDes Solutions
Gurgaon
Ph-9990869026


On Thu, May 14, 2009 at 7:42 PM, Miguel Beltran R. yourpa...@gmail.comwrote:

 'value':'var1 default value'});


 maybe no correct closing values
 chage to 'value':'var1', default:'value'});



 


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread T.J. Crowder

Hi,

I can think of two approaches off-hand:

1. Use Enumerable#include on the array of classes you want to test
against, using Element#hasClassName as the iterator function (bound to
the instance), e.g.:

var test = ['foo', 'bar', 'foob'];
if (test.any(element.hasClassName.bind(element))) {
// ...
}

or

if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
(element))) {
// ...
}

(You don't need to use $A() around array literals.)

2. Use $w on the class name to get an array of the individual class
names, then use Enumerable#any on that, passing in Enumerable#include
on the array you want to test against as the #any iterator.  Something
like this:

var test = ['foo', 'bar', 'foob'];
if ($w(element.className).any(test.include.bind(test))) {
log(true);
}

(Both of those bits of code are untested.)

But if this is going to be happening a lot (a tight loop, or a
mouseover handler, etc.), check the runtime cost of each of these by
going under the covers.

FWIW,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On May 13, 7:34 pm, louis w louiswa...@gmail.com wrote:
 I have an array containing a number of strings. I would like to
 continue exucuting my script only if an item has ANY/ALL of the
 strings assigned as a class name.

 $A(['foo', 'bar', 'foob']);

 Is there an elegant want to do this without having to loop through the
 items?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread Matt Foster

 var test = ['foo', 'bar', 'foob'];
 if (test.any(element.hasClassName.bind(element))) {

I believe using the non-methodized version of this method would be
better

Element.hasClassName.curry(element);

--

http://positionabsolute.net



On May 14, 12:30 pm, T.J. Crowder t...@crowdersoftware.com wrote:
 Hi,

 I can think of two approaches off-hand:

 1. Use Enumerable#include on the array of classes you want to test
 against, using Element#hasClassName as the iterator function (bound to
 the instance), e.g.:

     var test = ['foo', 'bar', 'foob'];
     if (test.any(element.hasClassName.bind(element))) {
         // ...
     }

 or

     if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
 (element))) {
         // ...
     }

 (You don't need to use $A() around array literals.)

 2. Use $w on the class name to get an array of the individual class
 names, then use Enumerable#any on that, passing in Enumerable#include
 on the array you want to test against as the #any iterator.  Something
 like this:

     var test = ['foo', 'bar', 'foob'];
     if ($w(element.className).any(test.include.bind(test))) {
         log(true);
     }

 (Both of those bits of code are untested.)

 But if this is going to be happening a lot (a tight loop, or a
 mouseover handler, etc.), check the runtime cost of each of these by
 going under the covers.

 FWIW,
 --
 T.J. Crowder
 tj / crowder software / com
 Independent Software Engineer, consulting services available

 On May 13, 7:34 pm, louis w louiswa...@gmail.com wrote:

  I have an array containing a number of strings. I would like to
  continue exucuting my script only if an item has ANY/ALL of the
  strings assigned as a class name.

  $A(['foo', 'bar', 'foob']);

  Is there an elegant want to do this without having to loop through the
  items?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread louis w

Thanks guys. I am going to compare the difference in processing time
of TJ's suggestions. It will be called often (from a Form Observer).
For now I am using this one:

if 
(_validate_field_classes.any(element.hasClassName.bind
(element))) {

Wasn't aware of the any function.

Matt. I tried swapping bind for curry and it gave an error.




On May 14, 3:32 pm, Matt Foster mattfoste...@gmail.com wrote:
      var test = ['foo', 'bar', 'foob'];
      if (test.any(element.hasClassName.bind(element))) {

 I believe using the non-methodized version of this method would be
 better

 Element.hasClassName.curry(element);

 --

 http://positionabsolute.net

 On May 14, 12:30 pm, T.J. Crowder t...@crowdersoftware.com wrote:

  Hi,

  I can think of two approaches off-hand:

  1. Use Enumerable#include on the array of classes you want to test
  against, using Element#hasClassName as the iterator function (bound to
  the instance), e.g.:

      var test = ['foo', 'bar', 'foob'];
      if (test.any(element.hasClassName.bind(element))) {
          // ...
      }

  or

      if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
  (element))) {
          // ...
      }

  (You don't need to use $A() around array literals.)

  2. Use $w on the class name to get an array of the individual class
  names, then use Enumerable#any on that, passing in Enumerable#include
  on the array you want to test against as the #any iterator.  Something
  like this:

      var test = ['foo', 'bar', 'foob'];
      if ($w(element.className).any(test.include.bind(test))) {
          log(true);
      }

  (Both of those bits of code are untested.)

  But if this is going to be happening a lot (a tight loop, or a
  mouseover handler, etc.), check the runtime cost of each of these by
  going under the covers.

  FWIW,
  --
  T.J. Crowder
  tj / crowder software / com
  Independent Software Engineer, consulting services available

  On May 13, 7:34 pm, louis w louiswa...@gmail.com wrote:

   I have an array containing a number of strings. I would like to
   continue exucuting my script only if an item has ANY/ALL of the
   strings assigned as a class name.

   $A(['foo', 'bar', 'foob']);

   Is there an elegant want to do this without having to loop through the
   items?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread Matt Foster

I think you misinterpreted what I was saying.  Simply swapping bind
for curry will certainly generate errors.

I don't really feel like explaining it and its of potentially trivial
performance results but, savor some of this syntax...

var ele = $(container);
var arr = $w(foo bar derka);
var bool = arr.any(Element.hasClassName.curry(ele));
console.log(bool);//if this throws an error, get firebug!!

...

div id=container class='foo'/div

--

http://positionabsolute.net

On May 14, 5:04 pm, louis w louiswa...@gmail.com wrote:
 Thanks guys. I am going to compare the difference in processing time
 of TJ's suggestions. It will be called often (from a Form Observer).
 For now I am using this one:

                         if 
 (_validate_field_classes.any(element.hasClassName.bind
 (element))) {

 Wasn't aware of the any function.

 Matt. I tried swapping bind for curry and it gave an error.

 On May 14, 3:32 pm, Matt Foster mattfoste...@gmail.com wrote:

       var test = ['foo', 'bar', 'foob'];
       if (test.any(element.hasClassName.bind(element))) {

  I believe using the non-methodized version of this method would be
  better

  Element.hasClassName.curry(element);

  --

 http://positionabsolute.net

  On May 14, 12:30 pm, T.J. Crowder t...@crowdersoftware.com wrote:

   Hi,

   I can think of two approaches off-hand:

   1. Use Enumerable#include on the array of classes you want to test
   against, using Element#hasClassName as the iterator function (bound to
   the instance), e.g.:

       var test = ['foo', 'bar', 'foob'];
       if (test.any(element.hasClassName.bind(element))) {
           // ...
       }

   or

       if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
   (element))) {
           // ...
       }

   (You don't need to use $A() around array literals.)

   2. Use $w on the class name to get an array of the individual class
   names, then use Enumerable#any on that, passing in Enumerable#include
   on the array you want to test against as the #any iterator.  Something
   like this:

       var test = ['foo', 'bar', 'foob'];
       if ($w(element.className).any(test.include.bind(test))) {
           log(true);
       }

   (Both of those bits of code are untested.)

   But if this is going to be happening a lot (a tight loop, or a
   mouseover handler, etc.), check the runtime cost of each of these by
   going under the covers.

   FWIW,
   --
   T.J. Crowder
   tj / crowder software / com
   Independent Software Engineer, consulting services available

   On May 13, 7:34 pm, louis w louiswa...@gmail.com wrote:

I have an array containing a number of strings. I would like to
continue exucuting my script only if an item has ANY/ALL of the
strings assigned as a class name.

$A(['foo', 'bar', 'foob']);

Is there an elegant want to do this without having to loop through the
items?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] InPlaceEditor does not show up in place?

2009-05-14 Thread Rob

I'm new to script.aculo.us and trying to use the InPlaceEditor to edit
a string on the same line as some HTML.   When I click on the text
controled by the Ajax.InPlaceEditor() call it always displays the
input control on the next line.  Is this a not so inplace editor?  Am
I missing something?  Searches on the web didn't come up with any bugs
in this, but it doesn't seem to be working as expected.  simple repro:

html
head
   script language='javascript' src='/approot/mainstreet/js/
prototype.js'   /script
   script language='javascript' src='/approot/mainstreet/js/
scriptaculous.js'   /script
   script language='javascript' src='/approot/mainstreet/js/
controls.js'/script
/head

body bgcolor=#B5CEEA

   div id=chkbox_col3 style=position:absolute; left:60px; top:
180px;


  a test:
  label name=lblTest id=lblTest
 test
  /label

  script type=text/javascript
 new Ajax.InPlaceEditor('lblTest', '/blank.htm',
 {
formId:'asdf',
cols:2,
rows:1,
okControl:false,
cancelControl:link,
highlightColor:#ff,
highlightEndColor:#B5CEEA
 });
  /script

   /div

/body
/html

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread T.J. Crowder

@Matt:

 I believe using the non-methodized version of this method would be
 better

 Element.hasClassName.curry(element);

Ah, yes, well spotted.  Probably not a huge difference, but certainly
a positive one.  E.g.:

if (['foo', 'bar', 'foob'].any(Element.hasClassName.curry(element))) {
   // ...
}

@OP:

All of Prototype's element extensions are also available via
Element.xyz.  E.g., these statements are functionally equivalent:

myElement.addClassName('foo');
Element.addClassName(myElement, 'foo');

The former (the methodized version) is just a wrapper for the latter
(and therefore incurs a tiny bit more overhead).
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available


On May 14, 8:32 pm, Matt Foster mattfoste...@gmail.com wrote:
      var test = ['foo', 'bar', 'foob'];
      if (test.any(element.hasClassName.bind(element))) {

 I believe using the non-methodized version of this method would be
 better

 Element.hasClassName.curry(element);

 --

 http://positionabsolute.net

 On May 14, 12:30 pm, T.J. Crowder t...@crowdersoftware.com wrote:

  Hi,

  I can think of two approaches off-hand:

  1. Use Enumerable#include on the array of classes you want to test
  against, using Element#hasClassName as the iterator function (bound to
  the instance), e.g.:

      var test = ['foo', 'bar', 'foob'];
      if (test.any(element.hasClassName.bind(element))) {
          // ...
      }

  or

      if (['foo', 'bar', 'foob'].any(element.hasClassName.bind
  (element))) {
          // ...
      }

  (You don't need to use $A() around array literals.)

  2. Use $w on the class name to get an array of the individual class
  names, then use Enumerable#any on that, passing in Enumerable#include
  on the array you want to test against as the #any iterator.  Something
  like this:

      var test = ['foo', 'bar', 'foob'];
      if ($w(element.className).any(test.include.bind(test))) {
          log(true);
      }

  (Both of those bits of code are untested.)

  But if this is going to be happening a lot (a tight loop, or a
  mouseover handler, etc.), check the runtime cost of each of these by
  going under the covers.

  FWIW,
  --
  T.J. Crowder
  tj / crowder software / com
  Independent Software Engineer, consulting services available

  On May 13, 7:34 pm, louis w louiswa...@gmail.com wrote:

   I have an array containing a number of strings. I would like to
   continue exucuting my script only if an item has ANY/ALL of the
   strings assigned as a class name.

   $A(['foo', 'bar', 'foob']);

   Is there an elegant want to do this without having to loop through the
   items?


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread Gabriel Gilini
On Wed, May 13, 2009 at 3:34 PM, louis w louiswa...@gmail.com wrote:


 I have an array containing a number of strings. I would like to
 continue exucuting my script only if an item has ANY/ALL of the
 strings assigned as a class name.

 $A(['foo', 'bar', 'foob']);

 Is there an elegant want to do this without having to loop through the
 items?


Supposing you have the aforementioned element stored in the - elm -
variable, and the classes' array in the - classesArr - variable:

var classNamesRegex = new RegExp('\\b(' + classesArr.join('|') + ')\\b'); //
Generates /\b(foo|bar|foob)\b/

if(!classNamesRegex.test(elm.className)){
   window.alert('get me out of here');
}

Gabriel Gilini

www.usosim.com.br
gabr...@usosim.com.br

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: AJAX exception handling

2009-05-14 Thread Glenn Maynard

On Thu, May 14, 2009 at 8:17 PM, T.J. Crowder t...@crowdersoftware.com wrote:
 Sure, after figuring out why exceptions are disappearing, and then
 figuring out how to get around that all-encompassing exception block
 surrounding the responder.  It's a lot of digging to get reasonable
 default behavior.

 Or, you know, read the documentation. ;-)

The documentation explains how to set exception handlers within AJAX.
It does not explain that if you don't set one, exceptions will be
silently ignored; to figure out why my callbacks were silently doing
nothing I had to trace the source.  Nor does it explain how to force
exceptions to be propagated normally; delaying the exception in a
defer() is hardly obvious.

 No, seriously, we'll have to agree to disagree on this.  I'm just one
 counterpoint to your statement that most people would expect
 something else.  I wouldn't.  I expected, and quickly found when I
 started using Prototype's Ajax stuff, exactly what's there.  I find
 the default behavior quite reasonable.

You find the default behavior of silently ignoring all exceptions
reasonable?  Seriously?

Please explain why it should not propagate exceptions normally when no
error handlers are set.  You havn't given any rational explanation.
If you're using exception callbacks, then this has zero impact on you.

-- 
Glenn Maynard

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread kangax

On May 14, 8:24 pm, Gabriel Gilini gabr...@usosim.com.br wrote:
 On Wed, May 13, 2009 at 3:34 PM, louis w louiswa...@gmail.com wrote:

  I have an array containing a number of strings. I would like to
  continue exucuting my script only if an item has ANY/ALL of the
  strings assigned as a class name.

  $A(['foo', 'bar', 'foob']);

  Is there an elegant want to do this without having to loop through the
  items?

 Supposing you have the aforementioned element stored in the - elm -
 variable, and the classes' array in the - classesArr - variable:

 var classNamesRegex = new RegExp('\\b(' + classesArr.join('|') + ')\\b'); //
 Generates /\b(foo|bar|foob)\b/

 if(!classNamesRegex.test(elm.className)){
    window.alert('get me out of here');

 }

Please don't use boundaries to separate class values. I wonder who
came up with this silly idea and why it keeps circulating around.

/\bfoo\b/ matches values such as foo-bar which is, of course, wrong.
Class tokens are separated by whitespace (well, technically there's a
particular set of characters. HTML5, for example, defines them as - [\
\u0020\\u0009\\u000A\\u000C\\u000D]) and so regex to match certain
className should be wrapped with whitespace characters (as well as
start of line/end of line tokens) -

/(^|\s)foo(\s|$)/

--
kangax
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[Proto-Scripty] Re: Check element class against array

2009-05-14 Thread Gabriel Gilini
On Fri, May 15, 2009 at 12:05 AM, kangax kan...@gmail.com wrote:


 On May 14, 8:24 pm, Gabriel Gilini gabr...@usosim.com.br wrote:
  var classNamesRegex = new RegExp('\\b(' + classesArr.join('|') + ')\\b');
 //
  Generates /\b(foo|bar|foob)\b/

 Please don't use boundaries to separate class values. I wonder who
 came up with this silly idea and why it keeps circulating around.


 /\bfoo\b/ matches values such as foo-bar which is, of course, wrong.


Hm, I didn't know that. Actually I have never used /b myself, I didn't even
know they existed in JavaScript. I thought they would replace just fine the
(^|\s) thing (which is what I usually use).
Thanks for the advice.

Gabriel Gilini

www.usosim.com.br
gabr...@usosim.com.br

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---