index.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html>
  3. <head>
  4. <title>jQuery Colorpicker</title>
  5. <!-- jQuery/jQueryUI (hosted) -->
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
  7. <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
  8. <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
  9. <style>
  10. body {
  11. font-family: 'Segoe UI', Verdana, Arial, Helvetica, sans-serif;
  12. font-size: 62.5%;
  13. }
  14. </style>
  15. <script src="jquery.colorpicker.js"></script>
  16. <link href="jquery.colorpicker.css" rel="stylesheet" type="text/css"/>
  17. <script src="i18n/jquery.ui.colorpicker-nl.js"></script>
  18. <script>
  19. $(function() {
  20. $('#tabs').tabs();
  21. });
  22. </script>
  23. </head>
  24. <body>
  25. <h1>jQuery ColorPicker</h1>
  26. <div id="tabs">
  27. <ul>
  28. <li><a href="#tab-input">Basic &lt;input&gt;</a></li>
  29. <li><a href="#tab-element">Basic element</a></li>
  30. <li><a href="#tab-full">All features</a></li>
  31. <li><a href="#tab-i18n">Localization</a></li>
  32. <li><a href="#tab-websafe">Websafe colors</a></li>
  33. <li><a href="#tab-alt">Alternative display field</a></li>
  34. <li><a href="#tab-events">Events</a></li>
  35. <li><a href="#tab-input-format">Input formatting</a></li>
  36. <li><a href="#tab-format">Output formatting</a></li>
  37. <li><a href="#tab-format-list">Output format list</a></li>
  38. <li><a href="#tab-dialog">In a dialog</a></li>
  39. <li><a href="#tab-modal">Modal</a></li>
  40. <li><a href="#tab-no-inline">Any element to popup</a></li>
  41. </ul>
  42. <div id="tab-input">
  43. <h2>Basic &lt;input&gt; example, without any options</h2>
  44. <input type="text" class="cp-basic" value="fe9810"/>
  45. </div>
  46. <div id="tab-element">
  47. <h2>Basic element (&lt;span&gt;> example, without any options</h2>
  48. <span class="cp-basic" style="display: inline-block; vertical-align: top;"></span>
  49. </div>
  50. <div id="tab-full">
  51. <h2>Fully-featured example</h2>
  52. <input type="text" class="cp-full" value="186aa7"/>
  53. </div>
  54. <div id="tab-i18n">
  55. <h2>Localized to Dutch (nl)</h2>
  56. <input type="text" class="cp-i18n" value="ccea73"/>
  57. </div>
  58. <div id="tab-websafe">
  59. <h2>Limit to websafe colors</h2>
  60. <input type="text" class="cp-websafe" value="0fa7c2"/>
  61. </div>
  62. <div id="tab-alt">
  63. <h2>Alternative field class</h2>
  64. <input type="text" class="cp-alt" value="b762ae"/>
  65. <span class="cp-alt-target" style="display: inline-block; border: thin solid black; padding: .5em 4em;">
  66. <div style=" background-color: white; border: thin solid black; padding: .25em 2em; font-size: 1.25em; font-weight: bold;">Background-color on outside, text color here</div>
  67. </span>
  68. </div>
  69. <div id="tab-events">
  70. <h2>Events</h2>
  71. <input type="text" class="cp-events" value="92b64a"/>
  72. <div class="cp-events-log" style="vertical-align: top; display: inline-block; border: thin solid black; height: 10em; overflow-y: scroll; width: 50em;"></div>
  73. </div>
  74. <div id="tab-format">
  75. <h2>Output formatting HSLA</h2>
  76. <input type="text" class="cp-format" value="918237"/>
  77. <span class="cp-format-output"></span>
  78. </div>
  79. <div id="tab-format-list">
  80. <h2>Output format list</h2>
  81. You can specify a list of output formats, the first perfect match for the color is output.
  82. <input type="text" class="cp-name" value="a92fb4"/>
  83. <span class="cp-name-output"></span>
  84. </div>
  85. <div id="tab-dialog">
  86. <h2>Dialog with Colorpicker popup (demonstrates z-index)</h2>
  87. <button id="cp-dialog-open">Open dialog</button>
  88. <div id="cp-dialog-modal" title="Basic modal dialog">
  89. Basic &lt;input&gt; example, without any options: <input type="text" class="cp-basic" value="fe9810"/>
  90. <br/>
  91. Basic element example, without any options: <span class="cp-basic" style="display: inline-block; vertical-align: top;"></span>
  92. </div>
  93. </div>
  94. <div id="tab-modal">
  95. <h2>Modal (and showCancelButton, closeOnEscape, showCloseButton)</h2>
  96. <input type="text" class="cp-modal" value="9ba73f"/>
  97. </div>
  98. <div id="tab-input-format">
  99. <h2>Input formatting</h2>
  100. Demonstrates the ability to parse common color formats as input.
  101. <input type="text" class="cp-input" value="rgb(123,42,87)"/>
  102. </div>
  103. <div id="tab-no-inline">
  104. <h2>Popup from any element (&lt;em&gt;)</h2>
  105. Just click on this <em>Emphasized</em> word to show the colorpicker.
  106. </div>
  107. </div>
  108. <script>
  109. $( function() {
  110. $('.cp-basic').colorpicker();
  111. $('.cp-full').colorpicker({
  112. parts: 'full',
  113. showOn: 'both',
  114. buttonColorize: true,
  115. showNoneButton: true,
  116. alpha: true
  117. });
  118. $('.cp-i18n').colorpicker({
  119. regional: 'nl',
  120. showNoneButton: true,
  121. alpha: true
  122. });
  123. $('.cp-websafe').colorpicker({
  124. limit: 'websafe'
  125. });
  126. $('.cp-alt').colorpicker({
  127. altField: '.cp-alt-target',
  128. altProperties: 'background-color,color',
  129. altAlpha: true,
  130. alpha: true
  131. });
  132. { // event log
  133. var count = 0;
  134. function addToEventLog(label, message) {
  135. var line = '<div>#'+(++count)+' '+label+': '+message+'</div>';
  136. var log = $('.cp-events-log');
  137. log.append(line).scrollTop(log[0].scrollHeight);
  138. }
  139. $('.cp-events').colorpicker({
  140. init: function(event, color) {
  141. addToEventLog('Init', color.formatted);
  142. },
  143. select: function(event, color) {
  144. addToEventLog('Select', color.formatted);
  145. },
  146. close: function(event, color) {
  147. addToEventLog('Close', color.formatted + ' r:' + color.rgb.r + ' g:' + color.rgb.g + ' b:' + color.rgb.b + ' a:' + color.a);
  148. }
  149. });
  150. }
  151. $('.cp-format').colorpicker({
  152. colorFormat: 'HSLA',
  153. alpha: true,
  154. init: function(event, color) {
  155. $('.cp-format-output').text(color.formatted);
  156. },
  157. select: function(event, color) {
  158. $('.cp-format-output').text(color.formatted);
  159. }
  160. });
  161. $('.cp-name').colorpicker({
  162. parts: 'full',
  163. colorFormat: ['EXACT', '#HEX3', 'RGB', 'RGBA'],
  164. init: function(event, color) {
  165. $('.cp-name-output').text(color.formatted);
  166. },
  167. select: function(event, color) {
  168. $('.cp-name-output').text(color.formatted);
  169. }
  170. });
  171. var dialog = $('#cp-dialog-modal').dialog({
  172. autoOpen: false,
  173. minWidth: 500,
  174. modal: true,
  175. buttons: { 'Close': function() {
  176. $(this).dialog('close');
  177. }
  178. }
  179. });
  180. $('#cp-dialog-open').click(function() {
  181. dialog.dialog('open');
  182. });
  183. $('.cp-modal').colorpicker({
  184. parts: 'draggable',
  185. showCloseButton: false,
  186. modal: true,
  187. showCancelButton: false,
  188. closeOnEscape: false
  189. });
  190. $('.cp-input').colorpicker({
  191. colorFormat: ['RGBA']
  192. });
  193. $('em').colorpicker({
  194. inline: false
  195. });
  196. });
  197. </script>
  198. </body>
  199. </html>