diff --git a/architecture-examples/agilityjs/bower_components/todomvc-common/base.js b/architecture-examples/agilityjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/agilityjs/bower_components/todomvc-common/base.js +++ b/architecture-examples/agilityjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/angularjs-perf/bower_components/todomvc-common/base.js b/architecture-examples/angularjs-perf/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/angularjs-perf/bower_components/todomvc-common/base.js +++ b/architecture-examples/angularjs-perf/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/angularjs/bower_components/todomvc-common/base.js b/architecture-examples/angularjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/angularjs/bower_components/todomvc-common/base.js +++ b/architecture-examples/angularjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/backbone/bower_components/todomvc-common/base.js b/architecture-examples/backbone/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/backbone/bower_components/todomvc-common/base.js +++ b/architecture-examples/backbone/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/canjs/bower_components/todomvc-common/base.js b/architecture-examples/canjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/canjs/bower_components/todomvc-common/base.js +++ b/architecture-examples/canjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/closure/bower_components/todomvc-common/base.js b/architecture-examples/closure/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/closure/bower_components/todomvc-common/base.js +++ b/architecture-examples/closure/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/dart/web/bower_components/todomvc-common/base.js b/architecture-examples/dart/web/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/dart/web/bower_components/todomvc-common/base.js +++ b/architecture-examples/dart/web/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/dojo/bower_components/todomvc-common/base.js b/architecture-examples/dojo/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/dojo/bower_components/todomvc-common/base.js +++ b/architecture-examples/dojo/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/emberjs/bower_components/todomvc-common/base.js b/architecture-examples/emberjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/emberjs/bower_components/todomvc-common/base.js +++ b/architecture-examples/emberjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/gwt/bower_components/todomvc-common/base.js b/architecture-examples/gwt/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/gwt/bower_components/todomvc-common/base.js +++ b/architecture-examples/gwt/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/jquery/bower_components/todomvc-common/base.js b/architecture-examples/jquery/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/jquery/bower_components/todomvc-common/base.js +++ b/architecture-examples/jquery/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/knockback/bower_components/todomvc-common/base.js b/architecture-examples/knockback/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/knockback/bower_components/todomvc-common/base.js +++ b/architecture-examples/knockback/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/knockoutjs/bower_components/todomvc-common/base.js b/architecture-examples/knockoutjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/knockoutjs/bower_components/todomvc-common/base.js +++ b/architecture-examples/knockoutjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/maria/bower_components/todomvc-common/base.js b/architecture-examples/maria/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/maria/bower_components/todomvc-common/base.js +++ b/architecture-examples/maria/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/spine/bower_components/todomvc-common/base.js b/architecture-examples/spine/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/spine/bower_components/todomvc-common/base.js +++ b/architecture-examples/spine/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/architecture-examples/yui/bower_components/todomvc-common/base.js b/architecture-examples/yui/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/architecture-examples/yui/bower_components/todomvc-common/base.js +++ b/architecture-examples/yui/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/dependency-examples/backbone_require/bower_components/todomvc-common/base.js b/dependency-examples/backbone_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/dependency-examples/backbone_require/bower_components/todomvc-common/base.js +++ b/dependency-examples/backbone_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/dependency-examples/flight/bower_components/todomvc-common/base.js b/dependency-examples/flight/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/dependency-examples/flight/bower_components/todomvc-common/base.js +++ b/dependency-examples/flight/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/ariatemplates/bower_components/todomvc-common/base.js b/labs/architecture-examples/ariatemplates/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/ariatemplates/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/ariatemplates/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/backbone.xmpp/bower_components/todomvc-common/base.js b/labs/architecture-examples/backbone.xmpp/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/backbone.xmpp/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/backbone.xmpp/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/backbone_marionette/bower_components/todomvc-common/base.js b/labs/architecture-examples/backbone_marionette/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/backbone_marionette/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/backbone_marionette/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/batman/bower_components/todomvc-common/base.js b/labs/architecture-examples/batman/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/batman/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/batman/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/cujo/bower_components/todomvc-common/base.js b/labs/architecture-examples/cujo/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/cujo/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/cujo/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/derby/public/components/todomvc-common/base.js b/labs/architecture-examples/derby/public/components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/derby/public/components/todomvc-common/base.js +++ b/labs/architecture-examples/derby/public/components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/dermis/bower_components/todomvc-common/base.js b/labs/architecture-examples/dermis/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/dermis/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/dermis/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/dijon/bower_components/todomvc-common/base.js b/labs/architecture-examples/dijon/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/dijon/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/dijon/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/duel/src/main/webapp/bower_components/todomvc-common/base.js b/labs/architecture-examples/duel/src/main/webapp/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/duel/src/main/webapp/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/duel/src/main/webapp/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/epitome/bower_components/todomvc-common/base.js b/labs/architecture-examples/epitome/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/epitome/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/epitome/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/extjs/bower_components/todomvc-common/base.js b/labs/architecture-examples/extjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/extjs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/extjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/extjs_deftjs/bower_components/todomvc-common/base.js b/labs/architecture-examples/extjs_deftjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/extjs_deftjs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/extjs_deftjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/kendo/bower_components/todomvc-common/base.js b/labs/architecture-examples/kendo/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/kendo/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/kendo/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/knockoutjs_classBindingProvider/bower_components/todomvc-common/base.js b/labs/architecture-examples/knockoutjs_classBindingProvider/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/knockoutjs_classBindingProvider/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/knockoutjs_classBindingProvider/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/meteor/client/bower_components/todomvc-common/base.js b/labs/architecture-examples/meteor/client/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/meteor/client/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/meteor/client/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/montage/bower_components/todomvc-common/base.js b/labs/architecture-examples/montage/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/montage/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/montage/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/o_O/bower_components/todomvc-common/base.js b/labs/architecture-examples/o_O/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/o_O/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/o_O/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/olives/bower_components/todomvc-common/base.js b/labs/architecture-examples/olives/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/olives/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/olives/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/plastronjs/bower_components/todomvc-common/base.js b/labs/architecture-examples/plastronjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/plastronjs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/plastronjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/puremvc/bower_components/todomvc-common/base.js b/labs/architecture-examples/puremvc/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/puremvc/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/puremvc/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/rappidjs/bower_components/todomvc-common/base.js b/labs/architecture-examples/rappidjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/rappidjs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/rappidjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/sammyjs/bower_components/todomvc-common/base.js b/labs/architecture-examples/sammyjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/sammyjs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/sammyjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/serenadejs/bower_components/todomvc-common/base.js b/labs/architecture-examples/serenadejs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/serenadejs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/serenadejs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/socketstream/client/code/libs/todomvc-common/base.js b/labs/architecture-examples/socketstream/client/code/libs/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/socketstream/client/code/libs/todomvc-common/base.js +++ b/labs/architecture-examples/socketstream/client/code/libs/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/somajs/bower_components/todomvc-common/base.js b/labs/architecture-examples/somajs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/somajs/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/somajs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/stapes/bower_components/todomvc-common/base.js b/labs/architecture-examples/stapes/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/stapes/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/stapes/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/thorax/bower_components/todomvc-common/base.js b/labs/architecture-examples/thorax/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/thorax/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/thorax/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/typescript-angular/bower_components/todomvc-common/base.js b/labs/architecture-examples/typescript-angular/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/typescript-angular/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/typescript-angular/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/architecture-examples/typescript-backbone/bower_components/todomvc-common/base.js b/labs/architecture-examples/typescript-backbone/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/architecture-examples/typescript-backbone/bower_components/todomvc-common/base.js +++ b/labs/architecture-examples/typescript-backbone/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/angularjs_require/bower_components/todomvc-common/base.js b/labs/dependency-examples/angularjs_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/angularjs_require/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/angularjs_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/backbone_marionette_require/bower_components/todomvc-common/base.js b/labs/dependency-examples/backbone_marionette_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/backbone_marionette_require/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/backbone_marionette_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/canjs_require/bower_components/todomvc-common/base.js b/labs/dependency-examples/canjs_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/canjs_require/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/canjs_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/chaplin-brunch/bower_components/todomvc-common/base.js b/labs/dependency-examples/chaplin-brunch/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/chaplin-brunch/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/chaplin-brunch/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/enyo_backbone/bower_components/todomvc-common/base.js b/labs/dependency-examples/enyo_backbone/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/enyo_backbone/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/enyo_backbone/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/knockoutjs_require/bower_components/todomvc-common/base.js b/labs/dependency-examples/knockoutjs_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/knockoutjs_require/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/knockoutjs_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/stapes_require/bower_components/todomvc-common/base.js b/labs/dependency-examples/stapes_require/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/stapes_require/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/stapes_require/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/thorax_lumbar/bower_components/todomvc-common/base.js b/labs/dependency-examples/thorax_lumbar/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/thorax_lumbar/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/thorax_lumbar/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/labs/dependency-examples/troopjs/bower_components/todomvc-common/base.js b/labs/dependency-examples/troopjs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/labs/dependency-examples/troopjs/bower_components/todomvc-common/base.js +++ b/labs/dependency-examples/troopjs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/learn.json b/learn.json index e723551d46..d80c8aa1fb 100644 --- a/learn.json +++ b/learn.json @@ -1800,6 +1800,6 @@ }] }, "templates": { - "todomvc": "

{{name}}


{{description}}


" + "todomvc": "

<%= name %>

<% examples.forEach(function (example) { %>
<%= example.name %>
<% if (!location.href.match(example.url + '/')) { %> \">Demo, <% } %> \">Source <% }); %>

<%= description %>


<% link_groups.forEach(function (link_group) { %>

<%= link_group.heading %>

<% }); %> " } } diff --git a/template/bower_components/todomvc-common/base.js b/template/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/template/bower_components/todomvc-common/base.js +++ b/template/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink(); diff --git a/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js b/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js index 06f16d4c94..56f3b7f8c4 100644 --- a/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js +++ b/vanilla-examples/vanillajs/bower_components/todomvc-common/base.js @@ -1,6 +1,116 @@ (function () { 'use strict'; + // Underscore's Template Module + // Courtesy of underscorejs.org + var _ = (function (_) { + _.defaults = function (object) { + if (!object) { + return object; + } + for (var argsIndex = 1, argsLength = arguments.length; argsIndex < argsLength; argsIndex++) { + var iterable = arguments[argsIndex]; + if (iterable) { + for (var key in iterable) { + if (object[key] == null) { + object[key] = iterable[key]; + } + } + } + } + return object; + } + + // By default, Underscore uses ERB-style template delimiters, change the + // following template settings to use alternative delimiters. + _.templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g, + escape : /<%-([\s\S]+?)%>/g + }; + + // When customizing `templateSettings`, if you don't want to define an + // interpolation, evaluation or escaping regex, we need one that is + // guaranteed not to match. + var noMatch = /(.)^/; + + // Certain characters need to be escaped so that they can be put into a + // string literal. + var escapes = { + "'": "'", + '\\': '\\', + '\r': 'r', + '\n': 'n', + '\t': 't', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + _.template = function(text, data, settings) { + var render; + settings = _.defaults({}, settings, _.templateSettings); + + // Combine delimiters into one regular expression via alternation. + var matcher = new RegExp([ + (settings.escape || noMatch).source, + (settings.interpolate || noMatch).source, + (settings.evaluate || noMatch).source + ].join('|') + '|$', 'g'); + + // Compile the template source, escaping string literals appropriately. + var index = 0; + var source = "__p+='"; + text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { + source += text.slice(index, offset) + .replace(escaper, function(match) { return '\\' + escapes[match]; }); + + if (escape) { + source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; + } + if (interpolate) { + source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; + } + if (evaluate) { + source += "';\n" + evaluate + "\n__p+='"; + } + index = offset + match.length; + return match; + }); + source += "';\n"; + + // If a variable is not specified, place data values in local scope. + if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; + + source = "var __t,__p='',__j=Array.prototype.join," + + "print=function(){__p+=__j.call(arguments,'');};\n" + + source + "return __p;\n"; + + try { + render = new Function(settings.variable || 'obj', '_', source); + } catch (e) { + e.source = source; + throw e; + } + + if (data) return render(data, _); + var template = function(data) { + return render.call(this, data, _); + }; + + // Provide the compiled function source as a convenience for precompilation. + template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; + + return template; + }; + + return _; + })({}); + if (location.hostname === 'todomvc.com') { window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); } @@ -88,6 +198,7 @@ framework = document.querySelector('[data-framework]').getAttribute('data-framework'); } + if (template && learnJSON[framework]) { this.frameworkJSON = learnJSON[framework]; this.template = template; @@ -96,84 +207,19 @@ } } - Learn.prototype._prepareTemplate = function () { - var aside = document.createElement('aside'); - aside.innerHTML = this.template; - - var header = aside.cloneNode(true); - header.removeChild(header.querySelector('ul')); - header.removeChild(header.querySelectorAll('footer')[1]); - - return { - header: header, - links: aside.cloneNode(true).querySelector('ul a'), - footer: aside.cloneNode(true).querySelectorAll('footer')[1] - }; - }; - - Learn.prototype._parseTemplate = function () { - if (!this.template) { - return; - } - - var frameworkJSON = this.frameworkJSON; - var template = this._prepareTemplate(); - + Learn.prototype.append = function () { var aside = document.createElement('aside'); - var linksTemplate = template.links.outerHTML; - var parser = /\{\{([^}]*)\}\}/g; - - var header, examples, links; + aside.innerHTML = _.template(this.template, this.frameworkJSON); + aside.className = 'learn'; - header = template.header.innerHTML.replace(parser, function (match, key) { - return frameworkJSON[key]; + // Localize demo links + var demoLinks = aside.querySelectorAll('.demo-link'); + Array.prototype.forEach.call(demoLinks, function (demoLink) { + demoLink.setAttribute('href', findRoot() + demoLink.getAttribute('href')); }); - aside.innerHTML = header; - - if (frameworkJSON.examples) { - examples = frameworkJSON.examples.map(function (example) { - return '' - + '
' + example.name + '
' - + '

' - + (location.href.match(example.url + '/') ? '' : ' Demo, ') - + ' Source' - + '

'; - }).join(''); - - aside.querySelector('.source-links').innerHTML = examples; - } - - if (frameworkJSON.link_groups) { - links = frameworkJSON.link_groups.map(function (linkGroup) { - return '' - + '

' + linkGroup.heading + '

' - + ''; - }).join(''); - - aside.innerHTML += links; - aside.innerHTML += template.footer.outerHTML; - } - - return aside; - }; - - Learn.prototype.append = function () { - var aside = this._parseTemplate(); - - aside.className = 'learn'; - document.body.className = (document.body.className + ' learn-bar').trim(); - document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); + document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); }; appendSourceLink();