]> git.proxmox.com Git - extjs.git/blame - extjs/packages/ux/classic/src/colorpick/ColorMap.js
add extjs 6.0.1 sources
[extjs.git] / extjs / packages / ux / classic / src / colorpick / ColorMap.js
CommitLineData
6527f429
DM
1/**\r
2 * The main colorful square for selecting color shades by dragging around the\r
3 * little circle.\r
4 * @private\r
5 */\r
6Ext.define('Ext.ux.colorpick.ColorMap', {\r
7 extend : 'Ext.container.Container',\r
8 alias : 'widget.colorpickercolormap',\r
9 controller : 'colorpickercolormapcontroller',\r
10\r
11 requires: [\r
12 'Ext.ux.colorpick.ColorMapController'\r
13 ],\r
14\r
15 cls : Ext.baseCSSPrefix + 'colorpicker-colormap',\r
16\r
17 // This is the drag "circle"; note it's 1x1 in size to allow full\r
18 // travel around the color map; the inner div has the bigger image\r
19 items: [{\r
20 xtype : 'component',\r
21 cls : Ext.baseCSSPrefix + 'colorpicker-colormap-draghandle-container',\r
22 itemId : 'dragHandle',\r
23 width : 1,\r
24 height : 1,\r
25 draggable : true,\r
26 html : '<div class="' + Ext.baseCSSPrefix + 'colorpicker-colormap-draghandle"></div>'\r
27 }],\r
28\r
29 listeners : {\r
30 boxready : {\r
31 single : true,\r
32 fn : 'onFirstBoxReady',\r
33 scope : 'controller'\r
34 },\r
35 colorbindingchanged: {\r
36 fn : 'onColorBindingChanged',\r
37 scope : 'controller'\r
38 },\r
39 huebindingchanged: {\r
40 fn : 'onHueBindingChanged',\r
41 scope : 'controller'\r
42 }\r
43 },\r
44\r
45 afterRender: function () {\r
46 var me = this,\r
47 src = me.mapGradientUrl,\r
48 el = me.el;\r
49\r
50 me.callParent();\r
51\r
52 if (!src) {\r
53 // We do this trick to allow the Sass to calculate resource image path for\r
54 // our package and pick up the proper image URL here.\r
55 src = el.getStyle('background-image');\r
56 src = src.substring(4, src.length - 1); // strip off outer "url(...)"\r
57\r
58 // In IE8 this path will have quotes around it\r
59 if (src.indexOf('"') === 0) {\r
60 src = src.substring(1, src.length-1);\r
61 }\r
62\r
63 // Then remember it on our prototype for any subsequent instances.\r
64 Ext.ux.colorpick.ColorMap.prototype.mapGradientUrl = src;\r
65 }\r
66\r
67 // Now clear that style because it will conflict with the background-color\r
68 el.setStyle('background-image', 'none');\r
69\r
70 // Create the image with transparent PNG with black and white gradient shades;\r
71 // it blends with the background color (which changes with hue selection). This\r
72 // must be an IMG in order to properly stretch to fit.\r
73 el = me.layout.getElementTarget(); // the el for items and html\r
74 el.createChild({\r
75 tag: 'img',\r
76 cls: Ext.baseCSSPrefix + 'colorpicker-colormap-blender',\r
77 src: src\r
78 });\r
79 },\r
80\r
81 // Called via data binding whenever selectedColor changes; fires "colorbindingchanged"\r
82 setPosition: function(data) {\r
83 var me = this,\r
84 dragHandle = me.down('#dragHandle');\r
85\r
86 // Too early in the render cycle? Skip event\r
87 if (!dragHandle.dd || !dragHandle.dd.constrain) {\r
88 return;\r
89 }\r
90\r
91 // User actively dragging? Skip event\r
92 if (typeof dragHandle.dd.dragEnded !== 'undefined' && !dragHandle.dd.dragEnded) {\r
93 return;\r
94 }\r
95\r
96 me.fireEvent('colorbindingchanged', data);\r
97 },\r
98\r
99 // Called via data binding whenever selectedColor.h changes; fires "huebindingchanged" event\r
100 setHue: function(hue) {\r
101 var me = this;\r
102\r
103 // Too early in the render cycle? Skip event\r
104 if (!me.getEl()) {\r
105 return;\r
106 }\r
107\r
108 me.fireEvent('huebindingchanged', hue);\r
109 }\r
110});\r