Aleksander Machniak
2012-05-08 e6e0d410ac92818679c03fc9bf5359562df81921
program/js/tiny_mce/themes/advanced/js/color_picker.js
@@ -1,6 +1,6 @@
tinyMCEPopup.requireLangPack();
var detail = 50, strhex = "0123456789ABCDEF", i, isMouseDown = false, isMouseOver = false;
var detail = 50, strhex = "0123456789abcdef", i, isMouseDown = false, isMouseOver = false;
var colors = [
   "#000000","#000033","#000066","#000099","#0000cc","#0000ff","#330000","#330033",
@@ -93,40 +93,56 @@
      return value.length > 1 ? value : '0' + value; // Padd with leading zero
   };
   color = color.replace(/[\s#]+/g, '').toLowerCase();
   color = tinymce.trim(color);
   color = color.replace(/^[#]/, '').toLowerCase();  // remove leading '#'
   color = namedLookup[color] || color;
   matches = /^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)|([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})|([a-f0-9])([a-f0-9])([a-f0-9])$/.exec(color);
   matches = /^rgb\((\d{1,3}),(\d{1,3}),(\d{1,3})\)$/.exec(color);
   if (matches) {
      if (matches[1]) {
         red = toInt(matches[1]);
         green = toInt(matches[2]);
         blue = toInt(matches[3]);
      } else if (matches[4]) {
         red = toInt(matches[4], 16);
         green = toInt(matches[5], 16);
         blue = toInt(matches[6], 16);
      } else if (matches[7]) {
         red = toInt(matches[7] + matches[7], 16);
         green = toInt(matches[8] + matches[8], 16);
         blue = toInt(matches[9] + matches[9], 16);
   } else {
      matches = /^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(color);
      if (matches) {
         red   = toInt(matches[1], 16);
         green = toInt(matches[2], 16);
         blue  = toInt(matches[3], 16);
      } else {
         matches = /^([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(color);
         if (matches) {
            red   = toInt(matches[1] + matches[1], 16);
            green = toInt(matches[2] + matches[2], 16);
            blue  = toInt(matches[3] + matches[3], 16);
         } else {
            return '';
         }
      }
      }
      return '#' + hex(red) + hex(green) + hex(blue);
   }
   return '';
}
function insertAction() {
   var color = document.getElementById("color").value, f = tinyMCEPopup.getWindowArg('func');
   var hexColor = toHexColor(color);
   if (hexColor === '') {
      var text = tinyMCEPopup.editor.getLang('advanced_dlg.invalid_color_value');
      tinyMCEPopup.alert(text + ': ' + color);
   }
   else {
   tinyMCEPopup.restoreSelection();
   if (f)
      f(toHexColor(color));
         f(hexColor);
   tinyMCEPopup.close();
   }
}
function showColor(color, name) {
@@ -266,10 +282,10 @@
}
function computeColor(e) {
   var x, y, partWidth, partDetail, imHeight, r, g, b, coef, i, finalCoef, finalR, finalG, finalB;
   var x, y, partWidth, partDetail, imHeight, r, g, b, coef, i, finalCoef, finalR, finalG, finalB, pos = tinyMCEPopup.dom.getPos(e.target);
   x = e.offsetX ? e.offsetX : (e.target ? e.clientX - e.target.x : 0);
   y = e.offsetY ? e.offsetY : (e.target ? e.clientY - e.target.y : 0);
   x = e.offsetX ? e.offsetX : (e.target ? e.clientX - pos.x : 0);
   y = e.offsetY ? e.offsetY : (e.target ? e.clientY - pos.y : 0);
   partWidth = document.getElementById('colors').width / 6;
   partDetail = detail / 2;