semantic-forms 3.1.0 → 3.2.1

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
@@ -20,6 +20,8 @@ Then apply the `semanticForms` class to your `<form>` elements:
20
20
 
21
21
  Then the CSS/JS enhancements to your forms will apply automatically, assuming the markup structure you use is one of the supported patterns.
22
22
 
23
+ This library also monitors changes to the DOM and will enhance any additional `semanticForms` forms you insert, but the monitoring may not be perfect. If you want to re-scan for new forms to enhance manually, simply call `window.semanticForms()`. If you only want to reinitialize one form instead of all of them, call `window.semanticForms.reinitialize(formName)`.
24
+
23
25
  # Features
24
26
 
25
27
  Overview of pattern library features:
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "semantic-forms",
3
3
  "description": "Semantic Forms",
4
4
  "author": "Eric Newport <kethinov@gmail.com>",
5
- "version": "3.1.0",
5
+ "version": "3.2.1",
6
6
  "files": [
7
7
  "semanticForms.css",
8
8
  "semanticForms.js",
@@ -15,15 +15,10 @@
15
15
  "dependencies": {},
16
16
  "devDependencies": {
17
17
  "less": "4.2.0",
18
- "eslint": "8.56.0",
19
- "eslint-plugin-html": "7.1.0",
18
+ "eslint": "9.5.0",
19
+ "eslint-plugin-html": "8.1.1",
20
20
  "standard": "17.1.0"
21
21
  },
22
- "eslintConfig": {
23
- "extends": [
24
- "standard"
25
- ]
26
- },
27
22
  "scripts": {
28
23
  "test": "echo \"TODO: tests\"",
29
24
  "coverage": "echo \"TODO: test coverage\"",
package/semanticForms.js CHANGED
@@ -11,6 +11,7 @@ window.semanticForms = () => {
11
11
  const clearfieldVerticalOffset = parseInt(form.getAttribute('data-clearfield-vertical-offset')) || 5
12
12
  const inputs = Array.prototype.slice.call(form.getElementsByTagName('input')).concat(Array.prototype.slice.call(form.getElementsByTagName('textarea'))).concat(Array.prototype.slice.call(form.getElementsByTagName('select')))
13
13
  for (const input of inputs) {
14
+ if (input.classList.contains('semanticform')) continue
14
15
  if (input.id) {
15
16
  const nodeName = input.nodeName
16
17
  const type = input.getAttribute('type')
@@ -22,6 +23,7 @@ window.semanticForms = () => {
22
23
  let label
23
24
  if (input.parentNode.parentNode.id && (type === 'checkbox' || type === 'radio')) label = document.querySelector('label[data-for=' + input.parentNode.parentNode.id.replace(/\./g, '\\.') + ']')
24
25
  else label = document.querySelector('label[for=' + input.id.replace(/\./g, '\\.') + ']')
26
+ input.classList.add('semanticform')
25
27
  if (type === 'checkbox' || type === 'radio') {
26
28
  dl = input.parentNode
27
29
  while (dl && dl.nodeName !== 'DD') dl = dl.parentNode
@@ -47,7 +49,6 @@ window.semanticForms = () => {
47
49
  if (nodeName !== 'SELECT' && type !== 'checkbox' && type !== 'radio') {
48
50
  // if it doesn't have a placeholder, add a blank one
49
51
  if (!input.getAttribute('placeholder')) input.setAttribute('placeholder', ' ')
50
- input.classList.add('semanticform')
51
52
  inputHandler(input) // force x to appear on inputs with prefilled value
52
53
  }
53
54
  input.addEventListener('input', inputHandler)
@@ -71,7 +72,7 @@ window.semanticForms = () => {
71
72
  const el = event.target
72
73
  const nodeName = el.nodeName
73
74
  const type = el.getAttribute('type')
74
- if (nodeName === 'TEXTAREA' || type === 'checkbox' || type === 'color' || type === 'date' || type === 'datetime-local' || type === 'email' || type === 'file' || type === 'month' || type === 'number' || type === 'password' || type === 'radio' || type === 'range' || type === 'search' || type === 'tel' || type === 'text' || type === 'time' || type === 'url' || type === 'week') {
75
+ if (nodeName === 'TEXTAREA' || type === 'color' || type === 'date' || type === 'datetime-local' || type === 'email' || type === 'file' || type === 'month' || type === 'number' || type === 'password' || type === 'search' || type === 'tel' || type === 'text' || type === 'time' || type === 'url' || type === 'week') {
75
76
  if (el.offsetWidth - clearfieldHorizontalOffset < event.clientX - el.getBoundingClientRect().left &&
76
77
  clearfieldHorizontalOffset + clearfieldVerticalOffset > event.clientY - el.getBoundingClientRect().top
77
78
  ) {
@@ -129,3 +130,8 @@ window.semanticForms = () => {
129
130
  window.semanticFormsObserver.observe(document.body, { attributes: false, childList: true, characterData: false, subtree: true })
130
131
  }
131
132
  }
133
+
134
+ window.semanticForms.reinitialize = (form) => {
135
+ form.classList.remove('semanticFormsActive')
136
+ window.semanticForms()
137
+ }