Skip to content

Commit

Permalink
Fix to processItemKey to make it more robust to deal with
Browse files Browse the repository at this point in the history
'unexpected situations', e.g. IE9 Beta, which seems to remove the
parentNode attribute from the immediate child nodes of a Document Fragment.
This change may also fix Issue 25.
  • Loading branch information
BorisMoore authored and Boris Moore committed Sep 28, 2010
1 parent f827fb6 commit e2ebcc9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions jquery.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
return dataItem ? newTmplItem( options, parentItem, tmpl, dataItem ) : null;
}) :
[ newTmplItem( options, parentItem, tmpl, data ) ];

return topLevel ? jQuery( build( parentItem, null, ret ) ) : ret;
},

Expand Down Expand Up @@ -396,11 +395,12 @@
var pntKey, pntNode = el, pntItem, tmplItem, key;
// Ensure that each rendered template inserted into the DOM has its own template item,
if ( (key = el.getAttribute( tmplItmAtt ))) {
while ((pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { }
if ( pntKey !== key ) {
// The next ancestor with a _tmplitem expando is on a different key than this one.
// So this is a top-level element within this template item
pntNode = pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0);
// Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment.
pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0;
if ( !(tmplItem = newTmplItems[key]) ) {
// The item is for wrapped content, and was copied from the temporary parent wrappedItem.
tmplItem = wrappedItems[key];
Expand Down

0 comments on commit e2ebcc9

Please sign in to comment.