-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
171 lines (163 loc) · 6.6 KB
/
index.html
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>String to Color | goYippi labs</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
@font-face {
font-family: 'Source Sans Pro';
font-style: normal;
font-weight: 400;
src: url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.eot'); /* IE9 Compat Modes */
src: local('Source Sans Pro Regular'), local('SourceSansPro-Regular'),
url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.woff2') format('woff2'), /* Super Modern Browsers */
url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.woff') format('woff'), /* Modern Browsers */
url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('https://www.goyippi.net/wp-content/themes/goyippi/fonts/source-sans-pro/source-sans-pro-v11-latin-ext_latin-regular.svg#SourceSansPro') format('svg'); /* Legacy iOS */
}
body {
font-family: 'Source Sans Pro', Arial, sans-serif;
font-size: 1.063em;
line-height: 1.5;
color: #000;
background-color: #000;
margin: 0;
padding: 0 20px;
transition: background-color 0.25s;
}
.input-box {
max-width: 600px;
margin: 0 auto;
background-color: #fff;
}
.input-box-inner {
padding: 20px;
}
input {
font-family: 'Source Sans Pro', Arial, sans-serif;
font-size: 1.063em;
border: 0;
background-color: #c0bab1;
width: 99%;
padding: 3px 1px;
border-radius: 0;
margin-bottom: 10px;
}
input::-webkit-input-placeholder {
color: #000;
opacity: 1;
}
input:-ms-input-placeholder{
color: #000;
opacity: 1;
}
input::-moz-placeholder {
color: #000;
opacity: 1;
}
input:-moz-placeholder {
color: #000;
opacity: 1;
}
#string {
-webkit-appearance: none;
}
.showstep-checkbox {
position: relative;
color: #c0bab1;
margin-bottom: 10px;
}
.showstep-checkbox label {
margin-left: 30px;
display: block;
}
#showstep {
position: absolute;
left: 0;
top: 3px;
width: auto;
background-color: transparent;
border-radius: 0;
border: 1px solid #000;
}
.output {
display: inline-block;
margin-right: 10px;
}
</style>
</head>
<body>
<div class="input-box">
<div class="input-box-inner">
<div class="input">
<input id="string" value="" placeholder="Type your string and press enter" />
<div class="showstep-checkbox">
<input id="showstep" name="showstep" type="checkbox" /> <label for="showstep">Show color change for each character input</label>
</div>
</div>
<div class="output output-hex"></div>
<div class="output output-rgb"></div>
</div>
</div>
<script src="https://goyippi-labs.github.io/assets/js/jquery.min.js"></script>
<script type="text/javascript">
var timer;
var d = new Date();
// Joe Freeman's answer: http://stackoverflow.com/questions/3426404/create-a-hexadecimal-colour-based-on-a-string-with-javascript
var stringToColour = function(str) {
var hash = 0;
for (var i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
var colour = '';
for (var i = 0; i < 3; i++) {
var value = (hash >> (i * 8)) & 0xFF;
colour += ('00' + value.toString(16)).substr(-2);
}
return colour;
}
// Pluto's comment: http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb
var hexToRgb = function(hex) {
return [(bigint = parseInt(hex, 16)) >> 16 & 255, bigint >> 8 & 255, bigint & 255].join();
}
var colorOutput = function(color) {
$('body').css('background-color', '#' + color);
$('.output-hex').show().empty().append( 'HEX: #' + color );
$('.output-rgb').show().empty().append( 'RGB: ' + hexToRgb(color) );
}
jQuery(document).ready(function($) {
if ($('#string').val()) {
colorOutput( stringToColour($('#string').val()) );
} else {
colorOutput( stringToColour('Type your string and press enter - ' + d) );
}
$('#string').on({
keydown: function() {
clearTimeout(timer);
}, keyup: function() {
if(document.getElementById('showstep').checked) {
colorOutput( stringToColour($('#string').val()) );
} else {
clearTimeout(timer);
timer = setTimeout(function() {
colorOutput( stringToColour($('#string').val()) );
}, 3000);
}
}, input: function() {
clearTimeout(timer);
timer = setTimeout(function() {
colorOutput( stringToColour($('#string').val()) );
}, 3000);
}
});
});
jQuery(document).keypress(function(e) {
if(e.which == 13) {
colorOutput( stringToColour($('#string').val()) );
}
});
</script>
</body>
</html>