From b7a3b8b6daee951ecb9f18c6a4b519c17655e37b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 2 Feb 2021 00:05:56 +0530 Subject: [PATCH 1/2] add jsdoc and solved the linting issues --- js/pastebox.js | 83 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/js/pastebox.js b/js/pastebox.js index 3a82ead63e..8ca0b9d143 100644 --- a/js/pastebox.js +++ b/js/pastebox.js @@ -9,12 +9,28 @@ // License along with this library; if not, write to the Free Software // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA -const PASTEBOX = ' '; +const PASTEBOX = + ' '; // A pop up for pasting from the browser clipboard + +/* global docById, createjs */ + +/* + Global locations + js/utils/utils.js + _ + js/activity.js + createjs +*/ + +/* exported PasteBox */ class PasteBox { - constructor() { + /** + * @constructor + */ + constructor() { this._canvas = null; this._stage = null; this._refreshCanvas = null; @@ -24,27 +40,50 @@ class PasteBox { this.close = null; this._scale = 1; } - + /** + * @public + * @param {Object} canvas object + * @returns {Object} createjs canvas + */ setCanvas(canvas) { this._canvas = canvas; return this; } + /** + * @public + * @param {Object} stage + * @returns {Object} createjs stage + */ setStage(stage) { this._stage = stage; return this; } + /** + * @public + * @param {Object} paste + * @returns {Object} paste + */ setPaste(paste) { this._paste = paste; return this; } + /** + * @public + * @param {Object} refreshCanvas + * @returns {Object} refreshCanvas + */ setRefreshCanvas(refreshCanvas) { this._refreshCanvas = refreshCanvas; return this; } + /** + * @public + * @returns {void} + */ hide() { if (this._container != null) { this._container.visible = false; @@ -55,6 +94,12 @@ class PasteBox { } } + /** + * @public + * @param {number} scale + * @param {number} x coordinate + * @param {number} y coordinate + */ createBox(scale, x, y) { if (this._container == null) { this._scale = scale; @@ -64,7 +109,7 @@ class PasteBox { this._container.x = x; this._container.y = y; - const __processBackground = (that, name, bitmap, extras) => { + const __processBackground = (that, name, bitmap) => { that._container.addChild(bitmap); that._loadClearContainerHandler(); that._container.visible = true; @@ -75,6 +120,10 @@ class PasteBox { } } + /** + * @public + * @returns {void} + */ show() { this._container.visible = true; this._refreshCanvas(); @@ -82,32 +131,34 @@ class PasteBox { docById("paste").style.visibility = "visible"; } + /** + * @public + * @returns {Object} + */ getPos() { return [this._container.x, this._container.y]; } + /** + * @private + * @returns {void} + */ _loadClearContainerHandler() { const hitArea = new createjs.Shape(); this.bounds = this._container.getBounds(); hitArea.graphics .beginFill("#FFF") - .drawRect( - this.bounds.x, - this.bounds.y, - this.bounds.width, - this.bounds.height - ); + .drawRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height); hitArea.x = 0; hitArea.y = 0; this._container.hitArea = hitArea; let locked = false; - const that = this; this._container.on("click", (event) => { // We need a lock to "debouce" the click. if (locked) { - console.debug("debouncing click"); + // console.debug("debouncing click"); return; } @@ -125,19 +176,19 @@ class PasteBox { }); } + /** + * @deprecated + */ _makeBoxBitmap(data, name, callback, extras) { // Async creation of bitmap from SVG data // Works with Chrome, Safari, Firefox (untested on IE) const img = new Image(); - const that = this; img.onload = () => { const bitmap = new createjs.Bitmap(img); callback(this, name, bitmap, extras); }; - img.src = - "data:image/svg+xml;base64," + - window.btoa(unescape(encodeURIComponent(data))); + img.src = "data:image/svg+xml;base64," + window.btoa(unescape(encodeURIComponent(data))); } } From a521c30ad355916d46e9ac414de877d96dfa4797 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 2 Feb 2021 00:06:27 +0530 Subject: [PATCH 2/2] prettify the code --- js/pastebox.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/js/pastebox.js b/js/pastebox.js index 8ca0b9d143..2c28746c0c 100644 --- a/js/pastebox.js +++ b/js/pastebox.js @@ -26,7 +26,6 @@ const PASTEBOX = /* exported PasteBox */ class PasteBox { - /** * @constructor */ @@ -52,7 +51,7 @@ class PasteBox { /** * @public - * @param {Object} stage + * @param {Object} stage * @returns {Object} createjs stage */ setStage(stage) { @@ -60,11 +59,11 @@ class PasteBox { return this; } - /** - * @public - * @param {Object} paste - * @returns {Object} paste - */ + /** + * @public + * @param {Object} paste + * @returns {Object} paste + */ setPaste(paste) { this._paste = paste; return this; @@ -72,7 +71,7 @@ class PasteBox { /** * @public - * @param {Object} refreshCanvas + * @param {Object} refreshCanvas * @returns {Object} refreshCanvas */ setRefreshCanvas(refreshCanvas) { @@ -96,7 +95,7 @@ class PasteBox { /** * @public - * @param {number} scale + * @param {number} scale * @param {number} x coordinate * @param {number} y coordinate */