aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/chromeapi.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/chromeapi.js')
-rw-r--r--js/io/system/chromeapi.js51
1 files changed, 42 insertions, 9 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js
index fb141687..6df41fd3 100644
--- a/js/io/system/chromeapi.js
+++ b/js/io/system/chromeapi.js
@@ -9,6 +9,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
9NOTES: 9NOTES:
10 The init function starts up the file system API, and a size must be 10 The init function starts up the file system API, and a size must be
11 set, no unlimited available as of now. 11 set, no unlimited available as of now.
12
13 Core API reference in NINJA: this.application.ninja.coreIoApi
14
12//////////////////////////////////////////////////////////////////////// 15////////////////////////////////////////////////////////////////////////
13///////////////////////////////////////////////////////////////////// */ 16///////////////////////////////////////////////////////////////////// */
14// 17//
@@ -61,24 +64,51 @@ exports.ChromeApi = Montage.create(Object.prototype, {
61 }, 64 },
62 //////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////
63 // 66 //
67 fileNew: {
68 enumerable: true,
69 value: function(filePath, content, mime, callback) {
70 //
71 this.fileSystem.root.getFile(filePath, {create: true}, function(f) {
72 //
73 f.createWriter(function(writer) {
74 //
75 var b = new window.WebKitBlobBuilder;
76 b.append(content);
77 writer.write(b.getBlob(mime));
78 //
79 if (callback) callback(true);
80 }, function (e) {if (callback) callback(false)});
81 }, function (e) {if (callback) callback(false)});
82 }
83 },
84 ////////////////////////////////////////////////////////////////////
85 //Creating directory from path, callback optional
64 directoryNew: { 86 directoryNew: {
65 enumerable: true, 87 enumerable: true,
66 value: function() { 88 value: function(directoryPath, callback) {
89 //Checking for directory not to already exist
90 this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) {
91 if (callback) callback(false);
92 return; //Directory already exists
93 });
94 //Creating new directory
95 this.fileSystem.root.getDirectory(directoryPath, {create: true}, function(dir) {
96 if (callback) callback(true);
97 }, function (e) {if (callback) callback(false)});
67 } 98 }
68 }, 99 },
69
70 //////////////////////////////////////////////////////////////////// 100 ////////////////////////////////////////////////////////////////////
71 // 101 //
72 directoryDelete: { 102 directoryDelete: {
73 enumerable: true, 103 enumerable: true,
74 value: function(directoryPath, callback) { 104 value: function(directoryPath, callback) {
75 // 105 //
76 this.fileSystem.getDirectory(directoryPath, {}, function(dirEntry) { 106 this.fileSystem.root.getDirectory(directoryPath, {}, function(dir) {
77 // 107 //
78 dirEntry.removeRecursively(function() { 108 dir.removeRecursively(function() {
79 callback(true); 109 if (callback) callback(true);
80 }); 110 });
81 }, function (e) {callback(false)}); 111 }, function (e) {if (callback) callback(false)});
82 } 112 }
83 }, 113 },
84 //////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////
@@ -125,9 +155,12 @@ exports.ChromeApi = Montage.create(Object.prototype, {
125 // 155 //
126 var lib = []; 156 var lib = [];
127 // 157 //
128 158 for(var i=0; contents[i]; i++) {
129 159 //
130 160 if (contents[i].isDirectory) {
161 lib.push(contents[i].name);
162 }
163 }
131 //Dispatching action ready event 164 //Dispatching action ready event
132 var libraryEvent = document.createEvent("CustomEvent"); 165 var libraryEvent = document.createEvent("CustomEvent");
133 libraryEvent.initEvent('library', true, true); 166 libraryEvent.initEvent('library', true, true);