Ivar преди 2 години
родител
ревизия
13ed5cd36d
променени са 4 файла, в които са добавени 58 реда и са изтрити 41 реда
  1. 29 19
      js/09/mult_table/index.js
  2. 20 6
      js/09/tasks/index.js
  3. 9 14
      js/10/regulator/index.js
  4. 0 2
      js/10/tasks/index.js

+ 29 - 19
js/09/mult_table/index.js

@@ -6,26 +6,14 @@ table.style.cursor = 'pointer'
 table.setAttribute('border', '1')
 table.setAttribute('frame', 'void')
 body.insertBefore(table, body.childNodes[0])
-let cells = []
-for (let rowIndex = 1; rowIndex < 10; rowIndex++) {
-   let tr = document.createElement("tr")
-   if (rowIndex % 2 === 0) {
-      tr.style.backgroundColor = '#CFCFCF'
-   }
-   table.appendChild(tr)
-      for (let colIndex = 1; colIndex < 10; colIndex++) {
-      let td = document.createElement("td")      
-      cells.push(td)
-      td.setAttribute('align', 'center')
-      td.setAttribute('width', '40px')
-      td.setAttribute('height', '40px')
-      tr.appendChild(td)
-      td.innerText = `${rowIndex*colIndex}`
 
-      let currColor = []
-      let currCells = []   
+let cells = []
+let wrappFunc = (cells) => {
+   let currColor = []
+   let currCells = [] 
+   return (td, i, j) => {
       td.onmouseover = function() {
-         currCells = cells.filter(item => item.cellIndex === colIndex - 1 || item.parentElement.rowIndex === rowIndex - 1)
+         currCells = cells.filter(item => item.cellIndex === j - 1 || item.parentElement.rowIndex === i - 1)
          for (const el of currCells) {
             currColor.push(el.style.backgroundColor)
             el.style.backgroundColor = 'red'
@@ -36,7 +24,29 @@ for (let rowIndex = 1; rowIndex < 10; rowIndex++) {
             let color = currColor.shift()
             el.style.backgroundColor = color
          }
-      }
+      }   
+   }
+}
+let innerFunc = wrappFunc(cells)
+
+for (let i = 1; i < 10; i++) {
+   let tr = document.createElement("tr")
+   if (i % 2 === 0) {
+      tr.style.backgroundColor = '#CFCFCF'
+   }
+   table.appendChild(tr)
+
+
+      for (let j = 1; j < 10; j++) {
+      let td = document.createElement("td")      
+      cells.push(td)
+
+      td.setAttribute('align', 'center')
+      td.setAttribute('width', '40px')
+      td.setAttribute('height', '40px')
+      tr.appendChild(td)
+      td.innerText = `${i*j}`
+      innerFunc(td, i, j)
    }
 }
 

+ 20 - 6
js/09/tasks/index.js

@@ -52,13 +52,26 @@ function finalCountdownWrapp() {
    })()
 }
 
-myBindWrapp()
+// myBindWrapp()
 function myBindWrapp() {
 
    function myBind(func, funcThis, array) {
-      let params = array
       return function () {
-         
+         let args = () => {
+            let newArr = []
+            let i = 0
+            for (const el of array) {
+               if (el === undefined) {
+                  newArr.push(arguments[i])
+                  i++
+               } else {
+                  newArr.push(el)
+               }
+            }
+            return newArr
+         }
+         // console.log(args())         
+         return func.apply(funcThis, args())
       } 
    }
 
@@ -73,10 +86,11 @@ function myBindWrapp() {
    chessMin(-1,-5,3,15) 
    console.log(chessMin(-1,-5,3,15))
 
-   // let zeroPrompt = myBind(prompt, window, [undefined, "0"])
-   // let someNumber = zeroPrompt("Введите число")  
+   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'
+   myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d') === 'abcdef'
+   console.log(myBind((...params) => params.join(''), null, [undefined, 'b', undefined, undefined, 'e', 'f'])('a','c','d'))   
 }
 
 

+ 9 - 14
js/10/regulator/index.js

@@ -13,7 +13,7 @@ function Control(el, {  value=0,
     const ratio = (maxAngle - minAngle) / (max - min)
     const getAngle = () => (value - min)*ratio + minAngle
 
-    this.setValue = newValue => {
+    this.setValue = (newValue, triggerEvent=true) => {
         if (newValue > max){
             newValue = max
         }
@@ -23,7 +23,7 @@ function Control(el, {  value=0,
         value = newValue
         img.style.transform = `rotate(${getAngle()}deg)`
 
-        if (typeof this.onchange === 'function') {
+        if (typeof this.onchange === 'function' && triggerEvent) {
             this.onchange(value)
         }
     }
@@ -103,7 +103,7 @@ const volumeControl  = new Control(container2, {value:100, min:0, max:100})
     volumeControl.onchange = setVolume
     audio.onvolumechange = () => {
         // console.log(audio.volume)
-        volumeControl.setValue(audio.volume*100)
+        volumeControl.setValue(audio.volume*100, false)
     }
 
 audio.onloadedmetadata = function() {
@@ -112,15 +112,10 @@ audio.onloadedmetadata = function() {
     }
     const playControl  = new Control(container2, {min:0, max:audio.duration})
         playControl.onchange = setTime
-    // setInterval(() => {
-    //     playControl.setValue(audio.currentTime)
-    // }, 10000);
-    // audio.ontimeupdate = (e) => {
-    //     e.preventDefault()
-    //     console.log(audio.currentTime)
-    // }
-}
-
-
-
 
+    audio.ontimeupdate = (e) => {
+        // e.preventDefault()
+        // console.log(audio.currentTime)
+        playControl.setValue(audio.currentTime, false)
+    }
+}

+ 0 - 2
js/10/tasks/index.js

@@ -564,5 +564,3 @@ function formWrapp() {
 
 
 
-
-