I'm using a html script to draw signatures on my app, in order to get the signature base encoded data on my app controllers. I've added an app event inside the html document, to send the data to another app event created on alloy.js.
When I call the app event created on html file (), only works on android, the logs are on the bottom of this question.
alloy.js
// saved signatures var signatures = Ti.App.Properties.getObject("signature") || {}; // log messages Ti.App.addEventListener("console",function(e) { if(isset(e)) { if(isset(e.msg)) { console.log("MESSAGE: "+e.msg); } } }); // app event to save signatures Ti.App.addEventListener("signature",function(properties) { if(isset(properties)) { if(isset(properties.name) && isset(properties.data)) { signatures[properties.name] = properties.data; } } Ti.App.Properties.setObject("signature",signatures); });sign.html
<canvas style="width:100%;height:100%;background:white;margin:0;padding:0;" id="sign"></canvas> <script src="sign.js"></script> <script> var canvas, view, name; sign_events(properties) { //log message, defined on alloy Ti.App.fireEvent("console",{ "msg":properties.type }); if(properties.type == "clear") { //clear signature view.clear(); } if(properties.type == "save") { //save sign on app event created on alloy Ti.App.fireEvent("signature",{ "name":canvas.getAttribute("name"), "data":view.toDataURL() }); } if(properties.type == "destructor") { //remove app event on html Ti.App.removeEventListener("signature_"+name,sign_events); } }; function sign_constructor(properties) { canvas = document.getElementById("sign"); view = new SignaturePad(canvas); name = properties.name; //add app event on html Ti.App.addEventListener("signature_"+name,sign_events); canvas.setAttribute("name",name); //log message, defined on alloy Ti.App.fireEvent("console",{ "msg":"sign name: "+name+", width: "+canvas.width+", height: "+canvas.height }); }; </script>sign.js
var signature = { "name":"test", "width":500, "height":300 }; signature.web = Ti.UI.createWebView({ "disableBounce":true, "enableZoomControls":false, "backgroundColor":"#ffffff" }); signature.load = function() { signature.web.removeEventListener('load',signature.load); this.evalJS("sign_constructor({ 'name':'"+signature.name+"', 'width':'"+signature.width+"', 'height':'"+signature.height+"' });"); }; signature.web.addEventListener('load',signature.load);I'm running Titanium Studio 3.4.1.201410281727 on MacBook Pro with Mac OS X Yosemite 10.10.1
iOS (iPad 2 simulator - iOS 8.1 - build: 12B411) logs:
//when webview load event is called, fires the sign_constructor event [INFO] : MESSAGE: sign name: test, width: 500, height: 300 //every time that I call sign_events (ex: clear) [INFO] : MESSAGE: signature_test //every time that I call sign_events (ex: save) [INFO] : MESSAGE: signature_testandroid (bq Edison 2 Quad Core 3G - android 4.2.2) logs:
//when webview load event is called, fires the sign_constructor event [INFO] : MESSAGE: sign name: test, width: 500, height: 300 //every time that I call sign_events (ex: clear) [INFO] : MESSAGE: clear //every time that I call sign_events (ex: save) [INFO] : MESSAGE: save