-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
93 lines (69 loc) · 1.82 KB
/
scripts.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
function convert(input) {
let str = '';
let isEven = true;
for (let char of input)
{
console.log(char);
if (isEven === true)
{
str += char.toUpperCase();
} else
{
str += char.toLowerCase();
}
isEven = isEven === true ? false : true;
}
return str;
}
function copyNoniOS(elementId) {
// Create a "hidden" input
var aux = document.createElement("input");
// Assign it the value of the specified element
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
// Append it to the body
document.body.appendChild(aux);
// Highlight its content
aux.select();
// Copy the highlighted text
document.execCommand("copy");
// Remove it from the body
document.body.removeChild(aux);
}
function copy(elementId) {
var input = document.getElementById(elementId);
var isiOSDevice = navigator.userAgent.match(/ipad|iphone/i);
if (isiOSDevice)
{
var editable = input.contentEditable;
var readOnly = input.readOnly;
input.contentEditable = true;
input.readOnly = false;
var range = document.createRange();
range.selectNodeContents(input);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
input.setSelectionRange(0, 999999);
input.contentEditable = editable;
input.readOnly = readOnly;
document.execCommand('copy');
}
else
{
copyNoniOS(elementId);
}
$('#copy-alert').slideDown('fast').delay(1000).slideUp('fast');
}
$(function () {
console.log('document ready');
$('#text-input').on('input', function () {
const convertedStr = convert(this.value);
if (convertedStr === null || convertedStr.length === 0)
{
$('#output').html('YoU WoUlDn\'t dOwNlOaD A CaR');
} else
{
$('#output').html(convertedStr);
}
});
});