aboutsummaryrefslogtreecommitdiffstats
path: root/library/bootstrap-colorpicker/index.html
blob: 6686b92e411ba84efb26546d447a8a935a8ae573 (plain) (blame)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Colorpicker for Twitter Bootstrap</title>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css" rel="stylesheet">
    <link href="dist/css/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="src/css/docs.css" rel="stylesheet">
    <!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
    <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
</head>

<body>
    <div class="container">
        <section id="typeahead">
            <div class="page-header">
                <h1><i class="glyphicon glyphicon-tint"></i> Bootstrap Colorpicker 2.0 <small>for Twitter Bootstrap</small></h1>
            </div>
            <div class="row">
                <article class="col-md-12">
                    <p>
                        Colorpicker plugin for the Twitter Bootstrap toolkit. Originally written by <a href="https://twitter.com/stefanpetre/" target="_blank">@eyecon</a>
                        and maintained in Github by <a href="http://twitter.com/mjolnic/" target="_blank">@mjolnic</a> and the community
                        <br>
                        <br>It basically adds a color picker to a field or any other element.
                    </p>
                    <ul>
                        <li>can be used as a component</li>
                        <li>alpha picker</li>
                        <li>multiple formats: hex, rgb, rgba, hsl, hsla</li>
                    </ul>
                    <hr>
                    <div class="social">
                        <a href="https://github.com/mjolnic/bootstrap-colorpicker/" target="_blank" class="btn btn-default btn-md"><i class="glyphicon glyphicon-random"></i> Fork me on Github</a>
                        <a href="https://github.com/mjolnic/bootstrap-colorpicker/archive/master.zip" target="_blank" class="btn btn-success btn-md"><i class="glyphicon glyphicon-download-alt"></i> Download</a>

                        <!-- Place this tag where you want the +1 button to render. -->
                        <div class="g-plusone" data-size="medium"></div>

                        <!-- Place this tag after the last +1 button tag. -->
                        <script type="text/javascript">
                            (function() {
                                var po = document.createElement('script');
                                po.type = 'text/javascript';
                                po.async = true;
                                po.src = 'https://apis.google.com/js/plusone.js';
                                var s = document.getElementsByTagName('script')[0];
                                s.parentNode.insertBefore(po, s);
                            })();
                        </script>

                        <a href="https://twitter.com/share" class="twitter-share-button" data-via="mjolnic" data-related="mjolnic" data-hashtags="bootstrap">Tweet</a>
                        <script>
                            ! function(d, s, id) {
                                var js, fjs = d.getElementsByTagName(s)[0],
                                    p = /^http:/.test(d.location) ? 'http' : 'https';
                                if (!d.getElementById(id)) {
                                    js = d.createElement(s);
                                    js.id = id;
                                    js.src = p + '://platform.twitter.com/widgets.js';
                                    fjs.parentNode.insertBefore(js, fjs);
                                }
                            }(document, 'script', 'twitter-wjs');
                        </script>
                    </div>
                    <br>
                </article>
            </div>
            <div class="row">

                <div class="col-md-6">
                    <h2>Examples</h2>
                    <div class="demo-wrapper">
                        <p>1) Attached to a field with hex format specified via options:</p>
                        <div class="well">
                            <input type="text" class="form-control demo demo-1 demo-auto" value="#5367ce" />
                            <pre class="markup">
&lt;input type="text" class="demo1" value="#5367ce" /&gt;
&lt;script&gt;
    $(function(){
        $('.demo1').colorpicker();
    });
&lt;/script&gt;
            </pre>
                        </div>
                    </div>
                    <p>As a component:</p>
                    <div class="well">
                        <div class="input-group colorpicker-component demo demo-auto">
                            <input type="text" value="" class="form-control" />
                            <span class="input-group-addon"><i></i></span>
                        </div>
                        <pre class="markup">
&lt;div class="input-group demo2"&gt;
    &lt;input type="text" value="" class="form-control" /&gt;
    &lt;span class="input-group-addon"&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;script&gt;
    $(function(){
        $('.demo2').colorpicker();
    });
