vendor: 24,461 bytes, lines 1-538
1/*! 2 * $ Templates Plugin 1.0.4 3 * https://github.com/KanbanSolutions/jquery-tmpl 4 * 5 * Copyright Software Freedom Conservancy, Inc. 6 * Dual licensed under the MIT or GPL Version 2 licenses. 7 * http://jquery.org/license 8 */ 9 10/* 11 Tags: 12 {%if <condition> %}<action>{%/if%} 13 {%if <condition> %}<action>{%else%}<action>{%/if%} 14 {%if <condition> %}<action>{%elif <condition> %}<action>{%else%}<action>{%/if%} 15 {%each <array_or_object> %}$value, $index{%/each%} 16 {%tmpl <template>%} 17 {%= js call %} 18 {%html js call %} 19*/ 20(function($, undefined) { 21 var oldManip = $.fn.domManip, tmplItmAtt = "_tmplitem", 22 newTmplItems = {}, wrappedItems = {}, appendToTmplItems, topTmplItem = { key: 0, data: {} }, itemKey = 0, cloneIndex = 0, stack = []; 23 24 25 var regex = { 26 sq_escape: /([\\'])/g, 27 sq_unescape: /\\'/g, 28 dq_unescape: /\\\\/g, 29 nl_strip: /[\r\t\n]/g, 30 shortcut_replace: /\$\{([^\}]*)\}/g, 31 lang_parse: /\{\%(\/?)(\w+|.)(?:\(((?:[^\%]|\%(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\%]|\%(?!\}))*?)\))?\s*\%\}/g, 32 old_lang_parse: /\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g, 33 template_anotate: /(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g, 34 text_only_template: /^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/, 35 html_expr: /^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! |\{\%! /, 36 last_word: /\w$/ 37 }; 38 39 function newTmplItem(options, parentItem, fn, data) { 40 // Returns a template item data structure for a new rendered instance of a template (a 'template item'). 41 // The content field is a hierarchical array of strings and nested items (to be 42 // removed and replaced by nodes field of dom elements, once inserted in DOM). 43 var newItem = { 44 data: data || (data === 0 || data === false) ? data : (parentItem ? parentItem.data : {}), 45 _wrap: parentItem ? parentItem._wrap : null, 46 tmpl: null, 47 parent: parentItem || null, 48 nodes: [], 49 calls: tiCalls, 50 nest: tiNest, 51 wrap: tiWrap, 52 html: tiHtml, 53 update: tiUpdate 54 }; 55 if(options) { 56 $.extend(newItem, options, { nodes: [], parent: parentItem }); 57 } 58 if(fn) { 59 // Build the hierarchical content to be used during insertion into DOM 60 newItem.tmpl = fn; 61 newItem._ctnt = newItem._ctnt || $.isFunction(newItem.tmpl) && newItem.tmpl($, newItem) || fn; 62 newItem.key = ++itemKey; 63 // Keep track of new template item, until it is stored as $ Data on DOM element 64 (stack.length ? wrappedItems : newTmplItems)[itemKey] = newItem; 65 } 66 return newItem; 67 } 68 69 // Override appendTo etc., in order to provide support for targeting multiple elements. (This code would disappear if integrated in jquery core). 70 $.each({ 71 appendTo: "append", 72 prependTo: "prepend", 73 insertBefore: "before", 74 insertAfter: "after", 75 replaceAll: "replaceWith" 76 }, function(name, original) { 77 $.fn[ name ] = function(selector) { 78 var ret = [], insert = $(selector), elems, i, l, tmplItems, 79 parent = this.length === 1 && this[0].parentNode; 80 81 appendToTmplItems = newTmplItems || {}; 82 if(parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1) { 83 insert[ original ](this[0]); 84 ret = this; 85 } else { 86 for(i = 0,l = insert.length; i < l; i++) { 87 cloneIndex = i; 88 elems = (i > 0 ? this.clone(true) : this).get(); 89 $(insert[i])[ original ](elems); 90 ret = ret.concat(elems); 91 } 92 cloneIndex = 0; 93 ret = this.pushStack(ret, name, insert.selector); 94 } 95 tmplItems = appendToTmplItems; 96 appendToTmplItems = null; 97 $.tmpl.complete(tmplItems); 98 return ret; 99 }; 100 }); 101 102 $.fn.extend({ 103 // Use first wrapped element as template markup. 104 // Return wrapped set of template items, obtained by rendering template against data. 105 tmpl: function(data, options, parentItem) { 106 var ret = $.tmpl(this[0], data, options, parentItem); 107 return ret; 108 }, 109 110 // Find which rendered template item the first wrapped DOM element belongs to 111 tmplItem: function() { 112 var ret = $.tmplItem(this[0]); 113 return ret; 114 }, 115 116 // Consider the first wrapped element as a template declaration, and get the compiled template or store it as a named template. 117 template: function(name) { 118 var ret = $.template(name, this[0]); 119 return ret; 120 }, 121 122 domManip: function(args, table, callback, options) { 123 if(args[0] && $.isArray(args[0])) { 124 var dmArgs = $.makeArray(arguments), elems = args[0], elemsLength = elems.length, i = 0, tmplItem; 125 while(i < elemsLength && !(tmplItem = $.data(elems[i++], "tmplItem"))) { 126 } 127 if(tmplItem && cloneIndex) { 128 dmArgs[2] = function(fragClone) { 129 // Handler called by oldManip when rendered template has been inserted into DOM. 130 $.tmpl.afterManip(this, fragClone, callback); 131 }; 132 } 133 oldManip.apply(this, dmArgs); 134 } else { 135 oldManip.apply(this, arguments); 136 } 137 cloneIndex = 0; 138 if(!appendToTmplItems) { 139 $.tmpl.complete(newTmplItems); 140 } 141 return this; 142 } 143 }); 144 145 $.extend({ 146 // Return wrapped set of template items, obtained by rendering template against data. 147 tmpl: function(tmpl, data, options, parentItem) { 148 var ret, topLevel = !parentItem; 149 if(topLevel) { 150 // This is a top-level tmpl call (not from a nested template using {{tmpl}}) 151 parentItem = topTmplItem; 152 tmpl = $.template[tmpl] || $.template(null, tmpl); 153 wrappedItems = {}; // Any wrapped items will be rebuilt, since this is top level 154 } else if(!tmpl) { 155 // The template item is already associated with DOM - this is a refresh. 156 // Re-evaluate rendered template for the parentItem 157 tmpl = parentItem.tmpl; 158 newTmplItems[parentItem.key] = parentItem; 159 parentItem.nodes = []; 160 if(parentItem.wrapped) { 161 updateWrapped(parentItem, parentItem.wrapped); 162 } 163 // Rebuild, without creating a new template item 164 return $(build(parentItem, null, parentItem.tmpl($, parentItem))); 165 } 166 if(!tmpl) { 167 return []; // Could throw... 168 } 169 if(typeof data === "function") { 170 data = data.call(parentItem || {}); 171 } 172 if(options && options.wrapped) { 173 updateWrapped(options, options.wrapped); 174 } 175 ret = $.isArray(data) ? 176 $.map(data, function(dataItem) { 177 return dataItem ? newTmplItem(options, parentItem, tmpl, dataItem) : null; 178 }) : 179 [ newTmplItem(options, parentItem, tmpl, data) ]; 180 return topLevel ? $(build(parentItem, null, ret)) : ret; 181 }, 182 183 // Return rendered template item for an element. 184 tmplItem: function(elem) { 185 var tmplItem; 186 if(elem instanceof $) { 187 elem = elem[0]; 188 } 189 while(elem && elem.nodeType === 1 && !(tmplItem = $.data(elem, 190 "tmplItem")) && (elem = elem.parentNode)) { 191 } 192 return tmplItem || topTmplItem; 193 }, 194 195 // Set: 196 // Use $.template( name, tmpl ) to cache a named template, 197 // where tmpl is a template string, a script element or a $ instance wrapping a script element, etc. 198 // Use $( "selector" ).template( name ) to provide access by name to a script block template declaration. 199 200 // Get: 201 // Use $.template( name ) to access a cached template. 202 // Also $( selectorToScriptBlock ).template(), or $.template( null, templateString ) 203 // will return the compiled template, without adding a name reference. 204 // If templateString includes at least one HTML tag, $.template( templateString ) is equivalent 205 // to $.template( null, templateString ) 206 template: function(name, tmpl) { 207 if(tmpl) { 208 // Compile template and associate with name 209 if(typeof tmpl === "string") { 210 // This is an HTML string being passed directly in. 211 tmpl = buildTmplFn(tmpl) 212 } else if(tmpl instanceof $) { 213 tmpl = tmpl[0] || {}; 214 } 215 if(tmpl.nodeType) { 216 // If this is a template block, use cached copy, or generate tmpl function and cache. 217 tmpl = $.data(tmpl, "tmpl") || $.data(tmpl, "tmpl", buildTmplFn(tmpl.innerHTML)); 218 // Issue: In IE, if the container element is not a script block, the innerHTML will remove quotes from attribute values whenever the value does not include white space. 219 // This means that foo="${x}" will not work if the value of x includes white space: foo="${x}" -> foo=value of x. 220 // To correct this, include space in tag: foo="${ x }" -> foo="value of x" 221 } 222 return typeof name === "string" ? ($.template[name] = tmpl) : tmpl; 223 } 224 // Return named compiled template 225 return name ? (typeof name !== "string" ? $.template(null, name) : 226 ($.template[name] || 227 // If not in map, treat as a selector. (If integrated with core, use quickExpr.exec) 228 $.template(null, name))) : null; 229 }, 230 231 encode: function(text) { 232 // Do HTML encoding replacing < > & and ' and " by corresponding entities. 233 return ("" + text).split("<").join("<").split(">").join(">").split('"').join(""").split("'").join("'"); 234 } 235 }); 236 237 $.extend($.tmpl, { 238 tag: { 239 "tmpl": { 240 _default: { $2: "null" }, 241 open: "if($notnull_1){__=__.concat($item.nest($1,$2));}" 242 // tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions) 243 // This means that {{tmpl foo}} treats foo as a template (which IS a function). 244 // Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}. 245 }, 246 "wrap": { 247 _default: { $2: "null" }, 248 open: "$item.calls(__,$1,$2);__=[];", 249 close: "call=$item.calls();__=call._.concat($item.wrap(call,__));" 250 }, 251 "each": { 252 _default: { $2: "$index, $value" }, 253 open: "if($notnull_1){$.each($1a,function($2){with(this){", 254 close: "}});}" 255 }, 256 "if": { 257 open: "if(($notnull_1) && $1a){", 258 close: "}" 259 }, 260 "else": { 261 open: "}else{" 262 }, 263 "elif": { 264 open: "}else if(($notnull_1) && $1a){" 265 }, 266 "elseif": { 267 open: "}else if(($notnull_1) && $1a){" 268 }, 269 "html": { 270 // Unecoded expression evaluation. 271 open: "if($notnull_1){__.push($1a);}" 272 }, 273 "=": { 274 // Encoded expression evaluation. Abbreviated form is ${}. 275 _default: { $1: "$data" }, 276 open: "if($notnull_1){__.push($.encode($1a));}" 277 }, 278 "!": { 279 // Comment tag. Skipped by parser 280 open: "" 281 } 282 }, 283 284 // This stub can be overridden, e.g. in jquery.tmplPlus for providing rendered events 285 complete: function(items) { 286 newTmplItems = {}; 287 }, 288 289 // Call this from code which overrides domManip, or equivalent 290 // Manage cloning/storing template items etc. 291 afterManip: function afterManip(elem, fragClone, callback) { 292 // Provides cloned fragment ready for fixup prior to and after insertion into DOM 293 var content = fragClone.nodeType === 11 ? 294 $.makeArray(fragClone.childNodes) : 295 fragClone.nodeType === 1 ? [fragClone] : []; 296 297 // Return fragment to original caller (e.g. append) for DOM insertion 298 callback.call(elem, fragClone); 299 300 // Fragment has been inserted:- Add inserted nodes to tmplItem data structure. Replace inserted element annotations by $.data. 301 storeTmplItems(content); 302 cloneIndex++; 303 } 304 }); 305 306 //========================== Private helper functions, used by code above ========================== 307 308 function build(tmplItem, nested, content) { 309 // Convert hierarchical content into flat string array 310 // and finally return array of fragments ready for DOM insertion 311 var frag, ret = content ? $.map(content, function(item) { 312 return (typeof item === "string") ? 313 // Insert template item annotations, to be converted to $.data( "tmplItem" ) when elems are inserted into DOM. 314 (tmplItem.key ? item.replace(regex.template_anotate, 315 "$1 " + tmplItmAtt + "=\"" + tmplItem.key + "\" $2") : item) : 316 // This is a child template item. Build nested template. 317 build(item, tmplItem, item._ctnt); 318 }) : 319 // If content is not defined, insert tmplItem directly. Not a template item. May be a string, or a string array, e.g. from {{html $item.html()}}. 320 tmplItem; 321 if(nested) { 322 return ret; 323 } 324 325 // top-level template 326 ret = ret.join(""); 327 328 // Support templates which have initial or final text nodes, or consist only of text 329 // Also support HTML entities within the HTML markup. 330 ret.replace(regex.text_only_template, function(all, before, middle, after) { 331 frag = $(middle).get(); 332 333 storeTmplItems(frag); 334 if(before) { 335 frag = unencode(before).concat(frag); 336 } 337 if(after) { 338 frag = frag.concat(unencode(after)); 339 } 340 }); 341 return frag ? frag : unencode(ret); 342 } 343 344 function unencode(text) { 345 // Use createElement, since createTextNode will not render HTML entities correctly 346 var el = document.createElement("div"); 347 el.innerHTML = text; 348 return $.makeArray(el.childNodes); 349 } 350 351 // Generate a reusable function that will serve to render a template against data 352 function buildTmplFn(markup) { 353 var parse_tag = function(all, slash, type, fnargs, target, parens, args) { 354 if(!type) { 355 return "');__.push('"; 356 } 357 358 var tag = $.tmpl.tag[ type ], def, expr, exprAutoFnDetect; 359 if(!tag) { 360 return "');__.push('"; 361 } 362 def = tag._default || []; 363 if(parens && !regex.last_word.test(target)) { 364 target += parens; 365 parens = ""; 366 } 367 if(target) { 368 target = unescape(target); 369 args = args ? ("," + unescape(args) + ")") : (parens ? ")" : ""); 370 // Support for target being things like a.toLowerCase(); 371 // In that case don't call with template item as 'this' pointer. Just evaluate... 372 expr = parens ? (target.indexOf(".") > -1 ? target + unescape(parens) : ("(" + target + ").call($item" + args)) : target; 373 exprAutoFnDetect = parens ? expr : "(typeof(" + target + ")==='function'?(" + target + ").call($item):(" + target + "))"; 374 } else { 375 exprAutoFnDetect = expr = def.$1 || "null"; 376 } 377 fnargs = unescape(fnargs); 378 return "');" + 379 tag[ slash ? "close" : "open" ] 380 .split("$notnull_1").join(target ? "typeof(" + target + ")!=='undefined' && (" + target + ")!=null" : "true") 381 .split("$1a").join(exprAutoFnDetect) 382 .split("$1").join(expr) 383 .split("$2").join(fnargs || def.$2 || "") + 384 "__.push('"; 385 }; 386 387 var depreciated_parse = function() { 388 if($.tmpl.tag[arguments[2]]) { 389 return parse_tag.apply(this, arguments); 390 } else { 391 return "');__.push('{{" + arguments[2] + "}}');__.push('"; 392 } 393 }; 394 395 // Use the variable __ to hold a string array while building the compiled template. (See https://github.com/jquery/jquery-tmpl/issues#issue/10). 396 // Introduce the data as local variables using with(){} 397 var parsed_markup_data = "var $=$,call,__=[],$data=$item.data; with($data){__.push('"; 398 399 // Convert the template into pure JavaScript 400 var parsed_markup = $.trim(markup); 401 parsed_markup = parsed_markup.replace(regex.sq_escape, "\\$1"); 402 parsed_markup = parsed_markup.replace(regex.nl_strip, " "); 403 parsed_markup = parsed_markup.replace(regex.shortcut_replace, "{%= $1%}"); 404 parsed_markup = parsed_markup.replace(regex.lang_parse, parse_tag); 405 parsed_markup = parsed_markup.replace(regex.old_lang_parse, depreciated_parse); 406 parsed_markup_data += parsed_markup; 407 408 parsed_markup_data += "');}return __;"; 409 410 return new Function("$", "$item", parsed_markup_data); 411 } 412 413 function updateWrapped(options, wrapped) { 414 // Build the wrapped content. 415 options._wrap = build(options, true, 416 // Suport imperative scenario in which options.wrapped can be set to a selector or an HTML string. 417 $.isArray(wrapped) ? wrapped : [regex.html_expr.test(wrapped) ? wrapped : $(wrapped).html()] 418 ).join(""); 419 } 420 421 function unescape(args) { 422 return args ? args.replace(regex.sq_unescape, "'").replace(regex.dq_unescape, "\\") : null; 423 } 424 425 function outerHtml(elem) { 426 var div = document.createElement("div"); 427 div.appendChild(elem.cloneNode(true)); 428 return div.innerHTML; 429 } 430 431 // Store template items in $.data(), ensuring a unique tmplItem data data structure for each rendered template instance. 432 function storeTmplItems(content) { 433 var keySuffix = "_" + cloneIndex, elem, elems, newClonedItems = {}, i, l, m; 434 for(i = 0,l = content.length; i < l; i++) { 435 if((elem = content[i]).nodeType !== 1) { 436 continue; 437 } 438 elems = elem.getElementsByTagName("*"); 439 for(m = elems.length - 1; m >= 0; m--) { 440 processItemKey(elems[m]); 441 } 442 processItemKey(elem); 443 } 444 function processItemKey(el) { 445 var pntKey, pntNode = el, pntItem, tmplItem, key; 446 // Ensure that each rendered template inserted into the DOM has its own template item, 447 if((key = el.getAttribute(tmplItmAtt))) { 448 while(pntNode.parentNode && (pntNode = pntNode.parentNode).nodeType === 1 && !(pntKey = pntNode.getAttribute(tmplItmAtt))) { 449 } 450 if(pntKey !== key) { 451 // The next ancestor with a _tmplitem expando is on a different key than this one. 452 // So this is a top-level element within this template item 453 // Set pntNode to the key of the parentNode, or to 0 if pntNode.parentNode is null, or pntNode is a fragment. 454 pntNode = pntNode.parentNode ? (pntNode.nodeType === 11 ? 0 : (pntNode.getAttribute(tmplItmAtt) || 0)) : 0; 455 if(!(tmplItem = newTmplItems[key])) { 456 // The item is for wrapped content, and was copied from the temporary parent wrappedItem. 457 tmplItem = wrappedItems[key]; 458 tmplItem = newTmplItem(tmplItem, newTmplItems[pntNode] || wrappedItems[pntNode]); 459 tmplItem.key = ++itemKey; 460 newTmplItems[itemKey] = tmplItem; 461 } 462 if(cloneIndex) { 463 cloneTmplItem(key); 464 } 465 } 466 el.removeAttribute(tmplItmAtt); 467 } else if(cloneIndex && (tmplItem = $.data(el, "tmplItem"))) { 468 // This was a rendered element, cloned during append or appendTo etc. 469 // TmplItem stored in $ data has already been cloned in cloneCopyEvent. We must replace it with a fresh cloned tmplItem. 470 cloneTmplItem(tmplItem.key); 471 newTmplItems[tmplItem.key] = tmplItem; 472 pntNode = $.data(el.parentNode, "tmplItem"); 473 pntNode = pntNode ? pntNode.key : 0; 474 } 475 if(tmplItem) { 476 pntItem = tmplItem; 477 // Find the template item of the parent element. 478 // (Using !=, not !==, since pntItem.key is number, and pntNode may be a string) 479 while(pntItem && pntItem.key != pntNode) { 480 // Add this element as a top-level node for this rendered template item, as well as for any 481 // ancestor items between this item and the item of its parent element 482 pntItem.nodes.push(el); 483 pntItem = pntItem.parent; 484 } 485 // Delete content built during rendering - reduce API surface area and memory use, and avoid exposing of stale data after rendering... 486 delete tmplItem._ctnt; 487 delete tmplItem._wrap; 488 // Store template item as $ data on the element 489 $.data(el, "tmplItem", tmplItem); 490 } 491 function cloneTmplItem(key) { 492 key = key + keySuffix; 493 tmplItem = newClonedItems[key] = 494 (newClonedItems[key] || newTmplItem(tmplItem, 495 newTmplItems[tmplItem.parent.key + keySuffix] || tmplItem.parent)); 496 } 497 } 498 } 499 500 //---- Helper functions for template item ---- 501 502 function tiCalls(content, tmpl, data, options) { 503 if(!content) { 504 return stack.pop(); 505 } 506 stack.push({ _: content, tmpl: tmpl, item:this, data: data, options: options }); 507 } 508 509 function tiNest(tmpl, data, options) { 510 // nested template, using {{tmpl}} tag 511 return $.tmpl($.template(tmpl), data, options, this); 512 } 513 514 function tiWrap(call, wrapped) { 515 // nested template, using {{wrap}} tag 516 var options = call.options || {}; 517 options.wrapped = wrapped; 518 // Apply the template, which may incorporate wrapped content, 519 return $.tmpl($.template(call.tmpl), call.data, options, call.item); 520 } 521 522 function tiHtml(filter, textOnly) { 523 var wrapped = this._wrap; 524 return $.map( 525 $($.isArray(wrapped) ? wrapped.join("") : wrapped).filter(filter || "*"), 526 function(e) { 527 return textOnly ? 528 e.innerText || e.textContent : 529 e.outerHTML || outerHtml(e); 530 }); 531 } 532 533 function tiUpdate() { 534 var coll = this.nodes; 535 $.tmpl(null, null, null, this).insertBefore(coll[0]); 536 $(coll).remove(); 537 } 538})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.