PageRenderTime 193ms CodeModel.GetById 114ms RepoModel.GetById 2ms app.codeStats 0ms

/ext-4.0.7/docs/source/Color.html

https://bitbucket.org/srogerf/javascript
HTML | 234 lines | 206 code | 28 blank | 0 comment | 0 complexity | 0fbcd9173d4220431fa96363df05694d MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-picker-Color'>/**
  19. </span> * Color picker provides a simple color palette for choosing colors. The picker can be rendered to any container. The
  20. * available default to a standard 40-color palette; this can be customized with the {@link #colors} config.
  21. *
  22. * Typically you will need to implement a handler function to be notified when the user chooses a color from the picker;
  23. * you can register the handler using the {@link #select} event, or by implementing the {@link #handler} method.
  24. *
  25. * @example
  26. * Ext.create('Ext.picker.Color', {
  27. * value: '993300', // initial selected color
  28. * renderTo: Ext.getBody(),
  29. * listeners: {
  30. * select: function(picker, selColor) {
  31. * alert(selColor);
  32. * }
  33. * }
  34. * });
  35. */
  36. Ext.define('Ext.picker.Color', {
  37. extend: 'Ext.Component',
  38. requires: 'Ext.XTemplate',
  39. alias: 'widget.colorpicker',
  40. alternateClassName: 'Ext.ColorPalette',
  41. <span id='Ext-picker-Color-cfg-componentCls'> /**
  42. </span> * @cfg {String} [componentCls='x-color-picker']
  43. * The CSS class to apply to the containing element.
  44. */
  45. componentCls : Ext.baseCSSPrefix + 'color-picker',
  46. <span id='Ext-picker-Color-cfg-selectedCls'> /**
  47. </span> * @cfg {String} [selectedCls='x-color-picker-selected']
  48. * The CSS class to apply to the selected element
  49. */
  50. selectedCls: Ext.baseCSSPrefix + 'color-picker-selected',
  51. <span id='Ext-picker-Color-cfg-value'> /**
  52. </span> * @cfg {String} value
  53. * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that the hex
  54. * codes are case-sensitive.
  55. */
  56. value : null,
  57. <span id='Ext-picker-Color-cfg-clickEvent'> /**
  58. </span> * @cfg {String} clickEvent
  59. * The DOM event that will cause a color to be selected. This can be any valid event name (dblclick, contextmenu).
  60. */
  61. clickEvent :'click',
  62. <span id='Ext-picker-Color-cfg-allowReselect'> /**
  63. </span> * @cfg {Boolean} allowReselect
  64. * If set to true then reselecting a color that is already selected fires the {@link #select} event
  65. */
  66. allowReselect : false,
  67. <span id='Ext-picker-Color-property-colors'> /**
  68. </span> * @property {String[]} colors
  69. * An array of 6-digit color hex code strings (without the # symbol). This array can contain any number of colors,
  70. * and each hex code should be unique. The width of the picker is controlled via CSS by adjusting the width property
  71. * of the 'x-color-picker' class (or assigning a custom class), so you can balance the number of colors with the
  72. * width setting until the box is symmetrical.
  73. *
  74. * You can override individual colors if needed:
  75. *
  76. * var cp = new Ext.picker.Color();
  77. * cp.colors[0] = 'FF0000'; // change the first box to red
  78. *
  79. * Or you can provide a custom array of your own for complete control:
  80. *
  81. * var cp = new Ext.picker.Color();
  82. * cp.colors = ['000000', '993300', '333300'];
  83. */
  84. colors : [
  85. '000000', '993300', '333300', '003300', '003366', '000080', '333399', '333333',
  86. '800000', 'FF6600', '808000', '008000', '008080', '0000FF', '666699', '808080',
  87. 'FF0000', 'FF9900', '99CC00', '339966', '33CCCC', '3366FF', '800080', '969696',
  88. 'FF00FF', 'FFCC00', 'FFFF00', '00FF00', '00FFFF', '00CCFF', '993366', 'C0C0C0',
  89. 'FF99CC', 'FFCC99', 'FFFF99', 'CCFFCC', 'CCFFFF', '99CCFF', 'CC99FF', 'FFFFFF'
  90. ],
  91. <span id='Ext-picker-Color-cfg-handler'> /**
  92. </span> * @cfg {Function} handler
  93. * A function that will handle the select event of this picker. The handler is passed the following parameters:
  94. *
  95. * - `picker` : ColorPicker
  96. *
  97. * The {@link Ext.picker.Color picker}.
  98. *
  99. * - `color` : String
  100. *
  101. * The 6-digit color hex code (without the # symbol).
  102. */
  103. <span id='Ext-picker-Color-cfg-scope'> /**
  104. </span> * @cfg {Object} scope
  105. * The scope (`this` reference) in which the `{@link #handler}` function will be called. Defaults to this
  106. * Color picker instance.
  107. */
  108. colorRe: /(?:^|\s)color-(.{6})(?:\s|$)/,
  109. renderTpl: [
  110. '&lt;tpl for=&quot;colors&quot;&gt;',
  111. '&lt;a href=&quot;#&quot; class=&quot;color-{.}&quot; hidefocus=&quot;on&quot;&gt;',
  112. '&lt;em&gt;&lt;span style=&quot;background:#{.}&quot; unselectable=&quot;on&quot;&gt;&amp;#160;&lt;/span&gt;&lt;/em&gt;',
  113. '&lt;/a&gt;',
  114. '&lt;/tpl&gt;'
  115. ],
  116. // private
  117. initComponent : function(){
  118. var me = this;
  119. me.callParent(arguments);
  120. me.addEvents(
  121. <span id='Ext-picker-Color-event-select'> /**
  122. </span> * @event select
  123. * Fires when a color is selected
  124. * @param {Ext.picker.Color} this
  125. * @param {String} color The 6-digit color hex code (without the # symbol)
  126. */
  127. 'select'
  128. );
  129. if (me.handler) {
  130. me.on('select', me.handler, me.scope, true);
  131. }
  132. },
  133. // private
  134. onRender : function(container, position){
  135. var me = this,
  136. clickEvent = me.clickEvent;
  137. Ext.apply(me.renderData, {
  138. itemCls: me.itemCls,
  139. colors: me.colors
  140. });
  141. me.callParent(arguments);
  142. me.mon(me.el, clickEvent, me.handleClick, me, {delegate: 'a'});
  143. // always stop following the anchors
  144. if(clickEvent != 'click'){
  145. me.mon(me.el, 'click', Ext.emptyFn, me, {delegate: 'a', stopEvent: true});
  146. }
  147. },
  148. // private
  149. afterRender : function(){
  150. var me = this,
  151. value;
  152. me.callParent(arguments);
  153. if (me.value) {
  154. value = me.value;
  155. me.value = null;
  156. me.select(value, true);
  157. }
  158. },
  159. // private
  160. handleClick : function(event, target){
  161. var me = this,
  162. color;
  163. event.stopEvent();
  164. if (!me.disabled) {
  165. color = target.className.match(me.colorRe)[1];
  166. me.select(color.toUpperCase());
  167. }
  168. },
  169. <span id='Ext-picker-Color-method-select'> /**
  170. </span> * Selects the specified color in the picker (fires the {@link #select} event)
  171. * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
  172. * @param {Boolean} suppressEvent (optional) True to stop the select event from firing. Defaults to false.
  173. */
  174. select : function(color, suppressEvent){
  175. var me = this,
  176. selectedCls = me.selectedCls,
  177. value = me.value,
  178. el;
  179. color = color.replace('#', '');
  180. if (!me.rendered) {
  181. me.value = color;
  182. return;
  183. }
  184. if (color != value || me.allowReselect) {
  185. el = me.el;
  186. if (me.value) {
  187. el.down('a.color-' + value).removeCls(selectedCls);
  188. }
  189. el.down('a.color-' + color).addCls(selectedCls);
  190. me.value = color;
  191. if (suppressEvent !== true) {
  192. me.fireEvent('select', me, color);
  193. }
  194. }
  195. },
  196. <span id='Ext-picker-Color-method-getValue'> /**
  197. </span> * Get the currently selected color value.
  198. * @return {String} value The selected value. Null if nothing is selected.
  199. */
  200. getValue: function(){
  201. return this.value || null;
  202. }
  203. });
  204. </pre>
  205. </body>
  206. </html>