CETEIcean 1.3.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ {
2
+ "cSpell.words": [
3
+ "Ordinality",
4
+ "prefixdef"
5
+ ]
6
+ }
package/README.md CHANGED
@@ -44,6 +44,14 @@ CETEIcean.getHTML5("URL_TO_YOUR_TEI.xml", function(data) {
44
44
  })
45
45
  ```
46
46
 
47
+ By default, CETEIcean saves and restores the scroll position for a document via a URL fragment. To turn this behavior off, particularly when using CETEIcean for Server Side Rendering, you can set the `ignoreFragmentId` option to `true`:
48
+
49
+ ```js
50
+ new CETEI({
51
+ ignoreFragmentId: true
52
+ })
53
+ ```
54
+
47
55
  ### Other methods
48
56
 
49
57
  #### getHTML5( url, callback, perElementFn )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "CETEIcean",
3
- "version": "1.3.0",
3
+ "version": "1.6.0",
4
4
  "description": "JavaScript library to load a TEI XML document and register it as HTML5 custom elements.",
5
5
  "main": "src/CETEI.js",
6
6
  "keywords": [
@@ -16,12 +16,13 @@
16
16
  "url": "https://github.com/TEIC/CETEIcean.git"
17
17
  },
18
18
  "devDependencies": {
19
- "babel-core": "^6.26.0",
20
- "babel-preset-env": "^1.6.1",
19
+ "@babel/core": "^7.15.5",
20
+ "@babel/preset-env": "7.15.6",
21
+ "babel-preset-env": "^1.7.0",
21
22
  "http-server": "^0.12.3",
22
23
  "onchange": "^6.1.1",
23
- "rollup": "0.62.0",
24
- "rollup-plugin-babel": "^3.0.3",
24
+ "rollup": "^2.57.0",
25
+ "@rollup/plugin-babel": "^5.3.0",
25
26
  "rollup-plugin-terser": "1.0.1",
26
27
  "terser": "^3.17.0"
27
28
  },
package/rollup.config.js CHANGED
@@ -1,4 +1,4 @@
1
- import babel from 'rollup-plugin-babel';
1
+ import babel from '@rollup/plugin-babel';
2
2
  import { terser } from 'rollup-plugin-terser';
3
3
 
4
4
  export default {
@@ -16,7 +16,7 @@ export default {
16
16
  "modules": false,
17
17
  "targets": {
18
18
  "chrome": 65,
19
- "safari": 11,
19
+ "safari": 13,
20
20
  "firefox": 60
21
21
  }
22
22
  }]
package/src/CETEI.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import defaultBehaviors from './defaultBehaviors';
2
2
  import * as utilities from './utilities';
3
3
  import {addBehaviors, addBehavior, applyBehaviors, removeBehavior} from './behaviors';
4
- import {learnElementNames} from './dom';
4
+ import {learnElementNames, learnCustomElementNames} from './dom';
5
5
 
6
6
  class CETEI {
7
7
  constructor(options){
@@ -30,6 +30,7 @@ class CETEI {
30
30
  this.hasStyle = false;
31
31
  this.prefixDefs = [];
32
32
  this.debug = this.options.debug === true ? true : false;
33
+ this.discardContent = this.options.discardContent === true ? true : false;
33
34
 
34
35
  if (this.options.base) {
35
36
  this.base = this.options.base;
@@ -50,6 +51,7 @@ class CETEI {
50
51
  window.removeEventListener("ceteiceanload", CETEI.restorePosition);
51
52
  }
52
53
  }
54
+
53
55
  }
54
56
 
55
57
  /*
@@ -95,8 +97,8 @@ class CETEI {
95
97
  */
96
98
  makeHTML5(XML, callback, perElementFn){
97
99
  // XML is assumed to be a string
98
- let XML_dom = ( new DOMParser() ).parseFromString(XML, "text/xml");
99
- return this.domToHTML5(XML_dom, callback, perElementFn);
100
+ this.XML_dom = ( new DOMParser() ).parseFromString(XML, "text/xml");
101
+ return this.domToHTML5(this.XML_dom, callback, perElementFn);
100
102
  }
101
103
 
102
104
  /*
@@ -215,6 +217,17 @@ class CETEI {
215
217
  }
216
218
  }
217
219
 
220
+ /*
221
+ Convenience method for HTML pages containing pre-processed CETEIcean Custom
222
+ Elements. Usage:
223
+ const c = new CETEI();
224
+ c.processPage();
225
+ */
226
+ processPage() {
227
+ this.els = learnCustomElementNames(document);
228
+ this.applyBehaviors();
229
+ }
230
+
218
231
  /*
219
232
  To change a namespace -> prefix mapping, the namespace must first be
220
233
  unset. Takes a namespace URI. In order to process a TEI P4 document, e.g.,
@@ -261,7 +274,11 @@ append(fn, elt) {
261
274
  }
262
275
 
263
276
  appendBasic(elt, content) {
264
- utilities.hideContent(elt, true);
277
+ if (this.discardContent) {
278
+ elt.innerHTML = "";
279
+ } else {
280
+ utilities.hideContent(elt, true);
281
+ }
265
282
  elt.appendChild(content);
266
283
  }
267
284
 
@@ -358,10 +375,7 @@ insert(elt, strings) {
358
375
  // If we have before and after tags have them parsed by
359
376
  // .innerHTML and then add the content to the resulting child
360
377
  if (strings[0].match("<[^>]+>") && strings[1] && strings[1].match("<[^>]+>")) {
361
- span.innerHTML = strings[0] + (strings[1]?strings[1]:"");
362
- for (let node of Array.from(elt.childNodes)) {
363
- span.firstElementChild.appendChild(node.cloneNode(true));
364
- }
378
+ span.innerHTML = strings[0] + elt.innerHTML + (strings[1]?strings[1]:"");
365
379
  } else {
366
380
  span.innerHTML = strings[0];
367
381
  span.setAttribute("data-before", strings[0].replace(/<[^>]+>/g,"").length);
package/src/behaviors.js CHANGED
@@ -19,6 +19,11 @@ export function addBehaviors(bhvs) {
19
19
  }
20
20
  }
21
21
  }
22
+ if (bhvs["functions"]) {
23
+ for (let fn of Object.keys(bhvs["functions"])) {
24
+ this.utilities[fn] = bhvs["functions"][fn];
25
+ }
26
+ }
22
27
  if (bhvs["handlers"]) {
23
28
  console.log("Behavior handlers are no longer used.")
24
29
  }
package/src/dom.js CHANGED
@@ -13,4 +13,8 @@ export function learnElementNames(XML_dom, namespaces) {
13
13
  // Add the root element to the array
14
14
  els.add(qname(root));
15
15
  return els
16
+ }
17
+
18
+ export function learnCustomElementNames(HTML_dom) {
19
+ return Array.from(HTML_dom.querySelectorAll("*[data-origname]"), e => e.localName.replace(/(\w+)-.+/,"$1:") + e.getAttribute("data-origname"));
16
20
  }
package/src/utilities.js CHANGED
@@ -71,6 +71,12 @@ export function hideContent(elt, rewriteIds = true) {
71
71
  hidden.setAttribute("data-original", "");
72
72
  for (let node of Array.from(elt.childNodes)) {
73
73
  if (node !== hidden) {
74
+ if (node.nodeType === Node.ELEMENT_NODE) {
75
+ node.setAttribute("data-processed", "");
76
+ for (let e of node.querySelectorAll("*")) {
77
+ e.setAttribute("data-processed", "");
78
+ }
79
+ }
74
80
  hidden.appendChild(elt.removeChild(node));
75
81
  }
76
82
  }
@@ -202,7 +208,6 @@ export function serialize(el, stripElt, ws) {
202
208
  return str;
203
209
  }
204
210
 
205
-
206
211
  export function unEscapeEntities(str) {
207
212
  return str.replace(/&gt;/, ">")
208
213
  .replace(/&quot;/, "\"")
package/test/TCW22.html CHANGED
@@ -2,11 +2,25 @@
2
2
  <html>
3
3
  <head>
4
4
  <meta charset="utf-8">
5
- <link rel="stylesheet" href="http://teic.github.io/css/tei.css" title="no title" charset="utf-8">
5
+ <link rel="stylesheet" href="https://teic.github.io/css/tei.css" title="no title" charset="utf-8">
6
6
  <script src="https://cdn.polyfill.io/v1/polyfill.js?features=modernizr:promises&unknown=polyfill" charset="utf-8"></script>
7
7
  <script src="../dist/CETEI.js" charset="utf-8"></script>
8
8
  <script type="text/javascript">
9
- (new CETEI).getHTML5('https://raw.githubusercontent.com/TEIC/Documentation/master/TCW/tcw22.xml?new=' + Date.now(), function(data) {
9
+ let ct = new CETEI();
10
+ let b = {
11
+ "tei": {
12
+ "title": [
13
+ ["tei-titlestmt>tei-title", function(e) {
14
+ let head = document.createElement("tei-head");
15
+ head.innerHTML = e.innerHTML;
16
+ let body = this.dom.querySelector("tei-body");
17
+ body.insertBefore(head, body.firstElementChild);
18
+ }]
19
+ ]
20
+ }
21
+ }
22
+ ct.addBehaviors(b);
23
+ ct.getHTML5('https://raw.githubusercontent.com/TEIC/Documentation/master/TCW/tcw22.xml?new=' + Date.now(), function(data) {
10
24
  document.getElementsByTagName("body")[0].appendChild(data);
11
25
  });
12
26
  </script>
@@ -19,7 +19,7 @@
19
19
  * is an HTML element. The function names must match the name of the
20
20
  * element they will be applied to.
21
21
  ***********************************/
22
- c.addBehaviors({"handlers":{
22
+ c.addBehaviors({"tei":{
23
23
  // Overrides the default ptr behavior, displaying a short link
24
24
  "ptr": function(elt) {
25
25
  var link = document.createElement("a");
@@ -34,7 +34,7 @@
34
34
  return b;
35
35
  },
36
36
  // Inserts the first array element before tei:add, and the second, after.
37
- "add": ["`","´"]
37
+ "add": ["<b>`","´</b>"]
38
38
  }});
39
39
  c.getHTML5('testTEI.xml', function(data) {
40
40
  document.getElementById("TEI").innerHTML = "";