Browse Source

chore: 优化下写法

es6
guy 3 years ago
parent
commit
9b6491406c
  1. 8
      src/case/colorchooser/colorchooser.custom.js
  2. 1
      src/case/colorchooser/colorchooser.js
  3. 1
      src/case/colorchooser/colorchooser.popup.hex.js
  4. 35
      src/case/colorchooser/farbtastic/farbtastic.js
  5. 42
      src/core/platform/web/dom.js

8
src/case/colorchooser/colorchooser.custom.js

@ -19,13 +19,15 @@ BI.CustomColorChooser = BI.inherit(BI.Widget, {
BI.CustomColorChooser.superclass._init.apply(this, arguments); BI.CustomColorChooser.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget(o.editor, { this.editor = BI.createWidget(o.editor, {
type: "bi.simple_hex_color_picker_editor" type: "bi.simple_hex_color_picker_editor",
value: o.value
}); });
this.editor.on(BI.ColorPickerEditor.EVENT_CHANGE, function () { this.editor.on(BI.ColorPickerEditor.EVENT_CHANGE, function () {
self.setValue(this.getValue()); self.setValue(this.getValue());
}); });
this.farbtastic = BI.createWidget({ this.farbtastic = BI.createWidget({
type: "bi.farbtastic" type: "bi.farbtastic",
value: o.value
}); });
this.farbtastic.on(BI.Farbtastic.EVENT_CHANGE, function () { this.farbtastic.on(BI.Farbtastic.EVENT_CHANGE, function () {
self.setValue(this.getValue()); self.setValue(this.getValue());
@ -66,4 +68,4 @@ BI.CustomColorChooser = BI.inherit(BI.Widget, {
} }
}); });
BI.CustomColorChooser.EVENT_CHANGE = "EVENT_CHANGE"; BI.CustomColorChooser.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.custom_color_chooser", BI.CustomColorChooser); BI.shortcut("bi.custom_color_chooser", BI.CustomColorChooser);

1
src/case/colorchooser/colorchooser.js

@ -33,6 +33,7 @@ BI.ColorChooser = BI.inherit(BI.Widget, {
ref: function (_ref) { ref: function (_ref) {
self.trigger = _ref; self.trigger = _ref;
}, },
value: o.value,
width: o.el.type ? o.width : o.width - 2, width: o.el.type ? o.width : o.width - 2,
height: o.el.type ? o.height : o.height - 2 height: o.el.type ? o.height : o.height - 2
}, o.el), }, o.el),

1
src/case/colorchooser/colorchooser.popup.hex.js

@ -141,6 +141,7 @@ BI.HexColorChooserPopup = BI.inherit(BI.Widget, {
title: BI.i18nText("BI-Custom_Color"), title: BI.i18nText("BI-Custom_Color"),
el: { el: {
type: "bi.custom_color_chooser", type: "bi.custom_color_chooser",
value: o.value,
editor: o.editor, editor: o.editor,
ref: function (_ref) { ref: function (_ref) {
self.customColorChooser = _ref; self.customColorChooser = _ref;

35
src/case/colorchooser/farbtastic/farbtastic.js

@ -127,42 +127,11 @@ BI.Farbtastic = BI.inherit(BI.BasicButton, {
}, },
_HSLToRGB: function (hsl) { _HSLToRGB: function (hsl) {
var m1, m2, r, g, b; return BI.DOM.hsl2rgb(hsl);
var h = hsl[0], s = hsl[1], l = hsl[2];
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
m1 = l * 2 - m2;
return [this._hueToRGB(m1, m2, h + 0.33333),
this._hueToRGB(m1, m2, h),
this._hueToRGB(m1, m2, h - 0.33333)];
},
_hueToRGB: function (m1, m2, h) {
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
if (h * 2 < 1) return m2;
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
return m1;
}, },
_RGBToHSL: function (rgb) { _RGBToHSL: function (rgb) {
var min, max, delta, h, s, l; return BI.DOM.rgb2hsl(rgb);
var r = rgb[0], g = rgb[1], b = rgb[2];
min = Math.min(r, Math.min(g, b));
max = Math.max(r, Math.max(g, b));
delta = max - min;
l = (min + max) / 2;
s = 0;
if (l > 0 && l < 1) {
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
}
h = 0;
if (delta > 0) {
if (max == r && max != g) h += (g - b) / delta;
if (max == g && max != b) h += (2 + (b - r) / delta);
if (max == b && max != r) h += (4 + (r - g) / delta);
h /= 6;
}
return [h, s, l];
}, },
_updateDisplay: function () { _updateDisplay: function () {

42
src/core/platform/web/dom.js

@ -205,6 +205,45 @@
return hexColour; return hexColour;
}, },
_hue2rgb: function (m1, m2, h) {
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
if (h * 2 < 1) return m2;
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
return m1;
},
hsl2rgb: function (hsl) {
var m1, m2, r, g, b;
var h = hsl[0], s = hsl[1], l = hsl[2];
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l * s;
m1 = l * 2 - m2;
return [this._hue2rgb(m1, m2, h + 0.33333),
this._hue2rgb(m1, m2, h),
this._hue2rgb(m1, m2, h - 0.33333)];
},
rgb2hsl: function (rgb) {
var min, max, delta, h, s, l;
var r = rgb[0], g = rgb[1], b = rgb[2];
min = Math.min(r, Math.min(g, b));
max = Math.max(r, Math.max(g, b));
delta = max - min;
l = (min + max) / 2;
s = 0;
if (l > 0 && l < 1) {
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
}
h = 0;
if (delta > 0) {
if (max == r && max != g) h += (g - b) / delta;
if (max == g && max != b) h += (2 + (b - r) / delta);
if (max == b && max != r) h += (4 + (r - g) / delta);
h /= 6;
}
return [h, s, l];
},
rgb2json: function (rgbColour) { rgb2json: function (rgbColour) {
if (!rgbColour) { if (!rgbColour) {
return {}; return {};
@ -346,7 +385,8 @@
}, },
isInnerLeftSpaceEnough: function (combo, popup, extraWidth) { isInnerLeftSpaceEnough: function (combo, popup, extraWidth) {
var viewBounds = popup.element.bounds(),windowBounds = BI.Widget._renderEngine.createElement("body").bounds(); var viewBounds = popup.element.bounds(),
windowBounds = BI.Widget._renderEngine.createElement("body").bounds();
return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width; return BI.DOM.getInnerLeftPosition(combo, popup, extraWidth).left + viewBounds.width <= windowBounds.width;
}, },

Loading…
Cancel
Save