Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes #172 - images would not be updated correctly and sent to the se…

…rver becayuse the onchange event would not fire
  • Loading branch information...
commit d3faf86330dc49ea45fa972617a4306384c6e7a1 1 parent 8fad5b7
Paul Kinlan authored
Showing with 13 additions and 8 deletions.
  1. +13 −8 server/demos/mememator/static/scripts/index.js
View
21 server/demos/mememator/static/scripts/index.js
@@ -7,7 +7,9 @@ var canvas;
var imageID;
var permissionKey;
-function textChanged() {
+function redrawImage(callback) {
+ var callback = callback || function() {};
+
if (context) {
topText = $('#top').val();
bottomText = $('#bottom').val();
@@ -27,7 +29,7 @@ function textChanged() {
context.strokeText(bottomText, width * 0.5, height * 0.95, width * 0.9);
if(imageID) {
- updateImageData(imageID, canvas, topText, bottomText);
+ updateImageData(imageID, canvas, topText, bottomText, callback);
// set a timeout to check for when an image becomes available.
}
}
@@ -53,14 +55,14 @@ var createBlobFromCanvas = function(c) {
return dataURLToBlob(data);
};
-var updateImageData = function(id, c, textTop, textBottom) {
+var updateImageData = function(id, c, textTop, textBottom, callback) {
+ var callback = callback || function() {};
var data = c.toDataURL('image/png');
$.ajax({
type: 'PUT',
url: '/image/' + id,
data: { image: data, permissionKey: permissionKey, textTop: textTop, textBottom: textBottom },
- success: function(data) {
- }
+ success: callback
});
};
@@ -162,7 +164,10 @@ $(function() {
$('#done').show();
$('#done').click(function() {
if (canvas) {
- window.intent.postResult(canvas.toDataURL());
+ //always save the image prior to sending back.
+ redrawImage(function() {
+ window.intent.postResult(canvas.toDataURL());
+ });
}
});
if(window.intent) {
@@ -211,8 +216,8 @@ $(function() {
startActivity.call(window.navigator, i);
});
- $('#top').change(textChanged);
- $('#bottom').change(textChanged);
+ $('#top').change(function() { redrawImage(); });
+ $('#bottom').change(function() { redrawImage(); });
});
// taken from filer.js by Eric Bidelman
Please sign in to comment.
Something went wrong with that request. Please try again.