Ivar 2 gadi atpakaļ
vecāks
revīzija
a225f4db3c

+ 0 - 1
js/09/mult_table/index.js

@@ -26,7 +26,6 @@ for (let rowIndex = 1; rowIndex < 10; rowIndex++) {
       let currCells = []   
       td.onmouseover = function() {
          currCells = cells.filter(item => item.cellIndex === colIndex - 1 || item.parentElement.rowIndex === rowIndex - 1)
-
          for (const el of currCells) {
             currColor.push(el.style.backgroundColor)
             el.style.backgroundColor = 'red'

+ 66 - 27
js/09/tasks/index.js

@@ -1,44 +1,83 @@
 
 // makeProfileTimerWrapp()
 function makeProfileTimerWrapp() {
+
    function makeProfileTimer() {
-      return performance.now()
+      return function () {
+         return performance.now()
+      } 
    }
-   let timer = makeProfileTimer
+   let timer = makeProfileTimer()
    alert('Замеряем время работы этого alert')
    alert(timer())
 }
 
-// makeSaver()
-function makeSaver() {
+// makeSaverWrapp()
+function makeSaverWrapp() {
+
+   function makeSaver(func) {
+      let storage = null
+      return function () {
+         if (storage === null) {
+            storage = func()
+            return storage
+         } else {
+            return storage
+         }
+      }    
+   } 
+
+   let saver = makeSaver(Math.random)
+   let value1 = saver()
+   let value2 = saver()
+   console.log(value1) 
+   console.log(value2)
+   console.log(value1 === value2) 
 
+   let saver2 = makeSaver(() => console.log('saved function called') || [null, undefined, false, '', 0, Math.random()][Math.ceil(Math.random()*6)])
+   let value3 = saver2()
+   let value4 = saver2()
+   console.log(value3 === value4) 
 }
 
-finalCountdown()
-function finalCountdown() {
-
-   // let timerId = setTimeout(counter, 1000)
-
-   // counter()
-   // function counter() {
-   //    let counter = 0;
-   //    return function () {
-   //       console.log(counter) 
-   //    }
-   // }
-
-   // setTimeout(function tick() {
-   //    (function makeCounter() {
-   //       let counter = 0     
-   //       counter++   
-   //       return () => console.log(counter)  
-   //    })()
-   //    setTimeout(tick, 1000)
-   // }, 1000)   
+// finalCountdownWrapp()
+function finalCountdownWrapp() {
+
+   let i = 0;
+   (function loop() {
+      setTimeout(function () {
+          console.log(++i)
+          loop()
+      }, 1000)
+   })()
 }
 
-myBind()
-function myBind() {
+myBindWrapp()
+function myBindWrapp() {
+
+   function myBind(func, funcThis, array) {
+      let params = array
+      return function () {
+         
+      } 
+   }
 
+   let pow5 = myBind(Math.pow, Math, [undefined, 5])
+   let cube = myBind(Math.pow, Math, [undefined, 3])
+   pow5(2)
+   cube(3) 
+   console.log(pow5(2))
+   console.log(cube(3))
+
+   let chessMin = myBind(Math.min, Math, [undefined, 4, undefined, 5,undefined, 8,undefined, 9])
+   chessMin(-1,-5,3,15) 
+   console.log(chessMin(-1,-5,3,15))
+
+   // let zeroPrompt = myBind(prompt, window, [undefined, "0"])
+   // let someNumber = zeroPrompt("Введите число")  
+
+   // myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'
 }
 
+
+

+ 17 - 2
js/10/regulator/index.html

@@ -3,18 +3,33 @@
     <head>
         <meta charset="utf-8">
         <meta name="viewport" content="width=device-width">
-        <title>Другой тайтл ПРИВЕТ 17й</title>
+        <title>Регуляторы</title>
         <style>
             #container1 {
                 padding: 40px;
             }
+            #container2 {
+                padding: 40px;
+            }
+            img {
+                width: 181px;
+                height: 181px;
+                margin: 15px;
+            }
         </style>
     </head>
     <body>
         <div id="color" style="height: 200px; width: 100%; background-color:  rgb(0, 0, 0);"></div>
 
-        <div id="container1" ></div>
+        <div id="container1"></div>
+
+        <div id="audio_container">
+            <audio id="audio" controls>
+                <source src="./music.mp3" type="audio/mpeg">
+            </audio>
+        </div>
 
+        <div id="container2"></div>
 
         <script src="index.js"></script>
     </body>

+ 17 - 13
js/10/regulator/index.js

@@ -31,9 +31,6 @@ function Control(el, {  value=0,
     this.getValue = () => value
 
 
-
-
-
     img.onmousewheel = e => {
         const {deltaY} = e
         const newValue = value + deltaY*wheelSpeed
@@ -53,6 +50,7 @@ function Control(el, {  value=0,
         }
     }
 
+    
     //перевод радианов в градусы и смещение в координаты от 0 до 360 градусов
     const toDeg = rad => ((rad * 180) / Math.PI + 360 + 90) % 360
 
@@ -65,7 +63,6 @@ function Control(el, {  value=0,
 
         e.preventDefault()
     }
-
     img.onmousemove = e => {
         if (prevMouseAngle === null) return
         const y = e.layerY - img.height/2
@@ -78,7 +75,6 @@ function Control(el, {  value=0,
 
         console.log()
     }
-
     img.onmouseout = img.onmouseup = e => {
         prevMouseAngle = null
     }
@@ -86,25 +82,33 @@ function Control(el, {  value=0,
 
     this.setValue(value)
 }
+// console.log(volumeControl.getValue())
+// setTimeout(() => volumeControl.setValue(80), 2000)
 
 function setRgb() {
     color.style.backgroundColor = `rgb(${red.getValue()}, ${green.getValue()}, ${blue.getValue()})`
 }
-
-// const volumeControl  = new Control(container1, {value: 50})
-//     volumeControl.onchange = value => console.log(value)
-
 const red = new Control(container1, {min:0, max:255})
     red.onchange = setRgb
-
 const green = new Control(container1, {min:0, max:255})
     green.onchange = setRgb
-
 const blue = new Control(container1, {min:0, max:255})
     blue.onchange = setRgb
 
-// console.log(volumeControl.getValue())
-// setTimeout(() => volumeControl.setValue(80), 2000)
+
+function setVolume() {
+    audio.volume = volumeControl.getValue()/100
+}
+const volumeControl  = new Control(container2, {value:100, min:0, max:100})
+    volumeControl.onchange = setVolume
+
+audio.onloadedmetadata = function() {
+    function setTime() {    
+        audio.currentTime = playControl.getValue()
+    }
+    const playControl  = new Control(container2, {min:0, max:audio.duration})
+        playControl.onchange = setTime
+}
 
 
 

BIN
js/10/regulator/music.mp3


+ 344 - 11
js/10/tasks/index.js

@@ -1,24 +1,357 @@
-htmlTree()
-function htmlTree() {
 
-}
+// passwordWrapp()
+function passwordWrapp() {
+
+   function Password(parent=document.body, open=false) {
+
+      const passField = document.createElement('input')
+
+      const checkBox = document.createElement('input')
+      checkBox.type = 'checkbox'
+
+      parent.append(passField)
+      parent.append(checkBox)
+
+      this.setValue = (newValue) => {
+         passField.value = newValue
+      }
+      this.getValue = () => passField.value
+
+      this.setOpen = (newOpen) => {
+         open = newOpen
+         
+         if (open === true) {
+            checkBox.checked = true
+            passField.type = 'text'
+         } else if (open === false) {
+            checkBox.checked = false
+            passField.type = 'password'
+         }
+      }
+      this.setOpen(open)
+
+      this.getOpen = () => checkBox.checked
+
 
-htmlTree()
-function htmlTree() {
+      passField.oninput = () => {
+         if (typeof this.onChange === 'function') {
+            this.onChange(this.getValue())
+         }      
+      }
 
+      checkBox.oninput = () => {
+         if (this.getOpen() === true) {
+            this.setOpen(true)
+         } else {
+            this.setOpen(false)
+         }
+         if (typeof this.onOpenChange === 'function') {
+            this.onOpenChange(this.getOpen())
+         } 
+      }
+   }
+
+   let p = new Password(document.body, true)
+
+   p.onChange = data => console.log(data)
+   p.onOpenChange = open => console.log(open)
+   // p.setValue('qwerty')
+   // console.log(p.getValue())
+   // p.setOpen(false)
+   // console.log(p.getOpen())
 }
 
-htmlTree()
-function htmlTree() {
 
+// loginFormWrapp()
+function loginFormWrapp() {
+
+   function LoginForm(parent=document.body, open=false) {
+
+      const loginField = document.createElement('input')
+      loginField.type = 'text'
+
+      const passField = document.createElement('input')
+
+      const checkBox = document.createElement('input')
+      checkBox.type = 'checkbox'
+
+      const button = document.createElement('button')
+      button.innerText = 'Подтвердить'
+      button.disabled = true
+
+      parent.append(loginField)
+      parent.append(passField)
+      parent.append(checkBox)
+      parent.append(button)
+
+      this.setLoginValue = (newValue) => {
+         loginField.value = newValue
+      }
+      this.getLoginValue = () => loginField.value
+
+
+      this.setPassValue = (newValue) => {
+         passField.value = newValue
+      }
+      this.getPassValue = () => passField.value
+
+
+      this.setOpen = (newOpen) => {
+         open = newOpen         
+         if (open === true) {
+            checkBox.checked = true
+            passField.type = 'text'
+         } else if (open === false) {
+            checkBox.checked = false
+            passField.type = 'password'
+         }
+      }
+      this.setOpen(open)
+      this.getOpen = () => checkBox.checked
+
+      loginField.oninput = () => {
+         if (this.getLoginValue() && this.getPassValue()) {
+            button.disabled = false
+         } else {
+            button.disabled = true
+         }
+         if (typeof this.onLoginChange === 'function') {
+            this.onLoginChange(this.getLoginValue())
+         }      
+      }
+
+      passField.oninput = () => {
+         if (this.getLoginValue() && this.getPassValue()) {
+            button.disabled = false
+         } else {
+            button.disabled = true
+         }
+         if (typeof this.onPassChange === 'function') {
+            this.onPassChange(this.getPassValue())
+         }      
+      }
+
+      checkBox.oninput = () => {
+         if (this.getOpen() === true) {
+            this.setOpen(true)
+         } else {
+            this.setOpen(false)
+         }
+         if (typeof this.onOpenChange === 'function') {
+            this.onOpenChange(this.getOpen())
+         } 
+      }
+   }
+
+   let loginForm = new LoginForm(document.body)
 }
 
-htmlTree()
-function htmlTree() {
 
+// loginFormConstructorWrapp()
+function loginFormConstructorWrapp() {
+
+   function LoginForm(parent=document.body, open=false) {
+
+      const loginField = document.createElement('input')
+      loginField.type = 'text'
+
+      const passField = document.createElement('input')
+
+      const checkBox = document.createElement('input')
+      checkBox.type = 'checkbox'
+
+      const button = document.createElement('button')
+      button.innerText = 'Подтвердить'
+
+      parent.append(loginField)
+      parent.append(passField)
+      parent.append(checkBox)
+      parent.append(button)
+
+
+      this.setLoginValue = (newValue) => {
+         loginField.value = newValue
+      }
+      this.getLoginValue = () => loginField.value
+
+
+      this.setPassValue = (newValue) => {
+         passField.value = newValue
+      }
+      this.getPassValue = () => passField.value
+
+
+      this.setOpen = (newOpen) => {
+         open = newOpen         
+         if (open === true) {
+            checkBox.checked = true
+            passField.type = 'text'
+         } else if (open === false) {
+            checkBox.checked = false
+            passField.type = 'password'
+         }
+      }
+      this.setOpen(open)
+      this.getOpen = () => checkBox.checked
+
+
+      let btnState = true
+      this.setBtn = (newValue=btnState) => {
+         btnState = newValue
+         button.disabled = btnState
+         if (this.getLoginValue() && this.getPassValue()) {
+            button.disabled = false
+         }
+      }
+      this.setBtn()
+      this.getBtn = () => button.disabled
+
+
+      this.makeCallback = (name, content) => {
+         if (typeof name === 'function') {
+            name(content)
+         } 
+      }
+
+
+      loginField.oninput = () => {
+         this.setBtn()
+         this.makeCallback(this.onLoginChange, this.getLoginValue())     
+      }
+
+      passField.oninput = () => {
+         this.setBtn()
+         this.makeCallback(this.onPassChange, this.getPassValue())     
+      }
+
+      checkBox.oninput = () => {
+         if (this.getOpen() === true) {
+            this.setOpen(true)
+         } else {
+            this.setOpen(false)
+         }
+         this.setBtn()
+         this.makeCallback(this.onOpenChange, this.getOpen())
+      }
+
+      button.onclick = () => {
+         this.makeCallback(this.onBtnClick, 'click')
+      }
+   }
+
+   let loginForm = new LoginForm(document.body)
+
+   loginForm.onLoginChange = data => console.log(data)
+   loginForm.onPassChange = data => console.log(data)
+   loginForm.onBtnClick = click => console.log(click)
 }
 
-htmlTree()
-function htmlTree() {
 
+// passwordVerifyWrapp()
+function passwordVerifyWrapp() {
+
+   function LoginForm(parent=document.body, open=false) {
+
+      const loginField = document.createElement('input')
+      loginField.type = 'text'
+
+      const passField = document.createElement('input')
+      const passField2 = document.createElement('input')
+
+      const checkBox = document.createElement('input')
+      checkBox.type = 'checkbox'
+
+      const button = document.createElement('button')
+      button.innerText = 'Подтвердить'
+
+      parent.append(loginField)
+      parent.append(passField)
+      parent.append(passField2)
+      parent.append(checkBox)
+      parent.append(button)
+
+
+      this.setLoginValue = (newValue) => {
+         loginField.value = newValue
+      }
+      this.getLoginValue = () => loginField.value
+
+
+      this.setPassValue = (newValue) => {
+         passField.value = newValue
+      }
+      this.getPassValue = () => passField.value
+
+      this.setPassValue2 = (newValue) => {
+         passField2.value = newValue
+      }
+      this.getPassValue2 = () => passField2.value
+
+      this.setOpen = (newOpen) => {
+         open = newOpen 
+         checkBox.checked = open
+         if (open === true) {
+            passField.type = 'text'
+            passField2.style.display = 'none'
+         } else if (open === false) {
+            passField.type = 'password'
+            passField2.style.display = 'inline'
+            passField2.type = 'password'
+         }
+      }
+      this.setOpen(open)
+      this.getOpen = () => checkBox.checked
+
+      let btnState = true
+      this.setBtn = (newValue=btnState) => {
+         btnState = newValue
+         button.disabled = btnState
+         if (this.getOpen() ? this.getLoginValue() && this.getPassValue() : 
+               this.getLoginValue() && this.getPassValue() && this.getPassValue() === this.getPassValue2()) {
+            button.disabled = false
+         }
+      }
+      this.setBtn()
+      this.getBtn = () => button.disabled
+
+
+
+      this.makeCallback = (name, content) => {
+         if (typeof name === 'function') {
+            name(content)
+         } 
+      }
+
+
+      loginField.oninput = () => {
+         this.setBtn()
+         this.makeCallback(this.onLoginChange, this.getLoginValue())     
+      }
+
+      passField.oninput = () => {
+         this.setBtn()
+         this.makeCallback(this.onPassChange, this.getPassValue())     
+      }
+
+      passField2.oninput = () => {
+         this.setBtn()
+         this.makeCallback(this.onPass2Change, this.getPassValue2())     
+      }
+
+      checkBox.oninput = () => {
+         if (this.getOpen() === true) {
+            this.setOpen(true)
+         } else {
+            this.setOpen(false)
+         }
+         this.setBtn()
+         this.makeCallback(this.onOpenChange, this.getOpen())
+      }
+
+      button.onclick = () => {
+         this.makeCallback(this.onBtnClick, 'click')
+      }
+   }
+
+   let loginForm = new LoginForm()
 }