( el )
| 398 | processItemKey( elem ); |
| 399 | } |
| 400 | function processItemKey( el ) { |
| 401 | var pntKey, pntNode = el, pntItem, tmplItem, key; |
| 402 | // Ensure that each rendered template inserted into the DOM has its own template item, |
| 403 | if ( (key = el.getAttribute( tmplItmAtt ))) { |
| 404 | while ( pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute( tmplItmAtt ))) { } |
| 405 | if ( pntKey !== key ) { |
| 406 | // The next ancestor with a _tmplitem expando is on a different key than this one. |
| 407 | // So this is a top-level element within this template item |
| 408 | // Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment. |
| 409 | pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute( tmplItmAtt ) || 0)) : 0; |
| 410 | if ( !(tmplItem = newTmplItems[key]) ) { |
| 411 | // The item is for wrapped content, and was copied from the temporary parent wrappedItem. |
| 412 | tmplItem = wrappedItems[key]; |
| 413 | tmplItem = newTmplItem( tmplItem, newTmplItems[pntNode]||wrappedItems[pntNode] ); |
| 414 | tmplItem.key = ++itemKey; |
| 415 | newTmplItems[itemKey] = tmplItem; |
| 416 | } |
| 417 | if ( cloneIndex ) { |
| 418 | cloneTmplItem( key ); |
| 419 | } |
| 420 | } |
| 421 | el.removeAttribute( tmplItmAtt ); |
| 422 | } else if ( cloneIndex && (tmplItem = jQuery.data( el, "tmplItem" )) ) { |
| 423 | // This was a rendered element, cloned during append or appendTo etc. |
| 424 | // TmplItem stored in jQuery data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem. |
| 425 | cloneTmplItem( tmplItem.key ); |
| 426 | newTmplItems[tmplItem.key] = tmplItem; |
| 427 | pntNode = jQuery.data( el.parentNode, "tmplItem" ); |
| 428 | pntNode = pntNode ? pntNode.key : 0; |
| 429 | } |
| 430 | if ( tmplItem ) { |
| 431 | pntItem = tmplItem; |
| 432 | // Find the template item of the parent element. |
| 433 | // (Using !=, not !==, since pntItem.key is number, and pntNode may be a string) |
| 434 | while ( pntItem && pntItem.key != pntNode ) { |
| 435 | // Add this element as a top-level node for this rendered template item, as well as for any |
| 436 | // ancestor items between this item and the item of its parent element |
| 437 | pntItem.nodes.push( el ); |
| 438 | pntItem = pntItem.parent; |
| 439 | } |
| 440 | // Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering... |
| 441 | delete tmplItem._ctnt; |
| 442 | delete tmplItem._wrap; |
| 443 | // Store template item as jQuery data on the element |
| 444 | jQuery.data( el, "tmplItem", tmplItem ); |
| 445 | } |
| 446 | function cloneTmplItem( key ) { |
| 447 | key = key + keySuffix; |
| 448 | tmplItem = newClonedItems[key] = |
| 449 | (newClonedItems[key] || newTmplItem( tmplItem, newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent )); |
| 450 | } |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | //---- Helper functions for template item ---- |
no test coverage detected