diff --git a/www/Canvas2ImagePlugin.js b/www/Canvas2ImagePlugin.js index e46b6db..07816af 100644 --- a/www/Canvas2ImagePlugin.js +++ b/www/Canvas2ImagePlugin.js @@ -1,3 +1,5 @@ +cordova.define("org.devgeeks.Canvas2ImagePlugin.Canvas2ImagePlugin", function(require, exports, module) { + // // Canvas2ImagePlugin.js // Canvas2ImagePlugin PhoneGap/Cordova plugin @@ -7,21 +9,46 @@ // MIT Licensed // - module.exports = { - - saveImageDataToLibrary:function(successCallback, failureCallback, canvasId) { - // successCallback required +module.exports = (function() { + + function validateCallBacks(successCallback, failureCallback){ + + var isValid = true; + if (typeof successCallback != "function") { console.log("Canvas2ImagePlugin Error: successCallback is not a function"); + isValid = false; } else if (typeof failureCallback != "function") { console.log("Canvas2ImagePlugin Error: failureCallback is not a function"); + isValid = false; } - else { + return isValid; + } + + function saveImageDataToLibrary(successCallback, failureCallback, canvasId) { + // successCallback required + if (validateCallBacks(successCallback, failureCallback)) { var canvas = (typeof canvasId === "string") ? document.getElementById(canvasId) : canvasId; var imageData = canvas.toDataURL().replace(/data:image\/png;base64,/,''); - return cordova.exec(successCallback, failureCallback, "Canvas2ImagePlugin","saveImageDataToLibrary",[imageData]); + return saveDataStringAsImageDataToLibrary(successCallback, failureCallback, imageData); } } - }; - + + function saveDataStringAsImageDataToLibrary(successCallback, failureCallback, imageData) { + if (validateCallBacks(successCallback, failureCallback)) { + return cordova.exec(successCallback, failureCallback, + "Canvas2ImagePlugin","saveImageDataToLibrary",[imageData]); + } + } + + return { + saveImageDataToLibrary: saveImageDataToLibrary, + saveDataStringAsImageDataToLibrary: saveDataStringAsImageDataToLibrary + } + +})() + +}); + +