Skip to content

Commit

Permalink
user can now change the color manually in the codemirror editor and t…
Browse files Browse the repository at this point in the history
…heir changes will be reflected in the colorpicker widget.
  • Loading branch information
toolness committed Jan 20, 2012
1 parent d159dc4 commit c7d126e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions static-files/scripts/editor.js
Expand Up @@ -60,6 +60,7 @@ var Editor = (function() {
var picker = null;
var pickerPos = null;
var inCursorActivity = false;
var inManualColorChange = false;

function removePicker() {
if (picker) {
Expand Down Expand Up @@ -128,17 +129,28 @@ var Editor = (function() {
return t.string
}).join("").trim();
if (pickerPos && pickerPos.line == pos.line &&
pickerPos.ch == tokensStart)
pickerPos.ch == tokensStart) {
if (pickerPos.lastValue != cssValue) {
inManualColorChange = true;
picker.colorpicker("setColor", cssValue);
inManualColorChange = false;
pickerPos.lastValue = cssValue;
}
return;
}
removePicker();
pickerPos = {line: pos.line, ch: tokensStart};
pickerPos = {
line: pos.line,
ch: tokensStart,
lastValue: cssValue
};
//console.log("cssValue is", cssValue);
picker = $('<div class="picker"></div>').appendTo(document.body);
picker.colorpicker({
alpha: true,
color: cssValue,
onSelect: function(hex, rgba, inst) {
if (!pickerPos)
if (!pickerPos || inManualColorChange)
return;
var value;
if (rgba.a == 1) {
Expand Down

0 comments on commit c7d126e

Please sign in to comment.