[Prototype-core] Event.observe

2007-09-14 Thread Roland

Hi there,

Events can be attached multiple times to the same element.. is there a
way to prevent this?

Something like ...

if(!$(el).hasEventAttached()) Event.observe($(el), 'click',
function());

... would be great

Any way to achieve this?

Roland,


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Event.observe

2007-09-14 Thread Mislav Marohnić
On 9/14/07, Roland [EMAIL PROTECTED] wrote:


 Events can be attached multiple times to the same element..


No, they can't. The addEventListener method doesn't attach a handler more
than once; and as for IE, Prototype 1.6 avoids attaching the same handler
twice. So, in IE we emulate addEventListener behavior.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: Event.observe

2007-09-14 Thread Tom Gregory


On Sep 14, 2007, at 1:08 AM, Roland wrote:


 Hi there,

 Events can be attached multiple times to the same element.. is there a
 way to prevent this?

 Something like ...

 if(!$(el).hasEventAttached()) Event.observe($(el), 'click',
 function());

If this is what you *really* need (and I'd suggest you may have a  
design problem if you think so), then don't use Event.observe-- 
instead, attach the handler directly:

// Not tested
var f = function (e) { ... }.bindAsEventListener(someObject);
if (el.onclick != f) {el.onclick = f;}


TAG


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: XML nodes and Element.readAttribute (IE bug)

2007-09-14 Thread Matt Foster

Wow I hate the attribute model, so broken heh.


What is wrong with the native getAttribute method, is there anything
different going on here?

Cheers,
   Matt

On Sep 13, 3:02 pm, Yanick [EMAIL PROTECTED] wrote:
 I don't know if anyone has encountered this problem before, but I was
 reading nodes from an XML document (ajax response) and I tried the
 Element.readAttribute function instead of my own home brewed
 algorithm. (This Web application goes all the way from before there
 was such function in the Prototype library...) Anyway, firefox didn't
 complain, but IE seemed to do so. Here's what I did to resolve this
 issue :

 readAttribute: function(element, name) {
 //element = $(element); // IE doesn't like this line (is it
 really necessary ?)
 if (Prototype.Browser.IE) {
   // XML nodes in IE has an array name attributes. Each index
   // is an object { name: [string], value: [mixed], ... }
   if ( element.attributes  element.attributes.length ) {
 // I'm sure some might find a better way to do this, but it
 works for now
 var attribute =
 $A(element.attributes).find(function(attribute) {return
 attribute.name==name; });
 // if we do not return here, we might throw an exception, so
 rather return null if not found
 return attribute ? attribute.value : null;
   }
   var t = Element._attributeTranslations.read;
   if (t.values[name]) return t.values[name](element, name);
   if (t.names[name]) name = t.names[name];
   if (name.include(':')) {
 return (!element.attributes || !element.attributes[name]) ?
 null :
  element.attributes[name].value;
   }
 }
 return element.getAttribute(name);
   },

 I'm sorry I'm not the best guy to provide more test with this matter,
 but I'm pretty sure some of you already have the proper setup to do
 them. So I'm leaving this into your more capable hands.

 Thank you.

 yanick


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---



[Prototype-core] Re: XML nodes and Element.readAttribute (IE bug)

2007-09-14 Thread Skip Baney
The values returned by getAttribute are not always the same across different
browsers.
Element#readAttribute simply wraps getAttribute and returns consistently.

If you read through the Prototype source, you can see the differences that
it resolves.

- Skip


On 9/14/07, Matt Foster [EMAIL PROTECTED] wrote:


 Wow I hate the attribute model, so broken heh.


 What is wrong with the native getAttribute method, is there anything
 different going on here?

 Cheers,
Matt

 On Sep 13, 3:02 pm, Yanick [EMAIL PROTECTED] wrote:
  I don't know if anyone has encountered this problem before, but I was
  reading nodes from an XML document (ajax response) and I tried the
  Element.readAttribute function instead of my own home brewed
  algorithm. (This Web application goes all the way from before there
  was such function in the Prototype library...) Anyway, firefox didn't
  complain, but IE seemed to do so. Here's what I did to resolve this
  issue :
 
  readAttribute: function(element, name) {
  //element = $(element); // IE doesn't like this line (is it
  really necessary ?)
  if (Prototype.Browser.IE) {
// XML nodes in IE has an array name attributes. Each index
// is an object { name: [string], value: [mixed], ... }
if ( element.attributes  element.attributes.length ) {
  // I'm sure some might find a better way to do this, but it
  works for now
  var attribute =
  $A(element.attributes).find(function(attribute) {return
  attribute.name==name; });
  // if we do not return here, we might throw an exception, so
  rather return null if not found
  return attribute ? attribute.value : null;
}
var t = Element._attributeTranslations.read;
if (t.values[name]) return t.values[name](element, name);
if (t.names[name]) name = t.names[name];
if (name.include(':')) {
  return (!element.attributes || !element.attributes[name]) ?
  null :
   element.attributes[name].value;
}
  }
  return element.getAttribute(name);
},
 
  I'm sorry I'm not the best guy to provide more test with this matter,
  but I'm pretty sure some of you already have the proper setup to do
  them. So I'm leaving this into your more capable hands.
 
  Thank you.
 
  yanick


 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Prototype: Core group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~--~~~~--~~--~--~---