@xiee/utils 1.2.12 → 1.2.13

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.
package/README.md CHANGED
@@ -63,9 +63,9 @@ Convert HTML comments of the form `<!--# comments -->` to
63
63
  document body will gain classes `has-notes` and `hide-notes`. You can use CSS to
64
64
  style the notes or hide/show them as you wish.
65
65
 
66
- ## header-link.js
66
+ ## heading-anchor.js
67
67
 
68
- Add anchor links to all section headers (e.g., `<h2>`) that have nonempty `id`
68
+ Add anchor links to all section headings (e.g., `<h2>`) that have nonempty `id`
69
69
  attributes.
70
70
 
71
71
  ## key-buttons.js
@@ -0,0 +1,2 @@
1
+ .anchor { display: none; }
2
+ :hover > .anchor { display: inline; }
@@ -0,0 +1 @@
1
+ .anchor{display:none}:hover>.anchor{display:inline}
package/js/alt-title.js CHANGED
@@ -1,7 +1,3 @@
1
- (function() {
2
- var img, imgs = document.getElementsByTagName('img');
3
- for (var i = 0; i < imgs.length; i++) {
4
- img = imgs[i];
5
- if (!img.title) img.title = img.alt;
6
- }
7
- })();
1
+ [...document.getElementsByTagName('img')].forEach(el => {
2
+ if (!el.title) el.title = el.alt;
3
+ });
@@ -1 +1 @@
1
- !function(){for(var t,e=document.getElementsByTagName("img"),l=0;l<e.length;l++)(t=e[l]).title||(t.title=t.alt)}();
1
+ [...document.getElementsByTagName("img")].forEach((t=>{t.title||(t.title=t.alt)}));
package/js/center-img.js CHANGED
@@ -24,14 +24,13 @@
24
24
  if (parent.nodeName === 'P') {
25
25
  parent.style.textAlign = 'center';
26
26
  if (!parentA && tagName === 'img') {
27
- parent.innerHTML = '<a href="' + tag.src + '" style="border: none;">' +
28
- tag.outerHTML + '</a>';
27
+ parent.innerHTML = `<a href="${tag.src}" style="border: none;">${tag.outerHTML}</a>`;
29
28
  }
30
29
  }
31
30
  }
32
31
  });
33
32
  }
34
- ['img', 'embed', 'object'].forEach(tag => center_el(tag));
33
+ ['img', 'embed', 'object'].forEach(center_el);
35
34
  // also center paragraphs that contain `* * *`
