-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
152 lines (143 loc) · 5.86 KB
/
script.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// *******************************************************************
// clean maintext text value on click
$('#mainText').click(()=>{
if ($('#mainText').text() == "write something beautiful..." ) {
$('#mainText').text('');
}
})
// *******************************************************************
// snippet taken from tutorial. only changed the id names
document.getElementById('mainText').contentEditable = 'true';
document.getElementById('mainText').designMode='on';
$(function() {
$("#downloadBt").click(function() {
html2canvas($("#mainText"), {
onrendered: function(canvas) {
/* getting the text value from the mainText to add a part of it to the file name */
let mainTextText = $('#mainText').text()
let mainTextArray = Array.from(mainTextText).splice(0, 60)
let mainTextArrayToPrint = mainTextArray.join('')
saveAs(canvas.toDataURL(), `${mainTextArrayToPrint} - Fancyxt.png`);
}
});
});
function saveAs(uri, filename) {
var link = document.createElement('a');
if (typeof link.download === 'string') {
link.href = uri;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
window.open(uri);
}
}
});
// *******************************************************************
// Info overlay
$('h2.info').click(()=>{
$('div.infoOverlay').css('display', 'block')
})
$('h3.domain-notice').click(()=>{
$('div.domainNoticeOverlay').css('display', 'block')
})
document.onclick = function(event){
let target = event.target;
if(target.className == 'infoOverlay' || target.className == 'domainNoticeOverlay') {
target.style.display = 'none';
}
}
// *******************************************************************
// font type change
$('button.fontTypeBt').click( function (font) {
font = $(this).css('font-family')
$('#mainText').css('font-family', font)
})
// *******************************************************************
// font size change
$('.fontSizeBtSmall').click(()=>{
$('#mainText').css('font-size', '30px')
})
$('.fontSizeBtNormal').click(()=>{
$('#mainText').css('font-size', '40px')
})
$('.fontSizeBtLarge').click(()=>{
$('#mainText').css('font-size', '50px')
})
$('.fontSizeBtLarger').click(()=>{
$('#mainText').css('font-size', '60px')
})
/* if statement to check the active font size buttons and visually activate it */
$('.fontSizeBt').click(()=>{
let mainTextFontSize = $('#mainText').css('font-size');
if (mainTextFontSize == '30px') {
$('.fontSizeBtSmall').addClass('btn-outline-primary')
} else { $('.fontSizeBtSmall').removeClass('btn-outline-primary') }
if (mainTextFontSize == '40px') {
$('.fontSizeBtNormal').addClass('btn-outline-primary')
} else { $('.fontSizeBtNormal').removeClass('btn-outline-primary') }
if (mainTextFontSize == '50px') {
$('.fontSizeBtLarge').addClass('btn-outline-primary')
} else { $('.fontSizeBtLarge').removeClass('btn-outline-primary') }
if (mainTextFontSize == '60px') {
$('.fontSizeBtLarger').addClass('btn-outline-primary')
} else { $('.fontSizeBtLarger').removeClass('btn-outline-primary') }
})
// *******************************************************************
// background color change
$('button.backgroundColorBt').click( function (gradient) {
gradient = $(this).css('background')
$('#mainText').css('background', gradient)
// making the active button visually active too
let currentBgColor = $('#mainText').css('background-color')
let backgroundColorButtons = Array.from($('div.backgroundColorSection').children())
for (const button of backgroundColorButtons) {
/* each time a button with this loop applied to it
is clicked, it'll check if any of it's kind has a value
applied to the mainText, if it finds a coincidence it visually activates said button.
When a different button is activated like this, the former loses the equality and
therefore the color activation */
if (currentBgColor == button.style.backgroundColor) {
button.classList.add('colorButtonActive')
} else { button.classList.remove('colorButtonActive') }
}
})
// *******************************************************************
// font color change
$('button.fontColorBt').click( function (color) {
color = $(this).css('background-color')
$('#mainText').css('color', color)
// making the active button visually active too
let currentColor = $('#mainText').css('color')
let colorButtons = Array.from($('div.fontColorSection').children())
for (const button of colorButtons) {
if (currentColor == button.style.backgroundColor) {
button.classList.add('colorButtonActive')
} else { button.classList.remove('colorButtonActive') }
}
})
// *******************************************************************
// border radius change
$('button.cornerCurveBt').click( function (curve) {
curve = $(this).css('border-radius')
$('#mainText').css('border-radius', curve)
// making the active button visually active too
let currentCurve = $('#mainText').css('border-radius')
let cornerCurveButtons = Array.from($('#cornerCurveSection').children())
for (const button of cornerCurveButtons) {
if (currentCurve == button.style.borderRadius) {
button.classList.add('btn-outline-primary')
} else { button.classList.remove('btn-outline-primary') }
}
})
// *******************************************************************
// text style change
$('#textShadowBt').click(()=> {
$('#mainText').toggleClass('textShadow')
$('#textShadowBt').toggleClass('btn-outline-primary')
})
$('#smallCapsBt').click(()=> {
$('#mainText').toggleClass('smallCapsText')
$('#smallCapsBt').toggleClass('btn-outline-primary')
})