-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
168 lines (145 loc) · 3.41 KB
/
Copy pathindex.html
File metadata and controls
168 lines (145 loc) · 3.41 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Spectrum</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="DogDigital">
<style type="text/css">
*
{
padding: 0;
margin: 0;
}
html
{
font-family: helvetica, arial, sans-serif;
font-size: 14px;
color: #333;
background-color: #eee;
text-shadow: 1px 1px 1px #fff;
padding: 10px;
}
dl
{
padding-top: 20px;
}
dt
{
font-weight: bold;
margin-bottom: 10px;
}
input
{
width: 120px;
margin-bottom: 10px;
}
dd{
margin-bottom: 10px;
}
label
{
display: block;
float: left;
width: 120px;
}
#hexinputErrorOutput
{
padding-left: 20px;
}
h1
{
font-weight: normal;
font-size: 32px;
}
h2
{
font-weight: normal;
font-size: 18px;
margin-bottom: 20px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">
function getIdRef(id)
{
return eval($('#' + id).attr('id'));
}
function init()
{
resetHexInputError();
$("#hexinput").change(function()
{
var cleanHex = stripInput($(this).val());
var rgbObj = hexToRgbObj(cleanHex);
if(rgbObj != null)
{
$("#xcodeOutput").html(generateXcodeOutput(rgbObj));
$("#cssRGBAOutput").html(generateCSSRGBAOutput(rgbObj));
$("#cleanHexOutput").html(cleanHex);
$("#cleanHexOutputColour").css("background-color","#" + cleanHex);
resetHexInputError();
}
else
{
$("#hexinputErrorOutput").html("Number out of bounds");
$("#cleanHexOutput").html(" ");
$("#cleanHexOutputColour").css("background-color","#ffffff");
}
});
}
function resetHexInputError()
{
$("#hexinputErrorOutput").html("e.g #c0ffee");
}
function hexToRgbObj(hex)
{
var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
function generateXcodeOutput(rgbObj)
{
return "[[UIColor alloc] initWithRed:" + rgbObj.r/255 + "f green:" + rgbObj.g/255 + "f blue:" + rgbObj.b/255 + "f alpha:1f];";
}
function generateCSSRGBAOutput(rgbObj)
{
return "background: rgba(" + rgbObj.r + ", " + rgbObj.g + ", " + rgbObj.b + ", 1);";
}
function stripInput(input)
{
return input.substring(input.length - 6);
}
window.log = function()
{
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console)
{
console.log( Array.prototype.slice.call(arguments));
}
};
</script>
</head>
<body>
<script>$(document).ready(function(){init();});</script>
<h1>Spectrum</h1>
<h2>Converts HEX into other colour formats</h2>
<div><label for="hexinput">Input HEX</label><input id="hexinput" type="text" value=""><span id="hexinputErrorOutput"></span></div>
<div><label for="cleanHexOutputColour" id="cleanHexOutput"> </label><input id="cleanHexOutputColour" type="text" value="" disabled="disabled"></div>
<div>
<dl>
<dt>CSS RGBA</dt>
<dd id="cssRGBAOutput"> </dd>
<dt>XCode UIColor RGBA Object</dt>
<dd id="xcodeOutput"> </dd>
</dl>
</div>
</body>
</html>