From 2a59e75cab5e98e6a7cc20e46960177a0efeb30f Mon Sep 17 00:00:00 2001 From: Agriya Dev5 Date: Fri, 5 Feb 2021 17:30:31 +0530 Subject: [PATCH] #46 jquery to js convertion changes --- src/editor/components/jgraduate/Slider.js | 17 +- src/editor/components/jgraduate/Util.js | 16 ++ .../components/jgraduate/jQuery.jGraduate.js | 14 +- .../components/jgraduate/jQuery.jPicker.js | 215 +++++++++--------- 4 files changed, 126 insertions(+), 136 deletions(-) create mode 100644 src/editor/components/jgraduate/Util.js diff --git a/src/editor/components/jgraduate/Slider.js b/src/editor/components/jgraduate/Slider.js index a9cb305e..8f736a48 100644 --- a/src/editor/components/jgraduate/Slider.js +++ b/src/editor/components/jgraduate/Slider.js @@ -1,6 +1,7 @@ /* eslint-disable unicorn/prefer-math-trunc */ /* eslint-disable no-bitwise */ /* eslint-disable unicorn/prefer-ternary */ +import {findPos} from './Util.js'; /** * Whether a value is `null` or `undefined`. * @param {any} val @@ -9,22 +10,6 @@ const isNullish = (val) => { return val === null || val === undefined; }; -/** - * @param {any} obj - * @returns {any} - */ -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. diff --git a/src/editor/components/jgraduate/Util.js b/src/editor/components/jgraduate/Util.js new file mode 100644 index 00000000..3673ef22 --- /dev/null +++ b/src/editor/components/jgraduate/Util.js @@ -0,0 +1,16 @@ +/** + * @param {any} obj + * @returns {any} + */ +export 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}; +} \ No newline at end of file diff --git a/src/editor/components/jgraduate/jQuery.jGraduate.js b/src/editor/components/jgraduate/jQuery.jGraduate.js index aa15f6bf..5d65ff09 100644 --- a/src/editor/components/jgraduate/jQuery.jGraduate.js +++ b/src/editor/components/jgraduate/jQuery.jGraduate.js @@ -23,6 +23,7 @@ /* globals $ */ import Paint from './paint.js'; import {jPickerDefaults, jPickerMethod} from './jQuery.jPicker.js'; +import {findPos} from './Util.js'; /** * @todo JFH: This jQuery plugin was adapted to work within a Web Component. @@ -54,19 +55,6 @@ 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}, diff --git a/src/editor/components/jgraduate/jQuery.jPicker.js b/src/editor/components/jgraduate/jQuery.jPicker.js index 8e35cbac..c969a2e5 100755 --- a/src/editor/components/jgraduate/jQuery.jPicker.js +++ b/src/editor/components/jgraduate/jQuery.jPicker.js @@ -1,7 +1,4 @@ -/* eslint-disable jsdoc/require-file-overview */ -import ColorValuePicker from './ColorValuePicker.js'; -import Slider from './Slider.js'; -/* globals $ */ +/* eslint-disable unicorn/prefer-modern-dom-apis */ /** * @file jPicker (Adapted from version 1.1.6) * @@ -18,6 +15,14 @@ import Slider from './Slider.js'; * John Dyers' website: {@link http://johndyer.name} * Color Picker page: {@link http://johndyer.name/photoshop-like-javascript-color-picker/} */ +/* globals $ */ +/* eslint-disable unicorn/prefer-math-trunc */ +/* eslint-disable no-unsanitized/property */ +/* eslint-disable no-bitwise */ +/* eslint-disable max-len */ +import ColorValuePicker from './ColorValuePicker.js'; +import Slider from './Slider.js'; +import {findPos} from './Util.js'; /** * @external Math @@ -626,15 +631,15 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc } } if (settings.window.expandable) { - that.insertAdjacentElement('afterend', ` - -   -   -   -   - - `); - // $(that).after('    '); + const content = document.createElement('span'); + content.classList.add('jPicker'); + content.innerHTML = ` +   +   +   +   + `; + that.insertAdjacentElement('afterend', content); } else { settings.window.liveUpdate = false; // Basic control binding for inline use - You will need to override the liveCallback or commitCallback function to retrieve results } @@ -1178,12 +1183,8 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc iconColor.style.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.style.backgroundColor = (hex && '#' + hex) || 'transparent'; - // settings.window.input.style.color = isNullish(va) || va.v > 75 ? '#000000' : '#ffffff'; - settings.window.input.css({ - backgroundColor: (hex && '#' + hex) || 'transparent', - color: isNullish(va) || va.v > 75 ? '#000000' : '#ffffff' - }); + settings.window.input.style.backgroundColor = (hex && '#' + hex) || 'transparent'; + settings.window.input.style.color = isNullish(va) || va.v > 75 ? '#000000' : '#ffffff'; } } /** @@ -1191,14 +1192,13 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc * @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')); + elementStartX = Number.parseInt(container.style.left); + elementStartY = Number.parseInt(container.style.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); + document.addEventListener('mousemove', documentMouseMove); + document.addEventListener('mouseup', documentMouseUp); e.preventDefault(); // prevent attempted dragging of the column } /** @@ -1209,11 +1209,9 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc container.style.left = elementStartX - (pageStartX - e.pageX) + 'px'; container.style.top = elementStartY - (pageStartY - e.pageY) + 'px'; if (settings.window.expandable && !$.support.boxModel) { - // const prev = container.previousElementSibling; - container.prev().css({ - left: container.css('left'), - top: container.css('top') - }); + const prev = container.previousElementSibling; + prev.style.left = container.style.left; + prev.style.top = container.style.top; } e.stopPropagation(); e.preventDefault(); @@ -1224,7 +1222,8 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc * @returns {false} */ function documentMouseUp (e) { - $(document).unbind('mousemove', documentMouseMove).unbind('mouseup', documentMouseUp); + document.removeEventListener('mousemove', documentMouseMove); + document.removeEventListener('mouseup', documentMouseUp); e.stopPropagation(); e.preventDefault(); return false; @@ -1236,7 +1235,7 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc function quickPickClicked (e) { e.preventDefault(); e.stopPropagation(); - color.active.val('ahex', $(this).attr('title') || null, e.target); + color.active.val('ahex', e.target.getAttribute('title') || null, e.target); return false; } /** @@ -1251,22 +1250,22 @@ export function jPickerMethod (elem, options, commitCallback, liveCallback, canc */ function attachIFrame () { if (!settings.window.expandable || $.support.boxModel) return; - const table = container.find('table:first'); - container.before('