diff options
author | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
---|---|---|
committer | Valerio Virgillito | 2012-07-09 14:35:44 -0700 |
commit | 84b3327bd92faafab7954b5eb64c7abe24a3fe13 (patch) | |
tree | 3f56cbed2f08c5a81ea79eaf0bcb9bd031d8a627 /js/io/system/ninjalibrary.js | |
parent | c0a42c56f768a873ba637f5b86d5f6a84d4a3312 (diff) | |
parent | 40c6eb2c06b34f65a74d59ef9687251952858bab (diff) | |
download | ninja-84b3327bd92faafab7954b5eb64c7abe24a3fe13.tar.gz |
Merge branch 'normalize' of https://github.com/kriskowal/ninja-internal
Conflicts:
js/components/gradientpicker.reel/gradientpicker.js
js/components/tools-properties/text-properties.reel/text-properties.js
js/document/views/base.js
js/document/views/design.js
js/helper-classes/3D/StageLine.js
js/helper-classes/3D/draw-utils.js
js/lib/drawing/world.js
js/lib/geom/circle.js
js/lib/geom/line.js
js/lib/geom/rectangle.js
js/lib/geom/shape-primitive.js
js/lib/rdge/materials/bump-metal-material.js
js/lib/rdge/materials/flag-material.js
js/lib/rdge/materials/fly-material.js
js/lib/rdge/materials/julia-material.js
js/lib/rdge/materials/keleidoscope-material.js
js/lib/rdge/materials/mandel-material.js
js/lib/rdge/materials/material.js
js/lib/rdge/materials/plasma-material.js
js/lib/rdge/materials/pulse-material.js
js/lib/rdge/materials/radial-gradient-material.js
js/lib/rdge/materials/taper-material.js
js/lib/rdge/materials/twist-vert-material.js
js/lib/rdge/materials/water-material.js
js/panels/Materials/materials-library-panel.reel/materials-library-panel.html
js/panels/Materials/materials-library-panel.reel/materials-library-panel.js
js/panels/Materials/materials-popup.reel/materials-popup.html
js/panels/Materials/materials-popup.reel/materials-popup.js
js/tools/LineTool.js
Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r-- | js/io/system/ninjalibrary.js | 490 |
1 files changed, 245 insertions, 245 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 1467d18f..be59fd07 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js | |||
@@ -34,7 +34,7 @@ var Montage = require("montage/core/core").Montage; | |||
34 | //////////////////////////////////////////////////////////////////////// | 34 | //////////////////////////////////////////////////////////////////////// |
35 | // | 35 | // |
36 | exports.NinjaLibrary = Montage.create(Object.prototype, { | 36 | exports.NinjaLibrary = Montage.create(Object.prototype, { |
37 | //////////////////////////////////////////////////////////////////// | 37 | //////////////////////////////////////////////////////////////////// |
38 | // | 38 | // |
39 | _chromeApi: { | 39 | _chromeApi: { |
40 | value: null | 40 | value: null |
@@ -42,7 +42,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
42 | //////////////////////////////////////////////////////////////////// | 42 | //////////////////////////////////////////////////////////////////// |
43 | // | 43 | // |
44 | chromeApi: { | 44 | chromeApi: { |
45 | get: function() {return this._chromeApi;}, | 45 | get: function() {return this._chromeApi;}, |
46 | set: function(value) {this._chromeApi = value;} | 46 | set: function(value) {this._chromeApi = value;} |
47 | }, | 47 | }, |
48 | //////////////////////////////////////////////////////////////////// | 48 | //////////////////////////////////////////////////////////////////// |
@@ -53,7 +53,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
53 | //////////////////////////////////////////////////////////////////// | 53 | //////////////////////////////////////////////////////////////////// |
54 | // | 54 | // |
55 | coreApi: { | 55 | coreApi: { |
56 | get: function() {return this._coreApi;}, | 56 | get: function() {return this._coreApi;}, |
57 | set: function(value) {this._coreApi = value;} | 57 | set: function(value) {this._coreApi = value;} |
58 | }, | 58 | }, |
59 | //////////////////////////////////////////////////////////////////// | 59 | //////////////////////////////////////////////////////////////////// |
@@ -64,7 +64,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
64 | //////////////////////////////////////////////////////////////////// | 64 | //////////////////////////////////////////////////////////////////// |
65 | // | 65 | // |
66 | libs: { | 66 | libs: { |
67 | get: function() {return this._libs;}, | 67 | get: function() {return this._libs;}, |
68 | set: function(value) {this._libs = value;} | 68 | set: function(value) {this._libs = value;} |
69 | }, | 69 | }, |
70 | //////////////////////////////////////////////////////////////////// | 70 | //////////////////////////////////////////////////////////////////// |
@@ -81,114 +81,114 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { | |||
81 | // | 81 | // |
82 | copyLibToCloud: { | 82 | copyLibToCloud: { |
83 | value: function (path, libName, callback) { | 83 | value: function (path, libName, callback) { |
84 | var libCheck = this.coreApi.directoryExists({uri: path+libName}); | 84 | var libCheck = this.coreApi.directoryExists({uri: path+libName}); |
85 | //Checking for library to exists | 85 | //Checking for library to exists |
86 | if(libCheck.status === 404) { | 86 | if(libCheck.status === 404) { |
87 | //Getting contents to begin copying | 87 | //Getting contents to begin copying |
88 | this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { | 88 | this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { |
89 | for (var i in contents) { | 89 | for (var i in contents) { |
90 | if (libName === contents[i].name) { | 90 | if (libName === contents[i].name) { |
91 | //Getting contents of library to be copied | 91 | //Getting contents of library to be copied |
92 | this.chromeApi.directoryContents(contents[i], function (lib) { | 92 | this.chromeApi.directoryContents(contents[i], function (lib) { |
93 | //Copying to cloud | 93 | //Copying to cloud |
94 | if (callback) { | 94 | if (callback) { |
95 | this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0, callback: callback.bind(this)}); | 95 | this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0, callback: callback.bind(this)}); |
96 | } else { | 96 | } else { |
97 | this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0}); | 97 | this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0}); |
98 | } | 98 | } |
99 | }.bind(this)); | 99 | }.bind(this)); |
100 | break; | 100 | break; |
101 | } | 101 | } |
102 | } | 102 | } |
103 | }.bind(this)); | 103 | }.bind(this)); |
104 | } else if (libCheck.status === 204){ | 104 | } else if (libCheck.status === 204){ |
105 | //Already present, so sending success | 105 | //Already present, so sending success |
106 | if (callback) callback(true); | 106 | if (callback) callback(true); |
107 | } else { | 107 | } else { |
108 | if (callback) callback(false); | 108 | if (callback) callback(false); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | }, | 111 | }, |
112 | //////////////////////////////////////////////////////////////////// | 112 | //////////////////////////////////////////////////////////////////// |
113 | // | 113 | // |
114 | copyDirectoryToCloud: { | 114 | copyDirectoryToCloud: { |
115 | value: function(root, folder, fileRoot, tracking) { | 115 | value: function(root, folder, fileRoot, tracking) { |
116 | //Setting up directory name | 116 | //Setting up directory name |
117 | if (folder.name) { | 117 | if (folder.name) { |
118 | var dir; | 118 | var dir; |
119 | if (root) { | 119 | if (root) { |
120 | dir = root+'/'+folder.name; | 120 | dir = root+'/'+folder.name; |
121 | } else { | 121 | } else { |
122 | dir = folder.name; | 122 | dir = folder.name; |
123 | } | 123 | } |
124 | //Creating directory | 124 | //Creating directory |
125 | if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) { | 125 | if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) { |
126 | //Error occured while creating folders | 126 | //Error occured while creating folders |
127 | return; //TODO: Add error handling | 127 | return; //TODO: Add error handling |
128 | } | 128 | } |
129 | } | 129 | } |
130 | //Checking for directory | 130 | //Checking for directory |
131 | if (folder.isDirectory) { | 131 | if (folder.isDirectory) { |
132 | //Using Chrome API to get directory contents | 132 | //Using Chrome API to get directory contents |
133 | this.chromeApi.directoryContents(folder, function (contents) { | 133 | this.chromeApi.directoryContents(folder, function (contents) { |
134 | //Looping through children of directory to copy | 134 | //Looping through children of directory to copy |
135 | for (var i in contents) { | 135 | for (var i in contents) { |
136 | //Checking for file or directory | 136 | //Checking for file or directory |
137 | if (contents[i].isDirectory) { | 137 | if (contents[i].isDirectory) { |
138 | //Recursive call if directory | 138 | //Recursive call if directory |
139 | this.copyDirectoryToCloud(dir, contents[i], fileRoot, tracking); | 139 | this.copyDirectoryToCloud(dir, contents[i], fileRoot, tracking); |
140 | } else if (contents[i].isFile){ | 140 | } else if (contents[i].isFile){ |
141 | // | 141 | // |
142 | tracking.total++; | 142 | tracking.total++; |
143 | //Copying file | 143 | //Copying file |
144 | this.chromeApi.fileContent(contents[i].fullPath, function (result) { | 144 | this.chromeApi.fileContent(contents[i].fullPath, function (result) { |
145 | //Using binary when copying files to allow images and such to work | 145 | //Using binary when copying files to allow images and such to work |
146 | var file = this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content}); | 146 | var file = this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content}); |
147 | //Checking for file copy success | 147 | //Checking for file copy success |
148 | if (file.status === 201) { | 148 | if (file.status === 201) { |
149 | tracking.copied++; | 149 | tracking.copied++; |
150 | } else { | 150 | } else { |
151 | //Error | 151 | //Error |
152 | tracking.callback(false); | 152 | tracking.callback(false); |
153 | } | 153 | } |
154 | //Checking for all files to be copied to make callback | 154 | //Checking for all files to be copied to make callback |
155 | if (tracking.copied === tracking.total && tracking.callback) { | 155 | if (tracking.copied === tracking.total && tracking.callback) { |
156 | tracking.callback(true); | 156 | tracking.callback(true); |
157 | } | 157 | } |
158 | }.bind(this)); | 158 | }.bind(this)); |
159 | } | 159 | } |
160 | } | 160 | } |
161 | }.bind(this)); | 161 | }.bind(this)); |
162 | } | 162 | } |
163 | } | 163 | } |
164 | }, | 164 | }, |
165 | //////////////////////////////////////////////////////////////////// | 165 | //////////////////////////////////////////////////////////////////// |
166 | // | 166 | // |
167 | synchronize: { | 167 | synchronize: { |
168 | value: function(chromeLibs, chrome) { | 168 | value: function(chromeLibs, chrome) { |
169 | //TODO: Remove | 169 | //TODO: Remove |
170 | window.wipeLibrary = this.deleteLibraries.bind(this); | 170 | window.wipeLibrary = this.deleteLibraries.bind(this); |
171 | //Getting instance of browser file API | 171 | //Getting instance of browser file API |
172 | this.chromeApi = chrome; | 172 | this.chromeApi = chrome; |
173 | //Local variables | 173 | //Local variables |
174 | var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; | 174 | var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; |
175 | //Getting known json list of libraries to copy to chrome (will be on a CDN later) | 175 | //Getting known json list of libraries to copy to chrome (will be on a CDN later) |
176 | xhr.open("GET", '/js/io/system/ninjalibrary.json', false); | 176 | xhr.open("GET", '/js/io/system/ninjalibrary.json', false); |
177 | xhr.send(); | 177 | xhr.send(); |
178 | //Checkng for correct reponse | 178 | //Checkng for correct reponse |
179 | if (xhr.readyState === 4) { | 179 | if (xhr.readyState === 4) { |
180 | //Parsing json libraries |