main.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. function Password(parent, open/* , onChange,onOpenChange */){
  2. let pswdInput = document.createElement('input');
  3. let showPswd = document.createElement('button');
  4. /* pswdInput.type = 'password'; */
  5. showPswd.innerText = 'show pswd';
  6. parent.append(pswdInput);
  7. parent.append(showPswd);
  8. if(open == true){
  9. pswdInput.type = 'text'
  10. } else {
  11. pswdInput.type = 'password'
  12. }
  13. /* this.open = open; \
  14. this.getOpen = function(){
  15. return this.open;
  16. }*/
  17. let pswdValue='';
  18. this.setValue = value =>{
  19. if(typeof this.onChange === 'function'){
  20. this.onChange(`change all time ${value}`);
  21. }
  22. pswdValue = value
  23. pswdInput.value = pswdValue
  24. }
  25. this.setValue(pswdValue);
  26. this.setType = (type) => pswdInput.type = type;
  27. this.getType = () => pswdInput.type;
  28. this.getValue = () => pswdValue;
  29. this.setOpen = (newOpen) =>{
  30. if(typeof this.onOpenChange ==='function'){
  31. this.onOpenChange(`change when opened input ${newOpen}`);
  32. }
  33. if(open !== newOpen ){
  34. pswdInput.type = 'password'
  35. } else {
  36. pswdInput.type = 'text';
  37. }
  38. };
  39. this.getOpen = () =>{
  40. if(pswdInput.type =='password'){
  41. console.log('closed');
  42. }else {
  43. console.log('open');
  44. }
  45. }
  46. pswdInput.oninput = () => {
  47. this.setValue(pswdInput.value);
  48. }
  49. /* this.onChange = onChange;
  50. this.onOpenChange = onOpenChange; */
  51. /* pswdInput.oninput = this.onChange(this.getValue()); */
  52. /* this.onOpenChange = opened =>{
  53. pswdInput.oninput = () => oninput(opened);
  54. } */
  55. /* this.onChange = data =>{
  56. pswdInput.onchange = () =>onchange(data);
  57. } */
  58. showPswd.addEventListener('click', function changeVision(e){
  59. if(pswdInput.getAttribute("type")=="password"){
  60. pswdInput.type = 'text';
  61. open = !open;
  62. /* console.log(` what happened in click ${open}`) */
  63. } else{
  64. pswdInput.type = 'password';
  65. !open;
  66. /* console.log(`what happened in click hide ${open}`) */
  67. }
  68. });
  69. /* if(typeof this.onOpenChange == 'function'){
  70. this.onOpenChange(this.getValue());
  71. } */
  72. /* pswdInput.oninput = () => {
  73. if(typeof this.onChange == 'function'){
  74. this.onChange(this.getValue());
  75. }
  76. } */
  77. /* pswdInput.oninput = () => this.onOpenChange(this.getValue()); */
  78. /* pswdInput.oninput = () =>this.onChange(this.getValue()); */
  79. }
  80. function Form (parent){
  81. /* let pswdCheck = new Password(parent,true,()=>{}, ()=>{}); */
  82. let login = document.createElement('input');
  83. let acceptButton = document.createElement('button');
  84. acceptButton.innerText = 'Ok';
  85. parent.append(login);
  86. let pswd = new Password(parent,true);
  87. parent.append(acceptButton);
  88. let loginValue='';
  89. /* let pswdCheckValue=''; */
  90. /* pswd.setValue('qwerty'); */
  91. let actionbutton = (passwordValue) => {
  92. /* (passwordValue && this.getloginValue())? acceptButton.disabled = false : acceptButton.disabled=true */
  93. if(passwordValue && this.getloginValue()){
  94. acceptButton.disabled = false
  95. }else {
  96. acceptButton.disabled = true
  97. }
  98. }
  99. this.setLoginValue = value =>{
  100. loginValue = value;
  101. login.value = loginValue
  102. actionbutton(pswd.getValue());
  103. }
  104. /* this.setCheckPswdValue = value => {
  105. pswdCheckValue = value;
  106. checkPswd.value = pswdCheckValue;
  107. }
  108. this.setCheckPswdValue(pswdCheckValue)
  109. this.getCheckPswdValue=()=>pswdCheckValue; */
  110. this.setLoginValue(loginValue);
  111. this.getloginValue = () => loginValue;
  112. login.oninput = () => {
  113. this.setLoginValue(login.value);
  114. }
  115. pswd.onChange = (newpswd) => {
  116. if(newpswd !== pswd.getValue() && typeof this.onChangePswd ==='function'){
  117. this.onChangePswd(newpswd);
  118. }
  119. actionbutton(pswd.getValue());
  120. }
  121. /* let pswdTrueOrNot = (passwordValue, checkPswdValue) =>{
  122. if(checkPswdValue !== passwordValue){
  123. checkPswd.style.border = 'red'
  124. }
  125. else {
  126. checkPswd.style.border = 'green'
  127. }
  128. }
  129. checkPswd.oninput = () => {
  130. let checkValue = checkPswd.value;
  131. this.setCheckPswdValue(checkValue);
  132. let pswdValue = pswd.getValue();
  133. pswdTrueOrNot(pswdValue,checkValue);
  134. } */
  135. /* if(pswd.getType() == 'text'){
  136. checkPswd.style.display = 'none';
  137. } else {
  138. checkPswd.style.display = '';
  139. pswd.setType('password');
  140. } */
  141. // trash set and get
  142. this.getValuePassword = () => pswd.getValue();
  143. this.setValuePassword = (newpswd) => {
  144. pswd.setValue(newpswd);
  145. }
  146. actionbutton(pswd.getValue());
  147. }
  148. function FormWithVerify(parent,open){
  149. let login = document.createElement('input');
  150. let pswd1 = document.createElement('input');
  151. let pswd2 = document.createElement('input');
  152. let showBtn = document.createElement('button');
  153. showBtn.innerText = 'show pswd';
  154. pswd1.type = this.open ? 'text' : 'password';
  155. login.placeholder = 'login';
  156. pswd1.placeholder = 'input pswd';
  157. pswd2.placeholder = 'input pswd for require';
  158. pswd2.type = 'password';
  159. pswd2.style.display = !open ? 'inline' : 'none';
  160. parent.append(login);
  161. parent.appendChild(pswd1);
  162. parent.appendChild(pswd2);
  163. parent.appendChild(showBtn);
  164. let pswdValue='';
  165. let pswdValue2=''
  166. this.setValue = value =>{
  167. if(typeof this.onChange === 'function'){
  168. this.onChange(`change all time ${value}`);
  169. }
  170. pswdValue = value
  171. pswd1.value = pswdValue
  172. }
  173. this.setValue(pswdValue);
  174. this.setType = (type) => pswd1.type = type;
  175. this.getType = () => pswd1.type;
  176. this.getValue = () => pswdValue;
  177. this.setOpen = (newOpen) =>{
  178. if(typeof this.onOpenChange ==='function'){
  179. this.onOpenChange(`change when opened input ${newOpen}`);
  180. }
  181. if(open !== newOpen ){
  182. pswd1.type = 'password'
  183. } else {
  184. pswd1.type = 'text';
  185. }
  186. open = newOpen;
  187. };
  188. this.getOpen = () =>{
  189. if(pswd1.type =='password'){
  190. console.log('closed');
  191. }else {
  192. console.log('open');
  193. }
  194. }
  195. pswd1.oninput = () => {
  196. this.setValue(pswdInput.value);
  197. }
  198. this.setValue2 = value =>{
  199. if(typeof this.onChange === 'function'){
  200. this.onChange(`change all time ${value}`);
  201. }
  202. pswdValue2 = value
  203. pswd2.value = pswdValue2
  204. }
  205. this.setValue2(pswdValue2);
  206. this.setType2 = (type) => pswd1.type = type;
  207. this.getType2 = () => pswd2.type;
  208. this.getValue2 = () => pswdValue2;
  209. this.setOpen2 = (newOpen) =>{
  210. if(typeof this.onOpenChange ==='function'){
  211. this.onOpenChange(`change when opened input ${newOpen}`);
  212. }
  213. if(open !== newOpen ){
  214. pswd2.type = 'password'
  215. } else {
  216. pswd2.type = 'text';
  217. }
  218. open = newOpen;
  219. };
  220. this.getOpen2 = () =>{
  221. if(pswd2.type =='password'){
  222. console.log('closed');
  223. }else {
  224. console.log('open');
  225. }
  226. }
  227. pswd2.oninput = () => {
  228. this.setValue2(pswdInput.value);
  229. }
  230. showBtn.addEventListener('click', function ShowPswd(){
  231. if(pswd1.getAttribute("type")=="password"){
  232. pswd1.type = 'text';
  233. pswd2.style.display = 'inline';
  234. open = !open;
  235. /* console.log(` what happened in click ${open}`) */
  236. } else{
  237. pswd1.type = 'password';
  238. pswd2.style.display = 'none'
  239. !open;
  240. /* console.log(`what happened in click hide ${open}`) */
  241. }
  242. })
  243. }
  244. /* let p = new Password(document.body, true); */
  245. /*
  246. p.onChange = data => console.log(data)
  247. p.onOpenChange = open => console.log(open)
  248. p.setValue('qwerty');
  249. console.log(p.getValue())
  250. p.setOpen(false);
  251. console.log(p.getOpen()) */
  252. //let form = new Form(form1);
  253. /* form.setLoginValue('Nik'); */
  254. //console.log(form.getloginValue());
  255. let form = new FormWithVerify(form1,true);