Skip to content

Commit

Permalink
Revert "adding classes to pastebox.js (#2641)"
Browse files Browse the repository at this point in the history
This reverts commit 9302909.
  • Loading branch information
meganindya authored Dec 5, 2020
1 parent 9302909 commit 7b8b27a
Showing 1 changed file with 42 additions and 44 deletions.
86 changes: 42 additions & 44 deletions js/pastebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,51 @@
// 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 = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="280" height="55"> <rect width="280" height="55" x="0" y="-3.5762787e-06" style="fill:#f0f0f0;fill-opacity:1;fill-rule:nonzero;stroke:none" /> <g transform="translate(225,0)" style="fill:#000000;display:block"> <path d="m 27.557,5.053 c -12.43,0 -22.5,10.076 -22.5,22.497 0,12.432 10.07,22.503 22.5,22.503 12.431,0 22.5,-10.071 22.5,-22.503 0,-12.421 -10.07,-22.497 -22.5,-22.497 z m 10.199,28.159 c 1.254,1.256 1.257,3.291 0,4.545 -0.628,0.629 -1.451,0.943 -2.274,0.943 -0.822,0 -1.644,-0.314 -2.27,-0.94 l -5.76,-5.761 -5.76,5.761 c -0.627,0.626 -1.449,0.94 -2.271,0.94 -0.823,0 -1.647,-0.314 -2.275,-0.943 -1.254,-1.254 -1.254,-3.289 0.004,-4.545 l 5.758,-5.758 -5.758,-5.758 c -1.258,-1.254 -1.258,-3.292 -0.004,-4.546 1.255,-1.254 3.292,-1.259 4.546,0 l 5.76,5.759 5.76,-5.759 c 1.252,-1.259 3.288,-1.254 4.544,0 1.257,1.254 1.254,3.292 0,4.546 l -5.758,5.758 5.758,5.758 z" style="fill:#000000;display:inline" /> </g></svg>';

// A pop up for pasting from the browser clipboard
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) {
function PasteBox() {
let PASTEBOX =
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="280" height="55"> <rect width="280" height="55" x="0" y="-3.5762787e-06" style="fill:#f0f0f0;fill-opacity:1;fill-rule:nonzero;stroke:none" /> <g transform="translate(225,0)" style="fill:#000000;display:block"> <path d="m 27.557,5.053 c -12.43,0 -22.5,10.076 -22.5,22.497 0,12.432 10.07,22.503 22.5,22.503 12.431,0 22.5,-10.071 22.5,-22.503 0,-12.421 -10.07,-22.497 -22.5,-22.497 z m 10.199,28.159 c 1.254,1.256 1.257,3.291 0,4.545 -0.628,0.629 -1.451,0.943 -2.274,0.943 -0.822,0 -1.644,-0.314 -2.27,-0.94 l -5.76,-5.761 -5.76,5.761 c -0.627,0.626 -1.449,0.94 -2.271,0.94 -0.823,0 -1.647,-0.314 -2.275,-0.943 -1.254,-1.254 -1.254,-3.289 0.004,-4.545 l 5.758,-5.758 -5.758,-5.758 c -1.258,-1.254 -1.258,-3.292 -0.004,-4.546 1.255,-1.254 3.292,-1.259 4.546,0 l 5.76,5.759 5.76,-5.759 c 1.252,-1.259 3.288,-1.254 4.544,0 1.257,1.254 1.254,3.292 0,4.546 l -5.758,5.758 5.758,5.758 z" style="fill:#000000;display:inline" /> </g></svg>';

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) {
this._canvas = canvas;
return this;
}
};

setStage(stage) {
this.setStage = function(stage) {
this._stage = stage;
return this;
}
};

setPaste(paste) {
this.setPaste = function(paste) {
this._paste = paste;
return this;
}
};

setRefreshCanvas(refreshCanvas) {
this.setRefreshCanvas = function(refreshCanvas) {
this._refreshCanvas = refreshCanvas;
return this;
}
};

hide() {
this.hide = function() {
if (this._container != null) {
this._container.visible = false;
this._refreshCanvas();
// paste.visible = false;
docById("paste").value = "";
docById("paste").value = "";
docById("paste").style.visibility = "hidden";
}
}
};

createBox(scale, x, y) {
this.createBox = function(scale, x, y) {
if (this._container == null) {
this._scale = scale;

Expand All @@ -64,7 +62,7 @@ class PasteBox {
this._container.x = x;
this._container.y = y;

const __processBackground = (that, name, bitmap, extras) => {
function __processBackground(that, name, bitmap, extras) {
that._container.addChild(bitmap);
that._loadClearContainerHandler();
that._container.visible = true;
Expand All @@ -73,20 +71,20 @@ class PasteBox {

this._makeBoxBitmap(PASTEBOX, "box", __processBackground, null);
}
}
};

show() {
this.show = function() {
this._container.visible = true;
this._refreshCanvas();
// this._paste.visibile = true;
docById("paste").style.visibility = "visible";
}
};

getPos() {
this.getPos = function() {
return [this._container.x, this._container.y];
}
};

_loadClearContainerHandler() {
this._loadClearContainerHandler = function() {
let hitArea = new createjs.Shape();
this.bounds = this._container.getBounds();
hitArea.graphics
Expand All @@ -104,7 +102,7 @@ class PasteBox {
let locked = false;
let that = this;

this._container.on("click", (event) => {
this._container.on("click", function(event) {
// We need a lock to "debouce" the click.
if (locked) {
console.debug("debouncing click");
Expand All @@ -113,31 +111,31 @@ class PasteBox {

locked = true;

setTimeout(() => {
setTimeout(function() {
locked = false;
}, 500);

let x = event.stageX / this._scale - this._container.x;
let y = event.stageY / this._scale - this._container.y;
let x = event.stageX / that._scale - that._container.x;
let y = event.stageY / that._scale - that._container.y;
if (x > 125 && y < 55) {
this.hide();
that.hide();
}
});
}
};

_makeBoxBitmap(data, name, callback, extras) {
this._makeBoxBitmap = function(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 = () => {
img.onload = function() {
let bitmap = new createjs.Bitmap(img);
callback(this, name, bitmap, extras);
callback(that, name, bitmap, extras);
};

img.src =
"data:image/svg+xml;base64," +
window.btoa(unescape(encodeURIComponent(data)));
}
};
}

0 comments on commit 7b8b27a

Please sign in to comment.