Log updates
[beagleboard.org.git] / code / .docs / prototype_Global / function_String.prototype.toHexColor.html
blobd79c7efbeef218a4c2061645c90fef861322ecaf
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
2 <html>
4 <head>
5 <title></title>
6 <style type="text/css">
8 body, p, td, th, li {
9 font-family: verdana, sans-serif;
10 font-size: 10pt;
13 big.top {
14 font-size: 18pt;
15 font-weight: bold;
18 big {
19 font-size: 13pt;
20 font-weight: bold;
23 a {
24 font-weight:bold;
25 color: #cc3333;
26 text-decoration:none;
28 a:hover {
29 text-decoration:underline;
32 .navig {
33 font-size: 9px;
34 text-decoration: none;
35 font-weight:normal;
38 li {
39 padding-bottom: 5px;
43 .mainbox {
44 border-color:#999999;
45 padding-top:5px;
46 padding-bottom:5px;
47 border-bottom-width:1px;
48 border-bottom-style:dotted;
51 .headline {
52 font-weight:bold;
53 background:#dfdfdf;
54 border-color:#999999;
55 padding-top:5px;
56 padding-bottom:5px;
59 </style>
60 </head>
62 <body>
64 <table width="90%" border="0" cellspacing="1" cellpadding="5">
65 <tr>
66 <td class="headline">
67 <big><tt>Global.String.prototype.toHexColor&nbsp;()</tt></big><br>
68 </td>
69 </tr>
71 <tr>
72 <td class="mainbox">
73 converts a string into a hexadecimal color
74 representation (e.g. "ffcc33"). also knows how to
75 convert a color string like "rgb (255, 204, 51)". <br><br>
77 <ul>
79 <li><b>Returns</b><br>
80 String the resulting hex color (w/o "#")
86 </ul>
87 </td>
88 </tr>
89 </table>
91 <table width="90%" border="0" cellspacing="1" cellpadding="5">
92 <tr>
93 <td>Sourcecode in /root/helma-1.6.1/modules/core/String.js:
94 <pre><font color="#aaaaaa">139:</font> String.prototype.toHexColor = function() {
95 <font color="#aaaaaa">140:</font> if (this.startsWith(<font color="#9999aa">&quot;rgb&quot;</font>)) {
96 <font color="#aaaaaa">141:</font> res.push();
97 <font color="#aaaaaa">142:</font> var col = this.replace(/[^0-9,]/g, String.NULL);
98 <font color="#aaaaaa">143:</font> var parts = col.split(<font color="#9999aa">&quot;,&quot;</font>);
99 <font color="#aaaaaa">144:</font> for (var i in parts) {
100 <font color="#aaaaaa">145:</font> var num = parseInt(parts[i], 10);
101 <font color="#aaaaaa">146:</font> var hex = num.toString(16);
102 <font color="#aaaaaa">147:</font> res.write(hex.pad(<font color="#9999aa">&quot;0&quot;</font>, 2, String.LEFT));
103 <font color="#aaaaaa">148:</font> }
104 <font color="#aaaaaa">149:</font> return res.pop();
105 <font color="#aaaaaa">150:</font> }
106 <font color="#aaaaaa">151:</font> var col = this.replace(new RegExp(String.HEXPATTERN.source), String.NULL);
107 <font color="#aaaaaa">152:</font> return col.toLowerCase().pad(<font color="#9999aa">&quot;0&quot;</font>, 6, String.LEFT);
108 <font color="#aaaaaa">153:</font> }
109 </pre>
110 </td>
111 </tr>
113 </table>
119 </body>
120 </html>