Pavel 7 years ago
parent
commit
7d059a0a5c

+ 54 - 0
module/module.md

@@ -0,0 +1,54 @@
+### objectToPairs
+
+```javascript
+var obj = { foo: 1,
+    bar: null,
+    baz: undefined
+}
+
+function objectToPairs(obj){
+	var arr = [];
+	var objKeys = Object.keys(obj);
+	for (var i = 0; i < objKeys.length ; i++) {
+		
+				arr.push(objKeys[i]);
+				arr.push(obj[objKeys[i]]);
+			
+		
+	
+	}
+	return arr;
+}
+
+objectToPairs(obj);
+```
+
+### objectSplit
+
+```javascript
+var obj = { foo: 1,
+    bar: null,
+    baz: undefined
+}
+
+objectSplit(obj);
+
+function objectSplit(obj){
+	var arr1 = [];
+	var arr2 = [];
+	var objKeys = Object.keys(obj);
+	for (var i = 0; i < objKeys.length; i++) {
+		arr1.push(objKeys[i]);
+		arr2.push(obj[objKeys[i]]);
+	}
+	var resObject = {};
+	resObject.keys = arr1;
+	resObject.values = arr2;
+	return resObject;
+}
+```
+
+### setPropertyBySelector
+
+ссылка
+

File diff suppressed because it is too large
+ 16 - 0
module/scrollButtons/index.html


+ 68 - 0
module/scrollButtons/js/scrollButtons.js

@@ -0,0 +1,68 @@
+function scrollButtons(element, range){
+	element.parentElement.style.position = "relative"
+	var buttonTop = document.createElement("div");
+	var buttonBottom = document.createElement("div");
+	var buttonLeft = document.createElement("div");
+	var buttonRight = document.createElement("div");
+
+	buttonTop.innerText = "Up";
+	buttonBottom.innerText = "Down";
+	buttonLeft.innerText = "Left";
+	buttonRight.innerText = "Right";
+
+	buttonTop.style.position = "absolute";
+	buttonBottom.style.position = "absolute";
+	buttonLeft.style.position = "absolute";
+	buttonRight.style.position = "absolute";
+
+	buttonTop.style.top = "20px";
+	buttonTop.style.left = "180px";
+
+	buttonBottom.style.bottom = "30px";
+	buttonBottom.style.left = "170px";
+
+	buttonLeft.style.left = "20px";
+	buttonLeft.style.top = "190px";
+
+	buttonRight.style.right = "1000px";
+	buttonRight.style.top = "190px";
+
+	buttonTop.style.background = "#fff";
+	buttonBottom.style.background = "#fff";
+	buttonLeft.style.background = "#fff";
+	buttonRight.style.background = "#fff";
+
+	buttonTop.style.borderRadius = "10px"
+	buttonBottom.style.borderRadius = "10px"
+	buttonLeft.style.borderRadius = "10px"
+	buttonRight.style.borderRadius = "10px"
+
+	buttonTop.style.padding = "3px"
+	buttonBottom.style.padding = "3px"
+	buttonLeft.style.padding = "3px"
+	buttonRight.style.padding = "3px"
+
+	element.parentElement.appendChild(buttonTop);
+	element.parentElement.appendChild(buttonBottom);
+	element.parentElement.appendChild(buttonLeft);
+	element.parentElement.appendChild(buttonRight);
+
+	buttonTop.onclick = function(){
+		element.scrollTop -= 10;
+	}
+	buttonBottom.onclick = function(){
+		element.scrollTop += 10;
+		
+	}
+	buttonLeft.onclick = function(){
+		element.scrollLeft -= 10;
+		
+	}
+	buttonRight.onclick = function(){
+		element.scrollLeft += 10;
+	}
+}
+
+var element = document.getElementById('someId');
+scrollButtons(element, 50);
+

+ 23 - 0
module/setPropertyBySelector/index.html

