color palette tooltip reimplemented

This commit is contained in:
Ezequiel Bergamaschi 2014-05-02 01:00:32 -03:00
parent 4414e0943d
commit 9b9ab78839

View File

@ -30,11 +30,10 @@ mindplot.widget.ColorPalettePanel = new Class({
if (!mindplot.widget.ColorPalettePanel._panelContent) { if (!mindplot.widget.ColorPalettePanel._panelContent) {
// Load all the CSS styles ... // Load all the CSS styles ...
$.ajax({ $('<link>')
url: this._baseUrl + '/colorPalette.css', .appendTo($('head'))
method: 'GET', .attr({type : 'text/css', rel : 'stylesheet'})
async: true .attr('href', this._baseUrl + '/colorPalette.css');
});
// Load panel html fragment ... // Load panel html fragment ...
var result; var result;
@ -64,13 +63,14 @@ mindplot.widget.ColorPalettePanel = new Class({
// Register on toolbar elements ... // Register on toolbar elements ...
var colorCells = content.find('div[class=palette-colorswatch]'); var colorCells = content.find('div[class=palette-colorswatch]');
var model = this.getModel(); var model = this.getModel();
var me = this;
_.each(colorCells, function (elem) { _.each(colorCells, function (elem) {
$(elem).on('click', function () { $(elem).on('click', function () {
var color = $(elem).css("background-color"); var color = $(elem).css("background-color");
model.setValue(color); model.setValue(color);
this.hide(); me.hide();
}.bind(this)); });
}.bind(this)); });
return content; return content;
}, },
@ -79,23 +79,20 @@ mindplot.widget.ColorPalettePanel = new Class({
var panelElem = this.getPanelElem(); var panelElem = this.getPanelElem();
// Clear selected cell based on the color ... // Clear selected cell based on the color ...
var tdCells = panelElem.find("td[class='palette-cell palette-cell-selected']"); panelElem.find("td[class='palette-cell palette-cell-selected']").attr('class', 'palette-cell');
_.each(tdCells, function (elem) {
elem.className = 'palette-cell';
});
// Mark the cell as selected ... // Mark the cell as selected ...
var colorCells = panelElem.find('div[class=palette-colorswatch]'); var colorCells = panelElem.find('div[class=palette-colorswatch]');
var model = this.getModel(); var model = this.getModel();
var modelValue = model.getValue(); var modelValue = model.getValue();
_.each(colorCells, function (elem) { _.each(colorCells, function (elem) {
var color = elem.css("background-color"); var color = $(elem).css("background-color").rgbToHex();
if (modelValue != null && modelValue[0] == 'r') { if (modelValue != null && modelValue[0] == 'r') {
modelValue = modelValue.rgbToHex(); modelValue = modelValue.rgbToHex();
} }
if (modelValue != null && modelValue.toUpperCase() == color.toUpperCase()) { if (modelValue != null && modelValue.toUpperCase() == color.toUpperCase()) {
elem.parentNode.className = 'palette-cell palette-cell-selected'; $(elem).parent().attr('class', 'palette-cell palette-cell-selected');
} }
}); });
return panelElem; return panelElem;