aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/ninjalibrary.js
diff options
context:
space:
mode:
authorJose Antonio Marquez2012-02-06 22:33:42 -0800
committerJose Antonio Marquez2012-02-06 22:33:42 -0800
commitad85ff92ba44fb3c8ccf24c2f1b9296804dfa8ca (patch)
treebaeb1aeb74176ba9d6f501aa42188df87cb32b58 /js/io/system/ninjalibrary.js
parentf6b9e5be4568cff6b87b2282dcf12f0426aa4301 (diff)
downloadninja-ad85ff92ba44fb3c8ccf24c2f1b9296804dfa8ca.tar.gz
Single file library syncing
Added the ability to store locally in chrome single file libraries used by Ninja. Working on adding multi-file libraries.
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r--js/io/system/ninjalibrary.js93
1 files changed, 91 insertions, 2 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index 3f8585ed..e3d855f1 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -7,6 +7,9 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot
7/* ///////////////////////////////////////////////////////////////////// 7/* /////////////////////////////////////////////////////////////////////
8//////////////////////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////////////////////
9NOTES: 9NOTES:
10
11 Core API reference in NINJA: this.application.ninja.coreIoApi
12
10//////////////////////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////////////////////
11///////////////////////////////////////////////////////////////////// */ 14///////////////////////////////////////////////////////////////////// */
12// 15//
@@ -16,12 +19,98 @@ var Montage = require("montage/core/core").Montage;
16exports.NinjaLibrary = Montage.create(Object.prototype, { 19exports.NinjaLibrary = Montage.create(Object.prototype, {
17 //////////////////////////////////////////////////////////////////// 20 ////////////////////////////////////////////////////////////////////
18 // 21 //
19 init: { 22 _chromeApi: {
23 enumerable: false,
24 value: null
25 },
26 ////////////////////////////////////////////////////////////////////
27 //
28 chromeApi: {
29 enumerable: false,
30 get: function() {
31 return this._chromeApi;
32 },
33 set: function(value) {
34 this._chromeApi = value;
35 }
36 },
37 ////////////////////////////////////////////////////////////////////
38 //
39 synchronize: {
40 enumerable: true,
41 value: function(chromeLibs, chrome) {
42 //
43 this.chromeApi = chrome;
44 //
45 var i, libs, xhr = new XMLHttpRequest(), tocopylibs = [];
46 //Getting known json list of libraries to copy to chrome
47 xhr.open("GET", '/ninja-internal/js/io/system/ninjalibrary.json', false);
48 xhr.send();
49 //Checkng for correct reponse
50 if (xhr.readyState === 4) {
51 //Parsing json libraries
52 libs = JSON.parse(xhr.response);
53 //
54 if (chromeLibs.length > 0) {
55 //Compare (always deleting for testing)
56 for (i=0; chromeLibs[i]; i++) {
57 this.chromeApi.directoryDelete(chromeLibs[i]);
58 }
59 } else {
60 //No library is present, must copy all
61 for (var j in libs.libraries) {
62 //name: used to folder container contents
63 //path: url of descriptor json or single file to load (descriptor has list of files)
64 //singular: indicates the path is the file to be loaded into folder
65 if (libs.libraries[j].file) {
66 tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file});
67 } else {
68 tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path});
69 }
70 }
71 }
72 //
73 if (tocopylibs.length > 0) {
74 for (i=0; tocopylibs[i]; i++) {
75 //Checking for library to be single file
76 if (tocopylibs[i].file) {
77 //Creating root folder
78 this.chromeApi.directoryNew('/'+tocopylibs[i].name);
79 //Getting file contents
80 xhr = new XMLHttpRequest();
81 xhr.open("GET", tocopylibs[i].path, false);
82 xhr.send();
83 //Checking for status
84 if (xhr.readyState === 4) { //TODO: add check for mime type
85 //Creating new file from loaded content
86 this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain');
87 //this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, 'text/plain', function (v){console.log(v)});
88 } else {
89 //Error
90 }
91 } else {
92 //
93 }
94 }
95 } else {
96 //No libraries to copy
97 }
98 } else {
99 //Error
100 }
101 }
102 }/*
103,
104 ////////////////////////////////////////////////////////////////////
105 //
106 createFolder: {
20 enumerable: true, 107 enumerable: true,
21 value: function() { 108 value: function(name) {
22 // 109 //
110 this.chromeApi.directoryNew(name);
23 } 111 }
24 } 112 }
113*/
25 //////////////////////////////////////////////////////////////////// 114 ////////////////////////////////////////////////////////////////////
26 //////////////////////////////////////////////////////////////////// 115 ////////////////////////////////////////////////////////////////////
27}); 116});