DevNexus | Vanilla.js: Modern 1st Party JavaScript
Setting things up ...
diff --git a/js/controls.js b/js/controls.js
index 64a8613..64ff9cb 100644
--- a/js/controls.js
+++ b/js/controls.js
@@ -85,6 +85,9 @@ export class Controls extends HTMLElement {
* Enables/disables buttons and updates position based on index in the deck
*/
refreshState() {
+ if (this._controlRef == null) {
+ return;
+ }
const next = this._deck.hasNext;
const prev = this._deck.hasPrevious;
this._controlRef.first.disabled = !prev;
diff --git a/js/slide.js b/js/slide.js
index 1aceb05..7f9f770 100644
--- a/js/slide.js
+++ b/js/slide.js
@@ -14,6 +14,11 @@ export class Slide {
* @type {string}
*/
this._text = text;
+ /**
+ * Context for embedded scripts
+ * @type {object}
+ */
+ this._context = {};
/**
* The HTML DOM hosting the slide contents
* @type {HTMLDivElement}
@@ -49,6 +54,42 @@ export class Slide {
else {
this._nextSlideName = null;
}
+ // execute any scripts
+ const script = this._html.querySelector("script");
+ if (script) {
+ (function (/** @type {string} */src) {
+ return eval(src)
+ }).call(this._context, script.innerText);
+ this.dataBind();
+ }
+ }
+
+ /**
+ * Scans for data-binding and applies the bindings
+ */
+ dataBind() {
+ const listBinding = this._html.querySelectorAll("[repeat]");
+ listBinding.forEach(elem => {
+ const parent = elem.parentElement;
+ const expression = elem.getAttribute("repeat");
+ elem.removeAttribute("repeat");
+ const template = elem.outerHTML;
+ parent.removeChild(elem);
+ this._context[expression].forEach(item => {
+ let newTemplate = `${template}`;
+ const matches = newTemplate.match(/\{\{([^\}]*?)\}\}/g);
+ if (matches) {
+ matches.forEach(match => {
+ match = match.replace("{{", "").replace("}}", "");
+ const value = (function (/** @type {string} */src) {
+ return eval(src)
+ }).call({ item }, match);
+ newTemplate = newTemplate.replace(`{{${match}}}`, value);
+ });
+ parent.innerHTML += newTemplate;
+ }
+ });
+ });
}
/**
diff --git a/slides/070-ng-conf2.html b/slides/070-ng-conf2.html
index b440fe9..fcfd829 100644
--- a/slides/070-ng-conf2.html
+++ b/slides/070-ng-conf2.html
@@ -2,4 +2,4 @@
I'm Not Anti-Angular!
Here's proof from 2014...
+ title="Inside the inaugural Angular conference ngConf" />
\ No newline at end of file
diff --git a/slides/data-binding.html b/slides/data-binding.html
new file mode 100644
index 0000000..1f325af
--- /dev/null
+++ b/slides/data-binding.html
@@ -0,0 +1,8 @@
+Data-Binding Example 1
+