index.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <div id="formContainer"></div>
  11. <script>
  12. //PASSWORD
  13. // function Password(parent, open) {
  14. // let formBody = document.createElement("div");
  15. // let passwordInput = document.createElement("input");
  16. // let isOpenInput = document.createElement("input");
  17. // parent.append(formBody);
  18. // passwordInput.type = open ? "text" : "password";
  19. // passwordInput.oninput = () => {
  20. // this.value = passwordInput.value;
  21. // if (typeof this.onChange === "function") {
  22. // this.onChange(this.value);
  23. // }
  24. // };
  25. // isOpenInput.type = "checkbox";
  26. // isOpenInput.checked = open;
  27. // isOpenInput.onchange = () => {
  28. // this.open = isOpenInput.checked;
  29. // passwordInput.type = this.open ? "text" : "password";
  30. // if (typeof this.onOpenChange === "function") {
  31. // this.onOpenChange(this.open);
  32. // }
  33. // };
  34. // const setValue = (value) => {
  35. // this.value = value;
  36. // passwordInput.value = this.value;
  37. // };
  38. // const getValue = () => {
  39. // return this.value;
  40. // };
  41. // const setOpen = (value) => {
  42. // this.open = value;
  43. // isOpenInput.checked = value;
  44. // passwordInput.type = this.open ? "text" : "password";
  45. // };
  46. // const getOpen = () => {
  47. // return this.open;
  48. // };
  49. // formBody.append(passwordInput);
  50. // formBody.append(isOpenInput);
  51. // this.open = open;
  52. // this.setValue = setValue;
  53. // this.getValue = getValue;
  54. // this.setOpen = setOpen;
  55. // this.getOpen = getOpen;
  56. // this.value = passwordInput.value;
  57. // }
  58. // let p = new Password(document.body, true);
  59. // p.onChange = (data) => console.log(data);
  60. // p.onOpenChange = (open) => console.log(open);
  61. // p.setValue("qwerty");
  62. // console.log(p.getValue());
  63. // p.setOpen(false);
  64. // console.log(p.getOpen());
  65. //LoginForm
  66. // function LoginForm(parent, open) {
  67. // let formBody = document.createElement("div");
  68. // let passwordInput = document.createElement("input");
  69. // let loginInput = document.createElement("input");
  70. // let isOpenInput = document.createElement("input");
  71. // let loginButton = document.createElement("button");
  72. // parent.append(formBody);
  73. // passwordInput.type = open ? "text" : "password";
  74. // passwordInput.oninput = () => {
  75. // this.passwordValue = passwordInput.value;
  76. // loginButton.disabled = checkIfBlank();
  77. // if (typeof this.onPasswordChange === "function") {
  78. // this.onPasswordChange(this.passwordValue);
  79. // }
  80. // };
  81. // loginInput.type = "text";
  82. // loginInput.oninput = () => {
  83. // this.loginValue = loginInput.value;
  84. // loginButton.disabled = checkIfBlank();
  85. // if (typeof this.onLoginChange === "function") {
  86. // this.onLoginChange(this.loginValue);
  87. // }
  88. // };
  89. // isOpenInput.type = "checkbox";
  90. // isOpenInput.checked = open;
  91. // isOpenInput.onchange = () => {
  92. // this.open = isOpenInput.checked;
  93. // passwordInput.type = this.open ? "text" : "password";
  94. // if (typeof this.onOpenChange === "function") {
  95. // this.onOpenChange(this.open);
  96. // }
  97. // };
  98. // loginButton.innerText = "Login";
  99. // const setPasswordValue = (value) => {
  100. // this.passwordValue = value;
  101. // passwordInput.value = this.passwordValue;
  102. // };
  103. // const getPasswordValue = () => {
  104. // return this.passwordValue;
  105. // };
  106. // const setLoginValue = (value) => {
  107. // this.loginValue = value;
  108. // loginInput.value = this.loginValue;
  109. // };
  110. // const getLoginValue = () => {
  111. // return this.loginValue;
  112. // };
  113. // const setOpen = (value) => {
  114. // this.open = value;
  115. // isOpenInput.checked = value;
  116. // passwordInput.type = this.open ? "text" : "password";
  117. // };
  118. // const getOpen = () => {
  119. // return this.open;
  120. // };
  121. // const checkIfBlank = () => {
  122. // if (this.loginValue.trim().length === 0 || this.passwordValue.trim().length === 0) {
  123. // return true;
  124. // }
  125. // return false;
  126. // };
  127. // formBody.append(loginInput);
  128. // formBody.append(passwordInput);
  129. // formBody.append(isOpenInput);
  130. // formBody.append(loginButton);
  131. // this.open = open;
  132. // this.setPasswordValue = setPasswordValue;
  133. // this.getPasswordValue = getPasswordValue;
  134. // this.setLoginValue = setLoginValue;
  135. // this.getLoginValue = getLoginValue;
  136. // this.setOpen = setOpen;
  137. // this.getOpen = getOpen;
  138. // this.passwordValue = passwordInput.value;
  139. // this.loginValue = loginInput.value;
  140. // loginButton.disabled = checkIfBlank();
  141. // }
  142. // let p = new LoginForm(document.body, true);
  143. // p.onPasswordChange = (data) => console.log(data);
  144. // p.onOpenChange = (open) => console.log(open);
  145. // p.onLoginChange = (data) => console.log(data);
  146. // p.setPasswordValue("qwerty");
  147. // console.log(p.getPasswordValue());
  148. // p.setLoginValue("qwerty");
  149. // console.log(p.getLoginValue());
  150. // p.setOpen(false);
  151. // console.log(p.getOpen());
  152. //PASSWORD VERIFY
  153. // function Password(parent, open) {
  154. // let formBody = document.createElement("div");
  155. // let passwordInput1 = document.createElement("input");
  156. // let passwordInput2 = document.createElement("input");
  157. // let isOpenInput = document.createElement("input");
  158. // let checkButton = document.createElement("button");
  159. // parent.append(formBody);
  160. // checkButton.innerText = "checkButton";
  161. // passwordInput1.type = open ? "text" : "password";
  162. // passwordInput1.oninput = () => {
  163. // this.value1 = passwordInput1.value;
  164. // checkButton.disabled = !isValid();
  165. // if (typeof this.onPassword1Change === "function") {
  166. // this.onPassword1Change(this.value1);
  167. // }
  168. // };
  169. // passwordInput2.type = "password";
  170. // passwordInput2.style.display = !open ? "inline" : "none";
  171. // passwordInput2.oninput = () => {
  172. // this.value2 = passwordInput2.value;
  173. // checkButton.disabled = !isValid();
  174. // console.log(isValid());
  175. // if (typeof this.onPassword2Change === "function") {
  176. // this.onPassword2Change(this.value2);
  177. // }
  178. // };
  179. // isOpenInput.type = "checkbox";
  180. // isOpenInput.checked = open;
  181. // isOpenInput.onchange = () => {
  182. // this.open = isOpenInput.checked;
  183. // checkButton.disabled = !isValid();
  184. // passwordInput1.type = this.open ? "text" : "password";
  185. // passwordInput2.style.display = !this.open ? "inline" : "none";
  186. // if (typeof this.onOpenChange === "function") {
  187. // this.onOpenChange(this.open);
  188. // }
  189. // };
  190. // const setValue1 = (newValue) => {
  191. // this.value1 = newValue;
  192. // passwordInput1.value = newValue;
  193. // checkButton.disabled = !isValid();
  194. // };
  195. // const setValue2 = (newValue) => {
  196. // this.value2 = newValue;
  197. // passwordInput2.value = newValue;
  198. // checkButton.disabled = !isValid();
  199. // };
  200. // const getValue1 = () => {
  201. // return this.value1;
  202. // };
  203. // const getValue2 = () => {
  204. // return this.value2;
  205. // };
  206. // const setOpen = (value) => {
  207. // this.open = value;
  208. // isOpenInput.checked = value;
  209. // passwordInput1.type = this.open ? "text" : "password";
  210. // passwordInput2.style.display = !this.open ? "inline" : "none";
  211. // checkButton.disabled = !isValid();
  212. // };
  213. // const getOpen = () => {
  214. // return this.open;
  215. // };
  216. // const isValid = () => {
  217. // if (this.open === true) {
  218. // return false;
  219. // }
  220. // if (this.value1 === this.value2 && this.value1.trim() !== "" && this.value2.trim()) {
  221. // return true;
  222. // }
  223. // return false;
  224. // };
  225. // formBody.append(passwordInput1);
  226. // formBody.append(passwordInput2);
  227. // formBody.append(isOpenInput);
  228. // formBody.append(checkButton);
  229. // this.open = open;
  230. // this.value1 = passwordInput1.value;
  231. // this.value2 = passwordInput2.value;
  232. // this.setOpen = setOpen;
  233. // this.getOpen = getOpen;
  234. // this.setValue1 = setValue1;
  235. // this.getValue1 = getValue1;
  236. // this.setValue2 = setValue2;
  237. // this.getValue2 = getValue2;
  238. // checkButton.disabled = !isValid();
  239. // }
  240. // let p = new Password(document.body, true);
  241. // p.onPassword1Change = (data) => console.log(data);
  242. // p.onPassword2Change = (data) => console.log(data);
  243. // p.onOpenChange = (open) => console.log(open);
  244. // p.setValue1("qwerty");
  245. // console.log(p.getValue1());
  246. // p.setValue2("qwer");
  247. // console.log(p.getValue2());
  248. // p.setOpen(false);
  249. // console.log(p.getOpen());
  250. //FORM
  251. // function Form(el, data, okCallback, cancelCallback) {
  252. // let formBody = document.createElement("div");
  253. // let inputBox = document.createElement("div");
  254. // let okButton = document.createElement("button");
  255. // let validatorErrors = new Set();
  256. // let requiredErrors = new Set();
  257. // let cancelButton = document.createElement("button");
  258. // let initData = { ...data };
  259. // okButton.innerHTML = "OK";
  260. // cancelButton.innerHTML = "Cancel";
  261. // el.appendChild(formBody);
  262. // formBody.append(inputBox);
  263. // let inputCreators = {
  264. // String(key, value, oninput) {
  265. // if (value.length > 20) {
  266. // let textarea = document.createElement("textarea");
  267. // textarea.value = value;
  268. // textarea.oninput = () => oninput(textarea.value);
  269. // return textarea;
  270. // } else {
  271. // let input = document.createElement("input");
  272. // input.type = "text";
  273. // if ([...value].every((el) => el === "*")) {
  274. // input.type = "password";
  275. // }
  276. // input.placeholder = key;
  277. // input.value = value;
  278. // input.oninput = () => oninput(input.value);
  279. // return input;
  280. // }
  281. // },
  282. // Boolean(key, value, oninput) {
  283. // let input = document.createElement("input");
  284. // input.type = "checkbox";
  285. // input.checked = value;
  286. // input.oninput = () => oninput(Boolean(input.checked));
  287. // return input;
  288. // },
  289. // Date(key, value, oninput) {
  290. // let input = document.createElement("input");
  291. // let timeOffset = new Date().getTimezoneOffset();
  292. // let dateInMillSec =
  293. // new Date(value.toISOString()).getTime() - new Date().getTimezoneOffset() * 1000 * 60;
  294. // input.type = "datetime-local";
  295. // input.value = new Date(dateInMillSec).toISOString().slice(0, 16);
  296. // input.oninput = () => oninput(new Date(input.value));
  297. // return input;
  298. // },
  299. // };
  300. // let createInputs = (data) => {
  301. // inputBox.innerHTML = "";
  302. // for (let [key, value] of Object.entries(data)) {
  303. // let inputWrapper = document.createElement("div");
  304. // let inputType = value.constructor.name;
  305. // let th = document.createElement("th");
  306. // let inputLabel = document.createElement("label");
  307. // let isRequired = key.trim()[0] === "*";
  308. // let isRequiredChar = document.createElement("span");
  309. // inputLabel.style.marginLeft = "5px";
  310. // isRequiredChar.innerText = "* ";
  311. // isRequiredChar.style.color = "red";
  312. // if (isRequired) {
  313. // th.prepend(isRequiredChar);
  314. // }
  315. // th.innerHTML += isRequired ? key.slice(1, key.length) : key;
  316. // let input = inputCreators[inputType](key, value, (value) => {
  317. // let validator;
  318. // if (isRequired && value.trim().length === 0) {
  319. // input.style.border = "1px solid red";
  320. // requiredErrors.add(key);
  321. // } else {
  322. // requiredErrors.delete(key);
  323. // }
  324. // if (this.validators && typeof this.validators[key] === "function") {
  325. // validator = this.validators[key];
  326. // }
  327. // if (validator) {
  328. // let validResult = validator(value, key, data, input);
  329. // if (validResult !== true && validResult.trim() !== "") {
  330. // inputLabel.innerText = validResult;
  331. // inputLabel.style.border = "1px solid red";
  332. // validatorErrors.add(key);
  333. // } else {
  334. // inputLabel.innerText = "";
  335. // inputLabel.style.border = "none";
  336. // validatorErrors.delete(key);
  337. // }
  338. // }
  339. // inputWrapper.append(inputLabel);
  340. // !validatorErrors.has(key) && (this.data[key] = value);
  341. // okButton.disabled = checkErrors();
  342. // });
  343. // inputWrapper.appendChild(th);
  344. // inputWrapper.appendChild(input);
  345. // inputBox.append(inputWrapper);
  346. // }
  347. // };
  348. // createInputs(data);
  349. // okButton.disabled = checkErrors();
  350. // function checkErrors() {
  351. // if (requiredErrors.size === 0 && validatorErrors.size === 0) {
  352. // return false;
  353. // }
  354. // return true;
  355. // }
  356. // if (typeof okCallback === "function") {
  357. // formBody.appendChild(okButton);
  358. // okButton.onclick = (e) => {
  359. // this.okCallback(data);
  360. // };
  361. // }
  362. // if (typeof cancelCallback === "function") {
  363. // formBody.appendChild(cancelButton);
  364. // cancelButton.onclick = () => {
  365. // this.data = { ...initData };
  366. // console.log(initData);
  367. // createInputs(this.data);
  368. // cancelCallback();
  369. // };
  370. // }
  371. // this.okCallback = okCallback;
  372. // this.cancelCallback = cancelCallback;
  373. // this.data = data;
  374. // this.validators = {};
  375. // }
  376. // let form = new Form(
  377. // formContainer,
  378. // {
  379. // "*name": "Anakin",
  380. // "*surname": "SkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalkerSkywalker",
  381. // married: true,
  382. // birthday: new Date(new Date().getTime() - 86400000 * 30 * 365),
  383. // },
  384. // () => console.log("ok"),
  385. // () => console.log("cancel")
  386. // );
  387. // form.okCallback = () => console.log("ok2");
  388. // form.validators.surname = (value, key, data, input) =>
  389. // value.length > 2 && value[0].toUpperCase() == value[0] && !value.includes(" ") ? true : "Wrong surname";
  390. // form.validators["*name"] = (value, key, data, input) =>
  391. // value.length > 3 && value[0].toUpperCase() == value[0] && !value.includes(" ") ? true : "Wrong name";
  392. // form.validators["birthday"] = (value, key, data, input) => {
  393. // if (new Date(value.toISOString().slice(0, 16)) <= new Date("1900-01-01")) {
  394. // return "Wrong date";
  395. // }
  396. // if (
  397. // new Date(value.toISOString().slice(0, 16)).getTime() >=
  398. // new Date().getTime() - new Date().getTimezoneOffset() * 1000 * 60 - 3 * 365 * 86400000
  399. // ) {
  400. // return "Wrong date";
  401. // }
  402. // return true;
  403. // };
  404. // console.log(form);
  405. //POWER OF THE FORM
  406. // function Password(parent, open) {
  407. // let formBody = document.createElement("div");
  408. // let passwordInput1 = document.createElement("input");
  409. // let passwordInput2 = document.createElement("input");
  410. // let isOpenInput = document.createElement("input");
  411. // let checkButton = document.createElement("button");
  412. // let errorDiv = document.createElement("div");
  413. // let errors = {
  414. // blankFields: "Password fields cannot be empty",
  415. // notMatch: "Password confirmation does not match",
  416. // };
  417. // let errorSet = new Set();
  418. // parent.append(formBody);
  419. // errorDiv.style.color = "red";
  420. // checkButton.innerText = "Submit";
  421. // passwordInput1.type = open ? "text" : "password";
  422. // passwordInput1.oninput = () => {
  423. // this.value1 = passwordInput1.value;
  424. // checkButton.disabled = !isValid();
  425. // if (typeof this.onPassword1Change === "function") {
  426. // this.onPassword1Change(this.value1);
  427. // }
  428. // };
  429. // passwordInput2.type = "password";
  430. // passwordInput2.style.display = !open ? "inline" : "none";
  431. // passwordInput2.oninput = () => {
  432. // this.value2 = passwordInput2.value;
  433. // checkButton.disabled = !isValid();
  434. // console.log(isValid());
  435. // if (typeof this.onPassword2Change === "function") {
  436. // this.onPassword2Change(this.value2);
  437. // }
  438. // };
  439. // isOpenInput.type = "checkbox";
  440. // isOpenInput.checked = open;
  441. // isOpenInput.onchange = () => {
  442. // this.open = isOpenInput.checked;
  443. // checkButton.disabled = !isValid();
  444. // passwordInput1.type = this.open ? "text" : "password";
  445. // passwordInput2.style.display = !this.open ? "inline" : "none";
  446. // if (typeof this.onOpenChange === "function") {
  447. // this.onOpenChange(this.open);
  448. // }
  449. // };
  450. // const setValue1 = (newValue) => {
  451. // this.value1 = newValue;
  452. // passwordInput1.value = newValue;
  453. // checkButton.disabled = !isValid();
  454. // };
  455. // const setValue2 = (newValue) => {
  456. // this.value2 = newValue;
  457. // passwordInput2.value = newValue;
  458. // checkButton.disabled = !isValid();
  459. // };
  460. // const getValue1 = () => {
  461. // return this.value1;
  462. // };
  463. // const getValue2 = () => {
  464. // return this.value2;
  465. // };
  466. // const setOpen = (value) => {
  467. // this.open = value;
  468. // isOpenInput.checked = value;
  469. // passwordInput1.type = this.open ? "text" : "password";
  470. // passwordInput2.style.display = !this.open ? "inline" : "none";
  471. // checkButton.disabled = !isValid();
  472. // };
  473. // const getOpen = () => {
  474. // return this.open;
  475. // };
  476. // const isValid = () => {
  477. // if (this.open === true) {
  478. // return false;
  479. // }
  480. // if (this.value1.trim() === "" || this.value2.trim() === "") {
  481. // errorSet.add(errors.blankFields);
  482. // showErrors();
  483. // return false;
  484. // } else {
  485. // errorSet.delete(errors.blankFields);
  486. // }
  487. // if (this.value1 !== this.value2) {
  488. // errorSet.add(errors.notMatch);
  489. // showErrors();
  490. // return false;
  491. // } else {
  492. // errorSet.delete(errors.notMatch);
  493. // }
  494. // showErrors();
  495. // return true;
  496. // };
  497. // const showErrors = () => {
  498. // let str = "";
  499. // for (let er of errorSet) {
  500. // str += er + "<br>";
  501. // }
  502. // errorDiv.innerHTML = str;
  503. // };
  504. // formBody.append(passwordInput1);
  505. // formBody.append(passwordInput2);
  506. // formBody.append(isOpenInput);
  507. // formBody.append(checkButton);
  508. // formBody.append(errorDiv);
  509. // this.open = open;
  510. // this.value1 = passwordInput1.value;
  511. // this.value2 = passwordInput2.value;
  512. // this.setOpen = setOpen;
  513. // this.getOpen = getOpen;
  514. // this.setValue1 = setValue1;
  515. // this.getValue1 = getValue1;
  516. // this.setValue2 = setValue2;
  517. // this.getValue2 = getValue2;
  518. // checkButton.disabled = !isValid();
  519. // }
  520. // let p = new Password(document.body, true);
  521. // p.onPassword1Change = (data) => console.log(data);
  522. // p.onPassword2Change = (data) => console.log(data);
  523. // p.onOpenChange = (open) => console.log(open);
  524. // p.setValue1("qwerty");
  525. // console.log(p.getValue1());
  526. // p.setValue2("qwer");
  527. // console.log(p.getValue2());
  528. // p.setOpen(false);
  529. // console.log(p.getOpen());
  530. </script>
  531. </body>
  532. </html>