Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | 1x 1x 1x 1x 2x 1x 2x 2x 1x 1x 1x 2x 2x 1x 1x 2x 2x 1x 2x 2x 1x 1x 1x 2x 2x 1x 1x 2x 2x 2x 3x 3x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 13x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 4x 8x 8x 5x 1x 1x 5x 5x 1x 1x 2x 1x 2x 2x 1x 1x 1x 2x 2x 1x 1x 4x 2x 4x 4x 2x 2x 2x 4x 4x 1x 1x 8x 8x 8x 1x 1x 6x 2x 6x 2x 2x 1x 1x 4x 1x 4x 1x 2x 2x 3x 2x 2x 4x 1x 1x 1x 1x 6x 6x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 1x 1x 2x 2x 2x 1x 1x 3x 3x 3x 1x 1x 2x 2x 2x 1x 1x 4x 4x 1x 4x 3x 3x 4x 4x 4x 4x 1x 4x 3x 3x 3x 4x 1x 1x 1x 1x 4x 1x 1x 1x 1x 1x 1x 4x 4x 4x 1x 1x 9x 9x 9x 9x 9x 9x 9x 9x 2x 9x 1x 14x 11x 14x 3x 3x 1x 1x 7x 1x 1x 2x 7x 7x 7x 7x 6x 8x 3x 3x 9x 3x 8x 5x 5x 5x 8x 7x 1x 1x 7x 1x 1x 7x 6x 2x 6x 4x 4x 6x 9x 9x 1x 1x 10x 2x 10x 2x 2x 2x 13x 13x 13x 13x 13x 13x 3x 3x 1x 1x 3x 3x 13x 13x 3x 13x 1x 10x 9x 3x 3x 3x 3x 9x 6x 6x 9x 13x 2x 8x 1x 6x 5x 5x 10x 1x 1x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 2x 2x 1x 3x 3x 1x 1x 2x 2x 2x 1x 1x 2x 2x 2x 1x 1x 2x 2x 2x 1x 1x 4x 4x 4x 1x 1x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x | import { _common } from "./_common.js";
export class _core {
/** @this {Jdm} */
static jdm_append(elementList) {
if (Array.isArray(elementList)) {
for (const element of elementList) {
this.node.appendChild(element);
}
} else if (elementList) {
this.node.appendChild(elementList);
}
return this.node;
}
/** @this {Jdm} */
static jdm_prepend(elementList) {
const firstChild = this.node.firstElementChild;
if (Array.isArray(elementList)) {
for (const element of elementList) {
this.node.prepend(element);
}
} else if (elementList) {
this.node.prepend(elementList);
}
return this.node;
}
/** @this {Jdm} */
static jdm_appendBefore(elementList) {
elementList = Array.isArray(elementList) ? elementList : [elementList];
const parent = this.node.parentNode;
for (const element of elementList) {
parent.insertBefore(element, this.node);
}
return this.node;
}
/** @this {Jdm} */
static jdm_appendAfter(elementList) {
elementList = Array.isArray(elementList) ? elementList : [elementList];
const parent = this.node.parentNode;
for (const element of elementList) {
parent.insertAfter(element, this.node);
}
return this.node;
}
/** @this {Jdm} */
static jdm_setAttribute(attribute, value = null) {
this.node.setAttribute(attribute, value);
return this.node;
}
/** @this {Jdm} */
static jdm_getAttribute(attribute) {
return this.node.getAttribute(attribute);
}
/** @this {Jdm} */
static jdm_removeAttribute(attribute) {
this.node.removeAttribute(attribute);
return this.node;
}
/** @this {Jdm} */
static jdm_addId(id) {
this.node.setAttribute("id", id);
return this.node;
}
/** @this {Jdm} */
static jdm_addClassList(classList) {
if (Array.isArray(classList)) {
for (const cls of classList) {
this.node.classList.add(cls);
}
} else if (classList) {
this.node.classList.add(classList);
}
return this.node;
}
/** @this {Jdm} */
static jdm_removeClassList(classList) {
if (Array.isArray(classList)) {
for (const cls of classList) {
this.node.classList.remove(cls);
}
} else if (classList) {
this.node.classList.remove(classList);
}
return this.node;
}
/** @this {Jdm} */
static jdm_toggleClassList(classList) {
if (Array.isArray(classList)) {
for (const cls of classList) {
this.node.classList.toggle(cls);
}
} else if (classList) {
this.node.classList.toggle(classList);
}
return this.node;
}
/** @this {Jdm} */
static jdm_findClassList(classList, some = false) {
classList = Array.isArray(classList) ? classList : [classList];
return some ? classList.some(cls => this.node.classList.contains(cls)) : classList.every(cls => this.node.classList.contains(cls));
}
/** @this {Jdm} */
static jdm_empty() {
if (this.tag === "input" && (this.node.type === "checkbox" || this.node.type === "radio")) {
this.node.checked = false;
} else if (this.tag === "input" || this.tag === "textarea") {
this.node.value = null;
} else if (this.tag === "form") {
if (this.node.elements?.length > 0) {
for (const element of this.node.elements) {
if (element.type === "checkbox" || element.type === "radio") {
element.checked = false;
} else if (element.type === "select-multiple" || element.type === "select-one") {
for (const option of element.options) {
element.value = null;
}
} else {
element.value = "";
}
}
}
} else {
this.node.innerHTML = "";
}
return this.node;
}
/** @this {Jdm} */
static jdm_destroy() {
this.node.remove();
return this.node;
}
/** @this {Jdm} */
static jdm_validate() {
const validity = this.node.checkValidity();
this.jdm_genEvent("validate", validity);
return this.node;
}
/** @this {Jdm} */
static jdm_setStyle(style, value) {
this.node.style[style] = value;
return this.node;
}
/** @this {Jdm} */
static jdm_extendNode(name, object = null) {
this.node[name] = object;
return this.node;
}
/** @this {Jdm} */
static jdm_innerHTML(value) {
this.node.innerHTML = value;
return this.node;
}
/** @this {Jdm} */
static jdm_binding(el, event = "input", twoWayDataBinding = true) {
let elementList = [];
if (Array.isArray(el)) {
elementList = elementList.concat(el);
} else {
elementList.push(el);
}
for (const element of elementList) {
if (
element.tagName.toLowerCase() === "input" ||
element.tagName.toLowerCase() === "select" ||
element.tagName.toLowerCase() === "textarea"
) {
this.node.addEventListener(event, () => {
element.jdm_setValue(this.jdm_getValue());
});
} else {
this.node.addEventListener(event, () => {
element.jdm_innerHTML(this.jdm_getValue());
});
}
if (twoWayDataBinding) {
const elementListTmp = elementList.filter(elementTmp => elementTmp !== element);
elementListTmp.push(this.node);
for (const elementTmp of elementListTmp) {
element.jdm_binding(elementListTmp, event, false);
}
}
}
return this.node;
}
/** @this {Jdm} */
static jdm_setValue(value, tooBoolean = true) {
if (tooBoolean) {
try {
value = value.toBoolean();
} catch (e) {
value = value;
}
}
if (this.node.type === "checkbox" || this.node.type === "radio") {
this.node.checked = value;
} else if (this.tag === "form") {
const setValue = (el, value) => {
if (el.type === "checkbox" || el.type === "radio") {
el.checked = value;
} else {
el.value = value;
}
};
const findElement = (form, name) => {
return form.querySelectorAll(`[name="${name}"]`);
};
const populateForm = (form, data, prefix = "") => {
for (const key in data) {
const value = data[key];
const name = prefix ? `${prefix}[${key}]` : key;
const elementList = findElement(form, Array.isArray(value) ? `${name}[]` : name);
if (elementList?.length > 0) {
for (const element of elementList) {
if (Array.isArray(value)) {
const checkboxes = form.querySelectorAll(`[name="${name}[]"]`);
checkboxes.forEach(checkbox => {
setValue(checkbox, value.includes(checkbox.value));
});
} else if (typeof value === "object") {
populateForm(form, value, name);
} else {
setValue(element, value);
}
}
} else if (typeof value === "object") {
populateForm(form, value, name);
}
}
};
populateForm(this.node, value);
} else {
if (this.node.jdm_getAttribute("type") === "number" || this.node.jdm_getAttribute("type") === "range") {
this.node.value = value * 1;
} else {
this.node.value = value;
}
}
return this.node;
}
/** @this {Jdm} */
static jdm_getValue() {
if (this.tag === "input" && (this.node.type === "checkbox" || this.node.type === "radio")) {
return this.node.checked;
} else if (this.tag === "form") {
const formData = new FormData(this.node);
const json = {};
for (let [key, value] of formData.entries()) {
value = value === "" ? null : value;
value = value === "null" ? null : value;
let currentObj = json;
const keys = key.split(/\[|\]\[|\]/).filter(Boolean);
const lastKey = keys.pop();
for (let i = 0; i < keys.length; i++) {
const currentKey = keys[i];
if (!currentObj[currentKey]) {
currentObj[currentKey] = isNaN(keys[i + 1]) ? {} : [];
}
currentObj = currentObj[currentKey];
}
if (lastKey === "") {
if (!currentObj.length) {
currentObj.length = 0;
}
currentObj[currentObj.length++] = value;
} else if (Array.isArray(currentObj[lastKey])) {
currentObj[lastKey].push(value);
} else if (currentObj[lastKey]) {
currentObj[lastKey] = [currentObj[lastKey], value];
} else {
if (key.endsWith("[]")) {
if (value) {
currentObj[lastKey] = new Array();
currentObj[lastKey].push(value);
}
} else {
currentObj[lastKey] = value;
}
}
}
return json;
} else if (this.tag === "select") {
return this.node.value;
} else {
return this.node.value;
}
}
/** @this {Jdm} */
static jdm_genEvent(name, data = null, propagateToParents = true) {
_common.genEvent(this.node, name, data, propagateToParents);
return this.node;
}
/** @this {Jdm} */
static jdm_addEventListener(name, fn = () => {}) {
this.node.addEventListener(name, fn);
return this.node;
}
/** @this {Jdm} */
static jdm_removeEventListener(name, fn = () => {}) {
this.node.removeEventListener(name, fn);
return this.node;
}
/** @this {Jdm} */
static jdm_extendChildNode() {
if (this.node?.jdm_childNode && Object.entries(this.node.jdm_childNode).length > 0) {
for (const [key, value] of Object.entries(this.node.jdm_childNode)) {
this.node.jdm_extendNode(key, value);
}
}
return this.node;
}
/** @this {Jdm} */
static jdm_onInput(fn = () => {}) {
this.node.addEventListener("input", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onChange(fn = () => {}) {
this.node.addEventListener("change", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onSelect(fn = () => {}) {
this.node.addEventListener("select", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onDebounce(fn = () => {}, timeout = 300, method = "input") {
this.node.addEventListener(method, _common.debounce(fn, timeout));
return this.node;
}
/** @this {Jdm} */
static jdm_onClick(fn = () => {}) {
this.node.addEventListener("click", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onRightClick(fn = () => {}) {
this.node.addEventListener("contextmenu", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onDoubleClick(fn = () => {}) {
this.node.addEventListener("dblclick", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onInvalid(fn = () => {}) {
this.node.addEventListener("invalid", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onLoad(fn = () => {}) {
this.node.addEventListener("load", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onError(fn = () => {}) {
this.node.addEventListener("error", fn);
return this.node;
}
/** @this {Jdm} */
static jdm_onSubmit(fn = e => {}) {
this.node.addEventListener("submit", fn);
return this.node;
}
}
|