Skip to content

TagSpaces is an offline, open source, document manager with tagging support

jshinting

Ilianb0e9eee6ce37
diff --git a/data/chrome/chrome.api.js b/data/chrome/chrome.api.js
index 783d2dcd3..031d399c0 100644
--- a/data/chrome/chrome.api.js
+++ b/data/chrome/chrome.api.js
@@ -1,15 +1,17 @@
/* Copyright (c) 2012-2014 The TagSpaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
-define(function(require, exports, module) {
+/* global define, nativeIO, isWin */
+
+ define(function(require, exports, module) {
"use strict";
-
- // Activating browser specific exports modul
- console.log("Loading chrome.api.js..");
- var TSCORE = require("tscore");
-
- var TSPOSTIO = require("tspostioapi");
+ // Activating browser specific exports modul
+ console.log("Loading chrome.api.js..");
+
+ var TSCORE = require("tscore");
+
+ var TSPOSTIO = require("tspostioapi");
/**
IO-API
@@ -32,49 +34,49 @@ IO-API
void launchFolder(std::string path); -- not implemented yet
*/
-
- var plugin = document.createElement("embed");
- plugin.setAttribute("type", "application/x-npapifileioforchrome");
- plugin.setAttribute("id", "npApiPlugin");
- plugin.style.position = "absolute";
- plugin.style.left = "-9999px";
-
- // Add plugin to document
+
+ var plugin = document.createElement("embed");
+ plugin.setAttribute("type", "application/x-npapifileioforchrome");
+ plugin.setAttribute("id", "npApiPlugin");
+ plugin.style.position = "absolute";
+ plugin.style.left = "-9999px";
+
+ // Add plugin to document
document.documentElement.appendChild(plugin);
-
- window.nativeIO = document.getElementById("npApiPlugin");
-
- function scanDirectory(dirPath, index) {
- try {
- var dirList = nativeIO.getDirEntries(dirPath);
+
+ window.nativeIO = document.getElementById("npApiPlugin");
+
+ function scanDirectory(dirPath, index) {
+ try {
+ var dirList = nativeIO.getDirEntries(dirPath);
for (var i=0; i < dirList.length; i++) {
- var path = dirPath+TSCORE.dirSeparator+dirList[i];
- var isDir = nativeIO.isDirectory(path);
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
+ var isDir = nativeIO.isDirectory(path);
var fileSize = 0;
var lastDateModified = 0;
if(!isDir) {
fileSize = nativeIO.getFileSize(path);
if(isWin) {
- lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
+ lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
}
}
index.push({
- "name": dirList[i],
- "isFile": !isDir,
- "size": fileSize,
- "lmdt": lastDateModified,
- "path": path
+ "name": dirList[i],
+ "isFile": !isDir,
+ "size": fileSize,
+ "lmdt": lastDateModified,
+ "path": path
});
- if (isDir) {
- scanDirectory(path, index);
- }
+ if (isDir) {
+ scanDirectory(path, index);
+ }
}
- return index;
- } catch(ex) {
- console.error("Listing directory failed "+ex);
- }
- }
-
+ return index;
+ } catch(ex) {
+ console.error("Listing directory failed "+ex);
+ }
+ }
+
function generateDirectoryTree(dirPath) {
try {
var tree = {};
@@ -92,7 +94,7 @@ IO-API
if (!isDir) {
fileSize = nativeIO.getFileSize(path);
if(isWin) {
- lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
+ lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
}
tree["children"].push({
"name": dirList[i],
@@ -110,17 +112,17 @@ IO-API
console.error("Scanning directory "+dirPath+" failed "+ex);
}
}
-
- function isWindows() {
- return (navigator.platform == 'Win32');
- }
-
+
+ function isWindows() {
+ return (navigator.platform == 'Win32');
+ }
+
var checkNewVersion = function() {
console.log("Checking for new version...");
var cVer = TSCORE.Config.DefaultSettings["appVersion"]+"."+TSCORE.Config.DefaultSettings["appBuild"];
$.ajax({
url: 'http://tagspaces.org/releases/version.json?cVer='+cVer,
- type: 'GET',
+ type: 'GET'
})
.done(function(data) {
TSPOSTIO.checkNewVersion(data);
@@ -130,11 +132,11 @@ IO-API
})
;
};
-
- var loadTextFile = function(filePath) {
- console.log("Loading file: "+filePath);
+
+ var loadTextFile = function(filePath) {
+ console.log("Loading file: "+filePath);
TSCORE.showLoadingAnimation();
- if(nativeIO.fileExists(filePath)) {
+ if(nativeIO.fileExists(filePath)) {
var blob;
var size = nativeIO.getFileSize(filePath);
if (size){
@@ -150,52 +152,52 @@ IO-API
TSPOSTIO.loadTextFile(e.target.result);
};
reader.readAsText(b);
- } else {
- console.error("File does not exists...");
- }
- };
-
- var listDirectory = function(dirPath) {
- console.log("Listing directory: "+dirPath);
+ } else {
+ console.error("File does not exists...");
+ }
+ };
+
+ var listDirectory = function(dirPath) {
+ console.log("Listing directory: "+dirPath);
TSCORE.showLoadingAnimation();
/* chrome.fileSystem.chooseEntry({ type: "openDirectory" }, function(d) {
if (!d) return;
var reader = d.createReader();
reader.readEntries(function(list) {
- console.log("Chrome FS: "+list);
+ console.log("Chrome FS: "+list);
});
}); */
- if(nativeIO.isDirectory(dirPath)) {
- var dirList = nativeIO.getDirEntries(dirPath);
+ if(nativeIO.isDirectory(dirPath)) {
+ var dirList = nativeIO.getDirEntries(dirPath);
var anotatedDirList = [];
for (var i=0; i < dirList.length; i++) {
- var path = dirPath+TSCORE.dirSeparator+dirList[i];
- var isDir = nativeIO.isDirectory(path);
+ var path = dirPath+TSCORE.dirSeparator+dirList[i];
+ var isDir = nativeIO.isDirectory(path);
var fileSize = 0;
var lastDateModified = 0;
if(!isDir) {
fileSize = nativeIO.getFileSize(path);
if(isWin) {
- lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
+ lastDateModified = new Date(nativeIO.getFileLastDateModified(path)*1000);
}
}
anotatedDirList.push({
- "name": dirList[i],
- "isFile": !isDir,
- "size": fileSize,
- "lmdt": lastDateModified,
- "path": path
+ "name": dirList[i],
+ "isFile": !isDir,
+ "size": fileSize,
+ "lmdt": lastDateModified,
+ "path": path
});
}
TSPOSTIO.listDirectory(anotatedDirList);
- } else {
- TSPOSTIO.errorOpeningPath();
- console.log("Directory does not exists.");
- }
- };
-
+ } else {
+ TSPOSTIO.errorOpeningPath();
+ console.log("Directory does not exists.");
+ }
+ };
+
var listSubDirectories = function(dirPath) {
console.log("Listing sub directories: "+dirPath);
TSCORE.showLoadingAnimation();
@@ -223,9 +225,9 @@ IO-API
console.log("Deleting: "+path);
TSCORE.showLoadingAnimation();
try {
- if(!nativeIO.isDirectory(path)) {
- nativeIO.removeRecursively(path);
- }
+ if(!nativeIO.isDirectory(path)) {
+ nativeIO.removeRecursively(path);
+ }
TSPOSTIO.deleteElement(path);
} catch(ex) {
console.error("Deleting file failed "+ex);
@@ -278,7 +280,7 @@ IO-API
console.error("Deleting file failed "+ex);
}
};
-
+
var renameFile = function(filePath, newFilePath) {
console.log("Renaming file: "+filePath+" to "+newFilePath);
TSCORE.showLoadingAnimation();
@@ -286,57 +288,57 @@ IO-API
console.log("Initial and target filenames are the same...");
return false;
}
- if(nativeIO.fileExists(newFilePath)) {
- console.log("File renaming failed! Target filename already exists.");
- return false;
- }
+ if(nativeIO.fileExists(newFilePath)) {
+ console.log("File renaming failed! Target filename already exists.");
+ return false;
+ }
if(isWin) {
- if(nativeIO.renameFile(filePath, newFilePath)) {
- TSPOSTIO.renameFile(filePath, newFilePath);
- } else {
- console.error("File renaming failed!");
- }
+ if(nativeIO.renameFile(filePath, newFilePath)) {
+ TSPOSTIO.renameFile(filePath, newFilePath);
+ } else {
+ console.error("File renaming failed!");
+ }
} else {
- if(nativeIO.fileExists(filePath)) {
- var blob;
- var size = nativeIO.getFileSize(filePath);
- // TODO remove the 5MB restriction
- if(size > 5*1024*1024) {
- TSCORE.showAlertDialog("In Chrome, TagSpaces does not support renaming/tagging of files bigger than 5MB!");
- return;
- }
- if (size){
- var byteArray = nativeIO.contentsAtPath(filePath);
- blob = new Int8Array(byteArray);
- } else {
- blob = new Int8Array(0);
- }
- var b = new Blob([blob]);
- b.size = size;
- var reader = new FileReader();
- reader.onloadend = function(e){
- var data = Array.prototype.slice.call(new Uint8Array(reader.result), 0);
- nativeIO.saveBlobToFile(newFilePath, data);
- if(nativeIO.fileExists(newFilePath)) {
- nativeIO.removeRecursively(filePath);
- }
- TSPOSTIO.renameFile(filePath,newFilePath);
- };
- reader.readAsArrayBuffer(b);
- } else {
- console.error("File does not exists...");
- }
+ if(nativeIO.fileExists(filePath)) {
+ var blob;
+ var size = nativeIO.getFileSize(filePath);
+ // TODO remove the 5MB restriction
+ if(size > 5*1024*1024) {
+ TSCORE.showAlertDialog("In Chrome, TagSpaces does not support renaming/tagging of files bigger than 5MB!");
+ return;
+ }
+ if (size){
+ var byteArray = nativeIO.contentsAtPath(filePath);
+ blob = new Int8Array(byteArray);
+ } else {
+ blob = new Int8Array(0);
+ }
+ var b = new Blob([blob]);
+ b.size = size;
+ var reader = new FileReader();
+ reader.onloadend = function(e){
+ var data = Array.prototype.slice.call(new Uint8Array(reader.result), 0);
+ nativeIO.saveBlobToFile(newFilePath, data);
+ if(nativeIO.fileExists(newFilePath)) {
+ nativeIO.removeRecursively(filePath);
+ }
+ TSPOSTIO.renameFile(filePath,newFilePath);
+ };
+ reader.readAsArrayBuffer(b);
+ } else {
+ console.error("File does not exists...");
+ }
}
};
- var selectDirectory = function() {
- console.log("Select directory!");
+ var selectDirectory = function() {
+ console.log("Select directory!");
nativeIO.launchFolderSelect(function(dirPath){
- if (dirPath && dirPath.length){
- TSPOSTIO.selectDirectory(dirPath);
- }
- });
- };
+ if (dirPath && dirPath.length){
+ TSPOSTIO.selectDirectory(dirPath);
+ }
+ });
+ };
var selectFile = function() {
console.log("Select file!");
@@ -362,20 +364,20 @@ IO-API
var openDirectory = function(dirPath) {
// TODO implement openDirectory
console.log("Open directory functionality not implemented in chrome yet!");
- TSCORE.showAlertDialog("Open directoriy functionality not implemented on chrome yet!");
+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openContainingDirectoryAlert"));
};
var openFile = function(filePath) {
// TODO implement openFile
console.log("Open file functionality not implemented in chrome yet!");
- TSCORE.showAlertDialog("Open files natively is not implemented on chrome yet!");
+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openFileNativelyAlert"));
+ };
+
+ var openExtensionsDirectory = function() {
+ // TODO implement openExtensionsDirectory
+ console.log("Open extensions directory functionality not implemented in chrome yet!");
+ TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");
};
-
- var openExtensionsDirectory = function() {
- // TODO implement openExtensionsDirectory
- console.log("Open extensions directory functionality not implemented in chrome yet!");
- TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");
- };
var getFileProperties = function(filePath) {
var fileSize = nativeIO.getFileSize(filePath);
@@ -389,26 +391,26 @@ IO-API
}
TSPOSTIO.getFileProperties(fileProperties);
} else {
- console.warn("Error getting file properties. "+filePath+" is directory");
+ console.log("Error getting file properties. "+filePath+" is directory");
}
};
-
- exports.createDirectory = createDirectory;
- exports.renameFile = renameFile;
- exports.loadTextFile = loadTextFile;
- exports.saveTextFile = saveTextFile;
- exports.listDirectory = listDirectory;
+
+ exports.createDirectory = createDirectory;
+ exports.renameFile = renameFile;
+ exports.loadTextFile = loadTextFile;
+ exports.saveTextFile = saveTextFile;
+ exports.listDirectory = listDirectory;
exports.listSubDirectories = listSubDirectories;
- exports.deleteElement = deleteElement;
+ exports.deleteElement = deleteElement;
exports.createDirectoryIndex = createDirectoryIndex;
exports.createDirectoryTree = createDirectoryTree;
- exports.selectDirectory = selectDirectory;
- exports.openDirectory = openDirectory;
+ exports.selectDirectory = selectDirectory;
+ exports.openDirectory = openDirectory;
exports.openFile = openFile;
- exports.selectFile = selectFile;
- exports.openExtensionsDirectory = openExtensionsDirectory;
- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
- exports.checkNewVersion = checkNewVersion;
+ exports.selectFile = selectFile;
+ exports.openExtensionsDirectory = openExtensionsDirectory;
+ exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;
+ exports.checkNewVersion = checkNewVersion;
exports.getFileProperties = getFileProperties;
-
+
});