Thursday 15 September 2011

javascript - Click on "Load" Button is not firing the event and also LocalFileSystem is not defined -



javascript - Click on "Load" Button is not firing the event and also LocalFileSystem is not defined -

i have next code link http://weblogs.asp.net/soever/cordova-file-transfer-unzip-and-present-adventures changed url according needs.

<!doctype html> <html> <head> <meta charset="utf-8" /> <title>demozipunzip</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0"> <!-- demozipunzip references --> <link href="css/index.css" rel="stylesheet" /> <!-- cordova reference, added app when it's built. --> <!--<script src="cordova.js"></script>--> <script src="scripts/platformoverrides.js"></script> <script src="scripts/index.js"></script> </head> <body> <button id="btnload">load</button> <button id="btnunzip">unzip</button> <hr /> <div id="statusplace"></div> <hr /> <img id="imgplace" src="http://lorempixel.com/320/200"> <br /> <div id="txtplace">text comes here</div> <script type="text/javascript"> document.addeventlistener("deviceready", ondeviceready, false); function registerhandlers() { document.getelementbyid("btnload").onclick = function () { var = this, app = new downloadapp(), filename = "archive.zip", uri = "http://localhost:63961/check/contentupdate/availableupdates", foldername = "content"; console.log("load button clicked"); document.getelementbyid("statusplace").innerhtml += "<br/>loading: " + uri; app.load(uri, foldername, filename, /*progress*/function (percentage) { document.getelementbyid("statusplace").innerhtml += "<br/>" + percentage + "%"; }, /*success*/function (entry) { document.getelementbyid("statusplace").innerhtml += "<br/>zip saved to: " + entry.tourl(); }, /*fail*/function () { document.getelementbyid("statusplace").innerhtml += "<br/>failed load zip: " + that.uri; } ); }; document.getelementbyid("btnunzip").onclick = function () { var = this, app = new downloadapp(), filename = "archive.zip", foldername = "content"; console.log("zip button clicked"); app.unzip(foldername, filename, /*success*/function () { alert("unzipped , assigned"); }, /*fail*/function (error) { alert("unzip failed: " + error.code); } ); }; } function ondeviceready() { // navigator.splashscreen.hide(); document.getelementbyid("statusplace").innerhtml += "<br/>deviceready event received"; registerhandlers(); } var downloadapp = function () { } downloadapp.prototype = { load: function (uri, foldername, filename, progress, success, fail) { var = this; that.progress = progress; that.success = success; that.fail = fail; filepath = ""; that.getfilesystem( function (filesystem) { console.log("gotfs"); that.getfolder(filesystem, foldername, function (folder) { filepath = folder.tourl() + "/" + filename; that.transferfile(uri, filepath, progress, success, fail); }, function (error) { console.log("failed folder: " + error.code); typeof that.fail === 'function' && that.fail(error); }); }, function (error) { console.log("failed filesystem: " + error.code); typeof that.fail === 'function' && that.fail(error); } ); }, getfilesystem:function (success, fail) { window.requestfilesystem = window.requestfilesystem || window.webkitrequestfilesystem; window.requestfilesystem(localfilesystem.persistent, 0, success, fail); }, getfolder: function (filesystem, foldername, success, fail) { filesystem.root.getdirectory(foldername, { create: true, exclusive: false }, success, fail) }, transferfile: function (uri, filepath, progress, success, fail) { var = this; that.progress = progress; that.success = success; that.fail = fail; var transfer = new filetransfer(); transfer.onprogress = function (progressevent) { if (progressevent.lengthcomputable) { var perc = math.floor(progressevent.loaded / progressevent.total * 100); typeof that.progress === 'function' && that.progress(perc); // progression on scale 0..100 (percentage) number } else { } }; transfer.download( uri, filepath, function (entry) { console.log("file saved to: " + entry.tourl()); typeof that.success === 'function' && that.success(entry); }, function (error) { console.log("an error has occurred: code = " + error.code); console.log("download error source " + error.source); console.log("download error target " + error.target); console.log("download error code " + error.code); typeof that.fail === 'function' && that.fail(error); } ); }, unzip: function (foldername, filename, success, fail) { var = this; that.success = success; that.fail = fail; zip.unzip("cdvfile://localhost/persistent/" + foldername + "/" + filename, "cdvfile://localhost/persistent/" + foldername, function (code) { console.log("result: " + code); that.getfilesystem( function (filesystem) { console.log("gotfs"); that.getfolder(filesystem, foldername + "/ftpack", function (folder) { document.getelementbyid("imgplace").src = folder.nativeurl + "/img.jpg"; folder.getfile("text.html", { create: false }, function (fileentry) { fileentry.file(function (file) { var reader = new filereader(); reader.onloadend = function (evt) { console.log("read text"); console.log(evt.target.result); document.getelementbyid("txtplace").innerhtml = evt.target.result; typeof that.success === ' function && that.success();' }; reader.readastext(file); }, function (error) { console.log("failed file"); typeof that.fail === 'function' && that.fail(error); }); }, function (error) { console.log("failed file: " + error.code); typeof that.fail === 'function' && that.fail(error); }); }, function (error) { console.log("failed folder: " + error.code); typeof that.fail === 'function' && that.fail(error); }); }, function (error) { console.log("failed filesystem: " + error.code); typeof that.fail === 'function' && that.fail(error); }); } ); } } </script>

since i'm trying accomplish guy in post download zip file , unzip local sandboxed file system. when copied , pasted code within visual studio 2013 using "multi device hybrid app" + cordova extension , tried running in using ripple-nexus7 (tablet) brings nice ui when clicked on "load" button first time giving me error in next piece of code.

getfilesystem:function (success, fail) { window.requestfilesystem = window.requestfilesystem || window.webkitrequestfilesystem; window.requestfilesystem(localfilesystem.persistent, 0, success, fail); },

"localfilesystem" not defined tried add together file, filetransfer plugins config.xml's plug-in tab within vs2013 failed fetch these plugins using plugman. downloaded these packages github , added plug_ins folder within project solution explorer , set these plugins plug_ins folder keeping internal file , folder construction intact.now not giving me error anymore (though i'm still not able find localfilesystem object in intellisense means weird reason it's not giving me same localfilesystem undefined error still these plugins not working).

now when run code , ui comes 1 time click "load" button nil happens absolutely nil , before "ondeviceready" function should invoked @ "deviceready" event nil happening there well.

please guys need great deal of help in regard i'm new javascript , cordova stuff. heartfelt can help me in getting these issues straighten out.

yes avani have figured out ripple culprit, sorry didn't update, should have though. letting plugins load during run-time not letting them initialize , that's why i'm having problem objects beingness undefined.and it's beta version in visual studio 2013 ripple has issues associated it. yes emulator giving me same pain.

javascript visual-studio cordova multi-device-hybrid-apps

No comments:

Post a Comment