diff --git a/js/pastebox.js b/js/pastebox.js index 3a82ead63e..2c28746c0c 100644 --- a/js/pastebox.js +++ b/js/pastebox.js @@ -9,12 +9,27 @@ // 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() { - this._canvas = null; this._stage = null; this._refreshCanvas = null; @@ -24,27 +39,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 +93,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 +108,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 +119,10 @@ class PasteBox { } } + /** + * @public + * @returns {void} + */ show() { this._container.visible = true; this._refreshCanvas(); @@ -82,32 +130,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 +175,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))); } }