aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/ninjalibrary.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r--js/io/system/ninjalibrary.js118
1 files changed, 118 insertions, 0 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
new file mode 100644
index 00000000..e3d855f1
--- /dev/null
+++ b/js/io/system/ninjalibrary.js
@@ -0,0 +1,118 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */
6
7/* /////////////////////////////////////////////////////////////////////
8////////////////////////////////////////////////////////////////////////
9NOTES:
10
11 Core API reference in NINJA: this.application.ninja.coreIoApi
12
13////////////////////////////////////////////////////////////////////////
14///////////////////////////////////////////////////////////////////// */
15//
16var Montage = require("montage/core/core").Montage;
17////////////////////////////////////////////////////////////////////////
18//
19exports.NinjaLibrary = Montage.create(Object.prototype, {
20 ////////////////////////////////////////////////////////////////////
21 //
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: {
107 enumerable: true,
108 value: function(name) {
109 //
110 this.chromeApi.directoryNew(name);
111 }
112 }
113*/
114 ////////////////////////////////////////////////////////////////////
115 ////////////////////////////////////////////////////////////////////
116});
117////////////////////////////////////////////////////////////////////////
118//////////////////////////////////////////////////////////////////////// \ No newline at end of file