MCPcopy
hub / github.com/BorisMoore/jquery-tmpl / newTmplItem

Function newTmplItem

jquery.tmpl.js:22–50  ·  view source on GitHub ↗
( options, parentItem, fn, data )

Source from the content-addressed store, hash-verified

20 newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = [];
21
22 function newTmplItem( options, parentItem, fn, data ) {
23 // Returns a template item data structure for a new rendered instance of a template (a 'template item').
24 // The content field is a hierarchical array of strings and nested items (to be
25 // removed and replaced by nodes field of dom elements, once inserted in DOM).
26 var newItem = {
27 data: data || (data === 0 || data === false) ? data : (parentItem ? parentItem.data : {}),
28 _wrap: parentItem ? parentItem._wrap : null,
29 tmpl: null,
30 parent: parentItem || null,
31 nodes: [],
32 calls: tiCalls,
33 nest: tiNest,
34 wrap: tiWrap,
35 html: tiHtml,
36 update: tiUpdate
37 };
38 if ( options ) {
39 jQuery.extend( newItem, options, { nodes: [], parent: parentItem });
40 }
41 if ( fn ) {
42 // Build the hierarchical content to be used during insertion into DOM
43 newItem.tmpl = fn;
44 newItem._ctnt = newItem._ctnt || newItem.tmpl( jQuery, newItem );
45 newItem.key = ++itemKey;
46 // Keep track of new template item, until it is stored as jQuery Data on DOM element
47 (stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem;
48 }
49 return newItem;
50 }
51
52 // Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core).
53 jQuery.each({

Callers 3

jquery.tmpl.jsFile · 0.85
processItemKeyFunction · 0.85
cloneTmplItemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected