derafu-js 0.1.2 → 0.1.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "derafu-js",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Why use a JS framework if we can do all from scratch?",
5
5
  "main": "src/derafu.js",
6
6
  "files": [
@@ -84,6 +84,52 @@ FormFields.showPassword = function (button) {
84
84
  }
85
85
  };
86
86
 
87
+ /**
88
+ * Fills the password field next to the button with a randomly generated
89
+ * password.
90
+ *
91
+ * Relies on Utils.generatePassword() to create the value, so utils.js must
92
+ * be loaded before this file for this function to work.
93
+ *
94
+ * @param {HTMLElement} button - Button used to activate the function, located
95
+ * next to the password field.
96
+ * @param {number} [length] - Length of the generated password. Default is 12
97
+ * (see Utils.generatePassword()).
98
+ * @returns {void}
99
+ */
100
+ FormFields.generatePassword = function (button, length) {
101
+ 'use strict';
102
+ if (!(button instanceof HTMLElement)) {
103
+ console.error(
104
+ 'FormFields.generatePassword: The provided argument is not a valid HTML element.',
105
+ );
106
+ return;
107
+ }
108
+ if (
109
+ typeof Utils === 'undefined' ||
110
+ typeof Utils.generatePassword !== 'function'
111
+ ) {
112
+ console.error(
113
+ 'FormFields.generatePassword: Utils.generatePassword() is not available. Make sure utils.js is loaded before this file.',
114
+ );
115
+ return;
116
+ }
117
+
118
+ // Try to find the related password field.
119
+ const input = button
120
+ .closest('.input-group')
121
+ .querySelector('input[type="password"], input[type="text"]');
122
+
123
+ if (!input) {
124
+ console.error('FormFields.generatePassword: Input not found.');
125
+ return;
126
+ }
127
+
128
+ // Fill the field and notify listeners (e.g. validation) of the change.
129
+ input.value = Utils.generatePassword(length);
130
+ input.dispatchEvent(new Event('input', { bubbles: true }));
131
+ };
132
+
87
133
  /**
88
134
  * Allows editing the content of a text field in a larger dialog box.
89
135
  * Useful for text fields with extensive content that would benefit from an
package/src/tabs.js CHANGED
@@ -89,7 +89,9 @@ Tabs.init = function () {
89
89
  */
90
90
  Tabs._injectStyles = function () {
91
91
  'use strict';
92
- if (document.getElementById('derafu-tabs-styles')) return;
92
+ if (document.getElementById('derafu-tabs-styles')) {
93
+ return;
94
+ }
93
95
  const style = document.createElement('style');
94
96
  style.id = 'derafu-tabs-styles';
95
97
  style.textContent =
@@ -121,8 +123,12 @@ Tabs._highlightElement = function (element, isCard) {
121
123
  : element.closest('.input-group') ||
122
124
  element.closest('.form-floating') ||
123
125
  element.parentElement;
124
- if (!target) return;
125
- if (isCard) target.classList.add('border-primary');
126
+ if (!target) {
127
+ return;
128
+ }
129
+ if (isCard) {
130
+ target.classList.add('border-primary');
131
+ }
126
132
  target.classList.add('deeplink-highlight');
127
133
  target.addEventListener(
128
134
  'animationend',