&lt;/script&gt;
            </pre>
                    </div>
                    <p>Using events to work with the color:</p>
                    <div class="well">
                        <a href="#" class="btn small demo" id="demo_apidemo" data-color="rgb(255, 255, 255)">Change background color</a>
                    </div>
                    <p>Horizonal mode:</p>
                    <div class="well">
                        <input type="text" class="form-control demo" data-horizontal="true" id="demo_forceformat" value="#8fff00">
                    </div>
                    <p>Inline mode:</p>
                    <div class="well">
                        <div id="demo_cont" class="demo demo-auto inl-bl" data-container="#demo_cont" data-color="rgba(150,216,62,0.55)" data-inline="true"></div>
                        <div class="demo demo-auto inl-bl" data-container="true" data-color="rgb(50,216,62)" data-inline="true"></div>
                    </div>
                    <p>Enabled / disabled</p>
                    <div class="well">
                        <div id="demo_endis" class="input-group demo demo-auto colorpicker-component">
                            <input disabled type="text" value="" class="form-control" />
                            <span class="input-group-addon"><i></i></span>
                        </div>
                        <br>
                        <a class="btn btn-sm btn-default enable-button" href="#">Enable</a>
                        <a class="btn btn-sm btn-default disable-button" href="#">Disable</a>
                    </div>
                    <a class="btn btn-default demo-destroy" href="#"><i class="glyphicon glyphicon-remove"></i> Destroy plugin instances</a>
                    <a class="btn btn-default demo-create" href="#"><i class="glyphicon glyphicon-plus"></i> Create instances again</a>
                </div>
                <article class="col-md-6">
                    <h2>Documentation</h2>
                    <p>Call the colopicker via javascript:</p>
                    <pre class="well">$('.sample-selector').colorpicker({ /*options...*/ });</pre>
                    <h3>Options</h3>
                    <p>
                        You can set colorpicker options either as a plugin parameter or data-* attributes
                    </p>
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th style="width: 100px;">Name</th>
                                <th style="width: 50px;">Type</th>
                                <th style="width: 100px;">Default</th>
                                <th>Description</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>format</td>
                                <td>string</td>
                                <td>false</td>
                                <td>If not false, forces the color format to be hex, rgb or rgba, otherwise the format is automatically detected.</td>
                            </tr>
                            <tr>
                                <td>color</td>
                                <td>string</td>
                                <td>false</td>
                                <td>If not false, sets the color to this value.</td>
                            </tr>
                            <tr>
                                <td>container</td>
                                <td>string or jQuery Element</td>
                                <td>false</td>
                                <td>If not false, the picker will be contained inside this element, otherwise it will be appended to the document body.</td>
                            </tr>
                            <tr>
                                <td>component</td>
                                <td>string or jQuery Element</td>
                                <td>'.add-on, .input-group-addon'</td>
                                <td>Children selector for the component or element that trigger the colorpicker and which background color will change (needs an inner &lt;i&gt; element).</td>
                            </tr>
                            <tr>
                                <td>input</td>
                                <td>string or jQuery Element</td>
                                <td>'input'</td>
                                <td>Children selector for the input that will store the picker selected value.</td>
                            </tr>
                            <tr>
                                <td>horizontal</td>
                                <td>boolean</td>
                                <td>false</td>
                                <td>If true, the hue and alpha channel bars will be rendered horizontally, above the saturation selector.</td>
                            </tr>
                            <tr>
                                <td>template</td>
                                <td>string</td>
                                <td><abbr title='please, read the source code for this value'>[...]</abbr>
                                </td>
                                <td>Customizes the default colorpicker HTML template.</td>
                            </tr>
                        </tbody>
                    </table>

                    <p class='alert alert-warning'>
                        (behind this line, docs need to be updated)
                    </p>

                    <h3>Methods</h3>
                    <h4>.colorpicker(options)</h4>
                    <p>Initializes an colorpicker.</p>
                    <h4>.colorpicker('show')</h4>
                    <p>Show the color picker</p>
                    <h4>.colorpicker('update')</h4>
                    <p>Refreshes the widget colors (this is done automatically)</p>
                    <h4>.colorpicker('hide')</h4>
                    <p>Hide the color picker</p>
                    <h4>.colorpicker('disable')</h4>
                    <p>Disable the color picker.</p>
                    <h4>.colorpicker('enable')</h4>
                    <p>Enable the color picker.</p>
                    <h4>.colorpicker('place')</h4>
                    <p>Updates the color picker's position relative to the element</p>
                    <h4>.colorpicker('destroy')</h4>
                    <p>Destroys the colorpicker widget and unbind all .colorpicker events from the element and component</p>
                    <h4>.colorpicker('setValue', value)</h4>
                    <p>Set a new value for the color picker (also for the input or component value). Triggers 'changeColor' event.</p>
                    <h3>Color object methods</h3>
                    <p>Each triggered events have a color object used internally by the picker. This object has several useful methods.</p>
                    <h4>.setColor(value)</h4>
                    <p>Set a new color. The value is parsed and tries to do a quess on the format.</p>
                    <h4>.setHue(value)</h4>
                    <p>Set the HUE with a value between 0 and 1.</p>
                    <h4>.setSaturation(value)</h4>
                    <p>Set the saturation with a value between 0 and 1.</p>
                    <h4>.setLightness(value)</h4>
                    <p>Set the lightness with a value between 0 and 1.</p>
                    <h4>.setAlpha(value)</h4>
                    <p>Set the transparency with a value between 0 and 1.</p>
                    <h4>.toRGB()</h4>
                    <p>Returns a hash with red, green, blue and alpha.</p>
                    <h4>.toHex()</h4>
                    <p>Returns a string with HEX format for the current color.</p>
                    <h4>.toHSL()</h4>
                    <p>Returns a hash with HSLA values.</p>
                    <h3>Events</h3>
                    <p>The colorpicker plugin exposes some events (with optional .colorpicker namespace)</p>
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th style="width: 150px;">Event</th>
                                <th>Description</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>create</td>
                                <td>This event fires immediately when the color picker is created.</td>
                            </tr>
                            <tr>
                                <td>showPicker</td>
                                <td>This event fires immediately when the color picker is displayed.</td>
                            </tr>
                            <tr>
                                <td>hidePicker</td>
                                <td>This event is fired immediately when the color picker is hidden.</td>
                            </tr>
                            <tr>
                                <td>disable</td>
                                <td>This event is fired immediately when the color picker is disabled, except if it was initialized as disabled.</td>
                            </tr>
                            <tr>
                                <td>enable</td>
                                <td>This event is fired immediately when the color picker is enabled, except upon initialization.</td>
                            </tr>
                            <tr>
                                <td>changeColor</td>
                                <td>This event is fired when the color is changed.</td>
                            </tr>
                            <tr>
                                <td>destroy</td>
                                <td>This event fires immediately when the color picker is destroyed.</td>
                            </tr>
                        </tbody>
                    </table>
                    <pre class="well">
$('.my-colorpicker-control').colorpicker().on('changeColor', function(ev){
  bodyStyle.backgroundColor = ev.color.toHex();
});
    </pre>
                </article>
            </div>
        </section>
    </div>
    <script src="//code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
    <script src="dist/js/bootstrap-colorpicker.js"></script>
    <script src="src/js/docs.js"></script>
</body>

</html>