36
35
  d.querySelectorAll('p').forEach(p => {
37
36
  if (p.innerText === '* * *') p.style.textAlign = 'center';
@@ -1 +1 @@
1
- !function(e){function t(e){if(1!==e.childElementCount)return!1;const t=e.childNodes;if(1===t.length)return!0;for(let e in t){let n=t[e];if("#text"===n.nodeName&&!/^\s$/.test(n.textContent))return!1}return!0}["img","embed","object"].forEach((n=>{return r=n,void e.querySelectorAll(r).forEach((e=>{let n=e.parentElement;if(t(n)){const o="A"===n.nodeName;if(o){if(n=n.parentElement,!t(n))return;n.firstElementChild.style.border="none"}"P"===n.nodeName&&(n.style.textAlign="center",o||"img"!==r||(n.innerHTML='<a href="'+e.src+'" style="border: none;">'+e.outerHTML+"</a>"))}}));var r})),e.querySelectorAll("p").forEach((e=>{"* * *"===e.innerText&&(e.style.textAlign="center")}))}(document);
1
+ !function(e){function t(e){if(1!==e.childElementCount)return!1;const t=e.childNodes;if(1===t.length)return!0;for(let e in t){let n=t[e];if("#text"===n.nodeName&&!/^\s$/.test(n.textContent))return!1}return!0}["img","embed","object"].forEach((function(n){e.querySelectorAll(n).forEach((e=>{let r=e.parentElement;if(t(r)){const o="A"===r.nodeName;if(o){if(r=r.parentElement,!t(r))return;r.firstElementChild.style.border="none"}"P"===r.nodeName&&(r.style.textAlign="center",o||"img"!==n||(r.innerHTML=`<a href="${e.src}" style="border: none;">${e.outerHTML}</a>`))}}))})),e.querySelectorAll("p").forEach((e=>{"* * *"===e.innerText&&(e.style.textAlign="center")}))}(document);
@@ -16,10 +16,10 @@
16
16
  // create a new script and change attribute 'data-src' to 'src' (to actually load the script)
17
17
  const s = a.querySelector('script[data-src]');
18
18
  if (!s) return;
19
- const r = s.dataset.src, s2 = d.createElement('script'), b = s.attributes;
20
- for (let i = 0; i < b.length; i++) {
21
- s2.setAttribute(b[i].name, b[i].value);
22
- }
19
+ const r = s.dataset.src, s2 = d.createElement('script');
20
+ [...s.attributes].forEach(b => {
21
+ s2.setAttribute(b.name, b.value);
22
+ });
23
23
  s2.src = r;
24
24
  s.remove();
25
25
  a.appendChild(s2);
@@ -1 +1 @@
1
- !function(t){const e=t.querySelector("section.comments");if(!e)return;if(function(){let t=!0;try{t=window.self!==window.top}catch(t){}return t}())return void e.remove();location.hash.match(/^#comment-[0-9]+$/)&&e.scrollIntoView();const r=e.querySelector("script[data-src]");if(!r)return;const n=r.dataset.src,c=t.createElement("script"),o=r.attributes;for(let t=0;t<o.length;t++)c.setAttribute(o[t].name,o[t].value);c.src=n,r.remove(),e.appendChild(c)}(document);
1
+ !function(t){const e=t.querySelector("section.comments");if(!e)return;if(function(){let t=!0;try{t=window.self!==window.top}catch(t){}return t}())return void e.remove();location.hash.match(/^#comment-[0-9]+$/)&&e.scrollIntoView();const r=e.querySelector("script[data-src]");if(!r)return;const c=r.dataset.src,n=t.createElement("script");[...r.attributes].forEach((t=>{n.setAttribute(t.name,t.value)})),n.src=c,r.remove(),e.appendChild(n)}(document);
@@ -0,0 +1,3 @@
1
+ document.querySelectorAll('h1,h2,h3').forEach(h => {
2
+ if (h.id) h.innerHTML += ` <span class="anchor"><a href="#${h.id}">#</a></span>`;
3
+ });
package/js/right-quote.js CHANGED
@@ -1,12 +1,5 @@
1
- (function() {
2
- var quotes = document.getElementsByTagName('blockquote'), i, quote;
3
- for (i = 0; i < quotes.length; i++) {
4
- quote = quotes[i];
5
- var n = quote.children.length;
6
- if (n === 0) continue;
7
- var el = quote.children[n - 1];
8
- if (!el || el.nodeName !== 'P') continue;
9
- // right-align a quote footer if it starts with ---
10
- if (/^—/.test(el.textContent)) el.style.textAlign = 'right';
11
- }
12
- })();
1
+ // right-align a quote footer if it starts with ---
2
+ [...document.getElementsByTagName('blockquote')].forEach(quote => {
3
+ const el = quote.lastElementChild;
4
+ if (el?.tagName === 'P' && /^—/.test(el.textContent)) el.style.textAlign = 'right';
5
+ });
@@ -1 +1 @@
1
- !function(){var e,t,n=document.getElementsByTagName("blockquote");for(e=0;e<n.length;e++){var l=(t=n[e]).children.length;if(0!==l){var o=t.children[l-1];o&&"P"===o.nodeName&&/^—/.test(o.textContent)&&(o.style.textAlign="right")}}}();
1
+ [...document.getElementsByTagName("blockquote")].forEach((t=>{const e=t.lastElementChild;"P"===e?.tagName&&/^—/.test(e.textContent)&&(e.style.textAlign="right")}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiee/utils",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "Miscellaneous tools and utilities to manipulate HTML pages",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
package/js/header-link.js DELETED
@@ -1,5 +0,0 @@
1
- (function() {
2
- document.querySelectorAll('h1,h2,h3').forEach(h => {
3
- if (h.id) h.innerHTML += ` <span class="anchor"><a href="#${h.id}">#</a></span>`;
4
- });
5
- })();