in archived/SharedContent/js/Microsoft.WinJS/js/base.js [22128:22539]
attribute: literal(binding.destination[0]),
initialValue: initialValue,
value: binding.value(),
}
);
};
},
}, {
_TreeCSE: TreeCSE,
compile: function TemplateCompiler_compile(template, templateElement, options) {
if (!(templateElement instanceof _Global.HTMLElement)) {
throw "Illegal";
}
writeProfilerMark("WinJS.Binding.Template:compile" + options.profilerMarkIdentifier + ",StartTM");
var compiler = new TemplateCompiler(templateElement, options);
compiler.analyze();
var importAliases = compiler.importAllSafe({
Signal: _Signal,
global: _Global,
document: _Global.document,
cancelBlocker: cancelBlocker,
promise_as: promise_as,
disposeInstance: disposeInstance,
markDisposable: markDisposable,
ui_processAll: ui_processAll,
binding_processAll: binding_processAll,
insertAdjacentHTMLUnsafe: insertAdjacentHTMLUnsafe,
promise: Promise,
utilities_data: utilities_data,
requireSupportedForProcessing: requireSupportedForProcessing,
htmlEscape: htmlEscape,
scopedSelect: scopedSelect,
delayedBindingProcessing: delayedBindingProcessing,
writeProfilerMark: writeProfilerMark
});
compiler.optimize();
compiler.deadCodeElimination();
compiler.lower();
var codeTemplate;
var delayBindings;
switch (options.target) {
case "render":
codeTemplate = compiler.async ? renderImplCodeAsyncTemplate : renderImplCodeTemplate;
delayBindings = false;
break;
case "renderItem":
codeTemplate = compiler.async ? renderItemImplCodeAsyncTemplate : renderItemImplCodeTemplate;
delayBindings = true;
break;
}
var body = compiler.compile(codeTemplate, importAliases, delayBindings);
var render = compiler.link(body);
compiler.done();
writeProfilerMark("WinJS.Binding.Template:compile" + options.profilerMarkIdentifier + ",StopTM");
return render;
}
});
//
// Templates
//
function trimLinesRight(string) {
// Replace all empty lines with just a newline
// Remove all trailing spaces
return string.replace(/^\s*$/gm, "").replace(/^(.*[^\s])( *)$/gm, function (unused, content) {
return content;
});
}
var renderImplMainCodePrefixTemplate = trimLinesRight(
"container.classList.add(\"win-template\"); \n" +
"var html = {html}; \n" +
"{insertAdjacentHTMLUnsafe}(container, \"beforeend\", html); \n" +
"returnedElement = {returnedElement}; \n" +
" \n" +
"// Capture Definitions \n" +
"{capture_definitions}; \n" +
"{set_msParentSelectorScope}; \n" +
" \n"
);
var renderImplControlAndBindingProcessing = trimLinesRight(
"// Control Processing \n" +
"{control_processing}; \n" +
" \n" +
"// Binding Processing \n" +
"{binding_processing}; \n" +
" \n" +
"var result = {promise_as}(returnedElement); \n"
);
var renderImplAsyncControlAndBindingProcessing = trimLinesRight(
"var controlSignal = new {Signal}(); \n" +
"var controlDone = function () {{ if (--{control_counter} === 0) {{ controlSignal.complete(); }} }}; \n" +
"controlDone(); \n" +
" \n" +
"// Control Processing \n" +
"{control_processing}; \n" +
" \n" +
"var result = controlSignal.promise.then(function () {{ \n" +
" // Binding Processing \n" +
" {binding_processing}; \n" +
" return {promise}.join({nestedTemplates}); \n" +
"}}).then(function () {{ \n" +
" return returnedElement; \n" +
"}}).then(null, function (e) {{ \n" +
" if (typeof e === \"object\" && e.name === \"Canceled\") {{ returnedElement.dispose(); }} \n" +
" return {promise}.wrapError(e); \n" +
"}}); \n"
);
var renderImplMainCodeSuffixTemplate = trimLinesRight(
"{markDisposable}(returnedElement, function () {{ {disposeInstance}(returnedElement, result); }}); \n" +
"{suffix_statements}; \n"
);
var renderImplCodeTemplate = trimLinesRight(
"function render(data, container) {{ \n" +
" {debug_break} \n" +
" if (typeof data === \"object\" && typeof data.then === \"function\") {{ \n" +
" // async data + a container falls back to interpreted path \n" +
" if (container) {{ \n" +
" var result = this._renderInterpreted(data, container); \n" +
" return result.element.then(function () {{ return result.renderComplete; }}); \n" +
" }} \n" +
" return {cancelBlocker}(data).then(function(data) {{ return render(data); }}); \n" +
" }} \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStart}); \n" +
" \n" +
" // Declarations \n" +
" var {instance_variable_declarations}; \n" +
" var returnedElement; \n" +
" \n" +
" // Global Definitions \n" +
" {global_definitions}; \n" +
" \n" +
" // Data Definitions \n" +
" data = (data === {global} ? data : {requireSupportedForProcessing}(data)); \n" +
" {data_definitions}; \n" +
" \n" +
" // Instance Variable Definitions \n" +
" {instance_variable_definitions}; \n" +
" \n" +
" // HTML Processing \n" +
" container = container || {document}.createElement({tagName}); \n" +
" var startIndex = container.childElementCount; \n" +
" " + trim(indent(4, renderImplMainCodePrefixTemplate)) + " \n" +
" \n" +
" " + trim(indent(4, renderImplControlAndBindingProcessing)) + " \n" +
" " + trim(indent(4, renderImplMainCodeSuffixTemplate)) + " \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStop}); \n" +
" \n" +
" return result; \n" +
"}} \n"
);
var renderImplCodeAsyncTemplate = trimLinesRight(
"function render(data, container) {{ \n" +
" {debug_break} \n" +
" if (typeof data === \"object\" && typeof data.then === \"function\") {{ \n" +
" // async data + a container falls back to interpreted path \n" +
" if (container) {{ \n" +
" var result = this._renderInterpreted(data, container); \n" +
" return result.element.then(function () {{ return result.renderComplete; }}); \n" +
" }} \n" +
" return {cancelBlocker}(data).then(function(data) {{ return render(data, container); }}); \n" +
" }} \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStart}); \n" +
" \n" +
" // Declarations \n" +
" var {instance_variable_declarations}; \n" +
" var returnedElement; \n" +
" \n" +
" // Global Definitions \n" +
" {global_definitions}; \n" +
" \n" +
" // Data Definitions \n" +
" data = (data === {global} ? data : {requireSupportedForProcessing}(data)); \n" +
" {data_definitions}; \n" +
" \n" +
" // Instance Variable Definitions \n" +
" {instance_variable_definitions}; \n" +
" \n" +
" // HTML Processing \n" +
" container = container || {document}.createElement({tagName}); \n" +
" var startIndex = container.childElementCount; \n" +
" " + trim(indent(4, renderImplMainCodePrefixTemplate)) + " \n" +
" \n" +
" " + trim(indent(4, renderImplAsyncControlAndBindingProcessing)) + " \n" +
" " + trim(indent(4, renderImplMainCodeSuffixTemplate)) + " \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStop}); \n" +
" \n" +
" return result; \n" +
"}} \n"
);
var renderItemImplMainCodeSuffixTemplate = trimLinesRight(
"{markDisposable}(returnedElement, function () {{ {disposeInstance}(returnedElement, result, renderComplete); }});\n" +
"{suffix_statements}; \n"
);
var renderItemImplCodeTemplate = trimLinesRight(
"function renderItem(itemPromise) {{ \n" +
" {debug_break} \n" +
" // Declarations \n" +
" var {instance_variable_declarations}; \n" +
" var element, renderComplete, data, returnedElement; \n" +
" \n" +
" element = itemPromise.then(function renderItem(item) {{ \n" +
" if (typeof item.data === \"object\" && typeof item.data.then === \"function\") {{ \n" +
" return {cancelBlocker}(item.data).then(function (data) {{ return renderItem({{ data: data }}); }});\n" +
" }} \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStart}); \n" +
" \n" +
" // Global Definitions \n" +
" {global_definitions}; \n" +
" \n" +
" // Data Definitions \n" +
" data = item.data; \n" +
" data = (data === {global} ? data : {requireSupportedForProcessing}(data)); \n" +
" {data_definitions}; \n" +
" \n" +
" // Instance Variable Definitions \n" +
" {instance_variable_definitions}; \n" +
" \n" +
" // HTML Processing \n" +
" var container = {document}.createElement({tagName}); \n" +
" var startIndex = 0; \n" +
" " + trim(indent(8, renderImplMainCodePrefixTemplate)) + " \n" +
" \n" +
" " + trim(indent(8, renderImplControlAndBindingProcessing)) + " \n" +
" " + trim(indent(8, renderItemImplMainCodeSuffixTemplate)) + " \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStop}); \n" +
" \n" +
" return result; \n" +
" }}); \n" +
" {renderComplete}; \n" +
" return {{ \n" +
" element: element, \n" +
" renderComplete: renderComplete || element, \n" +
" }}; \n" +
"}} \n"
);
var renderItemImplRenderCompleteTemplate = trimLinesRight(
"renderComplete = element.then(function () {{ \n" +
" return itemPromise; \n" +
"}}).then(function (item) {{ \n" +
" return item.ready || item; \n" +
"}}).then(function (item) {{ \n" +
" {delayed_binding_processing}; \n" +
" return element; \n" +
"}}); \n"
);
var renderItemImplCodeAsyncTemplate = trimLinesRight(
"function renderItem(itemPromise) {{ \n" +
" {debug_break} \n" +
" // Declarations \n" +
" var {instance_variable_declarations}; \n" +
" var element, renderComplete, data, returnedElement; \n" +
" \n" +
" element = itemPromise.then(function renderItem(item) {{ \n" +
" if (typeof item.data === \"object\" && typeof item.data.then === \"function\") {{ \n" +
" return {cancelBlocker}(item.data).then(function (data) {{ return renderItem({{ data: data }}); }});\n" +
" }} \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStart}); \n" +
" \n" +
" // Global Definitions \n" +
" {global_definitions}; \n" +
" \n" +
" // Data Definitions \n" +
" data = item.data; \n" +
" data = (data === {global} ? data : {requireSupportedForProcessing}(data)); \n" +
" {data_definitions}; \n" +
" \n" +
" // Instance Variable Definitions \n" +
" {instance_variable_definitions}; \n" +
" \n" +
" // HTML Processing \n" +
" var container = {document}.createElement({tagName}); \n" +
" var startIndex = 0; \n" +
" " + trim(indent(8, renderImplMainCodePrefixTemplate)) + " \n" +
" \n" +
" " + trim(indent(8, renderImplAsyncControlAndBindingProcessing)) + " \n" +
" " + trim(indent(8, renderItemImplMainCodeSuffixTemplate)) + " \n" +
" \n" +
" {writeProfilerMark}({profilerMarkIdentifierStop}); \n" +
" \n" +
" return result; \n" +
" }}); \n" +
" {renderComplete}; \n" +
" return {{ \n" +
" element: element, \n" +
" renderComplete: renderComplete || element, \n" +
" }}; \n" +
"}} \n"
);
var linkerCodeTemplate = trimLinesRight(
"\"use strict\"; \n" +
" \n" +
"// statics \n" +
"var {static_variable_declarations}; \n" +
"{static_variable_definitions}; \n" +
" \n" +
"// generated template rendering function \n" +
"return {body}; \n"
);
//
// End Templates
//
return TemplateCompiler;
})
});
});
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License.txt in the project root for license information.
define('WinJS/BindingTemplate',[
'exports',
'./Core/_Global',
'./Core/_WinRT',
'./Core/_Base',
'./Core/_BaseUtils',
'./Core/_Log',
'./Core/_WriteProfilerMark',
'./Binding/_Declarative',
'./BindingTemplate/_DataTemplateCompiler',
'./ControlProcessor',
'./Fragments',
'./Promise',
'./Utilities/_Dispose',
'./Utilities/_ElementUtilities'
], function dataTemplateInit(exports, _Global, _WinRT, _Base, _BaseUtils, _Log, _WriteProfilerMark, _Declarative, _DataTemplateCompiler, ControlProcessor, Fragments, Promise, _Dispose, _ElementUtilities) {
"use strict";
// not supported in WebWorker
if (!_Global.document) {
return;
}
var cancelBlocker = Promise._cancelBlocker;
_Base.Namespace._moduleDefine(exports, "WinJS.Binding", {
/// <field>
/// <summary locid="WinJS.Binding.Template">
/// Provides a reusable declarative binding element.
/// </summary>
/// </field>
/// <name locid="WinJS.Binding.Template_name">Template</name>
/// <htmlSnippet supportsContent="true"><![CDATA[<div data-win-control="WinJS.Binding.Template"><div>Place content here</div></div>]]></htmlSnippet>
/// <icon src="base_winjs.ui.template.12x12.png" width="12" height="12" />
/// <icon src="base_winjs.ui.template.16x16.png" width="16" height="16" />
/// <resource type="javascript" src="//WinJS.4.0/js/WinJS.js" shared="true" />
/// <resource type="css" src="//WinJS.4.0/css/ui-dark.css" shared="true" />
Template: _Base.Namespace._lazy(function () {
function interpretedRender(template, dataContext, container) {
_WriteProfilerMark("WinJS.Binding:templateRender" + template._profilerMarkIdentifier + ",StartTM");
if (++template._counter === 1 && (template.debugBreakOnRender || Template._debugBreakOnRender)) {
debugger; // jshint ignore:line
}
var workPromise = Promise.wrap();
var d = container || _Global.document.createElement(template.element.tagName);
_ElementUtilities.addClass(d, "win-template");
_ElementUtilities.addClass(d, "win-loading");
var that = template;
function done() {
_ElementUtilities.removeClass(d, "win-loading");
_WriteProfilerMark("WinJS.Binding:templateRender" + template._profilerMarkIdentifier + ",StopTM");
return extractedChild || d;
}
var initial = d.children.length;
var element;
var extractedChild;
var dispose = function () {
var bindings = _ElementUtilities.data(d).winBindings;
if (bindings) {
bindings.forEach(function (item) {