Fix related to bug 10932 and 26344. Need to reset all the event handlers of a dynamically created node after it has been inserted in the DOM. Also do not created a new recipient row when the user press enter after entering a recipient. R=mscott

This commit is contained in:
ducarroz%netscape.com 2000-02-08 02:39:41 +00:00
Родитель 6e1bcc4f3c
Коммит 48060129e5
2 изменённых файлов: 67 добавлений и 22 удалений

Просмотреть файл

@ -175,24 +175,21 @@ function awSetInputAndPopupFromArray(firstRow, inputArray, popupValue)
return(firstRow); return(firstRow);
} }
function awClickRow() function awNotAnEmptyArea(event)
{
dump("awClickRow\n");
if (! top.notAnEmptyArea)
awClickEmptySpace(true);
top.notAnEmptyArea=false;
return;
}
function awNotAnEmptyArea()
{ {
//This is temporary until i figure out how to ensure to always having an empty space after the last row
dump("awNotAnEmptyArea\n"); dump("awNotAnEmptyArea\n");
top.notAnEmptyArea=true;
return; var lastInput = awGetInputElement(top.MAX_RECIPIENTS);
if ( lastInput && lastInput.value )
awAppendNewRow(false);
event.preventBubble();
} }
function awClickEmptySpace(setFocus) function awClickEmptySpace(setFocus)
{ {
dump("awClickEmptySpace\n");
var lastInput = awGetInputElement(top.MAX_RECIPIENTS); var lastInput = awGetInputElement(top.MAX_RECIPIENTS);
if ( lastInput && lastInput.value ) if ( lastInput && lastInput.value )
@ -220,8 +217,12 @@ function awInputChanged(inputElement)
{ {
dump("awInputChanged\n"); dump("awInputChanged\n");
AutoCompleteAddress(inputElement); AutoCompleteAddress(inputElement);
//call awClickEmptySpace to add a new row if needed
awClickEmptySpace(false); //Do we need to add a new row?
var lastInput = awGetInputElement(top.MAX_RECIPIENTS);
if ( lastInput && lastInput.value && !top.doNotCreateANewRow)
awAppendNewRow(false);
top.doNotCreateANewRow = false;
} }
function awAppendNewRow(setFocus) function awAppendNewRow(setFocus)
@ -455,12 +456,11 @@ function _awSetFocus()
var tree = document.getElementById('addressingWidgetTree'); var tree = document.getElementById('addressingWidgetTree');
try try
{ {
theNewRow = awGetTreeRow(top.awRow);
//temporary patch for bug 26344 //temporary patch for bug 26344
//top.awInputElement.setAttribute("onclick", top.awInputElement.getAttribute("onclick")); awFinishCopyNode(theNewRow);
//top.awInputElement.setAttribute("onkeyup", top.awInputElement.getAttribute("onkeyup"));
//end of patch
tree.ensureElementIsVisible(awGetTreeRow(top.awRow)); tree.ensureElementIsVisible(theNewRow);
top.awInputElement.focus(); top.awInputElement.focus();
} }
catch(ex) catch(ex)
@ -475,3 +475,47 @@ function _awSetFocus()
dump("_awSetFocus failed, forget about it!\n"); dump("_awSetFocus failed, forget about it!\n");
} }
} }
//temporary patch for bug 26344
function awFinishCopyNode(node)
{
// dump ("awFinishCopyNode, node name=" + node.nodeName + "\n");
// Because event handler attributes set into a node before this node is inserted
// into the DOM are not recognised (in fact not compiled), we need to parsed again
// the whole node and reset event handlers.
var attributes = node.attributes;
if ( attributes && attributes.length )
{
var attrNode, name;
for ( var index = 0; index < attributes.length; index++ )
{
attrNode = attributes.item(index);
name = attrNode.nodeName;
if (name.substring(0, 2) == 'on')
{
node.setAttribute(name, attrNode.nodeValue);
// dump(" -->reset attribute " + name + "\n");
}
}
}
// children of nodes
if ( node.childNodes )
{
var childNode;
for ( var child = 0; child < node.childNodes.length; child++ )
childNode = awFinishCopyNode(node.childNodes[child]);
}
}
function awTabFromRecipient(element, event)
{
//If we are le last element in the tree, we don't want to create a new row.
if (element == awGetInputElement(top.MAX_RECIPIENTS))
top.doNotCreateANewRow = true;
}

Просмотреть файл

@ -36,7 +36,7 @@ Rights Reserved.
<tree id="addressingWidgetTree" <tree id="addressingWidgetTree"
class="addressingWidget" class="addressingWidget"
rows="3" rows="3"
onclick="awClickRow()" onclick="awClickEmptySpace(true)"
style="width:0px;height:0px;border:solid black 1px"> style="width:0px;height:0px;border:solid black 1px">
<treecol style="width:9em"/> <treecol style="width:9em"/>
@ -45,7 +45,7 @@ Rights Reserved.
<treechildren id="addressWidgetBody"> <treechildren id="addressWidgetBody">
<treeitem> <treeitem>
<treerow> <treerow>
<treecell allowevents="true" onclick="awNotAnEmptyArea()"> <treecell allowevents="true" onclick="awNotAnEmptyArea(event)">
<html:select id="msgRecipientType#1"> <html:select id="msgRecipientType#1">
<html:option value="addr_to">&toAddr.label;</html:option> <html:option value="addr_to">&toAddr.label;</html:option>
<html:option value="addr_cc">&ccAddr.label;</html:option> <html:option value="addr_cc">&ccAddr.label;</html:option>
@ -56,17 +56,18 @@ Rights Reserved.
</html:select> </html:select>
</treecell> </treecell>
<treecell onclick="awNotAnEmptyArea()"> <treecell onclick="awNotAnEmptyArea(event)">
<titledbutton/> <titledbutton/>
</treecell> </treecell>
<treecell allowevents="true" onclick="awNotAnEmptyArea();"> <treecell allowevents="true" onclick="awNotAnEmptyArea(event);">
<html:input id="msgRecipient#1" <html:input id="msgRecipient#1"
flex="100%" flex="100%"
class="addressingWidget" class="addressingWidget"
type="text" type="text"
onkeyup="if (event.which == 13) onkeyup="if (event.which == 13)
{ AutoCompleteAddress(this); awReturnHit(this); }" { AutoCompleteAddress(this); awReturnHit(this); }"
onkeydown="if (event.which == 9) awTabFromRecipient(this, event);"
onchange="awInputChanged(this);" onchange="awInputChanged(this);"
/> />
</treecell> </treecell>