@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<title>Document</title>
+</head>
+<body>
+<span>
+	<li>Элемент "li"</li>
+	<li>Элемент "li"</li>
+	<li>Элемент "li"</li>
+</span>
+	<table>
+		<tr>
+			<td><li>Элемент "li"</li></td>
+			<td></td>
+			<td></td>
+		</tr>
+	</table>
+
+	<script src="js/setPropertyBySelector.js"></script>
+</body>
+</html>

+ 12 - 0
module/setPropertyBySelector/js/setPropertyBySelector.js

@@ -0,0 +1,12 @@
+setPropertyBySelector("span > li", 'onclick', function(){
+    alert('click on span > li');
+});
+
+setPropertyBySelector("td", 'innerHTML', 'испортим все td на странице');
+
+function setPropertyBySelector(selector, property, value){
+	for (var i = 0; i < document.querySelectorAll(selector).length; i++) {
+		document.querySelectorAll(selector)[i][property] = value;
+	}
+	
+}

+ 11 - 0
module/tableEditor/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+	<meta charset="UTF-8">
+	<title>Document</title>
+</head>
+<body>
+	
+	<script src="js/tableEditor.js"></script>
+</body>
+</html>

+ 98 - 0
module/tableEditor/js/tableEditor.js

@@ -0,0 +1,98 @@
+
+
+// var table = document.createElement("table");
+// for (var i = 0; i < persons.length; i++) {
+//     tr = document.createElement("tr");
+//     var key = Object.keys(persons[i]);
+//     for (var c = 0; c < key.length; c++) {
+//         if(c < 3)
+//             str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
+//         if(c >= 3 && key[c] in persons[i])
+//             str += "<td>" + key[c] + ": " + persons[i][key[c]] + "</td>";
+//     }
+//     str += "</tr>"
+// }
+// str += "</table>";
+// document.write(str);
+
+var a = {
+    name: "Ivan",
+    surname: "Ivanov",
+}
+var b = {
+    name: "Petr",
+    surname: "Petrov",
+}
+var c = {
+    name: "Alex",
+    surname: "Sidarov",
+}
+
+a.age = 20;
+b.fathername = "Nikolai";
+c.sex = "male";
+
+var persons = [a,b,c,
+    {
+        name: "pasha",
+        surname: "efimenko",
+        age: 22
+    }
+]
+
+
+
+
+var element = document.createElement("div");
+document.body.appendChild(element);
+element.setAttribute("id","myId")
+
+
+var result = tableEditor(element, persons)
+console.log(result)
+
+function tableEditor(container, arr){
+	
+	function dblfunc(){
+		
+			var cont = document.createElement("input")
+			cont.setAttribute("type","text");
+			this.innerHTML = "";
+			this.appendChild(cont);
+			cont.ondblclick = inputDbl;
+		
+	}
+	function inputDbl(){
+			var val = this.value;
+			var objKeyss = Object.keys(arr[this.parentElement.parentElement.rowIndex]);
+			if(!(this.cellIndex % 2))
+				arr[this.parentElement.parentElement.rowIndex][objKeyss[this.cellIndex/2]] = val;
+			if(this.cellIndex % 2 > 0)
+				arr[this.parentElement.parentElement.rowIndex][val] = this.nextSibling.innerHTML;
+			this.parentElement.ondblclick = function(){};
+			this.parentElement.innerHTML = arr[this.parentElement.parentElement.rowIndex][objKeyss[this.cellIndex/2]];
+			console.log(arr);
+			this.parentElement.removeChild(this); 
+				console.log(arr);
+		}
+	
+	var table = document.createElement("table");
+	for (var i = 0; i < arr.length; i++) {
+		var tr = document.createElement("tr");
+		for (var j = 0; j < 3; j++) {
+			var td1 = document.createElement("td");
+			var td2 = document.createElement("td");
+			var objKeys = Object.keys(arr[i])
+			td1.innerHTML = objKeys[j] + ": ";
+			td2.innerHTML = arr[i][objKeys[j]];
+			td1.ondblclick = dblfunc;
+			td2.ondblclick = dblfunc;
+			tr.appendChild(td1);
+			tr.appendChild(td2);
+		}
+		 table.appendChild(tr);
+	}
+	container.appendChild(table);
+	
+	return arr;
+}