123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360 |
- //Password
- function Password(parent = document.body, open = false){
- const input = document.createElement('input');
- const btn = document.createElement('button');
-
- parent.append(input, btn);
- let value = '';
- let readProp = open;
- btn.innerText = readProp ? 'show' : 'hide' ;
- this.setValue = newValue => {
- if (newValue != ' ' && newValue && newValue !== value)
- value = newValue
- }
- this.setOpen = newOpen => {
- if (newOpen != readProp && newOpen != undefined)
- readProp = newOpen
-
- }
- input.oninput = this.onChange = (input) => {
- value = input.data;
- }
- btn.onclick = this.onOpenChange = (newOpen) => {
- readProp = !readProp;
- btn.innerText = readProp ? 'show' : 'hide';
- if (readProp){
- input.setAttribute('type','password')
- } else input.setAttribute('type','text')
- }
- this.getValue = () => value;
- this.getOpen = () => readProp;
- }
- //let p = new Password(root, true)
- // p.onChange = data => console.log(data)
- // p.onOpenChange = open => console.log(open)
- //p.setValue('qwerty')
- //console.log(p.getValue())
- //p.setOpen(true)
- //console.log(p.getOpen())
- /*
- LoginForm
- С помощью предыдущего кода Password сделайте форму логина, кнопка в которой будет активна только если и login и пароль не пусты */
- /* function Form(parent = document.body, open = false, active = false){
- const form = document.createElement('form');
- const input = document.createElement('input');
- const inputLog = document.createElement('input');
- const btn = document.createElement('button');
- const btnSend = document.createElement('button');
-
- form.append(input, inputLog, btn, btnSend);
- parent.append(form);
- let value = '';
- let login = '';
- let readProp = open;
- let btnActive = active;
-
- btn.innerText = readProp ? 'hide password' : 'show password';
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
-
- input.oninput = this.onChange = () => {
- value = input.value;
- if (value && login) {
- btnActive = true;
- console.log(btnActive)
-
- } else if (!value || !login){
- btnActive = false;
- console.log('false')
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- }
- inputLog.oninput = this.onChange = () => {
- login = inputLog.value;
- if (value && login) {
- btnActive = true;
- console.log(btnActive)
-
- } else if (!value || !login){
- btnActive = false;
- console.log('false')
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- }
- btn.onclick = this.onOpenChange = (e, newOpen) => {
- e.preventDefault();
- readProp = !readProp;
- btn.innerText = readProp ? 'show password' : 'hide password';
- if (readProp){
- input.setAttribute('type','password')
- } else input.setAttribute('type','text')
- }
-
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
-
- this.onsubmit = function(){
- formUploader.setFormLoading(form);
- }
- } */
- /*
- LoginForm Constructor
- оформите предыдущую задачу как функцию-конструктор. Продумайте и предусмотрите геттеры, сеттеры и колбэки. */
- /* function Form(parent = document.body, open = false, active = false){
- const form = document.createElement('form');
- const input = document.createElement('input');
- const inputLog = document.createElement('input');
- const btn = document.createElement('button');
- const btnSend = document.createElement('button');
-
- form.append(input, inputLog, btn, btnSend);
- parent.append(form);
- let value = '';
- let login = '';
- let readProp = open;
- let btnActive = active;
- btn.innerText = readProp ? 'hide password' : 'show password';
-
- input.oninput = this.onChange = () => {
- value = input.value;
- this.password = value;
- if (value && login) {
- btnActive = true;
- console.log(btnActive)
-
- } else if (!value || !login){
- btnActive = false;
- console.log('false')
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
- }
- inputLog.oninput = this.onChange = () => {
- login = inputLog.value;
- this.login = login;
- console.log(login)
- if (value && login) {
- btnActive = true;
- console.log(btnActive)
-
- } else if (!value || !login){
- btnActive = false;
- console.log('false')
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
- }
- btn.onclick = this.onOpenChange = (e, newOpen) => {
- e.preventDefault();
- readProp = !readProp;
- btn.innerText = readProp ? 'show password' : 'hide password';
- if (readProp){
- input.setAttribute('type','password')
- } else input.setAttribute('type','text')
- }
-
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
-
- this.onsubmit = function(){
- formUploader.setFormLoading(form);
- }
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
- this.login = login;
- this.password = value;
- this.getData = () => `Login : ${this.login} Passwqord: ${this.password}`;
- this.getLogin = () => this.login;
- this.getPassword = () => this.password;
- this.setLogin = (newLogin) => {
- this.login = newLogin;
- }
- this.setPassword = (newPassword) => {
- this.password = newPassword;
- }
- } */
- //let form1 = new Form(root, true, false);
- /* Password Verify
- С помощью Password сделайте пару инпутов, которые проверяют введеный пароль (в двух полях ввода) на совпадение. Кнопка должна активизироваться при совпадающих паролях. При открытом пароле второе поле вводы должно пропадать с экрана Таким образом:
- Когда Password в скрытом режиме - появляется второй инпут (<input type='password'>) с паролем в скрытом режиме
- Когда Password в открытом режиме - второй инпут пропадат */
- function PasswordVerify(parent = document.body, open = false) {
- const input = document.createElement('input');
- const inputVerify = document.createElement('input');
- const btn = document.createElement('button');
- const btnSend = document.createElement('button');
-
- parent.append(input, inputVerify, btn, btnSend);
- let value = '';
- let passVerify = null;
- let btnActive = false;
- let readProp = open;
-
- btn.innerText = readProp ? 'show' : 'hide' ;
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
- inputVerify.style.display = readProp ? 'block' : 'none';
- this.setValue = newValue => {
- if (newValue != ' ' && newValue)
- console.log(newValue);
- value = newValue
- if (value && !readProp ) {
- btnActive = true;
-
- } else if (!value || !passVerify){
- btnActive = false;
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
-
- }
- this.setPasswordVerify = newVerify => {
- passVerify = newVerify;
- if (newVerify && newVerify == value)
- console.log(newVerify, value)
- console.log(newVerify == value)
- if (value && passVerify) {
- btnActive = true;
-
- } else if (!value || !passVerify){
- btnActive = false;
- }
- if (btnActive && passVerify == value) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
- btnSend.innerText = btnActive ? 'SEND' : ' Enter data';
- if (passVerify == value) btnActive = true;
- }
- this.setOpen = newOpen => {
- if (newOpen != readProp && newOpen != undefined)
- readProp = newOpen
-
- }
- input.oninput = this.onChange = (input) => {
- value = input.data;
- this.setValue(value);
-
- }
- inputVerify.oninput = this.onChange = (inputVerify) => {
- passVerify = inputVerify.data;
- this.setPasswordVerify(passVerify);
- }
- btn.onclick = this.onOpenChange = (newOpen) => {
- readProp = !readProp;
- btn.innerText = readProp ? 'show' : 'hide';
- inputVerify.style.display = readProp ? 'block' : 'none';
- if (readProp){
- input.setAttribute('type','password')
- } else {
- input.setAttribute('type','text')
- }
- }
- if (btnActive) {
- btnSend.removeAttribute('disabled','')
- btnSend.setAttribute('enabled','')
- } else {
- btnSend.removeAttribute('enabled','')
- btnSend.setAttribute('disabled','')
- }
-
- }
-
- let pass1 = new PasswordVerify(root, false)
|