From aaf254cc3f2ca3261a57d5c63d3ab3373e52f829 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 30 Aug 2012 01:16:13 +0200 Subject: [PATCH 1/2] post --- index.html | 1 + js/piskel.js | 76 ++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 63 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 4800f151f..ede74f297 100644 --- a/index.html +++ b/index.html @@ -15,6 +15,7 @@
+ diff --git a/js/piskel.js b/js/piskel.js index 3600c233d..79521e44d 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -3,8 +3,8 @@ // Constants: TRANSPARENT_COLOR = 'tc', - //TRANSPARENT_COLOR = 'pink', DEFAULT_PEN_COLOR = '#000000', + PISKEL_SERVICE_URL = 'http://2.piskel-app.appspot.com', // Configuration: // Canvas size in pixel size (not dpi related) @@ -50,15 +50,51 @@ var piskel = { init : function () { frameSheet = FrameSheetModel.getInstance(framePixelWidth, framePixelHeight); - frameSheet.addEmptyFrame(); this.setActiveFrame(0); + frameSheet.addEmptyFrame(); + + var frameId = this.getFrameIdFromUrl(); + if (frameId) { + this.loadFramesheetFromService(frameId); + } else { + this.finishInit(); + } + }, + finishInit : function () { this.initPalette(); this.initDrawingArea(); this.initPreviewSlideshow(); this.initAnimationPreview(); this.initColorPicker(); - this.initLocalStorageBackup(); + this.initLocalStorageBackup(); + + this.startAnimation(); + }, + + getFrameIdFromUrl : function() { + var href = window.location.href; + if (href.indexOf('frameId=') != -1) { + console.log(href.substring(href.indexOf('frameId=')+8)); + return href.substring(href.indexOf('frameId=')+8); + } + }, + + loadFramesheetFromService : function (frameId) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', PISKEL_SERVICE_URL + '/get?l=' + frameId, true); + xhr.responseType = 'text'; + + xhr.onload = function(e) { + frameSheet.deserialize(this.responseText); + piskel.finishInit(); + }; + + xhr.onerror = function () { + piskel.finishInit(); + }; + + xhr.send(); }, initLocalStorageBackup: function() { @@ -170,17 +206,7 @@ this.createPreviews(); }, - initPreviewSlideshow: function() { - var addFrameButton = $('add-frame-button'); - addFrameButton.addEventListener('mousedown', function() { - frameSheet.addEmptyFrame(); - piskel.setActiveFrameAndRedraw(frameSheet.getFrameCount() - 1); - }); - this.createPreviews(); - }, - initAnimationPreview : function() { - var scope = this; var previewAnimationContainer = $('preview-canvas-container'); previewCanvas = document.createElement('canvas'); @@ -190,7 +216,10 @@ previewAnimationContainer.appendChild(previewCanvas); previewCanvas.setAttribute('width', framePixelWidth * previewAnimationCanvasDpi); previewCanvas.setAttribute('height', framePixelHeight * previewAnimationCanvasDpi); - + }, + + startAnimation : function () { + var scope = this; var animFPSTuner = document.getElementById("preview-fps"); var animPreviewFPS = parseInt(animFPSTuner.value, 10); var startPreviewRefresh = function() { @@ -428,6 +457,25 @@ x : x - canvasRect.left, y : y - canvasRect.top } + }, + + storeSheet : function (event) { + var xhr = new XMLHttpRequest(); + var formData = new FormData(); + formData.append('framesheet_content', frameSheet.serialize()); + formData.append('fps_speed', $('preview-fps').value); + xhr.open('POST', PISKEL_SERVICE_URL + "/store", true); + xhr.onload = function(e) { + if (this.status == 200) { + alert("stored key : " + this.responseText); + } + }; + + xhr.send(formData); + + event.stopPropagation(); + event.preventDefault(); + return false; } }; From a1872d35214fd65e2135528c0437175bd1f9a87b Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 30 Aug 2012 01:26:14 +0200 Subject: [PATCH 2/2] support post --- js/piskel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/piskel.js b/js/piskel.js index 79521e44d..50514232e 100644 --- a/js/piskel.js +++ b/js/piskel.js @@ -75,7 +75,6 @@ getFrameIdFromUrl : function() { var href = window.location.href; if (href.indexOf('frameId=') != -1) { - console.log(href.substring(href.indexOf('frameId=')+8)); return href.substring(href.indexOf('frameId=')+8); } }, @@ -467,7 +466,8 @@ xhr.open('POST', PISKEL_SERVICE_URL + "/store", true); xhr.onload = function(e) { if (this.status == 200) { - alert("stored key : " + this.responseText); + var baseUrl = window.location.href.replace(window.location.search, ""); + window.location.href = baseUrl + "?frameId=" + this.responseText; } };