4 * Copyright, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
12 * This class creates a color button control. This is a split button in which the main
13 * button has a visual representation of the currently selected color. When clicked
14 * the caret button displays a color picker, allowing the user to select a new color.
16 * @-x-less ColorButton.less
17 * @class tinymce.ui.ColorButton
18 * @extends tinymce.ui.PanelButton
20 define("tinymce/ui/ColorButton", [
21 "tinymce/ui/PanelButton",
22 "tinymce/dom/DOMUtils"
23 ], function(PanelButton, DomUtils) {
26 var DOM = DomUtils.DOM;
28 return PanelButton.extend({
30 * Constructs a new ColorButton instance with the specified settings.
33 * @param {Object} settings Name/value object with settings.
35 init: function(settings) {
36 this._super(settings);
37 this.addClass('colorbutton');
41 * Getter/setter for the current color.
44 * @param {String} [color] Color to set.
45 * @return {String|tinymce.ui.ColorButton} Current color or current instance.
47 color: function(color) {
50 this.getEl('preview').style.backgroundColor = color;
58 * Renders the control as a HTML string.
61 * @return {String} HTML representing the control.
63 renderHtml: function() {
64 var self = this, id = self._id, prefix = self.classPrefix;
65 var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
66 var image = self.settings.image ? ' style="background-image: url(\'' + self.settings.image + '\')"' : '';
69 '<div id="' + id + '" class="' + self.classes() + '">' +
70 '<button role="presentation" hidefocus type="button" tabindex="-1">' +
71 (icon ? '<i class="' + icon + '"' + image + '></i>' : '') +
72 '<span id="' + id + '-preview" class="' + prefix + 'preview"></span>' +
73 (self._text ? (icon ? ' ' : '') + (self._text) : '') +
75 '<button type="button" class="' + prefix + 'open" hidefocus tabindex="-1">' +
76 ' <i class="' + prefix + 'caret"></i>' +
83 * Called after the control has been rendered.
87 postRender: function() {
88 var self = this, onClickHandler = self.settings.onclick;
90 self.on('click', function(e) {
91 if (e.control == self && !DOM.getParent(e.target, '.' + self.classPrefix + 'open')) {
92 e.stopImmediatePropagation();
93 onClickHandler.call(self, e);
97 delete self.settings.onclick;