From eaa65b1329fd92d91b985efa4ff1f9e303afe13e Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Wed, 3 Feb 2021 20:48:22 +0530 Subject: [PATCH] #46 jquery remove and convert to pure javascript --- .../components/jgraduate/ColorValuePicker.js | 20 +- src/editor/components/jgraduate/Slider.js | 20 +- .../components/jgraduate/jQuery.jGraduate.js | 345 ++++++++++-------- .../components/jgraduate/jQuery.jPicker.js | 50 +-- 4 files changed, 248 insertions(+), 187 deletions(-) diff --git a/src/editor/components/jgraduate/ColorValuePicker.js b/src/editor/components/jgraduate/ColorValuePicker.js index a658ee6a..bcd16925 100644 --- a/src/editor/components/jgraduate/ColorValuePicker.js +++ b/src/editor/components/jgraduate/ColorValuePicker.js @@ -253,16 +253,16 @@ export default class ColorValuePicker { */ function colorChanged (ui, context) { const all = ui.val('all'); - if (context !== red.get(0)) red.val(!isNullish(all) ? all.r : ''); - if (context !== green.get(0)) green.val(!isNullish(all) ? all.g : ''); - if (context !== blue.get(0)) blue.val(!isNullish(all) ? all.b : ''); - if (alpha && context !== alpha.get(0)) alpha.val(!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : ''); - if (context !== hue.get(0)) hue.val(!isNullish(all) ? all.h : ''); - if (context !== saturation.get(0)) saturation.val(!isNullish(all) ? all.s : ''); - if (context !== value.get(0)) value.val(!isNullish(all) ? all.v : ''); - if (context !== hex.get(0) && ((bindedHex && context !== bindedHex.get(0)) || !bindedHex)) hex.val(!isNullish(all) ? all.hex : ''); - if (bindedHex && context !== bindedHex.get(0) && context !== hex.get(0)) bindedHex.val(!isNullish(all) ? all.hex : ''); - if (ahex && context !== ahex.get(0)) ahex.val(!isNullish(all) ? all.ahex.substring(6) : ''); + if (context !== red) red.value = (!isNullish(all) ? all.r : ''); + if (context !== green) green.value = (!isNullish(all) ? all.g : ''); + if (context !== blue) blue.value = (!isNullish(all) ? all.b : ''); + if (alpha && context !== alpha) alpha.value = (!isNullish(all) ? toFixedNumeric((all.a * 100) / 255, alphaPrecision) : ''); + if (context !== hue) hue.value = (!isNullish(all) ? all.h : ''); + if (context !== saturation) saturation.value = (!isNullish(all) ? all.s : ''); + if (context !== value) value.value = (!isNullish(all) ? all.v : ''); + if (context !== hex && ((bindedHex && context !== bindedHex) || !bindedHex)) hex.value = (!isNullish(all) ? all.hex : ''); + if (bindedHex && context !== bindedHex && context !== hex) bindedHex.value = (!isNullish(all) ? all.hex : ''); + if (ahex && context !== ahex) ahex.value = (!isNullish(all) ? all.ahex.substring(6) : ''); } /** * Unbind all events and null objects. diff --git a/src/editor/components/jgraduate/Slider.js b/src/editor/components/jgraduate/Slider.js index 315e30d5..44a67b2d 100644 --- a/src/editor/components/jgraduate/Slider.js +++ b/src/editor/components/jgraduate/Slider.js @@ -10,6 +10,18 @@ const isNullish = (val) => { return val === null || val === undefined; }; +function findPos (obj) { + let curleft = 0; + let curtop = 0; + if (obj.offsetParent) { + do { + curleft += obj.offsetLeft; + curtop += obj.offsetTop; + } while (obj = obj.offsetParent); + return {left: curleft, top: curtop}; + } + return {left: curleft, top: curtop}; +} /** * Encapsulate slider functionality for the ColorMap and ColorBar - * could be useful to use a jQuery UI draggable for this with certain extensions. @@ -39,7 +51,7 @@ export default class Slider { * @returns {void} */ function mouseDown (e) { - const off = bar.offset(); + const off = findPos(bar); offset = {l: off.left | 0, t: off.top | 0}; clearTimeout(timeout); // using setTimeout for visual updates - once the style is updated the browser will re-render internally allowing the next Javascript to run @@ -130,9 +142,9 @@ export default class Slider { if (arrowH >= barH) arrowOffsetY = (barH >> 1) - (arrowH >> 1); else arrowOffsetY -= arrowH >> 1; // set the arrow position based on these offsets - arrow.css({left: arrowOffsetX + 'px', top: arrowOffsetY + 'px'}); - // arrow.style.left = arrowOffsetX + 'px'; - // arrow.style.top = arrowOffsetY + 'px'; + // arrow.css({left: arrowOffsetX + 'px', top: arrowOffsetY + 'px'}); + arrow.style.left = arrowOffsetX + 'px'; + arrow.style.top = arrowOffsetY + 'px'; }); } diff --git a/src/editor/components/jgraduate/jQuery.jGraduate.js b/src/editor/components/jgraduate/jQuery.jGraduate.js index 329069f0..3dd456cf 100644 --- a/src/editor/components/jgraduate/jQuery.jGraduate.js +++ b/src/editor/components/jgraduate/jQuery.jGraduate.js @@ -1,3 +1,6 @@ +/* eslint-disable unicorn/prefer-node-remove */ +/* eslint-disable prefer-destructuring */ +/* eslint-disable no-unsanitized/property */ /** * @file jGraduate 0.4 * @@ -50,6 +53,19 @@ if (!window.console) { }; } +function findPos (obj) { + let curleft = 0; + let curtop = 0; + if (obj.offsetParent) { + do { + curleft += obj.offsetLeft; + curtop += obj.offsetTop; + } while (obj = obj.offsetParent); + return {left: curleft, top: curtop}; + } + return {left: curleft, top: curtop}; +} + /** * Adds {@link external:jQuery.jGraduate.Paint}, * {@link external:jQuery.fn.jGraduateDefaults}, @@ -244,11 +260,11 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { break; } typeof $this.okCallback === 'function' && $this.okCallback($this.paint); - $this.hide(); + $this.style.display = 'none'; }; const cancelClicked = function () { typeof $this.cancelCallback === 'function' && $this.cancelCallback(); - $this.hide(); + $this.style.display = 'none'; }; $.extend( @@ -265,13 +281,12 @@ export function jGraduateMethod (elem, options, okCallback, cancelCallback) { let // pos = $this.position(), color = null; - const $win = $(window); + const $win = window; if ($this.paint.type === 'none') { $this.paint = new jGraduate.Paint({solidColor: 'ffffff'}); } $this.classList.add('jGraduate_Picker'); - // $this.addClass('jGraduate_Picker'); /* eslint-disable max-len */ $this.innerHTML = '