From 36d50b6599ab98559c76e1fe57b1bb131c4433da Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 19 Apr 2012 15:53:18 -0700 Subject: Clean up --- js/io/system/fileio.js | 4 ++-- js/io/system/ninjalibrary.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js index f78ad173..1680ca7f 100755 --- a/js/io/system/fileio.js +++ b/js/io/system/fileio.js @@ -146,7 +146,7 @@ exports.FileIo = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// - // + //TODO: Add functionality deleteFile: { enumerable: true, value: function() { @@ -159,7 +159,7 @@ exports.FileIo = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// - // + //TODO: Add functionality copyFile: { enumerable: true, value: function() { diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 201598fc..78bdbe53 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -213,7 +213,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.responseType = "arraybuffer"; xhr.send(); //Checking for status - if (xhr.readyState === 4) { //TODO: add check for mime type + if (xhr.readyState === 4) { //Creating new file from loaded content this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { -- cgit v1.2.3 From 6356edefaea3fe78969c53fec2d371cb8f42d820 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 3 May 2012 15:28:38 -0700 Subject: Full CSS support on open Add full CSS for files on open (including loading cross-domain). This is only for files that are opened. --- js/io/system/coreioapi.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'js/io/system') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index a06f45c6..1e6518fe 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -192,6 +192,23 @@ exports.CoreIoApi = Montage.create(Component, { set: function(value) { this._fileServiceURL = value; } + }, + //////////////////////////////////////////////////////////////////// + //File service API URL + _webServiceURL: { + enumerable: false, + value: '/web' + }, + //////////////////////////////////////////////////////////////////// + // + webServiceURL: { + enumerable: false, + get: function() { + return String(this.rootUrl+this._webServiceURL); + }, + set: function(value) { + this._webServiceURL = value; + } }, //////////////////////////////////////////////////////////////////// //Directory service API URL @@ -647,6 +664,53 @@ exports.CoreIoApi = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// + // Reads an external file (cross-domain) + // Parameters: + // the file parameter must contain the following properties + // url: string value containing the full file path/URL i.e. "http://google.com/motorola.html" + // binary parameter is optional if the content is to be binary + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // content: string containing the file contents + // status: int indicating the request HTTP status code + // 200 - the file was read and its contents were returned + // 404 - the file does not exist + // 500 - unknown server error occurred + readExternalFile: { + enumerable: false, + value: function(file) { + // + var retValue = {success:null, content:null, status:null}; + // + if(file && file.url && file.url.length) { + try { + var serviceURL = this._prepareServiceURL(this.webServiceURL, ''), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL+"?url="+file.url, false); + if (file.binary) xhr.setRequestHeader("return-type", "binary"); + xhr.setRequestHeader("Content-Type", "text/plain"); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.response; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// // Create a new directory/folder // Parameters: // the dir parameter must contain the following properties -- cgit v1.2.3 From f9f8fdc3000042ba5b4504d91870dc9a32ef25eb Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 01:00:22 -0700 Subject: Squashed master into dom-architecture Signed-off-by: Valerio Virgillito --- js/io/system/ninjalibrary.js | 28 ++++++++++++---------------- js/io/system/ninjalibrary.json | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 78bdbe53..3de5fb69 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -152,7 +152,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { // this.chromeApi = chrome; // - var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = [], copied; +// debugger; + var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; //Getting known json list of libraries to copy to chrome xhr.open("GET", '/js/io/system/ninjalibrary.json', false); xhr.send(); @@ -166,23 +167,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { if (chromeLibs.length > 0) { // for (i=0; chromeLibs[i]; i++) { - copied = false; for (var j in libs.libraries) { if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() === chromeLibs[i]) { - copied = true; - } - } - // - if (!copied) { - if (libs.libraries[j].file) { - tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); - } else { - tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); - } - } else { - //TODO: Remove, currently manually removing copied libraries - //this.chromeApi.directoryDelete(chromeLibs[i]); - } + //TODO: Remove, currently manually removing copied libraries + // //this.chromeApi.directoryDelete(chromeLibs[i]); + } else { + if (libs.libraries[j].file) { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); + } else { + tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); + } + } + } } } else { diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index e236f2e0..feced079 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ - {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.7.0.0"}, - {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.5.0"} + {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.8.0.0"}, + {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.6.0"} ] } \ No newline at end of file -- cgit v1.2.3 From 13ae16997d4bbca14e255d5989d1c44a76eac72c Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 16 May 2012 15:23:48 -0700 Subject: montage v.0.10 integration Signed-off-by: Valerio Virgillito --- js/io/system/ninjalibrary.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index feced079..041e7ed7 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ - {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.8.0.0"}, + {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.10.0.0"}, {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.6.0"} ] } \ No newline at end of file -- cgit v1.2.3 From fe3b8f2d556c1919e4ad504f7f895f6c400d84d2 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Tue, 22 May 2012 00:37:02 -0700 Subject: Bumping RDGE version number This is to ensure there are no conflicts with older working files. --- js/io/system/ninjalibrary.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.json b/js/io/system/ninjalibrary.json index 041e7ed7..5c1eb875 100644 --- a/js/io/system/ninjalibrary.json +++ b/js/io/system/ninjalibrary.json @@ -1,6 +1,6 @@ { "libraries": [ {"name": "Montage", "path": "/node_modules/descriptor.json", "version": "0.10.0.0"}, - {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.6.0"} + {"name": "RDGE", "path": "/assets/descriptor.json", "version": "0.5.7.0"} ] } \ No newline at end of file -- cgit v1.2.3 From 526c2cee246c05fde7776e2d4e05f8c4adf27660 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 27 May 2012 17:03:37 -0700 Subject: Cleaning up --- js/io/system/ninjalibrary.js | 126 ++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 75 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index 3de5fb69..dab623c1 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -4,12 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -/* ///////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -NOTES: - -//////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////// */ // var Montage = require("montage/core/core").Montage; //////////////////////////////////////////////////////////////////////// @@ -18,73 +13,53 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // _chromeApi: { - enumerable: false, value: null }, //////////////////////////////////////////////////////////////////// // chromeApi: { - enumerable: false, - get: function() { - return this._chromeApi; - }, - set: function(value) { - this._chromeApi = value; - } + get: function() {return this._chromeApi;}, + set: function(value) {this._chromeApi = value;} }, //////////////////////////////////////////////////////////////////// // _coreApi: { - enumerable: false, value: null }, //////////////////////////////////////////////////////////////////// // coreApi: { - enumerable: false, - get: function() { - return this._coreApi; - }, - set: function(value) { - this._coreApi = value; - } + get: function() {return this._coreApi;}, + set: function(value) {this._coreApi = value;} }, //////////////////////////////////////////////////////////////////// // _libs: { - enumerable: false, value: null }, //////////////////////////////////////////////////////////////////// // libs: { - enumerable: false, - get: function() { - return this._libs; - }, - set: function(value) { - this._libs = value; - } + get: function() {return this._libs;}, + set: function(value) {this._libs = value;} }, //////////////////////////////////////////////////////////////////// // _libsToSync: { - enumerable: false, value: 0 }, //////////////////////////////////////////////////////////////////// // _syncedLibs: { - enumerable: false, value: 0 }, //////////////////////////////////////////////////////////////////// // copyLibToCloud: { - enumerable: false, value: function (path, libName, callback) { - // + //Checking for library to exists if(this.coreApi.directoryExists({uri: path+libName}).status === 404) { + //Getting contents to begin copying this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, function (contents) { for (var i in contents) { if (libName === contents[i].name) { @@ -98,16 +73,15 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } }.bind(this)); } else { - //Error + //TODO: Add error handling } } }, //////////////////////////////////////////////////////////////////// // copyDirectoryToCloud: { - enumerable: true, value: function(root, folder, fileRoot, callback) { - // + //Setting up directory name if (folder.name) { var dir; if (root) { @@ -115,23 +89,26 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } else { dir = folder.name; } - // + //Creating directory if (!this.coreApi.createDirectory({uri: dir.replace(/\/\//gi, '/')})) { //Error occured while creating folders - return; + return; //TODO: Add error handling } } - // + //Checking for directory if (folder.isDirectory) { + //Using Chrome API to get directory contents this.chromeApi.directoryContents(folder, function (contents) { + //Looping through children of directory to copy for (var i in contents) { + //Checking for file or directory if (contents[i].isDirectory) { + //Recursive call if directory this.copyDirectoryToCloud(dir, contents[i], fileRoot); } else if (contents[i].isFile){ - //File to copy + //Copying file this.chromeApi.fileContent(contents[i].fullPath, function (result) { - // - //this.coreApi.createFile({uri: fileRoot+result.file.fullPath, contents: blob.getBlob(result.data.type), contentType: result.data.type}); + //Using binary when copying files to allow images and such to work this.coreApi.createFile({uri: (fileRoot+result.file.fullPath).replace(/\/\//gi, '/'), contents: result.content}); }.bind(this)); } @@ -145,34 +122,31 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //////////////////////////////////////////////////////////////////// // synchronize: { - enumerable: true, value: function(chromeLibs, chrome) { //TODO: Remove window.wipeLibrary = this.deleteLibraries.bind(this); - // + //Getting instance of browser file API this.chromeApi = chrome; - // -// debugger; + //Local variables var i, l, libs, libjson, xhr = new XMLHttpRequest(), tocopylibs = []; - //Getting known json list of libraries to copy to chrome + //Getting known json list of libraries to copy to chrome (will be on a CDN later) xhr.open("GET", '/js/io/system/ninjalibrary.json', false); xhr.send(); //Checkng for correct reponse if (xhr.readyState === 4) { //Parsing json libraries libs = JSON.parse(xhr.response); - // + //Storing JSON data this.libs = libs.libraries; - // + //Checking for preview libraries to avoid duplicates if (chromeLibs.length > 0) { - // + //Looping through libraries on browser file system for (i=0; chromeLibs[i]; i++) { for (var j in libs.libraries) { - if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() === chromeLibs[i]) { - //TODO: Remove, currently manually removing copied libraries - // //this.chromeApi.directoryDelete(chromeLibs[i]); - } else { - if (libs.libraries[j].file) { + //Checking for matching names (directories are libraries names) + if (String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase() !== chromeLibs[i]) { + //Checking for library to be single file (special case) + if (libs.libraries[j].file) { tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path, file: libs.libraries[j].file}); } else { tocopylibs.push({name: String(libs.libraries[j].name+libs.libraries[j].version).toLowerCase(), path: libs.libraries[j].path}); @@ -194,9 +168,9 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } } } - // + //Storing list of libraries to copy this._libsToSync = tocopylibs.length; - // + //Check to see if libraries are needed to be copied if (tocopylibs.length > 0) { for (i=0; tocopylibs[i]; i++) { //Checking for library to be single file @@ -213,7 +187,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //Creating new file from loaded content this.chromeApi.fileNew('/'+tocopylibs[i].name+'/'+tocopylibs[i].file, xhr.response, function (status) {if(status) this.libraryCopied()}.bind(this)); } else { - //Error creating single file library + //TODO: Add error handling } } else { //Creating root folder @@ -224,16 +198,18 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { xhr.send(); //Checking for status if (xhr.readyState === 4) { - // + //Parsing JSON data of files to copy libjson = JSON.parse(xhr.response); - // + //Looping through list for (l=0; libjson.directories[l]; l++) { + //Initializing defaults libjson.dirsToCreate = libjson.directories.length; libjson.dirsCreated = 0; libjson.filesToCreate = libjson.files.length; libjson.filesCreated = 0; libjson.local = tocopylibs[i].name; libjson.main = this; + //Looping through list and creating directories first this.createDirectory(tocopylibs[i].name, libjson.directories[l], function (status) { //Checking for success on directories created if (status) { @@ -242,6 +218,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { //All directories created if (this.dirsCreated === this.dirsToCreate) { var xhr, i; + //Looping through files to copy now that directories are ready for (i=0; this.files[i]; i++) { xhr = new XMLHttpRequest(); xhr.open("GET", this.root+this.files[i], false); @@ -263,7 +240,7 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { }.bind(libjson)); } } else { - //Error + //TODO: Add error handling } } } @@ -272,26 +249,25 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { this._dispatchEvent(); } } else { - //Error + //TODO: Add error handling } } }, //////////////////////////////////////////////////////////////////// - // + //Creating a directory on the file system (and sub directories if nested) createDirectory: { - enumerable: true, value: function(root, folder, callback) { - // + //Checking for name, establishing format if (folder.name) { if (root) { dir = root+'/'+folder.name; } else { dir = folder.name; } - // + //Creating directory this.chromeApi.directoryNew(dir, function (status) {if (callback)callback(status)}); } - // + //Checking for children and making recursive calls if needed if (folder.children) { for (var j in folder.children) { if (root) { @@ -304,9 +280,8 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// - // + //Callback to keep track of copied libraries during sync libraryCopied: { - enumerable: true, value: function() { this._syncedLibs++; if (this._syncedLibs === this._libsToSync) { @@ -315,27 +290,28 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { } }, //////////////////////////////////////////////////////////////////// - // + //Method to remove libraries copied into browser file system (ALL) deleteLibraries: { - enumerable: true, value: function () { + //Used by file system API to callback function parseLibrary (contents) { - // + //Looping through contents to delete for(var i=0; contents[i]; i++) { - // + //Deleting entire directies (no single files are copied outside) if (contents[i].isDirectory) { this.chromeApi.directoryDelete(contents[i].name); + } else { + //TODO: Handle single files } } }; - // + //Making call to file system API to get all libraries (files) on file system this.chromeApi.directoryContents(this.chromeApi.fileSystem.root, parseLibrary.bind(this)); } }, //////////////////////////////////////////////////////////////////// // _dispatchEvent: { - enumerable: true, value: function () { var syncEvent = document.createEvent("CustomEvent"); syncEvent.initEvent('sync', true, true); -- cgit v1.2.3 From 6ca89e7233614b93c49a4feadb8a0a82e5800b8f Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Sun, 27 May 2012 17:32:41 -0700 Subject: Cleaning up --- js/io/system/ninjalibrary.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'js/io/system') diff --git a/js/io/system/ninjalibrary.js b/js/io/system/ninjalibrary.js index dab623c1..12af5988 100644 --- a/js/io/system/ninjalibrary.js +++ b/js/io/system/ninjalibrary.js @@ -65,8 +65,13 @@ exports.NinjaLibrary = Montage.create(Object.prototype, { if (libName === contents[i].name) { //Getting contents of library to be copied this.chromeApi.directoryContents(contents[i], function (lib) { - //Creating directory structure from subfolders - this.copyDirectoryToCloud(path, contents[i], path, callback); + //Copying to cloud, adding blocking if no callback specified + if (!callback) { + //TODO: Add blocking logic here + this.copyDirectoryToCloud(path, contents[i], path); + } else { + this.copyDirectoryToCloud(path, contents[i], path, callback); + } }.bind(this)); break; } -- cgit v1.2.3