Skip to content

Commit 3b6d305

Browse files
committed
Ejercicio de clipboard terminado
1 parent c4f19cc commit 3b6d305

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

day07/clipboard.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Portapapeles</title>
7+
<link rel="stylesheet" href="styles.css">
8+
</head>
9+
<body>
10+
<section>
11+
<form action="">
12+
<legend>Obtener 20% de descuento con el cupón</legend>
13+
<input type="text" name="coupon" id="coupon" placeholder="BOCAJRS12">
14+
<button id="copy">Copiar</button>
15+
</form>
16+
</section>
17+
<script src="clipboard.js"></script>
18+
</body>
19+
</html>

day07/clipboard.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const d = document,
2+
n = navigator;
3+
4+
console.log(n.clipboard);
5+
const $copy = d.getElementById("copy");
6+
const $coupon = d.getElementById("coupon");
7+
d.addEventListener("click", e =>{
8+
e.preventDefault();
9+
if(e.target === $copy){
10+
//n.clipboard.readText().then( (`${$coupon.value}`))
11+
console.log($coupon.placeholder)
12+
const datos = {
13+
"text/plain" : `${$coupon.placeholder}`
14+
}
15+
const action = new ClipboardItem(datos);
16+
n.clipboard.write([action]);
17+
console.log(action)
18+
//action.clipboardData.items.add(`${$coupon.value}`,'text/plain');
19+
20+
//d.dispatchEvent(action)
21+
}
22+
})

day07/styles.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
*{
2+
margin: 0;
3+
box-sizing: border-box;
4+
}
5+
body{
6+
background-color: rgb(70, 70, 94);
7+
color: white;
8+
}
9+
section{
10+
margin: 150px auto;
11+
padding: 4rem;
12+
width: 50%;
13+
}
14+
legend{
15+
font-size: large;
16+
font-weight: bold;
17+
}
18+
#copy{
19+
background-color: rgb(166, 250, 166);
20+
outline: none;
21+
cursor: pointer;
22+
border: none;
23+
padding: 1rem 2rem;
24+
border-radius: .5rem;
25+
}
26+
#coupon{
27+
outline: none;
28+
border: none;
29+
padding: 1rem 2rem;
30+
border-radius: .5rem;
31+
}

0 commit comments

Comments
 (0)