aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/ninjalibrary.js
diff options
context:
space:
mode:
authorJonathan Duran2012-07-17 09:30:22 -0700
committerJonathan Duran2012-07-17 09:30:22 -0700
commit53051672a62208fbc96957719d8285fac6431ed6 (patch)
tree79d542ee811044e8af2ef84aa0d6662c6eb895c4 /js/io/system/ninjalibrary.js
parent7e2c2dbd040ed79a3f0678f91bd4b6db9cf69231 (diff)
parent5146f224258929415adf4a8022e492454b4e2476 (diff)
downloadninja-53051672a62208fbc96957719d8285fac6431ed6.tar.gz
Merge branch 'refs/heads/NINJA-master' into TimelineUber
Conflicts: js/panels/Timeline/DragDrop.js js/panels/Timeline/Keyframe.reel/Keyframe.js js/panels/Timeline/Layer.reel/Layer.js js/panels/Timeline/PropertyTrack.reel/PropertyTrack.js js/panels/Timeline/Span.reel/Span.js js/panels/Timeline/Style.reel/Style.js js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js js/panels/Timeline/TimelineTrack.reel/TimelineTrack.js js/panels/Timeline/Track.reel/Track.html js/panels/Timeline/Track.reel/Track.js js/panels/Timeline/Track.reel/css/Track.css js/panels/Timeline/TrackSpacer.reel/TrackSpacer.html js/panels/Timeline/TrackSpacer.reel/TrackSpacer.js js/panels/Timeline/TrackSpacer.reel/css/TrackSpacer.css js/panels/Timeline/Tween.reel/Tween.js Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/io/system/ninjalibrary.js')
-rw-r--r--js/io/system/ninjalibrary.js513
1 files changed, 257 insertions, 256 deletions
diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js
index 1467d18f..962765ab 100644
--- a/js/io/system/ninjalibrary.js
+++ b/js/io/system/ninjalibrary.js
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -34,7 +35,7 @@ var Montage = require("montage/core/core").Montage;
34//////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////
35// 36//
36exports.NinjaLibrary = Montage.create(Object.prototype, { 37exports.NinjaLibrary = Montage.create(Object.prototype, {
37 //////////////////////////////////////////////////////////////////// 38 ////////////////////////////////////////////////////////////////////
38 // 39 //
39 _chromeApi: { 40 _chromeApi: {
40 value: null 41 value: null
@@ -42,7 +43,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
42 //////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////
43 // 44 //
44 chromeApi: { 45 chromeApi: {
45 get: function() {return this._chromeApi;}, 46 get: function() {return this._chromeApi;},
46 set: function(value) {this._chromeApi = value;} 47 set: function(value) {this._chromeApi = value;}
47 }, 48 },
48 //////////////////////////////////////////////////////////////////// 49 ////////////////////////////////////////////////////////////////////
@@ -53,7 +54,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
53 //////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////
54 // 55 //
55 coreApi: { 56 coreApi: {
56 get: function() {return this._coreApi;}, 57 get: function() {return this._coreApi;},
57 set: function(value) {this._coreApi = value;} 58 set: function(value) {this._coreApi = value;}
58 }, 59 },
59 //////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////
@@ -64,7 +65,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
64 //////////////////////////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////
65 // 66 //
66 libs: { 67 libs: {
67 get: function() {return this._libs;}, 68 get: function() {return this._libs;},
68 set: function(value) {this._libs = value;} 69 set: function(value) {this._libs = value;}
69 }, 70 },
70 //////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////
@@ -81,114 +82,114 @@ exports.NinjaLibrary = Montage.create(Object.prototype, {
81 // 82 //
82 copyLibToCloud: { 83 copyLibToCloud: {
83 value: function (path, libName, callback) { 84 value: function (path, libName, callback) {
84 var libCheck = this.coreApi.directoryExists({uri: path+libName}); 85 var libCheck = this.coreApi.directoryExists({uri: path+libName});
85 //Checking for library to exists 86 //Checking for library to exists
86 if(libCheck.status === 404) { 87 if(libCheck.status === 404) {
87 //Getting contents to begin copying 88 //Getting contents to begin copying
88 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { 89 this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) {
89 for (var i in contents) { 90 for (var i in contents) {
90 if (libName === contents[i].name) { 91 if (libName === contents[i].name) {
91 //Getting contents of library to be copied 92 //Getting contents of library to be copied
92 this.chromeApi.directoryContents(contents[i], function (lib) { 93 this.chromeApi.directoryContents(contents[i], function (lib) {
93 //Copying to cloud 94 //Copying to cloud
94 if (callback) { 95 if (callback) {
95 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0, callback: callback.bind(this)}); 96 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0, callback: callback.bind(this)});
96 } else { 97 } else {
97 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0}); 98 this.copyDirectoryToCloud(path, contents[i], path, {total: 0, copied: 0});
98 } 99 }
99 }.bind(this)); 100 }.bind(this));
100 break; 101 break;
101 } 102 }
102 } 103 }
103 }.bind(this)); 104 }.bind(this));
104 } else if (libCheck.status === 204){ 105 } else if (libCheck.status === 204){
105 //Already present, so sending success 106 //Already present, so sending success
106 if (callback) callback(true); 107 if (callback) callback(true);
107 } else { 108 } else {
108 if (callback) callback(false); 109 if (callback) callback(false);
109 } 110 }
110 } 111 }
111 }, 112 },
112 //////////////////////////////////////////////////////////////////// 113 ////////////////////////////////////////////////////////////////////
113 // 114 //
114 copyDirectoryToCloud: { 115 copyDirectoryToCloud: {
115 value: function(root, folder, fileRoot, tracking) { 116 value: function(root, folder, fileRoot, tracking) {
116 //Setting up directory name 117 //Setting up directory name
117 if (folder.name) { 118 if (folder.name) {
118 var dir; 119 var dir;
119 if (root) { 120 if (root) {
120 dir = root+'/'+folder.name; 121 dir = root+'/'+folder.name;
121 } else { 122 } else {
122 dir = folder.name; 123 dir = folder.name;
123 } 124 }
124 //Creating directory 125 //Creating directory
125 if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) { 126 if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) {
126 //Error occured while creating folders 127 //Error occured while creating folders
127 return; //TODO: Add error handling 128 return; //TODO: Add error handling
128 } 129 }
129 } 130 }
130 //Checking for directory 131 //Checking for directory
131 if (folder.isDirectory) { 132 if (folder.isDirectory) {
132 //Using Chrome API to get directory contents 133 //Using Chrome API to get directory contents
133 this.chromeApi.directoryContents(folder, function (contents) { 134 this.chromeApi.directoryContents(folder, function (contents) {
134 //Looping through children of directory to copy 135 //Looping through children of directory to copy
135 for (var i in contents) { 136 for (var i in contents) {
136 //Checking for file or directory 137 //Checking for file or directory
137 if (contents[i].isDirectory) { 138 if (contents[i].isDirectory) {
138 //Recursive call if directory 139 //Recursive call if directory
139 this.copyDirectoryToCloud(dir, contents[i], fileRoot, tracking); 140 this.copyDirectoryToCloud(dir, contents[i], fileRoot, tracking);
140 } else if (contents[i].isFile){ 141 } else if (contents[i].isFile){
141 // 142 //
142 tracking.total++; 143 tracking.total++;
143 //Copying file 144 //Copying file
144 this.chromeApi.fileContent(contents[i].fullPath, function (result) { 145 this.chromeApi.fileContent(contents[i].fullPath, function (result) {
145 //Using binary when copying files to allow images and such to work 146 //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}); 147 var file = this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content});
147 //Checking for file copy success 148 //Checking for file copy success
148 if (file.status === 201) { 149 if (file.status === 201) {
149 tracking.copied++; 150 tracking.copied++;
150 } else { 151 } else {
151 //Error 152 //Error
152 tracking.callback(false); 153 tracking.callback(false);
153 } 154 }
154 //Checking for all files to be copied to make callback 155 //Checking for all files to be copied to make callback
155 if (tracking.copied === tracking.total && tracking.callback) { 156 if (tracking.copied === tracking.total && tracking.callback) {
156 tracking.callback(true);