Skip to content

Commit

Permalink
convert the named form elements to use new dispatch table thingy
Browse files Browse the repository at this point in the history
  • Loading branch information
client9 committed Apr 23, 2010
1 parent 2f6bee6 commit a0342a6
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 43 deletions.
3 changes: 3 additions & 0 deletions src/html/button.js
Expand Up @@ -28,3 +28,6 @@ __extend__(HTMLButtonElement.prototype, {
}
});

// Named Element Support
HTMLElement.registerSetAttribute('BUTTON', 'name',
__updateFormForNamedElement__);
41 changes: 1 addition & 40 deletions src/html/element.js
Expand Up @@ -165,41 +165,6 @@ __extend__(HTMLElement.prototype, {
return ret;
},

/**
* Named Element Support
*/

/**
* Not all children of a form are named elements
* returns the parent form element or null if
* there is no parent form or if not a named element
*/
_isFormNamedElement: function(node) {
if (node.nodeType === Node.ELEMENT_NODE) {
switch (node.nodeName.toLowerCase()) {
case 'button':
case 'fieldset':
case 'input':
case 'keygen':
case 'select':
case 'output':
case 'select':
case 'textarea':
return true;
}
}
return false;
},
_updateFormForNamedElement: function() {
if (this._isFormNamedElement(this)) {
if (this.form) {
// to check for ID or NAME attribute too
// not, then nothing to do
this.form._updateElements();
}
}
},

/**
* setAttribute use a dispatch table that other tags can set to
* "listen" to various values being set. The dispatch table
Expand All @@ -211,8 +176,6 @@ __extend__(HTMLElement.prototype, {
setAttribute: function(name, value) {
var result = Element.prototype.setAttribute.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, name);
if (callback) {
Expand All @@ -222,7 +185,6 @@ __extend__(HTMLElement.prototype, {
setAttributeNS: function(namespaceURI, name, value) {
var result = Element.prototype.setAttributeNS.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, name);
Expand All @@ -235,7 +197,6 @@ __extend__(HTMLElement.prototype, {
setAttributeNode: function(newnode) {
var result = Element.prototype.setAttributeNode.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name);
Expand All @@ -247,7 +208,7 @@ __extend__(HTMLElement.prototype, {
setAttributeNodeNS: function(newnode) {
var result = Element.prototype.setAttributeNodeNS.apply(this, arguments);
this.ownerDocument._addNamedMap(this);
this._updateFormForNamedElement();

var tagname = this.tagName;
var callback = HTMLElement.getAttributeCallback('set', tagname, newnode.name);
if (callback) {
Expand Down
4 changes: 4 additions & 0 deletions src/html/fieldset.js
Expand Up @@ -20,3 +20,7 @@ __extend__(HTMLFieldSetElement.prototype, {
return '[object HTMLFieldSetElement]';
}
});

// Named Element Support
HTMLElement.registerSetAttribute('FIELDSET', 'name',
__updateFormForNamedElement__);
15 changes: 12 additions & 3 deletions src/html/input-elements.js
Expand Up @@ -10,12 +10,12 @@
* * legent (no value attr)
* * fieldset (no value attr)
* * label (no value attr)
* * option (custom)
* * option (custom value)
* HTMLTypeValueInputs (extends InputCommon)
* * select (custom)
* * select (custom value)
* * button (just sets value)
* HTMLInputAreaCommon (extends TypeValueIput)
* * input (X)
* * input (custom)
* * textarea (just sets value)
*
* -----------------------
Expand Down Expand Up @@ -264,3 +264,12 @@ __extend__(HTMLInputAreaCommon.prototype, {

}
});


var __updateFormForNamedElement__ = function(node, value) {
if (node.form) {
// to check for ID or NAME attribute too
// not, then nothing to do
node.form._updateElements();
}
};
4 changes: 4 additions & 0 deletions src/html/input.js
Expand Up @@ -69,3 +69,7 @@ HTMLElement.registerSetAttribute('INPUT', 'value', function(node, value) {
node.defaultValue = value;
}
});

// Named Element Support
HTMLElement.registerSetAttribute('INPUT', 'name',
__updateFormForNamedElement__);
4 changes: 4 additions & 0 deletions src/html/select.js
Expand Up @@ -108,3 +108,7 @@ __extend__(HTMLSelectElement.prototype, {
return '[object HTMLSelectElement]';
}
});

// Named Element Support
HTMLElement.registerSetAttribute('SELECT', 'name',
__updateFormForNamedElement__);
4 changes: 4 additions & 0 deletions src/html/textarea.js
Expand Up @@ -38,3 +38,7 @@ HTMLElement.registerSetAttribute('TEXTAREA', 'value', function(node, value) {
// complicated. For now, do nothing
});
*/

// Named Element Support
HTMLElement.registerSetAttribute('TEXTAREA', 'name',
__updateFormForNamedElement__);

0 comments on commit a0342a6

Please sign in to comment.