diff --git a/js/pastebox.js b/js/pastebox.js index 024d8ddfc4..2576a6610b 100644 --- a/js/pastebox.js +++ b/js/pastebox.js @@ -9,51 +9,53 @@ // 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 = ' '; + // A pop up for pasting from the browser clipboard -function PasteBox() { - let PASTEBOX = - ' '; - - this._canvas = null; - this._stage = null; - this._refreshCanvas = null; - this._paste = null; - this._container = null; - this.save = null; - this.close = null; - this._scale = 1; - - this.setCanvas = function(canvas) { +class PasteBox { + constructor() { + + this._canvas = null; + this._stage = null; + this._refreshCanvas = null; + this._paste = null; + this._container = null; + this.save = null; + this.close = null; + this._scale = 1; + } + + setCanvas(canvas) { this._canvas = canvas; return this; - }; + } - this.setStage = function(stage) { + setStage(stage) { this._stage = stage; return this; - }; + } - this.setPaste = function(paste) { + setPaste(paste) { this._paste = paste; return this; - }; + } - this.setRefreshCanvas = function(refreshCanvas) { + setRefreshCanvas(refreshCanvas) { this._refreshCanvas = refreshCanvas; return this; - }; + } - this.hide = function() { + hide() { if (this._container != null) { this._container.visible = false; this._refreshCanvas(); // paste.visible = false; - docById("paste").value = ""; + docById("paste").value = ""; docById("paste").style.visibility = "hidden"; } - }; + } - this.createBox = function(scale, x, y) { + createBox(scale, x, y) { if (this._container == null) { this._scale = scale; @@ -62,7 +64,7 @@ function PasteBox() { this._container.x = x; this._container.y = y; - function __processBackground(that, name, bitmap, extras) { + const __processBackground = (that, name, bitmap, extras) => { that._container.addChild(bitmap); that._loadClearContainerHandler(); that._container.visible = true; @@ -71,20 +73,20 @@ function PasteBox() { this._makeBoxBitmap(PASTEBOX, "box", __processBackground, null); } - }; + } - this.show = function() { + show() { this._container.visible = true; this._refreshCanvas(); // this._paste.visibile = true; docById("paste").style.visibility = "visible"; - }; + } - this.getPos = function() { + getPos() { return [this._container.x, this._container.y]; - }; + } - this._loadClearContainerHandler = function() { + _loadClearContainerHandler() { let hitArea = new createjs.Shape(); this.bounds = this._container.getBounds(); hitArea.graphics @@ -102,7 +104,7 @@ function PasteBox() { let locked = false; let that = this; - this._container.on("click", function(event) { + this._container.on("click", (event) => { // We need a lock to "debouce" the click. if (locked) { console.debug("debouncing click"); @@ -111,31 +113,31 @@ function PasteBox() { locked = true; - setTimeout(function() { + setTimeout(() => { locked = false; }, 500); - let x = event.stageX / that._scale - that._container.x; - let y = event.stageY / that._scale - that._container.y; + let x = event.stageX / this._scale - this._container.x; + let y = event.stageY / this._scale - this._container.y; if (x > 125 && y < 55) { - that.hide(); + this.hide(); } }); - }; + } - this._makeBoxBitmap = function(data, name, callback, extras) { + _makeBoxBitmap(data, name, callback, extras) { // Async creation of bitmap from SVG data // Works with Chrome, Safari, Firefox (untested on IE) let img = new Image(); let that = this; - img.onload = function() { + img.onload = () => { let bitmap = new createjs.Bitmap(img); - callback(that, name, bitmap, extras); + callback(this, name, bitmap, extras); }; img.src = "data:image/svg+xml;base64," + window.btoa(unescape(encodeURIComponent(data))); - }; + } }