-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
136 lines (124 loc) · 4.48 KB
/
Copy pathscript.js
File metadata and controls
136 lines (124 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// links
//https://ahkamboh.github.io/Portfolio/
//https://ahkamboh.github.com/@ahkamboh
// left right align button formations
let bold = document.querySelectorAll(".font button")[0];
let italic = document.querySelectorAll(".font button")[1];
let underline = document.querySelectorAll(".font button")[2];
let alignLeft = document.querySelectorAll(".align button")[0];
let alignCenter = document.querySelectorAll(".align button")[1];
let alignRight = document.querySelectorAll(".align button")[2];
let alignJustify = document.querySelectorAll(".align button")[3];
let artBoard = document.querySelector(".artboard");
let bullet = document.getElementById("bullet");
// bold formation
bold.addEventListener("click", function () {
artBoard.classList.toggle("bold");
bold.classList.toggle("b");
});
// italic formation
italic.addEventListener("click", function () {
artBoard.classList.toggle("italic");
italic.classList.toggle("i");
});
// underline formation
underline.addEventListener("click", function () {
artBoard.classList.toggle("underline");
underline.classList.toggle("u");
});
// alignLeft formation
alignLeft.addEventListener("click", function () {
artBoard.classList.add("alignLeft");
alignLeft.classList.add("l");
artBoard.classList.remove("alignCenter");
alignCenter.classList.remove("c");
artBoard.classList.remove("alignRight");
alignRight.classList.remove("r");
artBoard.classList.remove("alignJustify");
alignJustify.classList.remove("j");
});
// alignCenter formation
alignCenter.addEventListener("click", function () {
artBoard.classList.remove("alignLeft");
alignLeft.classList.remove("l");
artBoard.classList.add("alignCenter");
alignCenter.classList.add("c");
artBoard.classList.remove("alignRight");
alignRight.classList.remove("r");
artBoard.classList.remove("alignJustify");
alignJustify.classList.remove("j");
});
// alignRight formation
alignRight.addEventListener("click", function () {
artBoard.classList.remove("alignLeft");
alignLeft.classList.remove("l");
artBoard.classList.remove("alignCenter");
alignCenter.classList.remove("c");
artBoard.classList.add("alignRight");
alignRight.classList.add("r");
artBoard.classList.remove("alignJustify");
alignJustify.classList.remove("j");
});
// alignJustify formation
alignJustify.addEventListener("click", function () {
artBoard.classList.remove("alignLeft");
alignLeft.classList.remove("l");
artBoard.classList.remove("alignCenter");
alignCenter.classList.remove("c");
artBoard.classList.remove("alignRight");
alignRight.classList.remove("r");
artBoard.classList.add("alignJustify");
alignJustify.classList.add("j");
});
// Font change
changeFont = (font) => {
document.getElementById("font").style.fontFamily = font.value;
}
// Text Formation change
TextTransform = (textTransform)=> {
document.getElementById("font").style.textTransform = textTransform.value;
}
// color change
changecolor= () =>{
let input = document.getElementById("inputColor").value;
let artBoardtextcolor = document.querySelector(".artboard");
artBoardtextcolor.style.color = input;
}
// file save formation
let textarea = document.querySelector(".artboard");
let filenameInput = document.querySelector(".file-name input");
let selectMenu = document.querySelector(".save-as select");
let btn = document.querySelector(".btn");
//on user selected file format
selectMenu.addEventListener("change", () => {
//getting user selected format
let selectedFormat = selectMenu.options[selectMenu.selectedIndex].text;
//chanGing button text accorind to selected option
btn.innerText = `Save as ${selectedFormat.split(" ")[0]} file`;
});
//on button click
btn.addEventListener("click", () => {
//creating new blob with textarea value and selected file format
let blob = new Blob([textarea.value], { type: selectMenu.value });
//creating temporary url for the blob
let fileUrl = URL.createObjectURL(blob);
//creating new a tag
let link = document.createElement("a");
//passing file name input value as download value for the link
link.download = filenameInput.value;
//passing temporary url to link
link.href = fileUrl;
//on link click, file will be downloaded
link.click();
});
// speak to text
runSpeechRecog = () => {
let action = document.querySelector("textarea");
action.innerText = "Loading text...";
let recognization = new webkitSpeechRecognition();
recognization.onresult = (e) => {
let transcript = e.results[0][0].transcript;
action.innerText = transcript;
}
recognization.start();
}