(function () { var ns = $.namespace("pskl.controller.settings"); var URL_MAX_LENGTH = 30; var MAX_GIF_COLORS = 256; var MAX_EXPORT_ZOOM = 20; var DEFAULT_EXPORT_ZOOM = 10; ns.GifExportController = function (piskelController) { this.piskelController = piskelController; }; /** * List of Resolutions applicable for Gif export * @static * @type {Array} array of Objects {zoom:{Number}, default:{Boolean}} */ ns.GifExportController.RESOLUTIONS = []; for (var i = 1 ; i <= MAX_EXPORT_ZOOM ; i++) { ns.GifExportController.RESOLUTIONS.push({ zoom : i }); } ns.GifExportController.prototype.init = function () { this.optionTemplate_ = pskl.utils.Template.get("gif-export-option-template"); this.uploadStatusContainerEl = document.querySelector(".gif-upload-status"); this.previewContainerEl = document.querySelector(".gif-export-preview"); this.selectResolutionEl = document.querySelector(".gif-export-select-resolution"); this.uploadButton = $(".gif-upload-button"); this.uploadButton.click(this.onUploadButtonClick_.bind(this)); this.downloadButton = $(".gif-download-button"); this.downloadButton.click(this.onDownloadButtonClick_.bind(this)); this.createOptionElements_(); }; ns.GifExportController.prototype.onUploadButtonClick_ = function (evt) { evt.originalEvent.preventDefault(); var zoom = this.getSelectedZoom_(), fps = this.piskelController.getFPS(); this.renderAsImageDataAnimatedGIF(zoom, fps, this.uploadImageData_.bind(this)); }; ns.GifExportController.prototype.onDownloadButtonClick_ = function (evt) { var zoom = this.getSelectedZoom_(), fps = this.piskelController.getFPS(); this.renderAsImageDataAnimatedGIF(zoom, fps, this.downloadImageData_.bind(this)); }; ns.GifExportController.prototype.downloadImageData_ = function (imageData) { var fileName = this.piskelController.getPiskel().getDescriptor().name + '.gif'; pskl.utils.BlobUtils.dataToBlob(imageData, "image/gif", function(blob) { pskl.utils.FileUtils.downloadAsFile(blob, fileName); }); }; ns.GifExportController.prototype.uploadImageData_ = function (imageData) { this.updatePreview_(imageData); this.previewContainerEl.classList.add("preview-upload-ongoing"); console.log(imageData.length); pskl.app.imageUploadService.upload(imageData, this.onImageUploadCompleted_.bind(this), this.onImageUploadFailed_.bind(this)); }; ns.GifExportController.prototype.onImageUploadCompleted_ = function (imageUrl) { this.updatePreview_(imageUrl); this.updateStatus_(imageUrl); this.previewContainerEl.classList.remove("preview-upload-ongoing"); }; ns.GifExportController.prototype.onImageUploadFailed_ = function (event, xhr) { if (xhr.status === 500) { $.publish(Events.SHOW_NOTIFICATION, [{ "content": "Upload failed : " + xhr.responseText, "hideDelay" : 5000 }]); } }; ns.GifExportController.prototype.updatePreview_ = function (src) { this.previewContainerEl.innerHTML = "