// Copyright (c) 2014-17 Walter Bender // // This program is free software; you can redistribute it and/or // modify it under the terms of the The GNU Affero General Public // License as published by the Free Software Foundation; either // version 3 of the License, or (at your option) any later version. // // You should have received a copy of the GNU Affero General Public // License along with this library; if not, write to the Free Software // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA var CONFIRMBOX = ' confirm ' // A pop up for deleting projects function ClearBox () { this._canvas = null; this._stage = null; this._refreshCanvas = null; this._doClear = null; this._container = null; this.save = null; this.close = null; this._scale = 1; this.setCanvas = function (canvas) { this._canvas = canvas; return this; }; this.setStage = function (stage) { this._stage = stage; return this; }; this.setClear = function (clear) { this._doClear = clear; return this; }; this.setRefreshCanvas = function (refreshCanvas) { this._refreshCanvas = refreshCanvas; return this; }; this._hide = function () { if (this._container != null) { this._container.visible = false; this._refreshCanvas(); } }; this.show = function (scale) { this._scale = scale; if (this._container == null) { this._container = new createjs.Container(); this._stage.addChild(this._container); this._container.x = Math.floor(((this._canvas.width / scale) - 180) / 2); this._container.y = 27; function __processBackground(that, name, bitmap, extras) { that._container.addChild(bitmap); that._loadClearContainerHandler(); that._completeShow(); } this._makeBoxBitmap(CONFIRMBOX.replace(/confirm/g, _('confirm')), 'box', __processBackground, null); } else { this._completeShow(); } }; this._completeShow = function () { this._container.visible = true; this._refreshCanvas(); }; this._loadClearContainerHandler = function () { var 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); hitArea.x = 0; hitArea.y = 0; this._container.hitArea = hitArea; var locked = false; var that = this; this._container.on('click', function(event) { // We need a lock to "debouce" the click. if (locked) { console.log('debouncing click'); return; } locked = true; setTimeout(function () { locked = false; }, 500); var x = (event.stageX / that._scale) - that._container.x; var y = (event.stageY / that._scale) - that._container.y; if (x > 125 && y < 55) { that._hide(); } else if (y > 55) { // Clear that._doClear(true); that._hide(); } }); }; this._makeBoxBitmap = function (data, name, callback, extras) { // Async creation of bitmap from SVG data // Works with Chrome, Safari, Firefox (untested on IE) var img = new Image(); var that = this; img.onload = function() { var bitmap = new createjs.Bitmap(img); callback(that, name, bitmap, extras); }; img.src = 'data:image/svg+xml;base64,' + window.btoa(unescape(encodeURIComponent(data))); }; };