' +
@@ -310,7 +334,7 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) {
'
' +
'
' +
'
';
+ const div = document.createElement('div');
+ div.innerHTML = html;
+ while (div.children.length > 0) {
+ console.log(gradPicker);
+ gradPicker.appendChild(div.children[0]);
+ }
+ console.log(gradPicker);
+ /* eslint-enable max-len */
+ // --------------
+ // Set up all the SVG elements (the gradient, stops and rectangle)
+ const MAX = 256,
+ MARGINX = 0,
+ MARGINY = 0,
+ // STOP_RADIUS = 15 / 2,
+ SIZEX = MAX - 2 * MARGINX,
+ SIZEY = MAX - 2 * MARGINY;
- const attrInput = {};
+ const attrInput = {};
- const SLIDERW = 145;
- $wc('.jGraduate_SliderBar').width(SLIDERW);
- // JFH !!!!!!
- const container = $wc('#' + id + '_jGraduate_GradContainer')[0];
+ const SLIDERW = 145;
+ $wc('.jGraduate_SliderBar').width(SLIDERW);
+ // JFH !!!!!!
+ const container = $wc('#' + id + '_jGraduate_GradContainer')[0];
- const svg = mkElem('svg', {
- id: id + '_jgraduate_svg',
- width: MAX,
- height: MAX,
- xmlns: ns.svg
- }, container);
+ const svg = mkElem('svg', {
+ id: id + '_jgraduate_svg',
+ width: MAX,
+ height: MAX,
+ xmlns: ns.svg
+ }, container);
- // This wasn't working as designed
- // let curType;
- // curType = curType || $this.paint.type;
+ // This wasn't working as designed
+ // let curType;
+ // curType = curType || $this.paint.type;
- // if we are sent a gradient, import it
- let curType = $this.paint.type;
+ // if we are sent a gradient, import it
+ let curType = $this.paint.type;
- let grad = $this.paint[curType];
- let curGradient = grad;
+ let grad = $this.paint[curType];
+ let curGradient = grad;
- const gradalpha = $this.paint.alpha;
+ const gradalpha = $this.paint.alpha;
- const isSolid = curType === 'solidColor';
+ const isSolid = curType === 'solidColor';
- // Make any missing gradients
- switch (curType) {
- case 'solidColor':
- // fall through
- case 'linearGradient':
- if (!isSolid) {
- curGradient.id = id + '_lg_jgraduate_grad';
- grad = curGradient = svg.appendChild(curGradient);
- }
- mkElem('radialGradient', {
- id: id + '_rg_jgraduate_grad'
- }, svg);
- if (curType === 'linearGradient') { break; }
- // fall through
- case 'radialGradient':
- if (!isSolid) {
- curGradient.id = id + '_rg_jgraduate_grad';
- grad = curGradient = svg.appendChild(curGradient);
- }
- mkElem('linearGradient', {
- id: id + '_lg_jgraduate_grad'
- }, svg);
+ // Make any missing gradients
+ switch (curType) {
+ case 'solidColor':
+ // fall through
+ case 'linearGradient':
+ if (!isSolid) {
+ curGradient.id = id + '_lg_jgraduate_grad';
+ grad = curGradient = svg.appendChild(curGradient);
}
-
- let stopGroup; // eslint-disable-line prefer-const
- if (isSolid) {
- // JFH !!!!!!!!
- grad = curGradient = $wc('#' + id + '_lg_jgraduate_grad')[0];
- color = $this.paint[curType];
- mkStop(0, '#' + color, 1);
-
- const type = typeof $settings.newstop;
-
- if (type === 'string') {
- switch ($settings.newstop) {
- case 'same':
- mkStop(1, '#' + color, 1);
- break;
-
- case 'inverse': {
- // Invert current color for second stop
- let inverted = '';
- for (let i = 0; i < 6; i += 2) {
- // const ch = color.substr(i, 2);
- let inv = (255 - Number.parseInt(color.substr(i, 2), 16)).toString(16);
- if (inv.length < 2) inv = 0 + inv;
- inverted += inv;
- }
- mkStop(1, '#' + inverted, 1);
- break;
- } case 'white':
- mkStop(1, '#ffffff', 1);
- break;
-
- case 'black':
- mkStop(1, '#000000', 1);
- break;
- }
- } else if (type === 'object') {
- const opac = ('opac' in $settings.newstop) ? $settings.newstop.opac : 1;
- mkStop(1, ($settings.newstop.color || '#' + color), opac);
- }
- }
-
- const x1 = Number.parseFloat(grad.getAttribute('x1') || 0.0),
- y1 = Number.parseFloat(grad.getAttribute('y1') || 0.0),
- x2 = Number.parseFloat(grad.getAttribute('x2') || 1.0),
- y2 = Number.parseFloat(grad.getAttribute('y2') || 0.0);
-
- const cx = Number.parseFloat(grad.getAttribute('cx') || 0.5),
- cy = Number.parseFloat(grad.getAttribute('cy') || 0.5),
- fx = Number.parseFloat(grad.getAttribute('fx') || cx),
- fy = Number.parseFloat(grad.getAttribute('fy') || cy);
-
- const previewRect = mkElem('rect', {
- id: id + '_jgraduate_rect',
- x: MARGINX,
- y: MARGINY,
- width: SIZEX,
- height: SIZEY,
- fill: 'url(#' + id + '_jgraduate_grad)',
- 'fill-opacity': gradalpha / 100
+ mkElem('radialGradient', {
+ id: id + '_rg_jgraduate_grad'
}, svg);
+ if (curType === 'linearGradient') { break; }
+ // fall through
+ case 'radialGradient':
+ if (!isSolid) {
+ curGradient.id = id + '_rg_jgraduate_grad';
+ grad = curGradient = svg.appendChild(curGradient);
+ }
+ mkElem('linearGradient', {
+ id: id + '_lg_jgraduate_grad'
+ }, svg);
+ }
- // stop visuals created here
- const beginCoord = $('
').attr({
- class: 'grad_coord jGraduate_lg_field',
- title: 'Begin Stop'
- }).text(1).css({
- top: y1 * MAX,
- left: x1 * MAX
- }).data('coord', 'start').appendTo(container);
+ let stopGroup; // eslint-disable-line prefer-const
+ if (isSolid) {
+ // JFH !!!!!!!!
+ grad = curGradient = $wc('#' + id + '_lg_jgraduate_grad')[0];
+ color = $this.paint[curType];
+ mkStop(0, '#' + color, 1);
- const endCoord = beginCoord.clone().text(2).css({
- top: y2 * MAX,
- left: x2 * MAX
- }).attr('title', 'End stop').data('coord', 'end').appendTo(container);
+ const type = typeof $settings.newstop;
- const centerCoord = $('
').attr({
- class: 'grad_coord jGraduate_rg_field',
- title: 'Center stop'
- }).text('C').css({
- top: cy * MAX,
- left: cx * MAX
- }).data('coord', 'center').appendTo(container);
+ if (type === 'string') {
+ switch ($settings.newstop) {
+ case 'same':
+ mkStop(1, '#' + color, 1);
+ break;
- const focusCoord = centerCoord.clone().text('F').css({
- top: fy * MAX,
- left: fx * MAX,
- display: 'none'
- }).attr('title', 'Focus point').data('coord', 'focus').appendTo(container);
-
- focusCoord[0].id = id + '_jGraduate_focusCoord';
-
- let showFocus;
- $.each(['x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'fx', 'fy'], function (i, attr) {
- const isRadial = isNaN(attr[1]);
-
- let attrval = curGradient.getAttribute(attr);
- if (!attrval) {
- // Set defaults
- if (isRadial) {
- // For radial points
- attrval = '0.5';
- } else {
- // Only x2 is 1
- attrval = attr === 'x2' ? '1.0' : '0.0';
+ case 'inverse': {
+ // Invert current color for second stop
+ let inverted = '';
+ for (let i = 0; i < 6; i += 2) {
+ // const ch = color.substr(i, 2);
+ let inv = (255 - Number.parseInt(color.substr(i, 2), 16)).toString(16);
+ if (inv.length < 2) inv = 0 + inv;
+ inverted += inv;
}
+ mkStop(1, '#' + inverted, 1);
+ break;
+ } case 'white':
+ mkStop(1, '#ffffff', 1);
+ break;
+
+ case 'black':
+ mkStop(1, '#000000', 1);
+ break;
}
+ } else if (type === 'object') {
+ const opac = ('opac' in $settings.newstop) ? $settings.newstop.opac : 1;
+ mkStop(1, ($settings.newstop.color || '#' + color), opac);
+ }
+ }
- attrInput[attr] = $wc('#' + id + '_jGraduate_' + attr)
- .val(attrval)
- .change(function () {
- // TODO: Support values < 0 and > 1 (zoomable preview?)
- if (isNaN(Number.parseFloat(this.value)) || this.value < 0) {
- this.value = 0.0;
- } else if (this.value > 1) {
- this.value = 1.0;
- }
+ const x1 = Number.parseFloat(grad.getAttribute('x1') || 0.0),
+ y1 = Number.parseFloat(grad.getAttribute('y1') || 0.0),
+ x2 = Number.parseFloat(grad.getAttribute('x2') || 1.0),
+ y2 = Number.parseFloat(grad.getAttribute('y2') || 0.0);
- if (!(attr[0] === 'f' &&
- !showFocus) &&
- ((isRadial && curType === 'radialGradient') || (!isRadial && curType === 'linearGradient'))) {
- curGradient.setAttribute(attr, this.value);
- }
+ const cx = Number.parseFloat(grad.getAttribute('cx') || 0.5),
+ cy = Number.parseFloat(grad.getAttribute('cy') || 0.5),
+ fx = Number.parseFloat(grad.getAttribute('fx') || cx),
+ fy = Number.parseFloat(grad.getAttribute('fy') || cy);
- const $elem = isRadial
- ? attr[0] === 'c' ? centerCoord : focusCoord
- : attr[1] === '1' ? beginCoord : endCoord;
+ const previewRect = mkElem('rect', {
+ id: id + '_jgraduate_rect',
+ x: MARGINX,
+ y: MARGINY,
+ width: SIZEX,
+ height: SIZEY,
+ fill: 'url(#' + id + '_jgraduate_grad)',
+ 'fill-opacity': gradalpha / 100
+ }, svg);
- const cssName = attr.includes('x') ? 'left' : 'top';
+ // stop visuals created here
+ const beginCoord = $('
').attr({
+ class: 'grad_coord jGraduate_lg_field',
+ title: 'Begin Stop'
+ }).text(1).css({
+ top: y1 * MAX,
+ left: x1 * MAX
+ }).data('coord', 'start').appendTo(container);
- $elem.css(cssName, this.value * MAX);
- }).change();
- });
+ const endCoord = beginCoord.clone().text(2).css({
+ top: y2 * MAX,
+ left: x2 * MAX
+ }).attr('title', 'End stop').data('coord', 'end').appendTo(container);
- /**
- *
- * @param {Float} n
- * @param {Float|string} colr
- * @param {Float} opac
- * @param {boolean} [sel]
- * @param {SVGStopElement} [stopElem]
- * @returns {SVGStopElement}
- */
- function mkStop (n, colr, opac, sel, stopElem) {
- const stop = stopElem || mkElem('stop', {
- 'stop-color': colr,
- 'stop-opacity': opac,
- offset: n
- }, curGradient);
- if (stopElem) {
- colr = stopElem.getAttribute('stop-color');
- opac = stopElem.getAttribute('stop-opacity');
- n = stopElem.getAttribute('offset');
+ const centerCoord = $('
').attr({
+ class: 'grad_coord jGraduate_rg_field',
+ title: 'Center stop'
+ }).text('C').css({
+ top: cy * MAX,
+ left: cx * MAX
+ }).data('coord', 'center').appendTo(container);
+
+ const focusCoord = centerCoord.clone().text('F').css({
+ top: fy * MAX,
+ left: fx * MAX,
+ display: 'none'
+ }).attr('title', 'Focus point').data('coord', 'focus').appendTo(container);
+
+ focusCoord[0].id = id + '_jGraduate_focusCoord';
+
+ let showFocus;
+ $.each(['x1', 'y1', 'x2', 'y2', 'cx', 'cy', 'fx', 'fy'], function (i, attr) {
+ const isRadial = isNaN(attr[1]);
+
+ let attrval = curGradient.getAttribute(attr);
+ if (!attrval) {
+ // Set defaults
+ if (isRadial) {
+ // For radial points
+ attrval = '0.5';
} else {
- curGradient.append(stop);
+ // Only x2 is 1
+ attrval = attr === 'x2' ? '1.0' : '0.0';
}
- if (opac === null) opac = 1;
+ }
- const pickerD = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,' +
- '3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,' +
- '2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
-
- const pathbg = mkElem('path', {
- d: pickerD,
- fill: 'url(#jGraduate_trans)',
- transform: 'translate(' + (10 + n * MAX) + ', 26)'
- }, stopGroup);
-
- const path = mkElem('path', {
- d: pickerD,
- fill: colr,
- 'fill-opacity': opac,
- transform: 'translate(' + (10 + n * MAX) + ', 26)',
- stroke: '#000',
- 'stroke-width': 1.5
- }, stopGroup);
-
- $(path).mousedown(function (e) {
- selectStop(this);
- drag = curStop;
- $win.mousemove(dragColor).mouseup(remDrags);
- stopOffset = stopMakerDiv.offset();
- e.preventDefault();
- return false;
- }).data('stop', stop).data('bg', pathbg).dblclick(function () {
- $wc('div.jGraduate_LightBox').show();
- const colorhandle = this;
- let stopOpacity = Number(stop.getAttribute('stop-opacity')) || 1;
- let stopColor = stop.getAttribute('stop-color') || 1;
- let thisAlpha = (Number.parseFloat(stopOpacity) * 255).toString(16);
- while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
- colr = stopColor.substr(1) + thisAlpha;
- jPickerMethod($wc('#' + id + '_jGraduate_stopPicker').css({left: 100, bottom: 15}), {
- window: {title: 'Pick the start color and opacity for the gradient'},
- images: {clientPath: $settings.images.clientPath},
- color: {active: colr, alphaSupport: true}
- }, function (clr, arg2) {
- stopColor = clr.val('hex') ? ('#' + clr.val('hex')) : 'none';
- stopOpacity = clr.val('a') !== null ? clr.val('a') / 256 : 1;
- colorhandle.setAttribute('fill', stopColor);
- colorhandle.setAttribute('fill-opacity', stopOpacity);
- stop.setAttribute('stop-color', stopColor);
- stop.setAttribute('stop-opacity', stopOpacity);
- $wc('div.jGraduate_LightBox').hide();
- $wc('#' + id + '_jGraduate_stopPicker').hide();
- }, null, function () {
- $wc('div.jGraduate_LightBox').hide();
- $wc('#' + id + '_jGraduate_stopPicker').hide();
- });
- });
-
- $(curGradient).find('stop').each(function () {
- const curS = $(this);
- if (Number(this.getAttribute('offset')) > n) {
- if (!colr) {
- const newcolor = this.getAttribute('stop-color');
- const newopac = this.getAttribute('stop-opacity');
- stop.setAttribute('stop-color', newcolor);
- path.setAttribute('fill', newcolor);
- stop.setAttribute('stop-opacity', newopac === null ? 1 : newopac);
- path.setAttribute('fill-opacity', newopac === null ? 1 : newopac);
- }
- curS.before(stop);
- return false;
+ attrInput[attr] = $wc('#' + id + '_jGraduate_' + attr)
+ .val(attrval)
+ .change(function () {
+ // TODO: Support values < 0 and > 1 (zoomable preview?)
+ if (isNaN(Number.parseFloat(this.value)) || this.value < 0) {
+ this.value = 0.0;
+ } else if (this.value > 1) {
+ this.value = 1.0;
}
- return true;
- });
- if (sel) selectStop(path);
- return stop;
- }
- /**
- *
- * @returns {void}
- */
- function remStop () {
- delStop.setAttribute('display', 'none');
- const path = $wc(curStop);
- const stop = path.data('stop');
- const bg = path.data('bg');
- $([curStop, stop, bg]).remove();
- }
-
- const stopMakerDiv = $wc('#' + id + '_jGraduate_StopSlider');
-
- let stops, curStop, drag;
-
- const delStop = mkElem('path', {
- d: 'm9.75,-6l-19.5,19.5m0,-19.5l19.5,19.5',
- fill: 'none',
- stroke: '#D00',
- 'stroke-width': 5,
- display: 'none'
- }, undefined); // stopMakerSVG);
-
- /**
- * @param {Element} item
- * @returns {void}
- */
- function selectStop (item) {
- if (curStop) curStop.setAttribute('stroke', '#000');
- item.setAttribute('stroke', 'blue');
- curStop = item;
- }
-
- let stopOffset;
-
- /**
- *
- * @returns {void}
- */
- function remDrags () {
- $win.unbind('mousemove', dragColor);
- if (delStop.getAttribute('display') !== 'none') {
- remStop();
- }
- drag = null;
- }
-
- let scaleX = 1, scaleY = 1, angle = 0;
-
- let cX = cx;
- let cY = cy;
- /**
- *
- * @returns {void}
- */
- function xform () {
- const rot = angle ? 'rotate(' + angle + ',' + cX + ',' + cY + ') ' : '';
- if (scaleX === 1 && scaleY === 1) {
- curGradient.removeAttribute('gradientTransform');
- // $wc('#ang').addClass('dis');
- } else {
- const x = -cX * (scaleX - 1);
- const y = -cY * (scaleY - 1);
- curGradient.setAttribute(
- 'gradientTransform',
- rot + 'translate(' + x + ',' + y + ') scale(' +
- scaleX + ',' + scaleY + ')'
- );
- // $wc('#ang').removeClass('dis');
- }
- }
-
- /**
- * @param {Event} evt
- * @returns {void}
- */
- function dragColor (evt) {
- let x = evt.pageX - stopOffset.left;
- const y = evt.pageY - stopOffset.top;
- x = x < 10
- ? 10
- : x > MAX + 10
- ? MAX + 10
- : x;
-
- const xfStr = 'translate(' + x + ', 26)';
- if (y < -60 || y > 130) {
- delStop.setAttribute('display', 'block');
- delStop.setAttribute('transform', xfStr);
- } else {
- delStop.setAttribute('display', 'none');
- }
-
- drag.setAttribute('transform', xfStr);
- $.data(drag, 'bg').setAttribute('transform', xfStr);
- const stop = $.data(drag, 'stop');
- const sX = (x - 10) / MAX;
-
- stop.setAttribute('offset', sX);
-
- let last = 0;
- $(curGradient).find('stop').each(function (i) {
- const cur = this.getAttribute('offset');
- const t = $(this);
- if (cur < last) {
- t.prev().before(t);
- stops = $(curGradient).find('stop');
+ if (!(attr[0] === 'f' &&
+ !showFocus) &&
+ ((isRadial && curType === 'radialGradient') || (!isRadial && curType === 'linearGradient'))) {
+ curGradient.setAttribute(attr, this.value);
}
- last = cur;
- });
+
+ const $elem = isRadial
+ ? attr[0] === 'c' ? centerCoord : focusCoord
+ : attr[1] === '1' ? beginCoord : endCoord;
+
+ const cssName = attr.includes('x') ? 'left' : 'top';
+
+ $elem.css(cssName, this.value * MAX);
+ }).change();
+ });
+
+ /**
+ *
+ * @param {Float} n
+ * @param {Float|string} colr
+ * @param {Float} opac
+ * @param {boolean} [sel]
+ * @param {SVGStopElement} [stopElem]
+ * @returns {SVGStopElement}
+ */
+ function mkStop (n, colr, opac, sel, stopElem) {
+ const stop = stopElem || mkElem('stop', {
+ 'stop-color': colr,
+ 'stop-opacity': opac,
+ offset: n
+ }, curGradient);
+ if (stopElem) {
+ colr = stopElem.getAttribute('stop-color');
+ opac = stopElem.getAttribute('stop-opacity');
+ n = stopElem.getAttribute('offset');
+ } else {
+ console.log(curGradient);
+ curGradient.appendChild(stop);
}
+ if (opac === null) opac = 1;
- const stopMakerSVG = mkElem('svg', {
- width: '100%',
- height: 45
- }, stopMakerDiv[0]);
+ const pickerD = 'M-6.2,0.9c3.6-4,6.7-4.3,6.7-12.4c-0.2,7.9,' +
+ '3.1,8.8,6.5,12.4c3.5,3.8,2.9,9.6,0,12.3c-3.1,2.8-10.4,' +
+ '2.7-13.2,0C-9.6,9.9-9.4,4.4-6.2,0.9z';
- const transPattern = mkElem('pattern', {
- width: 16,
- height: 16,
- patternUnits: 'userSpaceOnUse',
- id: 'jGraduate_trans'
- }, stopMakerSVG);
+ const pathbg = mkElem('path', {
+ d: pickerD,
+ fill: 'url(#jGraduate_trans)',
+ transform: 'translate(' + (10 + n * MAX) + ', 26)'
+ }, stopGroup);
- const transImg = mkElem('image', {
- width: 16,
- height: 16
- }, transPattern);
+ const path = mkElem('path', {
+ d: pickerD,
+ fill: colr,
+ 'fill-opacity': opac,
+ transform: 'translate(' + (10 + n * MAX) + ', 26)',
+ stroke: '#000',
+ 'stroke-width': 1.5
+ }, stopGroup);
- const bgImage = $settings.images.clientPath + 'map-opacity.png';
-
- transImg.setAttributeNS(ns.xlink, 'xlink:href', bgImage);
-
- $(stopMakerSVG).click(function (evt) {
+ $(path).mousedown(function (e) {
+ selectStop(this);
+ drag = curStop;
+ $win.mousemove(dragColor).mouseup(remDrags);
stopOffset = stopMakerDiv.offset();
- const {target} = evt;
- if (target.tagName === 'path') return;
- let x = evt.pageX - stopOffset.left - 8;
- x = x < 10 ? 10 : x > MAX + 10 ? MAX + 10 : x;
- mkStop(x / MAX, 0, 0, true);
- evt.stopPropagation();
+ e.preventDefault();
+ return false;
+ }).data('stop', stop).data('bg', pathbg).dblclick(function () {
+ $wc('div.jGraduate_LightBox').show();
+ const colorhandle = this;
+ let stopOpacity = Number(stop.getAttribute('stop-opacity')) || 1;
+ let stopColor = stop.getAttribute('stop-color') || 1;
+ let thisAlpha = (Number.parseFloat(stopOpacity) * 255).toString(16);
+ while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
+ colr = stopColor.substr(1) + thisAlpha;
+ jPickerMethod($wc('#' + id + '_jGraduate_stopPicker').css({left: 100, bottom: 15}), {
+ window: {title: 'Pick the start color and opacity for the gradient'},
+ images: {clientPath: $settings.images.clientPath},
+ color: {active: colr, alphaSupport: true}
+ }, function (clr, arg2) {
+ stopColor = clr.val('hex') ? ('#' + clr.val('hex')) : 'none';
+ stopOpacity = clr.val('a') !== null ? clr.val('a') / 256 : 1;
+ colorhandle.setAttribute('fill', stopColor);
+ colorhandle.setAttribute('fill-opacity', stopOpacity);
+ stop.setAttribute('stop-color', stopColor);
+ stop.setAttribute('stop-opacity', stopOpacity);
+ $wc('div.jGraduate_LightBox').hide();
+ $wc('#' + id + '_jGraduate_stopPicker').hide();
+ }, null, function () {
+ $wc('div.jGraduate_LightBox').hide();
+ $wc('#' + id + '_jGraduate_stopPicker').hide();
+ });
});
- $(stopMakerSVG).mouseover(function () {
- stopMakerSVG.append(delStop);
- });
-
- stopGroup = mkElem('g', {}, stopMakerSVG);
-
- mkElem('line', {
- x1: 10,
- y1: 15,
- x2: MAX + 10,
- y2: 15,
- 'stroke-width': 2,
- stroke: '#000'
- }, stopMakerSVG);
-
- const spreadMethodOpt = gradPicker.find('.jGraduate_spreadMethod').change(function () {
- curGradient.setAttribute('spreadMethod', $(this).val());
- });
-
- // handle dragging the stop around the swatch
- let draggingCoord = null;
-
- const onCoordDrag = function (evt) {
- let x = evt.pageX - offset.left;
- let y = evt.pageY - offset.top;
-
- // clamp stop to the swatch
- x = x < 0 ? 0 : x > MAX ? MAX : x;
- y = y < 0 ? 0 : y > MAX ? MAX : y;
-
- draggingCoord.css('left', x).css('top', y);
-
- // calculate stop offset
- const fracx = x / SIZEX;
- const fracy = y / SIZEY;
-
- const type = draggingCoord.data('coord');
- const grd = curGradient;
-
- switch (type) {
- case 'start':
- attrInput.x1.val(fracx);
- attrInput.y1.val(fracy);
- grd.setAttribute('x1', fracx);
- grd.setAttribute('y1', fracy);
- break;
- case 'end':
- attrInput.x2.val(fracx);
- attrInput.y2.val(fracy);
- grd.setAttribute('x2', fracx);
- grd.setAttribute('y2', fracy);
- break;
- case 'center':
- attrInput.cx.val(fracx);
- attrInput.cy.val(fracy);
- grd.setAttribute('cx', fracx);
- grd.setAttribute('cy', fracy);
- cX = fracx;
- cY = fracy;
- xform();
- break;
- case 'focus':
- attrInput.fx.val(fracx);
- attrInput.fy.val(fracy);
- grd.setAttribute('fx', fracx);
- grd.setAttribute('fy', fracy);
- xform();
+ $(curGradient).find('stop').each(function () {
+ const curS = $(this);
+ if (Number(this.getAttribute('offset')) > n) {
+ if (!colr) {
+ const newcolor = this.getAttribute('stop-color');
+ const newopac = this.getAttribute('stop-opacity');
+ stop.setAttribute('stop-color', newcolor);
+ path.setAttribute('fill', newcolor);
+ stop.setAttribute('stop-opacity', newopac === null ? 1 : newopac);
+ path.setAttribute('fill-opacity', newopac === null ? 1 : newopac);
+ }
+ curS.before(stop);
+ return false;
}
+ return true;
+ });
+ if (sel) selectStop(path);
+ return stop;
+ }
- evt.preventDefault();
- };
+ /**
+ *
+ * @returns {void}
+ */
+ function remStop () {
+ delStop.setAttribute('display', 'none');
+ const path = $wc(curStop);
+ const stop = path.data('stop');
+ const bg = path.data('bg');
+ $([curStop, stop, bg]).remove();
+ }
- const onCoordUp = function () {
- draggingCoord = null;
- $win.unbind('mousemove', onCoordDrag).unbind('mouseup', onCoordUp);
- };
+ const stopMakerDiv = $wc('#' + id + '_jGraduate_StopSlider');
- // Linear gradient
- // (function () {
+ let stops, curStop, drag;
+ const delStop = mkElem('path', {
+ d: 'm9.75,-6l-19.5,19.5m0,-19.5l19.5,19.5',
+ fill: 'none',
+ stroke: '#D00',
+ 'stroke-width': 5,
+ display: 'none'
+ }, undefined); // stopMakerSVG);
+
+ /**
+ * @param {Element} item
+ * @returns {void}
+ */
+ function selectStop (item) {
+ if (curStop) curStop.setAttribute('stroke', '#000');
+ item.setAttribute('stroke', 'blue');
+ curStop = item;
+ }
+
+ let stopOffset;
+
+ /**
+ *
+ * @returns {void}
+ */
+ function remDrags () {
+ $win.unbind('mousemove', dragColor);
+ if (delStop.getAttribute('display') !== 'none') {
+ remStop();
+ }
+ drag = null;
+ }
+
+ let scaleX = 1, scaleY = 1, angle = 0;
+
+ let cX = cx;
+ let cY = cy;
+ /**
+ *
+ * @returns {void}
+ */
+ function xform () {
+ const rot = angle ? 'rotate(' + angle + ',' + cX + ',' + cY + ') ' : '';
+ if (scaleX === 1 && scaleY === 1) {
+ curGradient.removeAttribute('gradientTransform');
+ // $wc('#ang').addClass('dis');
+ } else {
+ const x = -cX * (scaleX - 1);
+ const y = -cY * (scaleY - 1);
+ curGradient.setAttribute(
+ 'gradientTransform',
+ rot + 'translate(' + x + ',' + y + ') scale(' +
+ scaleX + ',' + scaleY + ')'
+ );
+ // $wc('#ang').removeClass('dis');
+ }
+ }
+
+ /**
+ * @param {Event} evt
+ * @returns {void}
+ */
+ function dragColor (evt) {
+ let x = evt.pageX - stopOffset.left;
+ const y = evt.pageY - stopOffset.top;
+ x = x < 10
+ ? 10
+ : x > MAX + 10
+ ? MAX + 10
+ : x;
+
+ const xfStr = 'translate(' + x + ', 26)';
+ if (y < -60 || y > 130) {
+ delStop.setAttribute('display', 'block');
+ delStop.setAttribute('transform', xfStr);
+ } else {
+ delStop.setAttribute('display', 'none');
+ }
+
+ drag.setAttribute('transform', xfStr);
+ $.data(drag, 'bg').setAttribute('transform', xfStr);
+ const stop = $.data(drag, 'stop');
+ const sX = (x - 10) / MAX;
+
+ stop.setAttribute('offset', sX);
+
+ let last = 0;
+ $(curGradient).find('stop').each(function (i) {
+ const cur = this.getAttribute('offset');
+ const t = $(this);
+ if (cur < last) {
+ t.prev().before(t);
+ stops = $(curGradient).find('stop');
+ }
+ last = cur;
+ });
+ }
+
+ const stopMakerSVG = mkElem('svg', {
+ width: '100%',
+ height: 45
+ }, stopMakerDiv[0]);
+
+ const transPattern = mkElem('pattern', {
+ width: 16,
+ height: 16,
+ patternUnits: 'userSpaceOnUse',
+ id: 'jGraduate_trans'
+ }, stopMakerSVG);
+
+ const transImg = mkElem('image', {
+ width: 16,
+ height: 16
+ }, transPattern);
+
+ const bgImage = $settings.images.clientPath + 'map-opacity.png';
+
+ transImg.setAttributeNS(ns.xlink, 'xlink:href', bgImage);
+
+ $(stopMakerSVG).click(function (evt) {
+ stopOffset = stopMakerDiv.offset();
+ const {target} = evt;
+ if (target.tagName === 'path') return;
+ let x = evt.pageX - stopOffset.left - 8;
+ x = x < 10 ? 10 : x > MAX + 10 ? MAX + 10 : x;
+ mkStop(x / MAX, 0, 0, true);
+ evt.stopPropagation();
+ });
+
+ $(stopMakerSVG).mouseover(function () {
+ stopMakerSVG.append(delStop);
+ });
+
+ stopGroup = mkElem('g', {}, stopMakerSVG);
+
+ mkElem('line', {
+ x1: 10,
+ y1: 15,
+ x2: MAX + 10,
+ y2: 15,
+ 'stroke-width': 2,
+ stroke: '#000'
+ }, stopMakerSVG);
+ const spreadMethodOpt = gradPicker.querySelector('#jGraduate_spreadMethod');
+ spreadMethodOpt.addEventListener('change', function () {
+ curGradient.setAttribute('spreadMethod', this.value);
+ });
+
+ // handle dragging the stop around the swatch
+ let draggingCoord = null;
+
+ const onCoordDrag = function (evt) {
+ let x = evt.pageX - offset.left;
+ let y = evt.pageY - offset.top;
+
+ // clamp stop to the swatch
+ x = x < 0 ? 0 : x > MAX ? MAX : x;
+ y = y < 0 ? 0 : y > MAX ? MAX : y;
+
+ draggingCoord.css('left', x).css('top', y);
+
+ // calculate stop offset
+ const fracx = x / SIZEX;
+ const fracy = y / SIZEY;
+
+ const type = draggingCoord.data('coord');
+ const grd = curGradient;
+
+ switch (type) {
+ case 'start':
+ attrInput.x1.val(fracx);
+ attrInput.y1.val(fracy);
+ grd.setAttribute('x1', fracx);
+ grd.setAttribute('y1', fracy);
+ break;
+ case 'end':
+ attrInput.x2.val(fracx);
+ attrInput.y2.val(fracy);
+ grd.setAttribute('x2', fracx);
+ grd.setAttribute('y2', fracy);
+ break;
+ case 'center':
+ attrInput.cx.val(fracx);
+ attrInput.cy.val(fracy);
+ grd.setAttribute('cx', fracx);
+ grd.setAttribute('cy', fracy);
+ cX = fracx;
+ cY = fracy;
+ xform();
+ break;
+ case 'focus':
+ attrInput.fx.val(fracx);
+ attrInput.fy.val(fracy);
+ grd.setAttribute('fx', fracx);
+ grd.setAttribute('fy', fracy);
+ xform();
+ }
+
+ evt.preventDefault();
+ };
+
+ const onCoordUp = function () {
+ draggingCoord = null;
+ $win.unbind('mousemove', onCoordDrag).unbind('mouseup', onCoordUp);
+ };
+
+ // Linear gradient
+ // (function () {
+
+ stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
+
+ let numstops = stops.length;
+ // if there are not at least two stops, then
+ if (numstops < 2) {
+ while (numstops < 2) {
+ curGradient.append(document.createElementNS(ns.svg, 'stop'));
+ ++numstops;
+ }
stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
+ }
- let numstops = stops.length;
- // if there are not at least two stops, then
- if (numstops < 2) {
- while (numstops < 2) {
- curGradient.append(document.createElementNS(ns.svg, 'stop'));
- ++numstops;
- }
- stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
- }
+ for (let i = 0; i < numstops; i++) {
+ mkStop(0, 0, 0, 0, stops[i]);
+ }
- for (let i = 0; i < numstops; i++) {
- mkStop(0, 0, 0, 0, stops[i]);
- }
+ spreadMethodOpt.setAttribute('value', curGradient.getAttribute('spreadMethod') || 'pad');
- spreadMethodOpt.val(curGradient.getAttribute('spreadMethod') || 'pad');
+ let offset;
- let offset;
+ // No match, so show focus point
+ showFocus = false;
- // No match, so show focus point
- showFocus = false;
+ previewRect.setAttribute('fill-opacity', gradalpha / 100);
- previewRect.setAttribute('fill-opacity', gradalpha / 100);
+ $wc('#' + id + ' div.grad_coord').mousedown(function (evt) {
+ evt.preventDefault();
+ draggingCoord = $(this);
+ // const sPos = draggingCoord.offset();
+ offset = draggingCoord.parent().offset();
+ $win.mousemove(onCoordDrag).mouseup(onCoordUp);
+ });
- $wc('#' + id + ' div.grad_coord').mousedown(function (evt) {
- evt.preventDefault();
- draggingCoord = $(this);
- // const sPos = draggingCoord.offset();
- offset = draggingCoord.parent().offset();
- $win.mousemove(onCoordDrag).mouseup(onCoordUp);
- });
+ // bind GUI elements
+ $wc('#' + id + '_jGraduate_Ok').bind('click', function () {
+ $this.paint.type = curType;
+ $this.paint[curType] = curGradient.cloneNode(true);
+ $this.paint.solidColor = null;
+ okClicked();
+ });
+ $wc('#' + id + '_jGraduate_Cancel').bind('click', function (paint) {
+ cancelClicked();
+ });
- // bind GUI elements
- $wc('#' + id + '_jGraduate_Ok').bind('click', function () {
- $this.paint.type = curType;
- $this.paint[curType] = curGradient.cloneNode(true);
- $this.paint.solidColor = null;
- okClicked();
- });
- $wc('#' + id + '_jGraduate_Cancel').bind('click', function (paint) {
- cancelClicked();
- });
-
- if (curType === 'radialGradient') {
- if (showFocus) {
- focusCoord.show();
- } else {
- focusCoord.hide();
- attrInput.fx.val('');
- attrInput.fy.val('');
- }
- }
-
- $wc('#' + id + '_jGraduate_match_ctr')[0].checked = !showFocus;
-
- let lastfx, lastfy;
-
- $wc('#' + id + '_jGraduate_match_ctr').change(function () {
- showFocus = !this.checked;
- focusCoord.toggle(showFocus);
+ if (curType === 'radialGradient') {
+ if (showFocus) {
+ focusCoord.show();
+ } else {
+ focusCoord.hide();
attrInput.fx.val('');
attrInput.fy.val('');
- const grd = curGradient;
- if (!showFocus) {
- lastfx = grd.getAttribute('fx');
- lastfy = grd.getAttribute('fy');
- grd.removeAttribute('fx');
- grd.removeAttribute('fy');
- } else {
- const fX = lastfx || 0.5;
- const fY = lastfy || 0.5;
- grd.setAttribute('fx', fX);
- grd.setAttribute('fy', fY);
- attrInput.fx.val(fX);
- attrInput.fy.val(fY);
- }
- });
-
- stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
- numstops = stops.length;
- // if there are not at least two stops, then
- if (numstops < 2) {
- while (numstops < 2) {
- curGradient.append(document.createElementNS(ns.svg, 'stop'));
- ++numstops;
- }
- stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
}
+ }
- let slider;
+ $wc('#' + id + '_jGraduate_match_ctr')[0].checked = !showFocus;
- const setSlider = function (e) {
- const {offset: {left}} = slider;
- const div = slider.parent;
- let x = (e.pageX - left - Number.parseInt(div.css('border-left-width')));
- if (x > SLIDERW) x = SLIDERW;
- if (x <= 0) x = 0;
- const posx = x - 5;
- x /= SLIDERW;
+ let lastfx, lastfy;
- switch (slider.type) {
- case 'radius':
- x = (x * 2) ** 2.5;
- if (x > 0.98 && x < 1.02) x = 1;
- if (x <= 0.01) x = 0.01;
- curGradient.setAttribute('r', x);
- break;
- case 'opacity':
- $this.paint.alpha = Number.parseInt(x * 100);
- previewRect.setAttribute('fill-opacity', x);
- break;
- case 'ellip':
- scaleX = 1;
- scaleY = 1;
- if (x < 0.5) {
- x /= 0.5; // 0.001
- scaleX = x <= 0 ? 0.01 : x;
- } else if (x > 0.5) {
- x /= 0.5; // 2
- x = 2 - x;
- scaleY = x <= 0 ? 0.01 : x;
- }
- xform();
- x -= 1;
- if (scaleY === x + 1) {
- x = Math.abs(x);
- }
- break;
- case 'angle':
- x -= 0.5;
- angle = x *= 180;
- xform();
- x /= 100;
- break;
- }
- slider.elem.css({'margin-left': posx});
- x = Math.round(x * 100);
- slider.input.val(x);
- };
-
- let ellipVal = 0, angleVal = 0;
-
- if (curType === 'radialGradient') {
- const tlist = curGradient.gradientTransform.baseVal;
- if (tlist.numberOfItems === 2) {
- const t = tlist.getItem(0);
- const s = tlist.getItem(1);
- if (t.type === 2 && s.type === 3) {
- const m = s.matrix;
- if (m.a !== 1) {
- ellipVal = Math.round(-(1 - m.a) * 100);
- } else if (m.d !== 1) {
- ellipVal = Math.round((1 - m.d) * 100);
- }
- }
- } else if (tlist.numberOfItems === 3) {
- // Assume [R][T][S]
- const r = tlist.getItem(0);
- const t = tlist.getItem(1);
- const s = tlist.getItem(2);
-
- if (r.type === 4 &&
- t.type === 2 &&
- s.type === 3
- ) {
- angleVal = Math.round(r.angle);
- const m = s.matrix;
- if (m.a !== 1) {
- ellipVal = Math.round(-(1 - m.a) * 100);
- } else if (m.d !== 1) {
- ellipVal = Math.round((1 - m.d) * 100);
- }
- }
- }
+ $wc('#' + id + '_jGraduate_match_ctr').change(function () {
+ showFocus = !this.checked;
+ focusCoord.toggle(showFocus);
+ attrInput.fx.val('');
+ attrInput.fy.val('');
+ const grd = curGradient;
+ if (!showFocus) {
+ lastfx = grd.getAttribute('fx');
+ lastfy = grd.getAttribute('fy');
+ grd.removeAttribute('fx');
+ grd.removeAttribute('fy');
+ } else {
+ const fX = lastfx || 0.5;
+ const fY = lastfy || 0.5;
+ grd.setAttribute('fx', fX);
+ grd.setAttribute('fy', fY);
+ attrInput.fx.val(fX);
+ attrInput.fy.val(fY);
}
-
- const sliders = {
- radius: {
- handle: '#' + id + '_jGraduate_RadiusArrows',
- input: '#' + id + '_jGraduate_RadiusInput',
- val: (curGradient.getAttribute('r') || 0.5) * 100
- },
- opacity: {
- handle: '#' + id + '_jGraduate_OpacArrows',
- input: '#' + id + '_jGraduate_OpacInput',
- val: $this.paint.alpha || 100
- },
- ellip: {
- handle: '#' + id + '_jGraduate_EllipArrows',
- input: '#' + id + '_jGraduate_EllipInput',
- val: ellipVal
- },
- angle: {
- handle: '#' + id + '_jGraduate_AngleArrows',
- input: '#' + id + '_jGraduate_AngleInput',
- val: angleVal
- }
- };
-
- $.each(sliders, function (type, data) {
- const handle = $(data.handle);
- handle.mousedown(function (evt) {
- const parent = handle.parent();
- slider = {
- type,
- elem: handle,
- input: $(data.input),
- parent,
- offset: parent.offset()
- };
- $win.mousemove(dragSlider).mouseup(stopSlider);
- evt.preventDefault();
- });
-
- $(data.input).val(data.val).change(function () {
- const isRad = curType === 'radialGradient';
- let val = Number(this.value);
- let xpos = 0;
- switch (type) {
- case 'radius':
- if (isRad) curGradient.setAttribute('r', val / 100);
- xpos = (((val / 100) ** (1 / 2.5)) / 2) * SLIDERW;
- break;
-
- case 'opacity':
- $this.paint.alpha = val;
- previewRect.setAttribute('fill-opacity', val / 100);
- xpos = val * (SLIDERW / 100);
- break;
-
- case 'ellip':
- scaleX = scaleY = 1;
- if (val === 0) {
- xpos = SLIDERW * 0.5;
- break;
- }
- if (val > 99.5) val = 99.5;
- if (val > 0) {
- scaleY = 1 - (val / 100);
- } else {
- scaleX = -(val / 100) - 1;
- }
-
- xpos = SLIDERW * ((val + 100) / 2) / 100;
- if (isRad) xform();
- break;
-
- case 'angle':
- angle = val;
- xpos = angle / 180;
- xpos += 0.5;
- xpos *= SLIDERW;
- if (isRad) xform();
- }
- if (xpos > SLIDERW) {
- xpos = SLIDERW;
- } else if (xpos < 0) {
- xpos = 0;
- }
- handle.css({'margin-left': xpos - 5});
- }).change();
- });
-
- const dragSlider = function (evt) {
- setSlider(evt);
- evt.preventDefault();
- };
-
- const stopSlider = function (evt) {
- $win.unbind('mousemove', dragSlider).unbind('mouseup', stopSlider);
- slider = null;
- };
-
- // --------------
- let thisAlpha = ($this.paint.alpha * 255 / 100).toString(16);
- while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
- thisAlpha = thisAlpha.split('.')[0];
- color = $this.paint.solidColor === 'none' ? '' : $this.paint.solidColor + thisAlpha;
-
- if (!isSolid) {
- color = stops[0].getAttribute('stop-color');
- }
-
- // This should be done somewhere else, probably
- $.extend(jPickerDefaults.window, {
- alphaSupport: true, effects: {type: 'show', speed: 0}
- });
-
- jPickerMethod(colPicker,
- {
- window: {title: $settings.window.pickerTitle},
- images: {clientPath: $settings.images.clientPath},
- color: {active: color, alphaSupport: true}
- },
- function (clr) {
- $this.paint.type = 'solidColor';
- $this.paint.alpha = clr.val('ahex') ? Math.round((clr.val('a') / 255) * 100) : 100;
- $this.paint.solidColor = clr.val('hex') ? clr.val('hex') : 'none';
- $this.paint.radialGradient = null;
- okClicked();
- },
- null,
- function () { cancelClicked(); }
- );
- // JFH !!!!
- // const tabs = $wc(idref + ' .jGraduate_tabs li');
- const tabs = $wc('.jGraduate_tabs li');
- tabs.click(function () {
- tabs.removeClass('jGraduate_tab_current');
- $(this).addClass('jGraduate_tab_current');
- $wc(idref + ' > div').hide();
- const type = $(this).attr('data-type');
- $wc(idref + ' .jGraduate_gradPick').show();
- if (type === 'rg' || type === 'lg') {
- // Show/hide appropriate fields
- $wc('.jGraduate_' + type + '_field').show();
- $wc('.jGraduate_' + (type === 'lg' ? 'rg' : 'lg') + '_field').hide();
-
- $wc('#' + id + '_jgraduate_rect')[0]
- .setAttribute('fill', 'url(#' + id + '_' + type + '_jgraduate_grad)');
-
- // Copy stops
-
- curType = type === 'lg' ? 'linearGradient' : 'radialGradient';
-
- $wc('#' + id + '_jGraduate_OpacInput').val($this.paint.alpha).change();
-
- const newGrad = $wc('#' + id + '_' + type + '_jgraduate_grad')[0];
-
- if (curGradient !== newGrad) {
- const curStops = $(curGradient).find('stop');
- $(newGrad).empty().append(curStops);
- curGradient = newGrad;
- const sm = spreadMethodOpt.val();
- curGradient.setAttribute('spreadMethod', sm);
- }
- showFocus = type === 'rg' && curGradient.getAttribute('fx') !== null && !(cx === fx && cy === fy);
- $wc('#' + id + '_jGraduate_focusCoord').toggle(showFocus);
- if (showFocus) {
- $wc('#' + id + '_jGraduate_match_ctr')[0].checked = false;
- }
- } else {
- $wc(idref + ' .jGraduate_gradPick').hide();
- $wc(idref + ' .jGraduate_colPick').show();
- }
- });
- $wc(idref + ' > div').hide();
- tabs.removeClass('jGraduate_tab_current');
- let tab;
- switch ($this.paint.type) {
- case 'linearGradient':
- tab = $wc(idref + ' .jGraduate_tab_lingrad');
- break;
- case 'radialGradient':
- tab = $wc(idref + ' .jGraduate_tab_radgrad');
- break;
- default:
- tab = $wc(idref + ' .jGraduate_tab_color');
- break;
- }
- $this.show();
-
- // jPicker will try to show after a 0ms timeout, so need to fire this after that
- setTimeout(() => {
- tab.addClass('jGraduate_tab_current').click();
- }, 10);
});
+
+ stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
+ numstops = stops.length;
+ // if there are not at least two stops, then
+ if (numstops < 2) {
+ while (numstops < 2) {
+ curGradient.append(document.createElementNS(ns.svg, 'stop'));
+ ++numstops;
+ }
+ stops = curGradient.getElementsByTagNameNS(ns.svg, 'stop');
+ }
+
+ let slider;
+
+ const setSlider = function (e) {
+ const {offset: {left}} = slider;
+ const div = slider.parent;
+ let x = (e.pageX - left - Number.parseInt(div.css('border-left-width')));
+ if (x > SLIDERW) x = SLIDERW;
+ if (x <= 0) x = 0;
+ const posx = x - 5;
+ x /= SLIDERW;
+
+ switch (slider.type) {
+ case 'radius':
+ x = (x * 2) ** 2.5;
+ if (x > 0.98 && x < 1.02) x = 1;
+ if (x <= 0.01) x = 0.01;
+ curGradient.setAttribute('r', x);
+ break;
+ case 'opacity':
+ $this.paint.alpha = Number.parseInt(x * 100);
+ previewRect.setAttribute('fill-opacity', x);
+ break;
+ case 'ellip':
+ scaleX = 1;
+ scaleY = 1;
+ if (x < 0.5) {
+ x /= 0.5; // 0.001
+ scaleX = x <= 0 ? 0.01 : x;
+ } else if (x > 0.5) {
+ x /= 0.5; // 2
+ x = 2 - x;
+ scaleY = x <= 0 ? 0.01 : x;
+ }
+ xform();
+ x -= 1;
+ if (scaleY === x + 1) {
+ x = Math.abs(x);
+ }
+ break;
+ case 'angle':
+ x -= 0.5;
+ angle = x *= 180;
+ xform();
+ x /= 100;
+ break;
+ }
+ slider.elem.css({'margin-left': posx});
+ x = Math.round(x * 100);
+ slider.input.val(x);
+ };
+
+ let ellipVal = 0, angleVal = 0;
+
+ if (curType === 'radialGradient') {
+ const tlist = curGradient.gradientTransform.baseVal;
+ if (tlist.numberOfItems === 2) {
+ const t = tlist.getItem(0);
+ const s = tlist.getItem(1);
+ if (t.type === 2 && s.type === 3) {
+ const m = s.matrix;
+ if (m.a !== 1) {
+ ellipVal = Math.round(-(1 - m.a) * 100);
+ } else if (m.d !== 1) {
+ ellipVal = Math.round((1 - m.d) * 100);
+ }
+ }
+ } else if (tlist.numberOfItems === 3) {
+ // Assume [R][T][S]
+ const r = tlist.getItem(0);
+ const t = tlist.getItem(1);
+ const s = tlist.getItem(2);
+
+ if (r.type === 4 &&
+ t.type === 2 &&
+ s.type === 3
+ ) {
+ angleVal = Math.round(r.angle);
+ const m = s.matrix;
+ if (m.a !== 1) {
+ ellipVal = Math.round(-(1 - m.a) * 100);
+ } else if (m.d !== 1) {
+ ellipVal = Math.round((1 - m.d) * 100);
+ }
+ }
+ }
+ }
+
+ const sliders = {
+ radius: {
+ handle: '#' + id + '_jGraduate_RadiusArrows',
+ input: '#' + id + '_jGraduate_RadiusInput',
+ val: (curGradient.getAttribute('r') || 0.5) * 100
+ },
+ opacity: {
+ handle: '#' + id + '_jGraduate_OpacArrows',
+ input: '#' + id + '_jGraduate_OpacInput',
+ val: $this.paint.alpha || 100
+ },
+ ellip: {
+ handle: '#' + id + '_jGraduate_EllipArrows',
+ input: '#' + id + '_jGraduate_EllipInput',
+ val: ellipVal
+ },
+ angle: {
+ handle: '#' + id + '_jGraduate_AngleArrows',
+ input: '#' + id + '_jGraduate_AngleInput',
+ val: angleVal
+ }
+ };
+
+ $.each(sliders, function (type, data) {
+ const handle = $(data.handle);
+ handle.mousedown(function (evt) {
+ const parent = handle.parent();
+ slider = {
+ type,
+ elem: handle,
+ input: $(data.input),
+ parent,
+ offset: parent.offset()
+ };
+ $win.mousemove(dragSlider).mouseup(stopSlider);
+ evt.preventDefault();
+ });
+
+ $(data.input).val(data.val).change(function () {
+ const isRad = curType === 'radialGradient';
+ let val = Number(this.value);
+ let xpos = 0;
+ switch (type) {
+ case 'radius':
+ if (isRad) curGradient.setAttribute('r', val / 100);
+ xpos = (((val / 100) ** (1 / 2.5)) / 2) * SLIDERW;
+ break;
+
+ case 'opacity':
+ $this.paint.alpha = val;
+ previewRect.setAttribute('fill-opacity', val / 100);
+ xpos = val * (SLIDERW / 100);
+ break;
+
+ case 'ellip':
+ scaleX = scaleY = 1;
+ if (val === 0) {
+ xpos = SLIDERW * 0.5;
+ break;
+ }
+ if (val > 99.5) val = 99.5;
+ if (val > 0) {
+ scaleY = 1 - (val / 100);
+ } else {
+ scaleX = -(val / 100) - 1;
+ }
+
+ xpos = SLIDERW * ((val + 100) / 2) / 100;
+ if (isRad) xform();
+ break;
+
+ case 'angle':
+ angle = val;
+ xpos = angle / 180;
+ xpos += 0.5;
+ xpos *= SLIDERW;
+ if (isRad) xform();
+ }
+ if (xpos > SLIDERW) {
+ xpos = SLIDERW;
+ } else if (xpos < 0) {
+ xpos = 0;
+ }
+ handle.css({'margin-left': xpos - 5});
+ }).change();
+ });
+
+ const dragSlider = function (evt) {
+ setSlider(evt);
+ evt.preventDefault();
+ };
+
+ const stopSlider = function (evt) {
+ $win.unbind('mousemove', dragSlider).unbind('mouseup', stopSlider);
+ slider = null;
+ };
+
+ // --------------
+ let thisAlpha = ($this.paint.alpha * 255 / 100).toString(16);
+ while (thisAlpha.length < 2) { thisAlpha = '0' + thisAlpha; }
+ thisAlpha = thisAlpha.split('.')[0];
+ color = $this.paint.solidColor === 'none' ? '' : $this.paint.solidColor + thisAlpha;
+
+ if (!isSolid) {
+ color = stops[0].getAttribute('stop-color');
+ }
+
+ // This should be done somewhere else, probably
+ $.extend(jPickerDefaults.window, {
+ alphaSupport: true, effects: {type: 'show', speed: 0}
+ });
+
+ jPickerMethod(
+ colPicker,
+ {
+ window: {title: $settings.window.pickerTitle},
+ images: {clientPath: $settings.images.clientPath},
+ color: {active: color, alphaSupport: true}
+ },
+ function (clr) {
+ $this.paint.type = 'solidColor';
+ $this.paint.alpha = clr.val('ahex') ? Math.round((clr.val('a') / 255) * 100) : 100;
+ $this.paint.solidColor = clr.val('hex') ? clr.val('hex') : 'none';
+ $this.paint.radialGradient = null;
+ okClicked();
+ },
+ null,
+ function () { cancelClicked(); }
+ );
+ // JFH !!!!
+ // const tabs = $wc(idref + ' .jGraduate_tabs li');
+ const tabs = $wc('.jGraduate_tabs li');
+ tabs.click(function () {
+ tabs.removeClass('jGraduate_tab_current');
+ $(this).addClass('jGraduate_tab_current');
+ $wc(idref + ' > div').hide();
+ const type = $(this).attr('data-type');
+ $wc(idref + ' .jGraduate_gradPick').show();
+ if (type === 'rg' || type === 'lg') {
+ // Show/hide appropriate fields
+ $wc('.jGraduate_' + type + '_field').show();
+ $wc('.jGraduate_' + (type === 'lg' ? 'rg' : 'lg') + '_field').hide();
+
+ $wc('#' + id + '_jgraduate_rect')[0]
+ .setAttribute('fill', 'url(#' + id + '_' + type + '_jgraduate_grad)');
+
+ // Copy stops
+
+ curType = type === 'lg' ? 'linearGradient' : 'radialGradient';
+
+ $wc('#' + id + '_jGraduate_OpacInput').val($this.paint.alpha).change();
+
+ const newGrad = $wc('#' + id + '_' + type + '_jgraduate_grad')[0];
+
+ if (curGradient !== newGrad) {
+ const curStops = $(curGradient).find('stop');
+ $(newGrad).empty().append(curStops);
+ curGradient = newGrad;
+ const sm = spreadMethodOpt.getAttribute('value');
+ curGradient.setAttribute('spreadMethod', sm);
+ }
+ showFocus = type === 'rg' && curGradient.getAttribute('fx') !== null && !(cx === fx && cy === fy);
+ $wc('#' + id + '_jGraduate_focusCoord').toggle(showFocus);
+ if (showFocus) {
+ $wc('#' + id + '_jGraduate_match_ctr')[0].checked = false;
+ }
+ } else {
+ $wc(idref + ' .jGraduate_gradPick').hide();
+ $wc(idref + ' .jGraduate_colPick').show();
+ }
+ });
+ $wc(idref + ' > div').hide();
+ tabs.removeClass('jGraduate_tab_current');
+ let tab;
+ switch ($this.paint.type) {
+ case 'linearGradient':
+ tab = $wc(idref + ' .jGraduate_tab_lingrad');
+ break;
+ case 'radialGradient':
+ tab = $wc(idref + ' .jGraduate_tab_radgrad');
+ break;
+ default:
+ tab = $wc(idref + ' .jGraduate_tab_color');
+ break;
+ }
+ $this.style.display = 'block';
+
+ // jPicker will try to show after a 0ms timeout, so need to fire this after that
+ setTimeout(() => {
+ tab.addClass('jGraduate_tab_current').click();
+ }, 10);
+ // });
}
// return $;
diff --git a/src/editor/components/jgraduate/jQuery.jPicker.js b/src/editor/components/jgraduate/jQuery.jPicker.js
index 808abc65..9c64240e 100755
--- a/src/editor/components/jgraduate/jQuery.jPicker.js
+++ b/src/editor/components/jgraduate/jQuery.jPicker.js
@@ -606,1037 +606,1068 @@ const {Color, List, ColorMethods} = jPicker; // local copies for YUI compressor
* @returns {external:jQuery}
*/
export function jPickerMethod (elem, options, commitCallback, liveCallback, cancelCallback) {
- return elem.each(function () {
- const that = this,
- settings = $.extend(true, {}, jPickerDefaults, options); // local copies for YUI compressor
- if ($(that).get(0).nodeName.toLowerCase() === 'input') { // Add color picker icon if binding to an input element and bind the events to the input
- $.extend(true, settings, {
- window: {
- bindToInput: true,
- expandable: true,
- input: $(that)
- }
- });
- if ($(that).val() === '') {
- settings.color.active = new Color({hex: null});
- settings.color.current = new Color({hex: null});
- } else if (ColorMethods.validateHex($(that).val())) {
- settings.color.active = new Color({hex: $(that).val(), a: settings.color.active.val('a')});
- settings.color.current = new Color({hex: $(that).val(), a: settings.color.active.val('a')});
+ // return elem.each(function () {
+ const that = elem,
+ settings = $.extend(true, {}, jPickerDefaults, options); // local copies for YUI compressor
+ if ($(that).get(0).nodeName.toLowerCase() === 'input') { // Add color picker icon if binding to an input element and bind the events to the input
+ $.extend(true, settings, {
+ window: {
+ bindToInput: true,
+ expandable: true,
+ input: $(that)
}
+ });
+ if ($(that).val() === '') {
+ settings.color.active = new Color({hex: null});
+ settings.color.current = new Color({hex: null});
+ } else if (ColorMethods.validateHex($(that).val())) {
+ settings.color.active = new Color({hex: $(that).val(), a: settings.color.active.val('a')});
+ settings.color.current = new Color({hex: $(that).val(), a: settings.color.active.val('a')});
}
- if (settings.window.expandable) {
- $(that).after('
');
- } else {
- settings.window.liveUpdate = false; // Basic control binding for inline use - You will need to override the liveCallback or commitCallback function to retrieve results
- }
- const isLessThanIE7 = Number.parseFloat(navigator.appVersion.split('MSIE')[1]) < 7 && document.body.filters; // needed to run the AlphaImageLoader function for IE6
- // set color mode and update visuals for the new color mode
- /**
- *
- * @param {"h"|"s"|"v"|"r"|"g"|"b"|"a"} colorMode
- * @throws {Error} Invalid mode
- * @returns {void}
- */
- function setColorMode (colorMode) {
- const {active} = color, // local copies for YUI compressor
- // {clientPath} = images,
- hex = active.val('hex');
- let rgbMap, rgbBar;
- settings.color.mode = colorMode;
- switch (colorMode) {
- case 'h':
- setTimeout(function () {
- setBG.call(that, colorMapDiv, 'transparent');
- setImgLoc.call(that, colorMapL1, 0);
- setAlpha.call(that, colorMapL1, 100);
- setImgLoc.call(that, colorMapL2, 260);
- setAlpha.call(that, colorMapL2, 100);
- setBG.call(that, colorBarDiv, 'transparent');
- setImgLoc.call(that, colorBarL1, 0);
- setAlpha.call(that, colorBarL1, 100);
- setImgLoc.call(that, colorBarL2, 260);
- setAlpha.call(that, colorBarL2, 100);
- setImgLoc.call(that, colorBarL3, 260);
- setAlpha.call(that, colorBarL3, 100);
- setImgLoc.call(that, colorBarL4, 260);
- setAlpha.call(that, colorBarL4, 100);
- setImgLoc.call(that, colorBarL6, 260);
- setAlpha.call(that, colorBarL6, 100);
- }, 0);
- colorMap.range('all', {minX: 0, maxX: 100, minY: 0, maxY: 100});
- colorBar.range('rangeY', {minY: 0, maxY: 360});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('s'), y: 100 - active.val('v')}, colorMap);
- colorBar.val('y', 360 - active.val('h'), colorBar);
- break;
- case 's':
- setTimeout(function () {
- setBG.call(that, colorMapDiv, 'transparent');
- setImgLoc.call(that, colorMapL1, -260);
- setImgLoc.call(that, colorMapL2, -520);
- setImgLoc.call(that, colorBarL1, -260);
- setImgLoc.call(that, colorBarL2, -520);
- setImgLoc.call(that, colorBarL6, 260);
- setAlpha.call(that, colorBarL6, 100);
- }, 0);
- colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
- colorBar.range('rangeY', {minY: 0, maxY: 100});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('v')}, colorMap);
- colorBar.val('y', 100 - active.val('s'), colorBar);
- break;
- case 'v':
- setTimeout(function () {
- setBG.call(that, colorMapDiv, '000000');
- setImgLoc.call(that, colorMapL1, -780);
- setImgLoc.call(that, colorMapL2, 260);
- setBG.call(that, colorBarDiv, hex);
- setImgLoc.call(that, colorBarL1, -520);
- setImgLoc.call(that, colorBarL2, 260);
- setAlpha.call(that, colorBarL2, 100);
- setImgLoc.call(that, colorBarL6, 260);
- setAlpha.call(that, colorBarL6, 100);
- }, 0);
- colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
- colorBar.range('rangeY', {minY: 0, maxY: 100});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('s')}, colorMap);
- colorBar.val('y', 100 - active.val('v'), colorBar);
- break;
- case 'r':
- rgbMap = -1040;
- rgbBar = -780;
- colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
- colorBar.range('rangeY', {minY: 0, maxY: 255});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('b'), y: 255 - active.val('g')}, colorMap);
- colorBar.val('y', 255 - active.val('r'), colorBar);
- break;
- case 'g':
- rgbMap = -1560;
- rgbBar = -1820;
- colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
- colorBar.range('rangeY', {minY: 0, maxY: 255});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('b'), y: 255 - active.val('r')}, colorMap);
- colorBar.val('y', 255 - active.val('g'), colorBar);
- break;
- case 'b':
- rgbMap = -2080;
- rgbBar = -2860;
- colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
- colorBar.range('rangeY', {minY: 0, maxY: 255});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('r'), y: 255 - active.val('g')}, colorMap);
- colorBar.val('y', 255 - active.val('b'), colorBar);
- break;
- case 'a':
- setTimeout(function () {
- setBG.call(that, colorMapDiv, 'transparent');
- setImgLoc.call(that, colorMapL1, -260);
- setImgLoc.call(that, colorMapL2, -520);
- setImgLoc.call(that, colorBarL1, 260);
- setImgLoc.call(that, colorBarL2, 260);
- setAlpha.call(that, colorBarL2, 100);
- setImgLoc.call(that, colorBarL6, 0);
- setAlpha.call(that, colorBarL6, 100);
- }, 0);
- colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
- colorBar.range('rangeY', {minY: 0, maxY: 255});
- if (isNullish(active.val('ahex'))) break;
- colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('v')}, colorMap);
- colorBar.val('y', 255 - active.val('a'), colorBar);
- break;
- default:
- throw new Error('Invalid Mode');
- }
- switch (colorMode) {
- case 'h':
- break;
- case 's':
- case 'v':
- case 'a':
- setTimeout(function () {
- setAlpha.call(that, colorMapL1, 100);
- setAlpha.call(that, colorBarL1, 100);
- setImgLoc.call(that, colorBarL3, 260);
- setAlpha.call(that, colorBarL3, 100);
- setImgLoc.call(that, colorBarL4, 260);
- setAlpha.call(that, colorBarL4, 100);
- }, 0);
- break;
- case 'r':
- case 'g':
- case 'b':
- setTimeout(function () {
- setBG.call(that, colorMapDiv, 'transparent');
- setBG.call(that, colorBarDiv, 'transparent');
- setAlpha.call(that, colorBarL1, 100);
- setAlpha.call(that, colorMapL1, 100);
- setImgLoc.call(that, colorMapL1, rgbMap);
- setImgLoc.call(that, colorMapL2, rgbMap - 260);
- setImgLoc.call(that, colorBarL1, rgbBar - 780);
- setImgLoc.call(that, colorBarL2, rgbBar - 520);
- setImgLoc.call(that, colorBarL3, rgbBar);
- setImgLoc.call(that, colorBarL4, rgbBar - 260);
- setImgLoc.call(that, colorBarL6, 260);
- setAlpha.call(that, colorBarL6, 100);
- }, 0);
- break;
- }
- if (isNullish(active.val('ahex'))) return;
- activeColorChanged.call(that, active);
- }
- /**
- * Update color when user changes text values.
- * @param {external:jQuery} ui
- * @param {?module:jPicker.Slider} context
- * @returns {void}
- */
- function activeColorChanged (ui, context) {
- if (isNullish(context) || (context !== colorBar && context !== colorMap)) positionMapAndBarArrows.call(that, ui, context);
+ }
+ if (settings.window.expandable) {
+ $(that).after('
');
+ } else {
+ settings.window.liveUpdate = false; // Basic control binding for inline use - You will need to override the liveCallback or commitCallback function to retrieve results
+ }
+ const isLessThanIE7 = Number.parseFloat(navigator.appVersion.split('MSIE')[1]) < 7 && document.body.filters; // needed to run the AlphaImageLoader function for IE6
+ // set color mode and update visuals for the new color mode
+ /**
+ *
+ * @param {"h"|"s"|"v"|"r"|"g"|"b"|"a"} colorMode
+ * @throws {Error} Invalid mode
+ * @returns {void}
+ */
+ function setColorMode (colorMode) {
+ const {active} = color, // local copies for YUI compressor
+ // {clientPath} = images,
+ hex = active.val('hex');
+ let rgbMap, rgbBar;
+ settings.color.mode = colorMode;
+ switch (colorMode) {
+ case 'h':
setTimeout(function () {
- updatePreview.call(that, ui);
- updateMapVisuals.call(that, ui);
- updateBarVisuals.call(that, ui);
+ setBG.call(that, colorMapDiv, 'transparent');
+ setImgLoc.call(that, colorMapL1, 0);
+ setAlpha.call(that, colorMapL1, 100);
+ setImgLoc.call(that, colorMapL2, 260);
+ setAlpha.call(that, colorMapL2, 100);
+ setBG.call(that, colorBarDiv, 'transparent');
+ setImgLoc.call(that, colorBarL1, 0);
+ setAlpha.call(that, colorBarL1, 100);
+ setImgLoc.call(that, colorBarL2, 260);
+ setAlpha.call(that, colorBarL2, 100);
+ setImgLoc.call(that, colorBarL3, 260);
+ setAlpha.call(that, colorBarL3, 100);
+ setImgLoc.call(that, colorBarL4, 260);
+ setAlpha.call(that, colorBarL4, 100);
+ setImgLoc.call(that, colorBarL6, 260);
+ setAlpha.call(that, colorBarL6, 100);
}, 0);
+ colorMap.range('all', {minX: 0, maxX: 100, minY: 0, maxY: 100});
+ colorBar.range('rangeY', {minY: 0, maxY: 360});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('s'), y: 100 - active.val('v')}, colorMap);
+ colorBar.val('y', 360 - active.val('h'), colorBar);
+ break;
+ case 's':
+ setTimeout(function () {
+ setBG.call(that, colorMapDiv, 'transparent');
+ setImgLoc.call(that, colorMapL1, -260);
+ setImgLoc.call(that, colorMapL2, -520);
+ setImgLoc.call(that, colorBarL1, -260);
+ setImgLoc.call(that, colorBarL2, -520);
+ setImgLoc.call(that, colorBarL6, 260);
+ setAlpha.call(that, colorBarL6, 100);
+ }, 0);
+ colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
+ colorBar.range('rangeY', {minY: 0, maxY: 100});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('v')}, colorMap);
+ colorBar.val('y', 100 - active.val('s'), colorBar);
+ break;
+ case 'v':
+ setTimeout(function () {
+ setBG.call(that, colorMapDiv, '000000');
+ setImgLoc.call(that, colorMapL1, -780);
+ setImgLoc.call(that, colorMapL2, 260);
+ setBG.call(that, colorBarDiv, hex);
+ setImgLoc.call(that, colorBarL1, -520);
+ setImgLoc.call(that, colorBarL2, 260);
+ setAlpha.call(that, colorBarL2, 100);
+ setImgLoc.call(that, colorBarL6, 260);
+ setAlpha.call(that, colorBarL6, 100);
+ }, 0);
+ colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
+ colorBar.range('rangeY', {minY: 0, maxY: 100});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('s')}, colorMap);
+ colorBar.val('y', 100 - active.val('v'), colorBar);
+ break;
+ case 'r':
+ rgbMap = -1040;
+ rgbBar = -780;
+ colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
+ colorBar.range('rangeY', {minY: 0, maxY: 255});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('b'), y: 255 - active.val('g')}, colorMap);
+ colorBar.val('y', 255 - active.val('r'), colorBar);
+ break;
+ case 'g':
+ rgbMap = -1560;
+ rgbBar = -1820;
+ colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
+ colorBar.range('rangeY', {minY: 0, maxY: 255});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('b'), y: 255 - active.val('r')}, colorMap);
+ colorBar.val('y', 255 - active.val('g'), colorBar);
+ break;
+ case 'b':
+ rgbMap = -2080;
+ rgbBar = -2860;
+ colorMap.range('all', {minX: 0, maxX: 255, minY: 0, maxY: 255});
+ colorBar.range('rangeY', {minY: 0, maxY: 255});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('r'), y: 255 - active.val('g')}, colorMap);
+ colorBar.val('y', 255 - active.val('b'), colorBar);
+ break;
+ case 'a':
+ setTimeout(function () {
+ setBG.call(that, colorMapDiv, 'transparent');
+ setImgLoc.call(that, colorMapL1, -260);
+ setImgLoc.call(that, colorMapL2, -520);
+ setImgLoc.call(that, colorBarL1, 260);
+ setImgLoc.call(that, colorBarL2, 260);
+ setAlpha.call(that, colorBarL2, 100);
+ setImgLoc.call(that, colorBarL6, 0);
+ setAlpha.call(that, colorBarL6, 100);
+ }, 0);
+ colorMap.range('all', {minX: 0, maxX: 360, minY: 0, maxY: 100});
+ colorBar.range('rangeY', {minY: 0, maxY: 255});
+ if (isNullish(active.val('ahex'))) break;
+ colorMap.val('xy', {x: active.val('h'), y: 100 - active.val('v')}, colorMap);
+ colorBar.val('y', 255 - active.val('a'), colorBar);
+ break;
+ default:
+ throw new Error('Invalid Mode');
}
+ switch (colorMode) {
+ case 'h':
+ break;
+ case 's':
+ case 'v':
+ case 'a':
+ setTimeout(function () {
+ setAlpha.call(that, colorMapL1, 100);
+ setAlpha.call(that, colorBarL1, 100);
+ setImgLoc.call(that, colorBarL3, 260);
+ setAlpha.call(that, colorBarL3, 100);
+ setImgLoc.call(that, colorBarL4, 260);
+ setAlpha.call(that, colorBarL4, 100);
+ }, 0);
+ break;
+ case 'r':
+ case 'g':
+ case 'b':
+ setTimeout(function () {
+ setBG.call(that, colorMapDiv, 'transparent');
+ setBG.call(that, colorBarDiv, 'transparent');
+ setAlpha.call(that, colorBarL1, 100);
+ setAlpha.call(that, colorMapL1, 100);
+ setImgLoc.call(that, colorMapL1, rgbMap);
+ setImgLoc.call(that, colorMapL2, rgbMap - 260);
+ setImgLoc.call(that, colorBarL1, rgbBar - 780);
+ setImgLoc.call(that, colorBarL2, rgbBar - 520);
+ setImgLoc.call(that, colorBarL3, rgbBar);
+ setImgLoc.call(that, colorBarL4, rgbBar - 260);
+ setImgLoc.call(that, colorBarL6, 260);
+ setAlpha.call(that, colorBarL6, 100);
+ }, 0);
+ break;
+ }
+ if (isNullish(active.val('ahex'))) return;
+ activeColorChanged.call(that, active);
+ }
+ /**
+ * Update color when user changes text values.
+ * @param {external:jQuery} ui
+ * @param {?module:jPicker.Slider} context
+ * @returns {void}
+ */
+ function activeColorChanged (ui, context) {
+ if (isNullish(context) || (context !== colorBar && context !== colorMap)) positionMapAndBarArrows.call(that, ui, context);
+ setTimeout(function () {
+ updatePreview.call(that, ui);
+ updateMapVisuals.call(that, ui);
+ updateBarVisuals.call(that, ui);
+ }, 0);
+ }
- /**
- * User has dragged the ColorMap pointer.
- * @param {external:jQuery} ui
- * @param {?module:jPicker.Slider} context
- * @returns {void}
- */
- function mapValueChanged (ui, context) {
- const {active} = color;
- if (context !== colorMap && isNullish(active.val())) return;
- const xy = ui.val('all');
- switch (settings.color.mode) {
- case 'h':
- active.val('sv', {s: xy.x, v: 100 - xy.y}, context);
- break;
- case 's':
- case 'a':
- active.val('hv', {h: xy.x, v: 100 - xy.y}, context);
- break;
- case 'v':
- active.val('hs', {h: xy.x, s: 100 - xy.y}, context);
- break;
- case 'r':
- active.val('gb', {g: 255 - xy.y, b: xy.x}, context);
- break;
- case 'g':
- active.val('rb', {r: 255 - xy.y, b: xy.x}, context);
- break;
- case 'b':
- active.val('rg', {r: xy.x, g: 255 - xy.y}, context);
- break;
- }
+ /**
+ * User has dragged the ColorMap pointer.
+ * @param {external:jQuery} ui
+ * @param {?module:jPicker.Slider} context
+ * @returns {void}
+ */
+ function mapValueChanged (ui, context) {
+ const {active} = color;
+ if (context !== colorMap && isNullish(active.val())) return;
+ const xy = ui.val('all');
+ switch (settings.color.mode) {
+ case 'h':
+ active.val('sv', {s: xy.x, v: 100 - xy.y}, context);
+ break;
+ case 's':
+ case 'a':
+ active.val('hv', {h: xy.x, v: 100 - xy.y}, context);
+ break;
+ case 'v':
+ active.val('hs', {h: xy.x, s: 100 - xy.y}, context);
+ break;
+ case 'r':
+ active.val('gb', {g: 255 - xy.y, b: xy.x}, context);
+ break;
+ case 'g':
+ active.val('rb', {r: 255 - xy.y, b: xy.x}, context);
+ break;
+ case 'b':
+ active.val('rg', {r: xy.x, g: 255 - xy.y}, context);
+ break;
}
+ }
- /**
- * User has dragged the ColorBar slider.
- * @param {external:jQuery} ui
- * @param {?module:jPicker.Slider} context
- * @returns {void}
- */
- function colorBarValueChanged (ui, context) {
- const {active} = color;
- if (context !== colorBar && isNullish(active.val())) return;
- switch (settings.color.mode) {
- case 'h':
- active.val('h', {h: 360 - ui.val('y')}, context);
- break;
- case 's':
- active.val('s', {s: 100 - ui.val('y')}, context);
- break;
- case 'v':
- active.val('v', {v: 100 - ui.val('y')}, context);
- break;
- case 'r':
- active.val('r', {r: 255 - ui.val('y')}, context);
- break;
- case 'g':
- active.val('g', {g: 255 - ui.val('y')}, context);
- break;
- case 'b':
- active.val('b', {b: 255 - ui.val('y')}, context);
- break;
- case 'a':
- active.val('a', 255 - ui.val('y'), context);
- break;
- }
+ /**
+ * User has dragged the ColorBar slider.
+ * @param {external:jQuery} ui
+ * @param {?module:jPicker.Slider} context
+ * @returns {void}
+ */
+ function colorBarValueChanged (ui, context) {
+ const {active} = color;
+ if (context !== colorBar && isNullish(active.val())) return;
+ switch (settings.color.mode) {
+ case 'h':
+ active.val('h', {h: 360 - ui.val('y')}, context);
+ break;
+ case 's':
+ active.val('s', {s: 100 - ui.val('y')}, context);
+ break;
+ case 'v':
+ active.val('v', {v: 100 - ui.val('y')}, context);
+ break;
+ case 'r':
+ active.val('r', {r: 255 - ui.val('y')}, context);
+ break;
+ case 'g':
+ active.val('g', {g: 255 - ui.val('y')}, context);
+ break;
+ case 'b':
+ active.val('b', {b: 255 - ui.val('y')}, context);
+ break;
+ case 'a':
+ active.val('a', 255 - ui.val('y'), context);
+ break;
}
+ }
- /**
- * Position map and bar arrows to match current color.
- * @param {external:jQuery} ui
- * @param {?module:jPicker.Slider} context
- * @returns {void}
- */
- function positionMapAndBarArrows (ui, context) {
- if (context !== colorMap) {
- switch (settings.color.mode) {
- case 'h': {
- const sv = ui.val('sv');
- colorMap.val('xy', {x: !isNullish(sv) ? sv.s : 100, y: 100 - (!isNullish(sv) ? sv.v : 100)}, context);
- break;
- } case 's':
- // Fall through
- case 'a': {
- const hv = ui.val('hv');
- colorMap.val('xy', {x: (hv && hv.h) || 0, y: 100 - (!isNullish(hv) ? hv.v : 100)}, context);
- break;
- } case 'v': {
- const hs = ui.val('hs');
- colorMap.val('xy', {x: (hs && hs.h) || 0, y: 100 - (!isNullish(hs) ? hs.s : 100)}, context);
- break;
- } case 'r': {
- const bg = ui.val('bg');
- colorMap.val('xy', {x: (bg && bg.b) || 0, y: 255 - ((bg && bg.g) || 0)}, context);
- break;
- } case 'g': {
- const br = ui.val('br');
- colorMap.val('xy', {x: (br && br.b) || 0, y: 255 - ((br && br.r) || 0)}, context);
- break;
- } case 'b': {
- const rg = ui.val('rg');
- colorMap.val('xy', {x: (rg && rg.r) || 0, y: 255 - ((rg && rg.g) || 0)}, context);
- break;
- }
- }
- }
- if (context !== colorBar) {
- switch (settings.color.mode) {
- case 'h':
- colorBar.val('y', 360 - (ui.val('h') || 0), context);
- break;
- case 's': {
- const s = ui.val('s');
- colorBar.val('y', 100 - (!isNullish(s) ? s : 100), context);
- break;
- } case 'v': {
- const v = ui.val('v');
- colorBar.val('y', 100 - (!isNullish(v) ? v : 100), context);
- break;
- } case 'r':
- colorBar.val('y', 255 - (ui.val('r') || 0), context);
- break;
- case 'g':
- colorBar.val('y', 255 - (ui.val('g') || 0), context);
- break;
- case 'b':
- colorBar.val('y', 255 - (ui.val('b') || 0), context);
- break;
- case 'a': {
- const a = ui.val('a');
- colorBar.val('y', 255 - (!isNullish(a) ? a : 255), context);
- break;
- }
- }
- }
- }
- /**
- * @param {external:jQuery} ui
- * @returns {void}
- */
- function updatePreview (ui) {
- try {
- const all = ui.val('all');
- activePreview.css({backgroundColor: (all && '#' + all.hex) || 'transparent'});
- setAlpha.call(that, activePreview, (all && toFixedNumeric((all.a * 100) / 255, 4)) || 0);
- } catch (e) {}
- }
- /**
- * @param {external:jQuery} ui
- * @returns {void}
- */
- function updateMapVisuals (ui) {
+ /**
+ * Position map and bar arrows to match current color.
+ * @param {external:jQuery} ui
+ * @param {?module:jPicker.Slider} context
+ * @returns {void}
+ */
+ function positionMapAndBarArrows (ui, context) {
+ if (context !== colorMap) {
switch (settings.color.mode) {
- case 'h':
- setBG.call(that, colorMapDiv, new Color({h: ui.val('h') || 0, s: 100, v: 100}).val('hex'));
+ case 'h': {
+ const sv = ui.val('sv');
+ colorMap.val('xy', {x: !isNullish(sv) ? sv.s : 100, y: 100 - (!isNullish(sv) ? sv.v : 100)}, context);
break;
- case 's':
+ } case 's':
+ // Fall through
case 'a': {
+ const hv = ui.val('hv');
+ colorMap.val('xy', {x: (hv && hv.h) || 0, y: 100 - (!isNullish(hv) ? hv.v : 100)}, context);
+ break;
+ } case 'v': {
+ const hs = ui.val('hs');
+ colorMap.val('xy', {x: (hs && hs.h) || 0, y: 100 - (!isNullish(hs) ? hs.s : 100)}, context);
+ break;
+ } case 'r': {
+ const bg = ui.val('bg');
+ colorMap.val('xy', {x: (bg && bg.b) || 0, y: 255 - ((bg && bg.g) || 0)}, context);
+ break;
+ } case 'g': {
+ const br = ui.val('br');
+ colorMap.val('xy', {x: (br && br.b) || 0, y: 255 - ((br && br.r) || 0)}, context);
+ break;
+ } case 'b': {
+ const rg = ui.val('rg');
+ colorMap.val('xy', {x: (rg && rg.r) || 0, y: 255 - ((rg && rg.g) || 0)}, context);
+ break;
+ }
+ }
+ }
+ if (context !== colorBar) {
+ switch (settings.color.mode) {
+ case 'h':
+ colorBar.val('y', 360 - (ui.val('h') || 0), context);
+ break;
+ case 's': {
const s = ui.val('s');
- setAlpha.call(that, colorMapL2, 100 - (!isNullish(s) ? s : 100));
+ colorBar.val('y', 100 - (!isNullish(s) ? s : 100), context);
break;
} case 'v': {
const v = ui.val('v');
- setAlpha.call(that, colorMapL1, !isNullish(v) ? v : 100);
+ colorBar.val('y', 100 - (!isNullish(v) ? v : 100), context);
break;
} case 'r':
- setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('r') || 0) / 255 * 100, 4));
+ colorBar.val('y', 255 - (ui.val('r') || 0), context);
break;
case 'g':
- setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('g') || 0) / 255 * 100, 4));
+ colorBar.val('y', 255 - (ui.val('g') || 0), context);
break;
case 'b':
- setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('b') || 0) / 255 * 100));
+ colorBar.val('y', 255 - (ui.val('b') || 0), context);
+ break;
+ case 'a': {
+ const a = ui.val('a');
+ colorBar.val('y', 255 - (!isNullish(a) ? a : 255), context);
break;
}
+ }
+ }
+ }
+ /**
+ * @param {external:jQuery} ui
+ * @returns {void}
+ */
+ function updatePreview (ui) {
+ try {
+ const all = ui.val('all');
+ activePreview.css({backgroundColor: (all && '#' + all.hex) || 'transparent'});
+ setAlpha.call(that, activePreview, (all && toFixedNumeric((all.a * 100) / 255, 4)) || 0);
+ } catch (e) {}
+ }
+ /**
+ * @param {external:jQuery} ui
+ * @returns {void}
+ */
+ function updateMapVisuals (ui) {
+ switch (settings.color.mode) {
+ case 'h':
+ setBG.call(that, colorMapDiv, new Color({h: ui.val('h') || 0, s: 100, v: 100}).val('hex'));
+ break;
+ case 's':
+ case 'a': {
+ const s = ui.val('s');
+ setAlpha.call(that, colorMapL2, 100 - (!isNullish(s) ? s : 100));
+ break;
+ } case 'v': {
+ const v = ui.val('v');
+ setAlpha.call(that, colorMapL1, !isNullish(v) ? v : 100);
+ break;
+ } case 'r':
+ setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('r') || 0) / 255 * 100, 4));
+ break;
+ case 'g':
+ setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('g') || 0) / 255 * 100, 4));
+ break;
+ case 'b':
+ setAlpha.call(that, colorMapL2, toFixedNumeric((ui.val('b') || 0) / 255 * 100));
+ break;
+ }
+ const a = ui.val('a');
+ setAlpha.call(that, colorMapL3, toFixedNumeric(((255 - (a || 0)) * 100) / 255, 4));
+ }
+ /**
+ * @param {external:jQuery} ui
+ * @returns {void}
+ */
+ function updateBarVisuals (ui) {
+ switch (settings.color.mode) {
+ case 'h': {
const a = ui.val('a');
- setAlpha.call(that, colorMapL3, toFixedNumeric(((255 - (a || 0)) * 100) / 255, 4));
- }
- /**
- * @param {external:jQuery} ui
- * @returns {void}
- */
- function updateBarVisuals (ui) {
- switch (settings.color.mode) {
- case 'h': {
- const a = ui.val('a');
- setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - (a || 0)) * 100) / 255, 4));
- break;
- } case 's': {
- const hva = ui.val('hva'),
- saturatedColor = new Color({h: (hva && hva.h) || 0, s: 100, v: !isNullish(hva) ? hva.v : 100});
- setBG.call(that, colorBarDiv, saturatedColor.val('hex'));
- setAlpha.call(that, colorBarL2, 100 - (!isNullish(hva) ? hva.v : 100));
- setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((hva && hva.a) || 0)) * 100) / 255, 4));
- break;
- } case 'v': {
- const hsa = ui.val('hsa'),
- valueColor = new Color({h: (hsa && hsa.h) || 0, s: !isNullish(hsa) ? hsa.s : 100, v: 100});
- setBG.call(that, colorBarDiv, valueColor.val('hex'));
- setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((hsa && hsa.a) || 0)) * 100) / 255, 4));
- break;
- } case 'r':
- case 'g':
- case 'b': {
- const rgba = ui.val('rgba');
- let hValue = 0, vValue = 0;
- if (settings.color.mode === 'r') {
- hValue = (rgba && rgba.b) || 0;
- vValue = (rgba && rgba.g) || 0;
- } else if (settings.color.mode === 'g') {
- hValue = (rgba && rgba.b) || 0;
- vValue = (rgba && rgba.r) || 0;
- } else if (settings.color.mode === 'b') {
- hValue = (rgba && rgba.r) || 0;
- vValue = (rgba && rgba.g) || 0;
- }
- const middle = vValue > hValue ? hValue : vValue;
- setAlpha.call(that, colorBarL2, hValue > vValue ? toFixedNumeric(((hValue - vValue) / (255 - vValue)) * 100, 4) : 0);
- setAlpha.call(that, colorBarL3, vValue > hValue ? toFixedNumeric(((vValue - hValue) / (255 - hValue)) * 100, 4) : 0);
- setAlpha.call(that, colorBarL4, toFixedNumeric((middle / 255) * 100, 4));
- setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((rgba && rgba.a) || 0)) * 100) / 255, 4));
- break;
- } case 'a': {
- const a = ui.val('a');
- setBG.call(that, colorBarDiv, ui.val('hex') || '000000');
- setAlpha.call(that, colorBarL5, !isNullish(a) ? 0 : 100);
- setAlpha.call(that, colorBarL6, !isNullish(a) ? 100 : 0);
- break;
- }
+ setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - (a || 0)) * 100) / 255, 4));
+ break;
+ } case 's': {
+ const hva = ui.val('hva'),
+ saturatedColor = new Color({h: (hva && hva.h) || 0, s: 100, v: !isNullish(hva) ? hva.v : 100});
+ setBG.call(that, colorBarDiv, saturatedColor.val('hex'));
+ setAlpha.call(that, colorBarL2, 100 - (!isNullish(hva) ? hva.v : 100));
+ setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((hva && hva.a) || 0)) * 100) / 255, 4));
+ break;
+ } case 'v': {
+ const hsa = ui.val('hsa'),
+ valueColor = new Color({h: (hsa && hsa.h) || 0, s: !isNullish(hsa) ? hsa.s : 100, v: 100});
+ setBG.call(that, colorBarDiv, valueColor.val('hex'));
+ setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((hsa && hsa.a) || 0)) * 100) / 255, 4));
+ break;
+ } case 'r':
+ case 'g':
+ case 'b': {
+ const rgba = ui.val('rgba');
+ let hValue = 0, vValue = 0;
+ if (settings.color.mode === 'r') {
+ hValue = (rgba && rgba.b) || 0;
+ vValue = (rgba && rgba.g) || 0;
+ } else if (settings.color.mode === 'g') {
+ hValue = (rgba && rgba.b) || 0;
+ vValue = (rgba && rgba.r) || 0;
+ } else if (settings.color.mode === 'b') {
+ hValue = (rgba && rgba.r) || 0;
+ vValue = (rgba && rgba.g) || 0;
}
+ const middle = vValue > hValue ? hValue : vValue;
+ setAlpha.call(that, colorBarL2, hValue > vValue ? toFixedNumeric(((hValue - vValue) / (255 - vValue)) * 100, 4) : 0);
+ setAlpha.call(that, colorBarL3, vValue > hValue ? toFixedNumeric(((vValue - hValue) / (255 - hValue)) * 100, 4) : 0);
+ setAlpha.call(that, colorBarL4, toFixedNumeric((middle / 255) * 100, 4));
+ setAlpha.call(that, colorBarL5, toFixedNumeric(((255 - ((rgba && rgba.a) || 0)) * 100) / 255, 4));
+ break;
+ } case 'a': {
+ const a = ui.val('a');
+ setBG.call(that, colorBarDiv, ui.val('hex') || '000000');
+ setAlpha.call(that, colorBarL5, !isNullish(a) ? 0 : 100);
+ setAlpha.call(that, colorBarL6, !isNullish(a) ? 100 : 0);
+ break;
}
- /**
- * @param {external:jQuery} el
- * @param {string} [c="transparent"]
- * @returns {void}
- */
- function setBG (el, c) {
- el.css({backgroundColor: (c && c.length === 6 && '#' + c) || 'transparent'});
}
+ }
+ /**
+ * @param {external:jQuery} el
+ * @param {string} [c="transparent"]
+ * @returns {void}
+ */
+ function setBG (el, c) {
+ el.css({backgroundColor: (c && c.length === 6 && '#' + c) || 'transparent'});
+ }
- /**
- * @param {external:jQuery} img
- * @param {string} src The image source
- * @returns {void}
- */
- function setImg (img, src) {
- if (isLessThanIE7 && (src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png'))) {
- img.attr('pngSrc', src);
- img.css({backgroundImage: 'none', filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\')'});
- } else img.css({backgroundImage: 'url(\'' + src + '\')'});
- }
- /**
- * @param {external:jQuery} img
- * @param {Float} y
- * @returns {void}
- */
- function setImgLoc (img, y) {
- img.css({top: y + 'px'});
- }
- /**
- * @param {external:jQuery} obj
- * @param {Float} alpha
- * @returns {void}
- */
- function setAlpha (obj, alpha) {
- obj.css({visibility: alpha > 0 ? 'visible' : 'hidden'});
- if (alpha > 0 && alpha < 100) {
- if (isLessThanIE7) {
- const src = obj.attr('pngSrc');
- if (!isNullish(src) && (
- src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png')
- )) {
- obj.css({
- filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src +
- '\', sizingMethod=\'scale\') progid:DXImageTransform.Microsoft.Alpha(opacity=' + alpha + ')'
- });
- } else obj.css({opacity: toFixedNumeric(alpha / 100, 4)});
- } else obj.css({opacity: toFixedNumeric(alpha / 100, 4)});
- } else if (alpha === 0 || alpha === 100) {
- if (isLessThanIE7) {
- const src = obj.attr('pngSrc');
- if (!isNullish(src) && (
- src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png')
- )) {
- obj.css({
- filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src +
- '\', sizingMethod=\'scale\')'
- });
- } else obj.css({opacity: ''});
- } else obj.css({opacity: ''});
- }
- }
-
- /**
- * Revert color to original color when opened.
- * @returns {void}
- */
- function revertColor () {
- color.active.val('ahex', color.current.val('ahex'));
- }
- /**
- * Commit the color changes.
- * @returns {void}
- */
- function commitColor () {
- color.current.val('ahex', color.active.val('ahex'));
- }
- /**
- * @param {Event} e
- * @returns {void}
- */
- function radioClicked (e) {
- $(this).parents('tbody:first').find('input:radio[value!="' + e.target.value + '"]').removeAttr('checked');
- setColorMode.call(that, e.target.value);
- }
- /**
- *
- * @returns {void}
- */
- function currentClicked () {
- revertColor.call(that);
- }
- /**
- *
- * @returns {void}
- */
- function cancelClicked () {
- revertColor.call(that);
- settings.window.expandable && hide.call(that);
- typeof cancelCallback === 'function' && cancelCallback.call(that, color.active, cancelButton);
- }
- /**
- *
- * @returns {void}
- */
- function okClicked () {
- commitColor.call(that);
- settings.window.expandable && hide.call(that);
- typeof commitCallback === 'function' && commitCallback.call(that, color.active, okButton);
- }
- /**
- *
- * @returns {void}
- */
- function iconImageClicked () {
- show.call(that);
- }
- /**
- * @param {external:jQuery} ui
- * @returns {void}
- */
- function currentColorChanged (ui) {
- const hex = ui.val('hex');
- currentPreview.css({backgroundColor: (hex && '#' + hex) || 'transparent'});
- setAlpha.call(that, currentPreview, toFixedNumeric(((ui.val('a') || 0) * 100) / 255, 4));
- }
- /**
- * @param {external:jQuery} ui
- * @returns {void}
- */
- function expandableColorChanged (ui) {
- const hex = ui.val('hex');
- const va = ui.val('va');
- iconColor.css({backgroundColor: (hex && '#' + hex) || 'transparent'});
- setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - ((va && va.a) || 0)) * 100) / 255, 4));
- if (settings.window.bindToInput && settings.window.updateInputColor) {
- settings.window.input.css({
- backgroundColor: (hex && '#' + hex) || 'transparent',
- color: isNullish(va) || va.v > 75 ? '#000000' : '#ffffff'
- });
- }
- }
- /**
- * @param {Event} e
- * @returns {void}
- */
- function moveBarMouseDown (e) {
- // const {element} = settings.window, // local copies for YUI compressor
- // {page} = settings.window;
- elementStartX = Number.parseInt(container.css('left'));
- elementStartY = Number.parseInt(container.css('top'));
- pageStartX = e.pageX;
- pageStartY = e.pageY;
- // bind events to document to move window - we will unbind these on mouseup
- $(document).bind('mousemove', documentMouseMove).bind('mouseup', documentMouseUp);
- e.preventDefault(); // prevent attempted dragging of the column
- }
- /**
- * @param {Event} e
- * @returns {false}
- */
- function documentMouseMove (e) {
- container.css({
- left: elementStartX - (pageStartX - e.pageX) + 'px',
- top: elementStartY - (pageStartY - e.pageY) + 'px'
- });
- if (settings.window.expandable && !$.support.boxModel) {
- container.prev().css({
- left: container.css('left'),
- top: container.css('top')
- });
- }
- e.stopPropagation();
- e.preventDefault();
- return false;
- }
- /**
- * @param {Event} e
- * @returns {false}
- */
- function documentMouseUp (e) {
- $(document).unbind('mousemove', documentMouseMove).unbind('mouseup', documentMouseUp);
- e.stopPropagation();
- e.preventDefault();
- return false;
- }
- /**
- * @param {Event} e
- * @returns {false}
- */
- function quickPickClicked (e) {
- e.preventDefault();
- e.stopPropagation();
- color.active.val('ahex', $(this).attr('title') || null, e.target);
- return false;
- }
- /**
- *
- * @returns {void}
- */
- function show () {
- color.current.val('ahex', color.active.val('ahex'));
- /**
- *
- * @returns {void}
- */
- function attachIFrame () {
- if (!settings.window.expandable || $.support.boxModel) return;
- const table = container.find('table:first');
- container.before('
');
- container.prev().css({
- width: table.width(),
- height: container.height(),
- opacity: 0,
- position: 'absolute',
- left: container.css('left'),
- top: container.css('top')
- });
- }
- if (settings.window.expandable) {
- $(document.body).children('div.jPicker.Container').css({zIndex: 10});
- container.css({zIndex: 20});
- }
- switch (settings.window.effects.type) {
- case 'fade':
- container.fadeIn(settings.window.effects.speed.show, attachIFrame);
- break;
- case 'slide':
- container.slideDown(settings.window.effects.speed.show, attachIFrame);
- break;
- case 'show':
- default:
- container.show(settings.window.effects.speed.show, attachIFrame);
- break;
- }
- }
- /**
- *
- * @returns {void}
- */
- function hide () {
- /**
- *
- * @returns {void}
- */
- function removeIFrame () {
- if (settings.window.expandable) container.css({zIndex: 10});
- if (!settings.window.expandable || $.support.boxModel) return;
- container.prev().remove();
- }
- switch (settings.window.effects.type) {
- case 'fade':
- container.fadeOut(settings.window.effects.speed.hide, removeIFrame);
- break;
- case 'slide':
- container.slideUp(settings.window.effects.speed.hide, removeIFrame);
- break;
- case 'show':
- default:
- container.hide(settings.window.effects.speed.hide, removeIFrame);
- break;
- }
- }
- /**
- *
- * @returns {void}
- */
- function initialize () {
- const win = settings.window,
- popup = win.expandable ? $(that).next().find('.Container:first') : null;
- container = win.expandable ? $('
') : $(that);
- container.addClass('jPicker Container');
- if (win.expandable) container.hide();
- container.get(0).onselectstart = function (e) {
- if (e.target.nodeName.toLowerCase() !== 'input') return false;
- return true;
- };
- // inject html source code - we are using a single table for this control - I know tables are considered bad, but it takes care of equal height columns and
- // this control really is tabular data, so I believe it is the right move
- const all = color.active.val('all');
- if (win.alphaPrecision < 0) win.alphaPrecision = 0;
- else if (win.alphaPrecision > 2) win.alphaPrecision = 2;
- const controlHtml = `
`;
- if (win.expandable) {
- container.html(controlHtml);
- if (!$(document.body).children('div.jPicker.Container').length) {
- $(document.body).prepend(container);
- } else {
- $(document.body).children('div.jPicker.Container:last').after(container);
- }
- container.mousedown(
- function () {
- $(document.body).children('div.jPicker.Container').css({zIndex: 10});
- container.css({zIndex: 20});
- }
- );
- container.css( // positions must be set and display set to absolute before source code injection or IE will size the container to fit the window
- {
- left:
- win.position.x === 'left'
- ? (popup.offset().left - 530 - (win.position.y === 'center' ? 25 : 0)) + 'px'
- : win.position.x === 'center'
- ? (popup.offset().left - 260) + 'px'
- : win.position.x === 'right'
- ? (popup.offset().left - 10 + (win.position.y === 'center' ? 25 : 0)) + 'px'
- : win.position.x === 'screenCenter'
- ? (($(document).width() >> 1) - 260) + 'px'
- : (popup.offset().left + Number.parseInt(win.position.x)) + 'px',
- position: 'absolute',
- top: win.position.y === 'top'
- ? (popup.offset().top - 312) + 'px'
- : win.position.y === 'center'
- ? (popup.offset().top - 156) + 'px'
- : win.position.y === 'bottom'
- ? (popup.offset().top + 25) + 'px'
- : (popup.offset().top + Number.parseInt(win.position.y)) + 'px'
- }
- );
- } else {
- container = $(that);
- container.html(controlHtml);
- }
- // initialize the objects to the source code just injected
- const tbody = container.find('tbody:first');
- colorMapDiv = tbody.find('div.Map:first');
- colorBarDiv = tbody.find('div.Bar:first');
- const MapMaps = colorMapDiv.find('span');
- const BarMaps = colorBarDiv.find('span');
- colorMapL1 = MapMaps.filter('.Map1:first');
- colorMapL2 = MapMaps.filter('.Map2:first');
- colorMapL3 = MapMaps.filter('.Map3:first');
- colorBarL1 = BarMaps.filter('.Map1:first');
- colorBarL2 = BarMaps.filter('.Map2:first');
- colorBarL3 = BarMaps.filter('.Map3:first');
- colorBarL4 = BarMaps.filter('.Map4:first');
- colorBarL5 = BarMaps.filter('.Map5:first');
- colorBarL6 = BarMaps.filter('.Map6:first');
- // create color pickers and maps
- colorMap = new Slider(
- colorMapDiv,
- {
- map: {
- width: images.colorMap.width,
- height: images.colorMap.height
- },
- arrow: {
- image: images.clientPath + images.colorMap.arrow.file,
- width: images.colorMap.arrow.width,
- height: images.colorMap.arrow.height
- }
- }
- );
- colorMap.bind(mapValueChanged);
- colorBar = new Slider(
- colorBarDiv,
- {
- map: {
- width: images.colorBar.width,
- height: images.colorBar.height
- },
- arrow: {
- image: images.clientPath + images.colorBar.arrow.file,
- width: images.colorBar.arrow.width,
- height: images.colorBar.arrow.height
- }
- }
- );
- colorBar.bind(colorBarValueChanged);
- colorPicker = new ColorValuePicker(
- tbody,
- color.active,
- win.expandable && win.bindToInput ? win.input : null,
- win.alphaPrecision
- );
- const hex = !isNullish(all) ? all.hex : null,
- preview = tbody.find('.Preview'),
- button = tbody.find('.Button');
- activePreview = preview.find('.Active:first').css({backgroundColor: (hex && '#' + hex) || 'transparent'});
- currentPreview = preview.find('.Current:first').css({backgroundColor: (hex && '#' + hex) || 'transparent'}).bind('click', currentClicked);
- setAlpha.call(that, currentPreview, toFixedNumeric((color.current.val('a') * 100) / 255, 4));
- okButton = button.find('.Ok:first').bind('click', okClicked);
- cancelButton = button.find('.Cancel:first').bind('click', cancelClicked);
- grid = button.find('.Grid:first');
- setTimeout(function () {
- setImg.call(that, colorMapL1, images.clientPath + 'Maps.png');
- setImg.call(that, colorMapL2, images.clientPath + 'Maps.png');
- setImg.call(that, colorMapL3, images.clientPath + 'map-opacity.png');
- setImg.call(that, colorBarL1, images.clientPath + 'Bars.png');
- setImg.call(that, colorBarL2, images.clientPath + 'Bars.png');
- setImg.call(that, colorBarL3, images.clientPath + 'Bars.png');
- setImg.call(that, colorBarL4, images.clientPath + 'Bars.png');
- setImg.call(that, colorBarL5, images.clientPath + 'bar-opacity.png');
- setImg.call(that, colorBarL6, images.clientPath + 'AlphaBar.png');
- setImg.call(that, preview.find('div:first'), images.clientPath + 'preview-opacity.png');
- }, 0);
- tbody.find('td.Radio input').bind('click', radioClicked);
- // initialize quick list
- if (color.quickList && color.quickList.length > 0) {
- let html = '';
- for (let i = 0; i < color.quickList.length; i++) {
- /* if default colors are hex strings, change them to color objects */
- if ((typeof (color.quickList[i])).toString().toLowerCase() === 'string') {
- color.quickList[i] = new Color({hex: color.quickList[i]});
- }
- const alpha = color.quickList[i].val('a');
- let ahex = color.quickList[i].val('ahex');
- if (!win.alphaSupport && ahex) ahex = ahex.substring(0, 6) + 'ff';
- const quickHex = color.quickList[i].val('hex');
- if (!ahex) ahex = '00000000';
- html += '
';
- }
- setImg.call(that, grid, images.clientPath + 'bar-opacity.png');
- grid.html(html);
- grid.find('.QuickColor').click(quickPickClicked);
- }
- setColorMode.call(that, settings.color.mode);
- color.active.bind(activeColorChanged);
- typeof liveCallback === 'function' && color.active.bind(liveCallback);
- color.current.bind(currentColorChanged);
- // bind to input
- if (win.expandable) {
- that.icon = popup.parents('.Icon:first');
- iconColor = that.icon.find('.Color:first').css({backgroundColor: (hex && '#' + hex) || 'transparent'});
- iconAlpha = that.icon.find('.Alpha:first');
- setImg.call(that, iconAlpha, images.clientPath + 'bar-opacity.png');
- setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (!isNullish(all) ? all.a : 0)) * 100) / 255, 4));
- iconImage = that.icon.find('.Image:first').css({
- backgroundImage: 'url(\'' + images.clientPath + images.picker.file + '\')'
- }).bind('click', iconImageClicked);
- if (win.bindToInput && win.updateInputColor) {
- win.input.css({
- backgroundColor: (hex && '#' + hex) || 'transparent',
- color: isNullish(all) || all.v > 75 ? '#000000' : '#ffffff'
+ /**
+ * @param {external:jQuery} img
+ * @param {string} src The image source
+ * @returns {void}
+ */
+ function setImg (img, src) {
+ if (isLessThanIE7 && (src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png'))) {
+ img.setAttribute('pngSrc', src);
+ img.style.backgroundImage = 'none';
+ img.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\')';
+ // img.attr('pngSrc', src);
+ // img.css({backgroundImage: 'none', filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src + '\', sizingMethod=\'scale\')'});
+ } else img.style.backgroundImage = 'url(\'' + src + '\')';
+ // img.css({backgroundImage: 'url(\'' + src + '\')'});
+ }
+ /**
+ * @param {external:jQuery} img
+ * @param {Float} y
+ * @returns {void}
+ */
+ function setImgLoc (img, y) {
+ // img.css({top: y + 'px'});
+ img.style.top = y + 'px';
+ }
+ /**
+ * @param {external:jQuery} obj
+ * @param {Float} alpha
+ * @returns {void}
+ */
+ function setAlpha (obj, alpha) {
+ obj.style.visibility = (alpha > 0) ? 'visible' : 'hidden';
+ if (alpha > 0 && alpha < 100) {
+ if (isLessThanIE7) {
+ const src = obj.getAttribute('pngSrc');
+ if (!isNullish(src) && (
+ src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png')
+ )) {
+ obj.css({
+ filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src +
+ '\', sizingMethod=\'scale\') progid:DXImageTransform.Microsoft.Alpha(opacity=' + alpha + ')'
});
- }
- moveBar = tbody.find('.Move:first').bind('mousedown', moveBarMouseDown);
- color.active.bind(expandableColorChanged);
- } else show.call(that);
+ } else obj.style.opacity = toFixedNumeric(alpha / 100, 4);
+ } else obj.style.opacity = toFixedNumeric(alpha / 100, 4);
+ } else if (alpha === 0 || alpha === 100) {
+ if (isLessThanIE7) {
+ const src = obj.getAttribute('pngSrc');
+ if (!isNullish(src) && (
+ src.includes('AlphaBar.png') || src.includes('Bars.png') || src.includes('Maps.png')
+ )) {
+ obj.css({
+ filter: 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + src +
+ '\', sizingMethod=\'scale\')'
+ });
+ } else obj.style.opacity = '';
+ } else obj.style.opacity = '';
}
+ }
+
+ /**
+ * Revert color to original color when opened.
+ * @returns {void}
+ */
+ function revertColor () {
+ color.active.val('ahex', color.current.val('ahex'));
+ }
+ /**
+ * Commit the color changes.
+ * @returns {void}
+ */
+ function commitColor () {
+ color.current.val('ahex', color.active.val('ahex'));
+ }
+ /**
+ * @param {Event} e
+ * @returns {void}
+ */
+ function radioClicked (e) {
+ $(this).parents('tbody:first').find('input:radio[value!="' + e.target.value + '"]').removeAttr('checked');
+ setColorMode.call(that, e.target.value);
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function currentClicked () {
+ revertColor.call(that);
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function cancelClicked () {
+ revertColor.call(that);
+ settings.window.expandable && hide.call(that);
+ typeof cancelCallback === 'function' && cancelCallback.call(that, color.active, cancelButton);
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function okClicked () {
+ commitColor.call(that);
+ settings.window.expandable && hide.call(that);
+ typeof commitCallback === 'function' && commitCallback.call(that, color.active, okButton);
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function iconImageClicked () {
+ show.call(that);
+ }
+ /**
+ * @param {external:jQuery} ui
+ * @returns {void}
+ */
+ function currentColorChanged (ui) {
+ const hex = ui.val('hex');
+ currentPreview.css({backgroundColor: (hex && '#' + hex) || 'transparent'});
+ setAlpha.call(that, currentPreview, toFixedNumeric(((ui.val('a') || 0) * 100) / 255, 4));
+ }
+ /**
+ * @param {external:jQuery} ui
+ * @returns {void}
+ */
+ function expandableColorChanged (ui) {
+ const hex = ui.val('hex');
+ const va = ui.val('va');
+ iconColor.css({backgroundColor: (hex && '#' + hex) || 'transparent'});
+ setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - ((va && va.a) || 0)) * 100) / 255, 4));
+ if (settings.window.bindToInput && settings.window.updateInputColor) {
+ settings.window.input.css({
+ backgroundColor: (hex && '#' + hex) || 'transparent',
+ color: isNullish(va) || va.v > 75 ? '#000000' : '#ffffff'
+ });
+ }
+ }
+ /**
+ * @param {Event} e
+ * @returns {void}
+ */
+ function moveBarMouseDown (e) {
+ // const {element} = settings.window, // local copies for YUI compressor
+ // {page} = settings.window;
+ elementStartX = Number.parseInt(container.css('left'));
+ elementStartY = Number.parseInt(container.css('top'));
+ pageStartX = e.pageX;
+ pageStartY = e.pageY;
+ // bind events to document to move window - we will unbind these on mouseup
+ $(document).bind('mousemove', documentMouseMove).bind('mouseup', documentMouseUp);
+ e.preventDefault(); // prevent attempted dragging of the column
+ }
+ /**
+ * @param {Event} e
+ * @returns {false}
+ */
+ function documentMouseMove (e) {
+ container.css({
+ left: elementStartX - (pageStartX - e.pageX) + 'px',
+ top: elementStartY - (pageStartY - e.pageY) + 'px'
+ });
+ if (settings.window.expandable && !$.support.boxModel) {
+ container.prev().css({
+ left: container.css('left'),
+ top: container.css('top')
+ });
+ }
+ e.stopPropagation();
+ e.preventDefault();
+ return false;
+ }
+ /**
+ * @param {Event} e
+ * @returns {false}
+ */
+ function documentMouseUp (e) {
+ $(document).unbind('mousemove', documentMouseMove).unbind('mouseup', documentMouseUp);
+ e.stopPropagation();
+ e.preventDefault();
+ return false;
+ }
+ /**
+ * @param {Event} e
+ * @returns {false}
+ */
+ function quickPickClicked (e) {
+ e.preventDefault();
+ e.stopPropagation();
+ color.active.val('ahex', $(this).attr('title') || null, e.target);
+ return false;
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function show () {
+ color.current.val('ahex', color.active.val('ahex'));
/**
*
* @returns {void}
*/
- function destroy () {
- container.find('td.Radio input').unbind('click', radioClicked);
- currentPreview.unbind('click', currentClicked);
- cancelButton.unbind('click', cancelClicked);
- okButton.unbind('click', okClicked);
- if (settings.window.expandable) {
- iconImage.unbind('click', iconImageClicked);
- moveBar.unbind('mousedown', moveBarMouseDown);
- that.icon = null;
+ function attachIFrame () {
+ if (!settings.window.expandable || $.support.boxModel) return;
+ const table = container.find('table:first');
+ container.before('
');
+ container.prev().css({
+ width: table.width(),
+ height: container.height(),
+ opacity: 0,
+ position: 'absolute',
+ left: container.css('left'),
+ top: container.css('top')
+ });
+ }
+ if (settings.window.expandable) {
+ $(document.body).children('div.jPicker.Container').css({zIndex: 10});
+ container.css({zIndex: 20});
+ }
+ switch (settings.window.effects.type) {
+ case 'fade':
+ container.fadeIn(settings.window.effects.speed.show, attachIFrame);
+ break;
+ case 'slide':
+ container.slideDown(settings.window.effects.speed.show, attachIFrame);
+ break;
+ case 'show':
+ default:
+ container.show(settings.window.effects.speed.show, attachIFrame);
+ break;
+ }
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function hide () {
+ /**
+ *
+ * @returns {void}
+ */
+ function removeIFrame () {
+ if (settings.window.expandable) container.css({zIndex: 10});
+ if (!settings.window.expandable || $.support.boxModel) return;
+ container.prev().remove();
+ }
+ switch (settings.window.effects.type) {
+ case 'fade':
+ container.fadeOut(settings.window.effects.speed.hide, removeIFrame);
+ break;
+ case 'slide':
+ container.slideUp(settings.window.effects.speed.hide, removeIFrame);
+ break;
+ case 'show':
+ default:
+ container.hide(settings.window.effects.speed.hide, removeIFrame);
+ break;
+ }
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function initialize () {
+ console.log('$(that).next() --> ', that.nextElementSibling);
+ console.log('$(that).next() --> ', that.nextElementSibling.querySelector('#Container'));
+ const win = settings.window,
+ popup = win.expandable ? that.nextElementSibling.querySelector('#Container') : null;
+ container = win.expandable ? $('
') : that;
+ // container.addClass('jPicker Container');
+ container.classList.add('jPicker');
+ container.classList.add('Container');
+ if (win.expandable) container.hide();
+ container.onselectstart = function (e) {
+ if (e.target.nodeName.toLowerCase() !== 'input') return false;
+ return true;
+ };
+ // inject html source code - we are using a single table for this control - I know tables are considered bad, but it takes care of equal height columns and
+ // this control really is tabular data, so I believe it is the right move
+ const all = color.active.val('all');
+ if (win.alphaPrecision < 0) win.alphaPrecision = 0;
+ else if (win.alphaPrecision > 2) win.alphaPrecision = 2;
+ const controlHtml = `
`;
+ if (win.expandable) {
+ container.html(controlHtml);
+ if (!$(document.body).children('div.jPicker.Container').length) {
+ $(document.body).prepend(container);
+ } else {
+ $(document.body).children('div.jPicker.Container:last').after(container);
}
- container.find('.QuickColor').unbind('click', quickPickClicked);
- colorMapDiv = null;
- colorBarDiv = null;
- colorMapL1 = null;
- colorMapL2 = null;
- colorMapL3 = null;
- colorBarL1 = null;
- colorBarL2 = null;
- colorBarL3 = null;
- colorBarL4 = null;
- colorBarL5 = null;
- colorBarL6 = null;
- colorMap.destroy();
- colorMap = null;
- colorBar.destroy();
- colorBar = null;
- colorPicker.destroy();
- colorPicker = null;
- activePreview = null;
- currentPreview = null;
- okButton = null;
- cancelButton = null;
- grid = null;
- commitCallback = null;
- cancelCallback = null;
- liveCallback = null;
- container.html('');
- for (let i = 0; i < List.length; i++) {
- if (List[i] === that) {
- List.splice(i, 1);
- i--; // Decrement to ensure we don't miss next item (lgtm warning)
+ container.mousedown(
+ function () {
+ $(document.body).children('div.jPicker.Container').css({zIndex: 10});
+ container.css({zIndex: 20});
+ }
+ );
+ container.css( // positions must be set and display set to absolute before source code injection or IE will size the container to fit the window
+ {
+ left:
+ win.position.x === 'left'
+ ? (popup.offset().left - 530 - (win.position.y === 'center' ? 25 : 0)) + 'px'
+ : win.position.x === 'center'
+ ? (popup.offset().left - 260) + 'px'
+ : win.position.x === 'right'
+ ? (popup.offset().left - 10 + (win.position.y === 'center' ? 25 : 0)) + 'px'
+ : win.position.x === 'screenCenter'
+ ? (($(document).width() >> 1) - 260) + 'px'
+ : (popup.offset().left + Number.parseInt(win.position.x)) + 'px',
+ position: 'absolute',
+ top: win.position.y === 'top'
+ ? (popup.offset().top - 312) + 'px'
+ : win.position.y === 'center'
+ ? (popup.offset().top - 156) + 'px'
+ : win.position.y === 'bottom'
+ ? (popup.offset().top + 25) + 'px'
+ : (popup.offset().top + Number.parseInt(win.position.y)) + 'px'
+ }
+ );
+ } else {
+ container = that;
+ const div = document.createElement('div');
+ div.innerHTML = controlHtml;
+ while (div.children.length > 0) {
+ container.appendChild(div.children[0]);
+ }
+ }
+ // initialize the objects to the source code just injected
+ const tbody = container.querySelector('tbody');
+ colorMapDiv = tbody.querySelector('#Map');
+ colorBarDiv = tbody.querySelector('#Bar');
+ // const MapMaps = colorMapDiv.find('span');
+ // const BarMaps = colorBarDiv.find('span');
+ colorMapL1 = colorMapDiv.querySelector('#MMap1');
+ colorMapL2 = colorMapDiv.querySelector('#MMap2');
+ colorMapL3 = colorMapDiv.querySelector('#MMap3');
+ colorBarL1 = colorBarDiv.querySelector('#Map1');
+ colorBarL2 = colorBarDiv.querySelector('#Map2');
+ colorBarL3 = colorBarDiv.querySelector('#Map3');
+ colorBarL4 = colorBarDiv.querySelector('#Map4');
+ colorBarL5 = colorBarDiv.querySelector('#Map5');
+ colorBarL6 = colorBarDiv.querySelector('#Map6');
+ // create color pickers and maps
+ colorMap = new Slider(
+ colorMapDiv,
+ {
+ map: {
+ width: images.colorMap.width,
+ height: images.colorMap.height
+ },
+ arrow: {
+ image: images.clientPath + images.colorMap.arrow.file,
+ width: images.colorMap.arrow.width,
+ height: images.colorMap.arrow.height
}
}
- }
- const {images, localization} = settings; // local copies for YUI compressor
- const color = {
- active: (typeof settings.color.active).toString().toLowerCase() === 'string'
- ? new Color({ahex: !settings.window.alphaSupport && settings.color.active
- ? settings.color.active.substring(0, 6) + 'ff'
- : settings.color.active
- })
- : new Color({ahex: !settings.window.alphaSupport &&
- settings.color.active.val('ahex')
- ? settings.color.active.val('ahex').substring(0, 6) + 'ff'
- : settings.color.active.val('ahex')
- }),
- current: (typeof settings.color.active).toString().toLowerCase() === 'string'
- ? new Color({ahex: !settings.window.alphaSupport && settings.color.active
- ? settings.color.active.substring(0, 6) + 'ff'
- : settings.color.active})
- : new Color({ahex: !settings.window.alphaSupport &&
- settings.color.active.val('ahex')
- ? settings.color.active.val('ahex').substring(0, 6) + 'ff'
- : settings.color.active.val('ahex')
- }),
- quickList: settings.color.quickList
- };
-
- if (typeof commitCallback !== 'function') {
- commitCallback = null;
- }
- if (typeof liveCallback !== 'function') {
- liveCallback = null;
- }
- if (typeof cancelCallback !== 'function') {
- cancelCallback = null;
- }
-
- let elementStartX = null, // Used to record the starting css positions for dragging the control
- elementStartY = null,
- pageStartX = null, // Used to record the mousedown coordinates for dragging the control
- pageStartY = null,
- container = null,
- colorMapDiv = null,
- colorBarDiv = null,
- colorMapL1 = null, // different layers of colorMap and colorBar
- colorMapL2 = null,
- colorMapL3 = null,
- colorBarL1 = null,
- colorBarL2 = null,
- colorBarL3 = null,
- colorBarL4 = null,
- colorBarL5 = null,
- colorBarL6 = null,
- colorMap = null, // color maps
- colorBar = null,
- colorPicker = null,
- activePreview = null, // color boxes above the radio buttons
- currentPreview = null,
- okButton = null,
- cancelButton = null,
- grid = null, // preset colors grid
- iconColor = null, // iconColor for popup icon
- iconAlpha = null, // iconAlpha for popup icon
- iconImage = null, // iconImage popup icon
- moveBar = null; // drag bar
-
- $.extend(true, that, {
- // public properties, methods, and callbacks
- commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK"
- liveCallback, // liveCallback function can be overridden to return the selected color to a method you specify in live mode (continuous update)
- cancelCallback, // cancelCallback function can be overridden to a method you specify when the user clicks "Cancel"
- color,
- show,
- hide,
- destroy // destroys this control entirely, removing all events and objects, and removing itself from the List
- });
- List.push(that);
+ );
+ colorMap.bind(mapValueChanged);
+ colorBar = new Slider(
+ colorBarDiv,
+ {
+ map: {
+ width: images.colorBar.width,
+ height: images.colorBar.height
+ },
+ arrow: {
+ image: images.clientPath + images.colorBar.arrow.file,
+ width: images.colorBar.arrow.width,
+ height: images.colorBar.arrow.height
+ }
+ }
+ );
+ colorBar.bind(colorBarValueChanged);
+ colorPicker = new ColorValuePicker(
+ tbody,
+ color.active,
+ win.expandable && win.bindToInput ? win.input : null,
+ win.alphaPrecision
+ );
+ const hex = !isNullish(all) ? all.hex : null,
+ preview = tbody.querySelector('#Preview'),
+ button = tbody.querySelector('#Button');
+ activePreview = preview.querySelector('#Active');
+ activePreview.style.backgroundColor = (hex) ? '#' + hex : 'transparent';
+ // .css({backgroundColor: (hex && '#' + hex) || 'transparent'});
+ currentPreview = preview.querySelector('#Current');
+ currentPreview.style.backgroundColor = (hex) ? '#' + hex : 'transparent';
+ currentPreview.addEventListener('click', currentClicked);
+ // .css({backgroundColor: (hex && '#' + hex) || 'transparent'}).bind('click', currentClicked);
+ setAlpha.call(that, currentPreview, toFixedNumeric((color.current.val('a') * 100) / 255, 4));
+ okButton = button.querySelector('#Ok');
+ okButton.addEventListener('click', okClicked);
+ cancelButton = button.querySelector('#Cancel');
+ cancelButton.addEventListener('click', cancelClicked);
+ grid = button.querySelector('#Grid');
setTimeout(function () {
- initialize.call(that);
+ setImg.call(that, colorMapL1, images.clientPath + 'Maps.png');
+ setImg.call(that, colorMapL2, images.clientPath + 'Maps.png');
+ setImg.call(that, colorMapL3, images.clientPath + 'map-opacity.png');
+ setImg.call(that, colorBarL1, images.clientPath + 'Bars.png');
+ setImg.call(that, colorBarL2, images.clientPath + 'Bars.png');
+ setImg.call(that, colorBarL3, images.clientPath + 'Bars.png');
+ setImg.call(that, colorBarL4, images.clientPath + 'Bars.png');
+ setImg.call(that, colorBarL5, images.clientPath + 'bar-opacity.png');
+ setImg.call(that, colorBarL6, images.clientPath + 'AlphaBar.png');
+ setImg.call(that, preview.find('div:first'), images.clientPath + 'preview-opacity.png');
}, 0);
+ const radioInputs = tbody.querySelectorAll('td.Radio input');
+ for (const radioInput of radioInputs) {
+ radioInput.addEventListener('click', radioClicked);
+ }
+ // initialize quick list
+ if (color.quickList && color.quickList.length > 0) {
+ let html = '';
+ for (let i = 0; i < color.quickList.length; i++) {
+ /* if default colors are hex strings, change them to color objects */
+ if ((typeof (color.quickList[i])).toString().toLowerCase() === 'string') {
+ color.quickList[i] = new Color({hex: color.quickList[i]});
+ }
+ const alpha = color.quickList[i].val('a');
+ let ahex = color.quickList[i].val('ahex');
+ if (!win.alphaSupport && ahex) ahex = ahex.substring(0, 6) + 'ff';
+ const quickHex = color.quickList[i].val('hex');
+ if (!ahex) ahex = '00000000';
+ html += '
';
+ }
+ setImg.call(that, grid, images.clientPath + 'bar-opacity.png');
+ const div = document.createElement('div');
+ div.innerHTML = html;
+ while (div.children.length > 0) {
+ grid.appendChild(div.children[0]);
+ }
+ // grid.html(html);
+ const QuickColorSels = grid.querySelectorAll('.QuickColor');
+ for (const QuickColorSel of QuickColorSels) {
+ QuickColorSel.addEventListener('click', quickPickClicked);
+ }
+ }
+ setColorMode.call(that, settings.color.mode);
+ color.active.bind(activeColorChanged);
+ typeof liveCallback === 'function' && color.active.bind(liveCallback);
+ color.current.bind(currentColorChanged);
+ // bind to input
+ if (win.expandable) {
+ that.icon = popup.parents('.Icon:first');
+ iconColor = that.icon.find('.Color:first').css({backgroundColor: (hex && '#' + hex) || 'transparent'});
+ iconAlpha = that.icon.find('.Alpha:first');
+ setImg.call(that, iconAlpha, images.clientPath + 'bar-opacity.png');
+ setAlpha.call(that, iconAlpha, toFixedNumeric(((255 - (!isNullish(all) ? all.a : 0)) * 100) / 255, 4));
+ iconImage = that.icon.find('.Image:first').css({
+ backgroundImage: 'url(\'' + images.clientPath + images.picker.file + '\')'
+ }).bind('click', iconImageClicked);
+ if (win.bindToInput && win.updateInputColor) {
+ win.input.css({
+ backgroundColor: (hex && '#' + hex) || 'transparent',
+ color: isNullish(all) || all.v > 75 ? '#000000' : '#ffffff'
+ });
+ }
+ moveBar = tbody.find('.Move:first').bind('mousedown', moveBarMouseDown);
+ color.active.bind(expandableColorChanged);
+ } else show.call(that);
+ }
+ /**
+ *
+ * @returns {void}
+ */
+ function destroy () {
+ container.find('td.Radio input').unbind('click', radioClicked);
+ currentPreview.unbind('click', currentClicked);
+ cancelButton.unbind('click', cancelClicked);
+ okButton.unbind('click', okClicked);
+ if (settings.window.expandable) {
+ iconImage.unbind('click', iconImageClicked);
+ moveBar.unbind('mousedown', moveBarMouseDown);
+ that.icon = null;
+ }
+ container.find('.QuickColor').unbind('click', quickPickClicked);
+ colorMapDiv = null;
+ colorBarDiv = null;
+ colorMapL1 = null;
+ colorMapL2 = null;
+ colorMapL3 = null;
+ colorBarL1 = null;
+ colorBarL2 = null;
+ colorBarL3 = null;
+ colorBarL4 = null;
+ colorBarL5 = null;
+ colorBarL6 = null;
+ colorMap.destroy();
+ colorMap = null;
+ colorBar.destroy();
+ colorBar = null;
+ colorPicker.destroy();
+ colorPicker = null;
+ activePreview = null;
+ currentPreview = null;
+ okButton = null;
+ cancelButton = null;
+ grid = null;
+ commitCallback = null;
+ cancelCallback = null;
+ liveCallback = null;
+ container.html('');
+ for (let i = 0; i < List.length; i++) {
+ if (List[i] === that) {
+ List.splice(i, 1);
+ i--; // Decrement to ensure we don't miss next item (lgtm warning)
+ }
+ }
+ }
+ const {images, localization} = settings; // local copies for YUI compressor
+ const color = {
+ active: (typeof settings.color.active).toString().toLowerCase() === 'string'
+ ? new Color({ahex: !settings.window.alphaSupport && settings.color.active
+ ? settings.color.active.substring(0, 6) + 'ff'
+ : settings.color.active
+ })
+ : new Color({ahex: !settings.window.alphaSupport &&
+ settings.color.active.val('ahex')
+ ? settings.color.active.val('ahex').substring(0, 6) + 'ff'
+ : settings.color.active.val('ahex')
+ }),
+ current: (typeof settings.color.active).toString().toLowerCase() === 'string'
+ ? new Color({ahex: !settings.window.alphaSupport && settings.color.active
+ ? settings.color.active.substring(0, 6) + 'ff'
+ : settings.color.active})
+ : new Color({ahex: !settings.window.alphaSupport &&
+ settings.color.active.val('ahex')
+ ? settings.color.active.val('ahex').substring(0, 6) + 'ff'
+ : settings.color.active.val('ahex')
+ }),
+ quickList: settings.color.quickList
+ };
+
+ if (typeof commitCallback !== 'function') {
+ commitCallback = null;
+ }
+ if (typeof liveCallback !== 'function') {
+ liveCallback = null;
+ }
+ if (typeof cancelCallback !== 'function') {
+ cancelCallback = null;
+ }
+
+ let elementStartX = null, // Used to record the starting css positions for dragging the control
+ elementStartY = null,
+ pageStartX = null, // Used to record the mousedown coordinates for dragging the control
+ pageStartY = null,
+ container = null,
+ colorMapDiv = null,
+ colorBarDiv = null,
+ colorMapL1 = null, // different layers of colorMap and colorBar
+ colorMapL2 = null,
+ colorMapL3 = null,
+ colorBarL1 = null,
+ colorBarL2 = null,
+ colorBarL3 = null,
+ colorBarL4 = null,
+ colorBarL5 = null,
+ colorBarL6 = null,
+ colorMap = null, // color maps
+ colorBar = null,
+ colorPicker = null,
+ activePreview = null, // color boxes above the radio buttons
+ currentPreview = null,
+ okButton = null,
+ cancelButton = null,
+ grid = null, // preset colors grid
+ iconColor = null, // iconColor for popup icon
+ iconAlpha = null, // iconAlpha for popup icon
+ iconImage = null, // iconImage popup icon
+ moveBar = null; // drag bar
+
+ $.extend(true, that, {
+ // public properties, methods, and callbacks
+ commitCallback, // commitCallback function can be overridden to return the selected color to a method you specify when the user clicks "OK"
+ liveCallback, // liveCallback function can be overridden to return the selected color to a method you specify in live mode (continuous update)
+ cancelCallback, // cancelCallback function can be overridden to a method you specify when the user clicks "Cancel"
+ color,
+ show,
+ hide,
+ destroy // destroys this control entirely, removing all events and objects, and removing itself from the List
});
+ List.push(that);
+ setTimeout(function () {
+ initialize.call(that);
+ }, 0);
+ //});
}
/**
* @typedef {PlainObject} external:jQuery.fn.jPickerOptionsIconInfo
diff --git a/src/editor/components/seColorPicker.js b/src/editor/components/seColorPicker.js
index 1daa12c2..49b8ce58 100644
--- a/src/editor/components/seColorPicker.js
+++ b/src/editor/components/seColorPicker.js
@@ -172,13 +172,13 @@ export class SeColorPicker extends HTMLElement {
this.paintBox = new PaintBox(this.$block, this.type);
let {paint} = this.paintBox;
$(this.$picker).click(() => {
- $(this.$color_picker)
+ /* $(this.$color_picker)
.draggable({
cancel: '.jGraduate_tabs, .jGraduate_colPick, .jGraduate_gradPick, .jPicker',
containment: 'window'
- });
+ }); */
jGraduateMethod(
- $(this.$color_picker),
+ this.$color_picker,
{
images: {clientPath: './components/jgraduate/images/'},
paint,