You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@
3
3
An implementation of HTML template by way of the microdata mechanism.
4
4
### The Gist
5
5
This JavaScript module should simplify adding dynamic content to HTML documents while staying true to the recommendations of web standards. There are no dependencies here except the JavaScript [ECMA5 standard](http://www.ecma-international.org/ecma-262/5.1/) which enjoys [nearly universal support](http://kangax.github.io/compat-table/es5/) in modern browsers. Also, since the HTML recommendations for integral technologies such as [template](https://www.w3.org/TR/html52/semantics-scripting.html#the-template-element) and [microdata](https://www.w3.org/TR/microdata/) are variably implemented by modern browsers, this module serves as a [polyfill](https://en.wikipedia.org/wiki/Polyfill) to assure reliable results. Best of all, this methodology encourages the writing of low-dependency JavaScript and perfectly valid HTML — even within fully-functional templated markup.
6
+
7
+
***
6
8
### Simple Usage
7
9
**1:** In the HTML document, simply load the module and instantiate when ready:
8
10
```html
@@ -27,7 +29,6 @@ This JavaScript module should simplify adding dynamic content to HTML documents
27
29
</nav>
28
30
```
29
31
30
-
31
32
**3:** In JavaScript, create a corresponding set of data and then render it (note that the designated element can be an outer scope):
32
33
```javascript
33
34
var data = [{
@@ -42,7 +43,6 @@ var templater = new MicrodataTemplate();
**4:** The resulting HTML will look like this (the template source persists for future use but remains hidden):
47
47
```html
48
48
<nav>
@@ -62,7 +62,6 @@ var templater = new MicrodataTemplate();
62
62
</nav>
63
63
```
64
64
65
-
66
65
**Note:** The example above is simplified for clarity, but more compliant microdata could look like this:
67
66
```html
68
67
<nav>
@@ -75,6 +74,8 @@ var templater = new MicrodataTemplate();
75
74
</menu>
76
75
</nav>
77
76
```
77
+
78
+
***
78
79
### Advanced Usage
79
80
Alternatively, the module can be assigned to a discrete namespace:
80
81
```html
@@ -89,8 +90,41 @@ Alternatively, the module can be assigned to a discrete namespace:
89
90
});
90
91
</script>
91
92
```
93
+
This module is organized to be attached to an HTML document as a simple external script, but also in a project governed by [Asynchronous Module Definition](https://en.wikipedia.org/wiki/Asynchronous_module_definition) (AMD) with a library such as [RequireJS](https://github.com/requirejs/requirejs), or a [CommonJS](https://en.wikipedia.org/wiki/CommonJS) project governed by a framework such as [NodeJS](https://en.wikipedia.org/wiki/Node.js). The expectations are the same, but the syntax used to load, instantiate, and then address the module will be as a local reference rather than a window namespace.
94
+
95
+
**AMD (RequireJS) Implementation:**
96
+
```javascript
97
+
require.config({
98
+
paths: { auth:"/path/to/idmorg-auth"},
99
+
shim: { auth: { exports:"auth" }}
100
+
});
92
101
102
+
define(["auth"], function(Auth) {
103
+
Auth.init({
104
+
applicationName:"SomeAppName",
105
+
endpoint:"https://comps-dev.idmod.org/api/",
106
+
parentElement: someDOMElement
107
+
});
108
+
109
+
Auth.signout();
110
+
});
111
+
```
112
+
**CommonJS (NodeJS) Implementation:**
113
+
```javascript
114
+
importAuthfrom"path/to/idmorg-auth.js";
115
+
116
+
$(function() {
117
+
Auth.init({
118
+
applicationName:"SomeAppName",
119
+
endpoint:"https://comps-dev.idmod.org/api/",
120
+
parentElement: someDOMElement
121
+
});
122
+
123
+
Auth.signout();
124
+
});
125
+
```
93
126
127
+
***
94
128
### The Whole Spiel
95
129
When displaying information in an HTML page, it sometimes makes sense for a script to loop over a set of data to extract its values and embed them into a repeatable pattern of markup. This sort of routine is what can easily populate the many rows and columns of a complex `<table>` of data, but is also convenient for rendering more pedestrian page elements like `<menu>` and `<select><option>` lists. Of course, this is nothing new and many JavaScript frameworks and libraries provide for exactly this sort of routine as core to their technology, but standard HTML provides for this as well with the `<template>` element. Even more, HTML has long-supported a special set of [microdata](https://www.w3.org/TR/microdata/) attributes designed to make such rendered information more comprehensible to the machine-reading done by search engine crawlers and the like.
0 commit comments