diff options
author | Jose Antonio Marquez | 2012-02-06 11:40:15 -0800 |
---|---|---|
committer | Jose Antonio Marquez | 2012-02-06 11:40:15 -0800 |
commit | 295d72960cad391850803e8c4e83d5133bbe82f7 (patch) | |
tree | 5a53af8978ec982b74b01edeb125ee24f8b59234 /js/io/system | |
parent | 17bda238bc6973832394c0ba8fb08da09557931e (diff) | |
download | ninja-295d72960cad391850803e8c4e83d5133bbe82f7.tar.gz |
Setting up library detection for Chrome File System
Diffstat (limited to 'js/io/system')
-rw-r--r-- | js/io/system/chromeapi.js | 30 | ||||
-rwxr-xr-x | js/io/system/coreioapi.js | 19 |
2 files changed, 44 insertions, 5 deletions
diff --git a/js/io/system/chromeapi.js b/js/io/system/chromeapi.js index 6bf6b9fe..f4e04a09 100644 --- a/js/io/system/chromeapi.js +++ b/js/io/system/chromeapi.js | |||
@@ -31,6 +31,8 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
31 | var readyEvent = document.createEvent("CustomEvent"); | 31 | var readyEvent = document.createEvent("CustomEvent"); |
32 | readyEvent.initEvent('ready', true, true); | 32 | readyEvent.initEvent('ready', true, true); |
33 | this.dispatchEvent(readyEvent); | 33 | this.dispatchEvent(readyEvent); |
34 | //Building data of local Ninja Library | ||
35 | this._listNinjaChromeLibrary(); | ||
34 | }.bind(this), function (e) {return false}); //Returns false on error (not able to init) | 36 | }.bind(this), function (e) {return false}); //Returns false on error (not able to init) |
35 | // | 37 | // |
36 | return true; | 38 | return true; |
@@ -73,10 +75,17 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
73 | } | 75 | } |
74 | }, | 76 | }, |
75 | //////////////////////////////////////////////////////////////////// | 77 | //////////////////////////////////////////////////////////////////// |
76 | // | 78 | //Returns the directory contents to a callback function |
77 | directoryContents: { | 79 | directoryContents: { |
78 | enumerable: true, | 80 | enumerable: true, |
79 | value: function() { | 81 | value: function(directory, callback) { |
82 | //Creating instance of directory reader | ||
83 | this.fileSystem.directoryReader = directory.createReader(); | ||
84 | //Getting directory contents and sending results to callback | ||
85 | this.fileSystem.directoryReader.readEntries(function(results) { | ||
86 | //Calling callback with results (null if invalid directory) | ||
87 | callback(results); | ||
88 | }, function (e) {callback(null)}); | ||
80 | } | 89 | } |
81 | }, | 90 | }, |
82 | //////////////////////////////////////////////////////////////////// | 91 | //////////////////////////////////////////////////////////////////// |
@@ -102,11 +111,24 @@ exports.ChromeApi = Montage.create(Object.prototype, { | |||
102 | }, | 111 | }, |
103 | //////////////////////////////////////////////////////////////////// | 112 | //////////////////////////////////////////////////////////////////// |
104 | // | 113 | // |
105 | getLocalLibrary: { | 114 | _listNinjaChromeLibrary: { |
106 | enumerable: false, | 115 | enumerable: false, |
107 | value: function () { | 116 | value: function () { |
117 | function parseLibrary (contents) { | ||
118 | // | ||
119 | var lib = []; | ||
120 | // | ||
121 | |||
122 | |||
123 | |||
124 | //Dispatching action ready event | ||
125 | var libraryEvent = document.createEvent("CustomEvent"); | ||
126 | libraryEvent.initEvent('library', true, true); | ||
127 | libraryEvent.ninjaChromeLibrary = lib; | ||
128 | this.dispatchEvent(libraryEvent); | ||
129 | }; | ||
108 | // | 130 | // |
109 | return {}; | 131 | this.directoryContents(this.fileSystem.root, parseLibrary.bind(this)); |
110 | } | 132 | } |
111 | } | 133 | } |
112 | //////////////////////////////////////////////////////////////////// | 134 | //////////////////////////////////////////////////////////////////// |
diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 3fb9374a..3be6011d 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js | |||
@@ -55,8 +55,25 @@ exports.CoreIoApi = Montage.create(Component, { | |||
55 | handleReady: { | 55 | handleReady: { |
56 | enumerable: false, | 56 | enumerable: false, |
57 | value: function (e) { | 57 | value: function (e) { |
58 | // | ||
58 | this.chromeFileSystem.removeEventListener('ready', this, false); | 59 | this.chromeFileSystem.removeEventListener('ready', this, false); |
59 | this.chromeNinjaLibrary = this.chromeFileSystem.getLocalLibrary(); | 60 | // |
61 | this.chromeFileSystem.addEventListener('library', this, false); | ||
62 | } | ||
63 | }, | ||
64 | //////////////////////////////////////////////////////////////////// | ||
65 | // | ||
66 | handleLibrary: { | ||
67 | enumerable: false, | ||
68 | value: function (e) { | ||
69 | // | ||
70 | this.chromeFileSystem.removeEventListener('library', this, false); | ||
71 | // | ||
72 | if (e._event.ninjaChromeLibrary.length < 1) { | ||
73 | console.log('no libraries'); | ||
74 | } else { | ||
75 | console.log('found libraries'); | ||
76 | } | ||
60 | } | 77 | } |
61 | }, | 78 | }, |
62 | //////////////////////////////////////////////////////////////////// | 79 | //////////////////////////////////////////////////////////////////// |