#161 ✓resolved
nickg

setAttribute collisions!

Reported by nickg | April 20th, 2010 @ 11:18 AM

I overloaded 'setAttribute' in img and link thinking I was clever. Turns out a few other people were clever too.

input-elements (form element common functionality) and css stomp on each other, and maybe more.

$ find . -name '*.js' | xargs grep 'setAttribute:'
./html/link.js:    setAttribute: function(name, value) {
./html/element.js:    setAttribute: function(name, value) {  // ORIGINAL
./html/img.js:    setAttribute: function(name, value) { 
./html/input-elements.js:    setAttribute: function(name, value){
./css/htmlelement.js:    setAttribute: function (name, value) { // Blows aways everyone else
$

The same problem happens with appendChild/removeChild (I think).

We didn't see this before since our tests have big gaps.

A quick survey says

  • css/htmlelement -- looks to see if "style"
  • input-elements -- looks for 'value', should also look for name
  • link: looks for href
  • img: looks for src (and name)

So I think the way to do this is to have a mechanism in html where tags can register themselves


// this starts as a plain {}
// but then gets filled in like this
var setAttributeMap = {
 link: {
    'href': onLinkHref
 },
 img: {
    'src': onImgSrc
 }
};

regsiterSetAttribute(nodename, argname, callback) {
   if (! setAttributeMap.hasOwnProperty(nodename)) {
      setAttributeMap[nodename] = {};
   }
   if (setAttributeMap[nodename].hasOwnProperty(argname)) {
      // ERROR, overwritting, or something
   }
   setAttribute[nodename][argname] = callback;
}

HTMLElement.prototype.setAttribute(name, value) {
   try { 
      (setAttributeMap[this.nodeName][name])(this, name, value);
   } catch (e) {
       // blah
   }
   //Normal code
}

I just freestyled that.

Then as code loads it can fill in this map. Much like we do adding to prototypes. THis would also allow end-applications to do stuff too (what I have no idea!)

p.s. I'm using this not google since google group is failing big time today.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

a javascript browser environment

People watching this ticket

Pages