TagSpaces is an offline, open source, document manager with tagging support
js code beautifying
uggrockeae33f4220b9
diff --git a/data/chromelight/background.js b/data/chromelight/background.jsindex cfebed29b..2c68100d6 100644--- a/data/chromelight/background.js+++ b/data/chromelight/background.js@@ -1,5 +1,5 @@/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that+ * Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. *//*chrome.browserAction.onClicked.addListener(function() {chrome.tabs.create({ url: 'index.html'});@@ -12,4 +12,4 @@console.log("Updated from " + details.previousVersion + " to " + thisVersion +" !");}});*/-//chrome.runtime.setUninstallURL("http://www.tagspaces.org/uninstallsurvey/");\ No newline at end of file+//chrome.runtime.setUninstallURL("http://www.tagspaces.org/uninstallsurvey/");diff --git a/data/chromelight/captureContent.js b/data/chromelight/captureContent.jsindex 9e20059c1..536cf489d 100644--- a/data/chromelight/captureContent.js+++ b/data/chromelight/captureContent.js@@ -1,53 +1,53 @@function DOMtoString(document_root) {- var html = '',- node = document_root.firstChild;- while (node) {- switch (node.nodeType) {- case Node.ELEMENT_NODE:- html += node.outerHTML;- break;- case Node.TEXT_NODE:- html += node.nodeValue;- break;- case Node.CDATA_SECTION_NODE:- html += '<![CDATA[' + node.nodeValue + ']]>';- break;- case Node.COMMENT_NODE:- html += '<!--' + node.nodeValue + '-->';- break;- case Node.DOCUMENT_TYPE_NODE:- // (X)HTML documents are identified by public identifiers- html += "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';- break;- }- node = node.nextSibling;+ var html = '',+ node = document_root.firstChild;+ while (node) {+ switch (node.nodeType) {+ case Node.ELEMENT_NODE:+ html += node.outerHTML;+ break;+ case Node.TEXT_NODE:+ html += node.nodeValue;+ break;+ case Node.CDATA_SECTION_NODE:+ html += '<![CDATA[' + node.nodeValue + ']]>';+ break;+ case Node.COMMENT_NODE:+ html += '<!--' + node.nodeValue + '-->';+ break;+ case Node.DOCUMENT_TYPE_NODE:+ // (X)HTML documents are identified by public identifiers+ html += "<!DOCTYPE " + node.name + (node.publicId ? ' PUBLIC "' + node.publicId + '"' : '') + (!node.publicId && node.systemId ? ' SYSTEM' : '') + (node.systemId ? ' "' + node.systemId + '"' : '') + '>\n';+ break;}- return html;+ node = node.nextSibling;+ }+ return html;}function getSelectionHtml() {- var html = "";- if (typeof window.getSelection != "undefined") {- var sel = window.getSelection();- if (sel.rangeCount) {- var container = document.createElement("div");- for (var i = 0, len = sel.rangeCount; i < len; ++i) {- container.appendChild(sel.getRangeAt(i).cloneContents());- }- html = container.innerHTML;- }- } else if (typeof document.selection != "undefined") {- if (document.selection.type == "Text") {- html = document.selection.createRange().htmlText;- }+ var html = "";+ if (typeof window.getSelection != "undefined") {+ var sel = window.getSelection();+ if (sel.rangeCount) {+ var container = document.createElement("div");+ for (var i = 0, len = sel.rangeCount; i < len; ++i) {+ container.appendChild(sel.getRangeAt(i).cloneContents());+ }+ html = container.innerHTML;}- return html;+ } else if (typeof document.selection != "undefined") {+ if (document.selection.type == "Text") {+ html = document.selection.createRange().htmlText;+ }+ }+ return html;}chrome.extension.sendMessage({- action: "getSource",- //source: DOMtoString(document)- source: getSelectionHtml()+ action: "getSource",+ //source: DOMtoString(document)+ source: getSelectionHtml()});/*@@ -86,4 +86,4 @@ chrome.extension.sendMessage({// }//}return html;- }*/\ No newline at end of file+ }*/diff --git a/data/chromelight/chrome.api.js b/data/chromelight/chrome.api.jsindex 411fc0996..c3e581662 100644--- a/data/chromelight/chrome.api.js+++ b/data/chromelight/chrome.api.js@@ -1,374 +1,380 @@/* Copyright (c) 2012-2014 The TagSpaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that+ * Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. *//* global define, nativeIO, isWin */- define(function(require, exports, module) {-"use strict";+define(function(require, exports, module) {+ "use strict";- // Activating browser specific exports modul- console.log("Loading light chrome.api.js..");+ // Activating browser specific exports modul+ console.log("Loading light chrome.api.js..");- // changing the name of the app- $("#logo").text("TagSpaces Light");+ // changing the name of the app+ $("#logo").text("TagSpaces Light");- var TSCORE = require("tscore");+ var TSCORE = require("tscore");- var TSPOSTIO = require("tspostioapi");+ var TSPOSTIO = require("tspostioapi");- require("libs/filesaver.js/FileSaver");+ require("libs/filesaver.js/FileSaver");- var dataBegin = "<script>addRow(";- var dataEnd = ");</script>";- var dataFile = '",0,"';- var dataDir = '",1,"';+ var dataBegin = "<script>addRow(";+ var dataEnd = ");</script>";+ var dataFile = '",0,"';+ var dataDir = '",1,"';- // chrome.browserAction.setBadgeBackgroundColor({ color: '#00ff00' });- // chrome.browserAction.setBadgeText({text: '9999'});+ // chrome.browserAction.setBadgeBackgroundColor({ color: '#00ff00' });+ // chrome.browserAction.setBadgeText({text: '9999'});- var handleStartParameters = function () {- var openFile = getURLParameter("openFile");- if (openFile !== undefined && (openFile.length > 0)) { // && openFile.indexOf("file://") === 0- console.log("Opening file in browser: " + openFile);- openFile = openFile.split("file://")[1];- //var dirPath = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);- //TSCORE.IO.listDirectory(dirPath);- TSCORE.FileOpener.openFileOnStartup(openFile);- }- };-- function getURLParameter(variable){- var query = window.location.search.substring(1);- var vars = query.split("&");- for (var i=0;i<vars.length;i++) {- var pair = vars[i].split("=");- if(pair[0] == variable){return pair[1];}- }- return(false);- }-- function scanDirectory(dirPath, index) {-/* $.ajax({- url: "file://"+dirPath,- type: 'GET'- })- .done(function(data) {- //console.log("Dir List "+data);- var folders = data.substring(data.indexOf(dataBegin)+dataBegin.length,data.lastIndexOf(dataEnd));- folders = folders.split(dataBegin).join("");- folders = folders.split(dataEnd);-- var name,- path,- isFile,- fileSize,- lastDateModified,- fileProp;-- // sciping the first entry pointing to the parent directory- for (var i=1; i < folders.length; i++) {- console.log("Dir Req "+folders[i]);- name = folders[i].substring(2,folders[i].indexOf('","'));- path = dirPath+TSCORE.dirSeparator+name;- isFile = (folders[i].indexOf(dataFile) > 1);- fileSize = 0;- lastDateModified = 0;- if(isFile) {- fileProp = folders[i].substring(folders[i].indexOf(dataFile)+dataFile.length+1,folders[i].length-1);- fileProp = fileProp.split('","');- fileSize = fileProp[0];- lastDateModified = fileProp[1];- }- index.push({- "name": name,- "isFile": isFile,- "size": fileSize,- "lmdt": lastDateModified,- "path": path- });- if (!isFile) {- scanDirectory(path, index);- }- }- return index;- })- .fail(function(data) {- TSPOSTIO.errorOpeningPath(dirPath);- console.log("Error opening path "+data);- });*/+ var handleStartParameters = function() {+ var openFile = getURLParameter("openFile");+ if (openFile !== undefined && (openFile.length > 0)) { // && openFile.indexOf("file://") === 0+ console.log("Opening file in browser: " + openFile);+ openFile = openFile.split("file://")[1];+ //var dirPath = TSCORE.TagUtils.extractContainingDirectoryPath(filePath);+ //TSCORE.IO.listDirectory(dirPath);+ TSCORE.FileOpener.openFileOnStartup(openFile);+ }+ };++ function getURLParameter(variable) {+ var query = window.location.search.substring(1);+ var vars = query.split("&");+ for (var i = 0; i < vars.length; i++) {+ var pair = vars[i].split("=");+ if (pair[0] == variable) {+ return pair[1];+ }}+ return (false);+ }- function generateDirectoryTree(dirPath) {-- }-- 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'- })- .done(function(data) {- TSPOSTIO.checkNewVersion(data);- })- .fail(function(data) {- console.log("AJAX failed "+data);- });- };-- var loadTextFile = function(filePath) {- console.log("Loading file: "+filePath);- $.ajax({- url: "file://"+filePath,- type: 'POST'- })- .done(function(data) {- TSPOSTIO.loadTextFile(data);+ function scanDirectory(dirPath, index) {+ /* $.ajax({+ url: "file://"+dirPath,+ type: 'GET'})- .fail(function(data) {- console.log("AJAX failed "+data);- });- };-- var listDirectory = function(dirPath) {- console.log("Listing directory: "+dirPath);- TSCORE.showLoadingAnimation();-- $.ajax({- url: "file://"+dirPath,- type: 'GET'- })- .done(function(data) {- //console.log("Dir List "+data);- var folders = data.substring(data.indexOf(dataBegin)+dataBegin.length,data.lastIndexOf(dataEnd));- folders = folders.split(dataBegin).join("");- folders = folders.split(dataEnd);-- var name,- path,- isFile,- fileSize,- lastDateModified,- fileProp;-- var anotatedDirList = [];- // sciping the first entry pointing to the parent directory- for (var i=1; i < folders.length; i++) {- console.log("Dir "+folders[i]);- name = folders[i].substring(2,folders[i].indexOf('","'));- path = dirPath+TSCORE.dirSeparator+name;- isFile = (folders[i].indexOf(dataFile) > 1);- fileSize = 0;- lastDateModified = 0;- if(isFile) {- fileProp = folders[i].substring(folders[i].indexOf(dataFile)+dataFile.length+1,folders[i].length-1);- fileProp = fileProp.split('","');- fileSize = fileProp[0];- lastDateModified = fileProp[1];- }- anotatedDirList.push({- "name": name,- "isFile": isFile,- "size": fileSize,- "lmdt": lastDateModified,- "path": path- });- }- TSPOSTIO.listDirectory(anotatedDirList);- })- .fail(function(data) {- TSPOSTIO.errorOpeningPath(dirPath);- console.log("Error opening path "+data);- });- };-- var listSubDirectories = function(dirPath) {- console.log("Listing sub directories: "+dirPath);- TSCORE.showLoadingAnimation();-- $.ajax({- url: "file://"+dirPath,- type: 'GET'- })- .done(function(data) {- //console.log("Dir List "+data);- var folders = data.substring(data.indexOf(dataBegin)+dataBegin.length,data.lastIndexOf(dataEnd));- folders = folders.split(dataBegin).join("");- folders = folders.split(dataEnd);-- var name,- path,- isDir;-- var anotatedDirList = [];- // skiping the first entry pointing to the parent directory- for (var i=1; i < folders.length; i++) {- console.log("Dir "+folders[i]);- name = folders[i].substring(2,folders[i].indexOf('","'));- if(dirPath === TSCORE.dirSeparator) {- path = dirPath+name;- } else {+ .done(function(data) {+ //console.log("Dir List "+data);+ var folders = data.substring(data.indexOf(dataBegin)+dataBegin.length,data.lastIndexOf(dataEnd));+ folders = folders.split(dataBegin).join("");+ folders = folders.split(dataEnd);++ var name,+ path,+ isFile,+ fileSize,+ lastDateModified,+ fileProp;++ // sciping the first entry pointing to the parent directory+ for (var i=1; i < folders.length; i++) {+ console.log("Dir Req "+folders[i]);+ name = folders[i].substring(2,folders[i].indexOf('","'));path = dirPath+TSCORE.dirSeparator+name;- }- isDir = (folders[i].indexOf(dataDir) > 1);- if(isDir) {- anotatedDirList.push({+ isFile = (folders[i].indexOf(dataFile) > 1);+ fileSize = 0;+ lastDateModified = 0;+ if(isFile) {+ fileProp = folders[i].substring(folders[i].indexOf(dataFile)+dataFile.length+1,folders[i].length-1);+ fileProp = fileProp.split('","');+ fileSize = fileProp[0];+ lastDateModified = fileProp[1];+ }+ index.push({"name": name,+ "isFile": isFile,+ "size": fileSize,+ "lmdt": lastDateModified,"path": path});+ if (!isFile) {+ scanDirectory(path, index);+ }}- }- TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);- })- .fail(function(data) {- TSPOSTIO.errorOpeningPath(dirPath);- console.log("Error opening path "+data);- });-- };-- var deleteElement = function(path) {- TSCORE.showAlertDialog("Deleting files is not supported in TagSpaces Light, please use the desktop version.");- };-- var deleteDirectory = function(dirPath) {- TSCORE.showAlertDialog("Deleting directory is not supported in TagSpaces Light, please use the desktop version.");- };-- var createDirectoryIndex = function(dirPath) {- console.log("Creating index for directory: "+dirPath);- TSCORE.showLoadingAnimation();- var directoryIndex = [];- directoryIndex = scanDirectory(dirPath, directoryIndex);- console.log(JSON.stringify(directoryIndex));- TSPOSTIO.createDirectoryIndex(directoryIndex);- };-- var createDirectoryTree = function(dirPath) {- TSCORE.showLoadingAnimation();- console.log("Creating directory index for: "+dirPath);- var directoyTree = generateDirectoryTree(dirPath);- //console.log(JSON.stringify(directoyTree));- TSPOSTIO.createDirectoryTree(directoyTree);- };-- var saveTextFile = function(filePath,content) {- TSCORE.showLoadingAnimation();- console.log("Saving file: "+filePath);-- var blob = new Blob([content], {type: "text/plain;charset=utf-8"});- saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));- // TODO close file after save-- //TSPOSTIO.saveTextFile(filePath);-- };-- var saveBinaryFile = function(filePath,content) {- TSCORE.showLoadingAnimation();- console.log("Saving binary file: "+filePath);-- var blob = new Blob([content], {type: "text/plain;charset=utf-8"});- saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));- // TODO close file after save-- //TSPOSTIO.saveTextFile(filePath);-- };-- var createDirectory = function(dirPath) {- TSCORE.showAlertDialog("Creating directory is not supported in TagSpaces Light, please use the desktop version.");- };-- var renameDirectory = function(filePath, newFilePath) {- TSCORE.showAlertDialog("Renaming directory is not supported in TagSpaces Light, please use the desktop version.");- };-- var renameFile = function(filePath, newFilePath) {- TSCORE.showAlertDialog("Tagging/Renaming files is not supported in TagSpaces Light, please use the desktop version.");- };-- var copyFile = function(filePath, newFilePath) {- TSCORE.showAlertDialog("Copy files is not supported in TagSpaces Light, please use the desktop version.");- };-- var selectDirectory = function() {- console.log("Select directory!");- var rootPath = "/";- if(isWin) {- rootPath = "C:"+ return index;+ })+ .fail(function(data) {+ TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Error opening path "+data);+ });*/+ }++ function generateDirectoryTree(dirPath) {++ }++ 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'+ })+ .done(function(data) {+ TSPOSTIO.checkNewVersion(data);+ })+ .fail(function(data) {+ console.log("AJAX failed " + data);+ });+ };++ var loadTextFile = function(filePath) {+ console.log("Loading file: " + filePath);+ $.ajax({+ url: "file://" + filePath,+ type: 'POST'+ })+ .done(function(data) {+ TSPOSTIO.loadTextFile(data);+ })+ .fail(function(data) {+ console.log("AJAX failed " + data);+ });+ };++ var listDirectory = function(dirPath) {+ console.log("Listing directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ $.ajax({+ url: "file://" + dirPath,+ type: 'GET'+ })+ .done(function(data) {+ //console.log("Dir List "+data);+ var folders = data.substring(data.indexOf(dataBegin) + dataBegin.length, data.lastIndexOf(dataEnd));+ folders = folders.split(dataBegin).join("");+ folders = folders.split(dataEnd);++ var name,+ path,+ isFile,+ fileSize,+ lastDateModified,+ fileProp;++ var anotatedDirList = [];+ // sciping the first entry pointing to the parent directory+ for (var i = 1; i < folders.length; i++) {+ console.log("Dir " + folders[i]);+ name = folders[i].substring(2, folders[i].indexOf('","'));+ path = dirPath + TSCORE.dirSeparator + name;+ isFile = (folders[i].indexOf(dataFile) > 1);+ fileSize = 0;+ lastDateModified = 0;+ if (isFile) {+ fileProp = folders[i].substring(folders[i].indexOf(dataFile) + dataFile.length + 1, folders[i].length - 1);+ fileProp = fileProp.split('","');+ fileSize = fileProp[0];+ lastDateModified = fileProp[1];+ }+ anotatedDirList.push({+ "name": name,+ "isFile": isFile,+ "size": fileSize,+ "lmdt": lastDateModified,+ "path": path+ });}- TSCORE.showDirectoryBrowserDialog(rootPath);- };-- var selectFile = function() {- console.log("Select file not implemented!");- };-- var checkAccessFileURLAllowed = function() {- chrome.extension.isAllowedFileSchemeAccess(function(isAllowedAccess) {- if(!isAllowedAccess) {- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:accessFileURLNotAllowedAlert"));- }- });- };-- var openDirectory = function(dirPath) {- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openContainingDirectoryAlert"));- };-- var openFile = function(filePath) {- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openFileNativelyAlert"));- };-- var openExtensionsDirectory = function() {- TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");- };-- var getFileProperties = function(filePath) {- var fileProperties = {};- fileProperties.path = filePath;- fileProperties.size = 0; // TODO use listDirectory to get size and lmdt- fileProperties.lmdt = 0;- TSPOSTIO.getFileProperties(fileProperties);- };-- var saveSettings = function(content) {- /*chrome.storage.sync.set({'tagSpacesSettings': content}, function() {- // Notify that we saved.- message('Settings saved');- });*/- };-- // Bring the TagSpaces window on top of the windows- var focusWindow = function() {- window.focus();- };-- exports.focusWindow = focusWindow;- exports.createDirectory = createDirectory;- exports.copyFile = copyFile;- exports.renameFile = renameFile;- exports.renameDirectory = renameDirectory;- exports.loadTextFile = loadTextFile;- exports.saveTextFile = saveTextFile;- exports.saveBinaryFile = saveBinaryFile;- exports.listDirectory = listDirectory;- exports.listSubDirectories = listSubDirectories;- exports.deleteElement = deleteElement;- exports.deleteDirectory = deleteDirectory;- exports.createDirectoryIndex = createDirectoryIndex;- exports.createDirectoryTree = createDirectoryTree;- exports.selectDirectory = selectDirectory;- exports.openDirectory = openDirectory;- exports.openFile = openFile;- exports.selectFile = selectFile;- exports.openExtensionsDirectory = openExtensionsDirectory;- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;- exports.checkNewVersion = checkNewVersion;- exports.getFileProperties = getFileProperties;- exports.saveSettings = saveSettings;- exports.handleStartParameters = handleStartParameters;+ TSPOSTIO.listDirectory(anotatedDirList);+ })+ .fail(function(data) {+ TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Error opening path " + data);+ });+ };++ var listSubDirectories = function(dirPath) {+ console.log("Listing sub directories: " + dirPath);+ TSCORE.showLoadingAnimation();++ $.ajax({+ url: "file://" + dirPath,+ type: 'GET'+ })+ .done(function(data) {+ //console.log("Dir List "+data);+ var folders = data.substring(data.indexOf(dataBegin) + dataBegin.length, data.lastIndexOf(dataEnd));+ folders = folders.split(dataBegin).join("");+ folders = folders.split(dataEnd);++ var name,+ path,+ isDir;++ var anotatedDirList = [];+ // skiping the first entry pointing to the parent directory+ for (var i = 1; i < folders.length; i++) {+ console.log("Dir " + folders[i]);+ name = folders[i].substring(2, folders[i].indexOf('","'));+ if (dirPath === TSCORE.dirSeparator) {+ path = dirPath + name;+ } else {+ path = dirPath + TSCORE.dirSeparator + name;+ }+ isDir = (folders[i].indexOf(dataDir) > 1);+ if (isDir) {+ anotatedDirList.push({+ "name": name,+ "path": path+ });+ }+ }+ TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);+ })+ .fail(function(data) {+ TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Error opening path " + data);+ });++ };++ var deleteElement = function(path) {+ TSCORE.showAlertDialog("Deleting files is not supported in TagSpaces Light, please use the desktop version.");+ };++ var deleteDirectory = function(dirPath) {+ TSCORE.showAlertDialog("Deleting directory is not supported in TagSpaces Light, please use the desktop version.");+ };++ var createDirectoryIndex = function(dirPath) {+ console.log("Creating index for directory: " + dirPath);+ TSCORE.showLoadingAnimation();+ var directoryIndex = [];+ directoryIndex = scanDirectory(dirPath, directoryIndex);+ console.log(JSON.stringify(directoryIndex));+ TSPOSTIO.createDirectoryIndex(directoryIndex);+ };++ var createDirectoryTree = function(dirPath) {+ TSCORE.showLoadingAnimation();+ console.log("Creating directory index for: " + dirPath);+ var directoyTree = generateDirectoryTree(dirPath);+ //console.log(JSON.stringify(directoyTree));+ TSPOSTIO.createDirectoryTree(directoyTree);+ };++ var saveTextFile = function(filePath, content) {+ TSCORE.showLoadingAnimation();+ console.log("Saving file: " + filePath);++ var blob = new Blob([content], {+ type: "text/plain;charset=utf-8"+ });+ saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));+ // TODO close file after save++ //TSPOSTIO.saveTextFile(filePath);++ };++ var saveBinaryFile = function(filePath, content) {+ TSCORE.showLoadingAnimation();+ console.log("Saving binary file: " + filePath);++ var blob = new Blob([content], {+ type: "text/plain;charset=utf-8"+ });+ saveAs(blob, TSCORE.TagUtils.extractFileName(filePath));+ // TODO close file after save++ //TSPOSTIO.saveTextFile(filePath);++ };++ var createDirectory = function(dirPath) {+ TSCORE.showAlertDialog("Creating directory is not supported in TagSpaces Light, please use the desktop version.");+ };++ var renameDirectory = function(filePath, newFilePath) {+ TSCORE.showAlertDialog("Renaming directory is not supported in TagSpaces Light, please use the desktop version.");+ };++ var renameFile = function(filePath, newFilePath) {+ TSCORE.showAlertDialog("Tagging/Renaming files is not supported in TagSpaces Light, please use the desktop version.");+ };++ var copyFile = function(filePath, newFilePath) {+ TSCORE.showAlertDialog("Copy files is not supported in TagSpaces Light, please use the desktop version.");+ };++ var selectDirectory = function() {+ console.log("Select directory!");+ var rootPath = "/";+ if (isWin) {+ rootPath = "C:"+ }+ TSCORE.showDirectoryBrowserDialog(rootPath);+ };++ var selectFile = function() {+ console.log("Select file not implemented!");+ };++ var checkAccessFileURLAllowed = function() {+ chrome.extension.isAllowedFileSchemeAccess(function(isAllowedAccess) {+ if (!isAllowedAccess) {+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:accessFileURLNotAllowedAlert"));+ }+ });+ };++ var openDirectory = function(dirPath) {+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openContainingDirectoryAlert"));+ };++ var openFile = function(filePath) {+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openFileNativelyAlert"));+ };++ var openExtensionsDirectory = function() {+ TSCORE.showAlertDialog("Open extensions directory functionality not implemented on chrome yet!");+ };++ var getFileProperties = function(filePath) {+ var fileProperties = {};+ fileProperties.path = filePath;+ fileProperties.size = 0; // TODO use listDirectory to get size and lmdt+ fileProperties.lmdt = 0;+ TSPOSTIO.getFileProperties(fileProperties);+ };++ var saveSettings = function(content) {+ /*chrome.storage.sync.set({'tagSpacesSettings': content}, function() {+ // Notify that we saved.+ message('Settings saved');+ });*/+ };++ // Bring the TagSpaces window on top of the windows+ var focusWindow = function() {+ window.focus();+ };++ exports.focusWindow = focusWindow;+ exports.createDirectory = createDirectory;+ exports.copyFile = copyFile;+ exports.renameFile = renameFile;+ exports.renameDirectory = renameDirectory;+ exports.loadTextFile = loadTextFile;+ exports.saveTextFile = saveTextFile;+ exports.saveBinaryFile = saveBinaryFile;+ exports.listDirectory = listDirectory;+ exports.listSubDirectories = listSubDirectories;+ exports.deleteElement = deleteElement;+ exports.deleteDirectory = deleteDirectory;+ exports.createDirectoryIndex = createDirectoryIndex;+ exports.createDirectoryTree = createDirectoryTree;+ exports.selectDirectory = selectDirectory;+ exports.openDirectory = openDirectory;+ exports.openFile = openFile;+ exports.selectFile = selectFile;+ exports.openExtensionsDirectory = openExtensionsDirectory;+ exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;+ exports.checkNewVersion = checkNewVersion;+ exports.getFileProperties = getFileProperties;+ exports.saveSettings = saveSettings;+ exports.handleStartParameters = handleStartParameters;});diff --git a/data/chromelight/popup.js b/data/chromelight/popup.jsindex f8e2a0dbd..82c7c6bd4 100644--- a/data/chromelight/popup.js+++ b/data/chromelight/popup.js@@ -5,185 +5,195 @@'use strict';(function() {- console.log("Loading Popup...");- var tags;- var title;- var html;- var htmlTemplate;- var tagLibrary;-- function init() {- $("#startTagSpaces").on("click", function (e) {- chrome.tabs.create({url: '../index.html'});- });-- loadSettingsLocalStorage();-- var tagList = extractAllTags(tagLibrary);- chrome.tabs.getSelected(null, function (tab) {- $('#title').val(tab.title);- });-- $('#title').focus();-- $('#tags').select2('data', null);- $("#tags").select2({- multiple: true,- tags: tagList,- tokenSeparators: [","," "],- minimumInputLength: 2,- selectOnBlur: true- });-- $("#saveAsMhtml").on('click', saveAsMHTML);-- $("#saveSelectionAsHtml").on("click", function () {- chrome.tabs.executeScript(null, {- file: "chromelight/captureContent.js"- }, function () {- if (chrome.extension.lastError) {- console.log('There was an error injecting script : \n' + chrome.extension.lastError.message);- }- });- });-- $("#saveScreenshot").on("click", saveScreenshot);-- chrome.extension.onMessage.addListener(function (request, sender) {- if (request.action == "getSource") {- chrome.tabs.getSelected(null, function (tab) {- //console.log("HTML: " + request.source);- var cleanenHTML = prepareContent(request.source);- var htmlBlob = new Blob([cleanenHTML], {type: "text/html;charset=utf-8"});- tags = document.getElementById("tags").value;- title = document.getElementById("title").value;- if (tags) {- tags = tags.split(",").join(" ");- saveAs(htmlBlob, title + ' [' + tags + '].html');- } else {- saveAs(htmlBlob, title + '.html');- }- });- }- });- }-- function saveAsMHTML() {- chrome.tabs.getSelected(null, function (tab) {- tags = document.getElementById("tags").value;- chrome.pageCapture.saveAsMHTML({tabId: tab.id}, function (mhtml) {- if (tags) {- tags = tags.split(",").join(" ");- saveAs(mhtml, $('#title').val() + ' [' + tags + '].mhtml');- } else {- saveAs(mhtml, $('#title').val() + '.mhtml');- }- });- });- }-- function saveScreenshot() {- chrome.tabs.getSelected(null, function (tab) {- tags = document.getElementById("tags").value;- chrome.tabs.captureVisibleTab(null, {"format": "png"}, function (image) {- console.log("Screenshot: " + image);- if (tags) {- tags = tags.split(",").join(" ");- saveAs(dataURItoBlob(image), $('#title').val() + ' [' + tags + '].png');- } else {- saveAs(dataURItoBlob(image), $('#title').val() + '.png');- }- });+ console.log("Loading Popup...");+ var tags;+ var title;+ var html;+ var htmlTemplate;+ var tagLibrary;++ function init() {+ $("#startTagSpaces").on("click", function(e) {+ chrome.tabs.create({+ url: '../index.html'+ });+ });++ loadSettingsLocalStorage();++ var tagList = extractAllTags(tagLibrary);+ chrome.tabs.getSelected(null, function(tab) {+ $('#title').val(tab.title);+ });++ $('#title').focus();++ $('#tags').select2('data', null);+ $("#tags").select2({+ multiple: true,+ tags: tagList,+ tokenSeparators: [",", " "],+ minimumInputLength: 2,+ selectOnBlur: true+ });++ $("#saveAsMhtml").on('click', saveAsMHTML);++ $("#saveSelectionAsHtml").on("click", function() {+ chrome.tabs.executeScript(null, {+ file: "chromelight/captureContent.js"+ }, function() {+ if (chrome.extension.lastError) {+ console.log('There was an error injecting script : \n' + chrome.extension.lastError.message);+ }+ });+ });++ $("#saveScreenshot").on("click", saveScreenshot);++ chrome.extension.onMessage.addListener(function(request, sender) {+ if (request.action == "getSource") {+ chrome.tabs.getSelected(null, function(tab) {+ //console.log("HTML: " + request.source);+ var cleanenHTML = prepareContent(request.source);+ var htmlBlob = new Blob([cleanenHTML], {+ type: "text/html;charset=utf-8"+ });+ tags = document.getElementById("tags").value;+ title = document.getElementById("title").value;+ if (tags) {+ tags = tags.split(",").join(" ");+ saveAs(htmlBlob, title + ' [' + tags + '].html');+ } else {+ saveAs(htmlBlob, title + '.html');+ }});- }-- function dataURItoBlob(dataURI) {- // convert base64 to raw binary data held in a string- var byteString = atob(dataURI.split(',')[1]);-- // separate out the mime component- var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];-- // write the bytes of the string to an ArrayBuffer- var arrayBuffer = new ArrayBuffer(byteString.length);- var _ia = new Uint8Array(arrayBuffer);- for (var i = 0; i < byteString.length; i++) {- _ia[i] = byteString.charCodeAt(i);+ }+ });+ }++ function saveAsMHTML() {+ chrome.tabs.getSelected(null, function(tab) {+ tags = document.getElementById("tags").value;+ chrome.pageCapture.saveAsMHTML({+ tabId: tab.id+ }, function(mhtml) {+ if (tags) {+ tags = tags.split(",").join(" ");+ saveAs(mhtml, $('#title').val() + ' [' + tags + '].mhtml');+ } else {+ saveAs(mhtml, $('#title').val() + '.mhtml');}-- var dataView = new DataView(arrayBuffer);- var blob = new Blob([dataView], {type: mimeString});- return blob;+ });+ });+ }++ function saveScreenshot() {+ chrome.tabs.getSelected(null, function(tab) {+ tags = document.getElementById("tags").value;+ chrome.tabs.captureVisibleTab(null, {+ "format": "png"+ }, function(image) {+ console.log("Screenshot: " + image);+ if (tags) {+ tags = tags.split(",").join(" ");+ saveAs(dataURItoBlob(image), $('#title').val() + ' [' + tags + '].png');+ } else {+ saveAs(dataURItoBlob(image), $('#title').val() + '.png');+ }+ });+ });+ }++ function dataURItoBlob(dataURI) {+ // convert base64 to raw binary data held in a string+ var byteString = atob(dataURI.split(',')[1]);++ // separate out the mime component+ var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];++ // write the bytes of the string to an ArrayBuffer+ var arrayBuffer = new ArrayBuffer(byteString.length);+ var _ia = new Uint8Array(arrayBuffer);+ for (var i = 0; i < byteString.length; i++) {+ _ia[i] = byteString.charCodeAt(i);}- function getBase64Image(imgURL) {- var canvas = document.createElement("canvas");- var img = new Image();- img.src = imgURL;- canvas.width = img.width;- canvas.height = img.height;- var ctx = canvas.getContext("2d");- ctx.drawImage(img, 0, 0);- return canvas.toDataURL("image/png");+ var dataView = new DataView(arrayBuffer);+ var blob = new Blob([dataView], {+ type: mimeString+ });+ return blob;+ }++ function getBase64Image(imgURL) {+ var canvas = document.createElement("canvas");+ var img = new Image();+ img.src = imgURL;+ canvas.width = img.width;+ canvas.height = img.height;+ var ctx = canvas.getContext("2d");+ ctx.drawImage(img, 0, 0);+ return canvas.toDataURL("image/png");+ }++ function prepareContent(uncleanedHTML) {+ //console.log("uncleaned "+uncleanedHTML);+ var cleanedHTML = DOMPurify.sanitize(uncleanedHTML);++ /*console.log("cleaned "+cleanedHTML);+ // saving all images as png in base64 format+ var match,+ urls = [],+ imgUrl = "",+ rex = /<img.*?src="([^">]*\/([^">]*?))".*?>/g;++ while ( match = rex.exec( cleanedHTML ) ) {+ imgUrl = match[1];+ //console.log("URLs: "+imgUrl);+ urls.push([imgUrl, getBase64Image(imgUrl)]);}- function prepareContent(uncleanedHTML) {- //console.log("uncleaned "+uncleanedHTML);- var cleanedHTML = DOMPurify.sanitize(uncleanedHTML);-- /*console.log("cleaned "+cleanedHTML);- // saving all images as png in base64 format- var match,- urls = [],- imgUrl = "",- rex = /<img.*?src="([^">]*\/([^">]*?))".*?>/g;-- while ( match = rex.exec( cleanedHTML ) ) {- imgUrl = match[1];- //console.log("URLs: "+imgUrl);- urls.push([imgUrl, getBase64Image(imgUrl)]);- }-- urls.forEach(function(dataURLObject) {- cleanedHTML = cleanedHTML.split(dataURLObject[0]).join(dataURLObject[1]);- //console.log(dataURLObject[0]+" - "+dataURLObject[1]);- });- // end saving all images*/-- cleanedHTML = "<body>"+cleanedHTML+"</body>";- cleanedHTML = htmlTemplate.replace(/\<body[^>]*\>([^]*)\<\/body>/m,cleanedHTML);- return cleanedHTML;+ urls.forEach(function(dataURLObject) {+ cleanedHTML = cleanedHTML.split(dataURLObject[0]).join(dataURLObject[1]);+ //console.log(dataURLObject[0]+" - "+dataURLObject[1]);+ });+ // end saving all images*/++ cleanedHTML = "<body>" + cleanedHTML + "</body>";+ cleanedHTML = htmlTemplate.replace(/\<body[^>]*\>([^]*)\<\/body>/m, cleanedHTML);+ return cleanedHTML;+ }++ function loadSettingsLocalStorage() {+ try {+ var settings = JSON.parse(localStorage.getItem('tagSpacesSettings'));+ //console.log("Settings: "+JSON.stringify(tmpSettings));+ if (settings !== null) {+ htmlTemplate = settings.newHTMLFileContent;+ tagLibrary = settings.tagGroups;+ }+ console.log("Loaded settings from local storage: " + JSON.stringify(tagLibrary));+ } catch (ex) {+ console.log("Loading settings from local storage failed due exception: " + ex);}+ }- function loadSettingsLocalStorage() {- try {- var settings = JSON.parse(localStorage.getItem('tagSpacesSettings'));- //console.log("Settings: "+JSON.stringify(tmpSettings));- if(settings !== null) {- htmlTemplate = settings.newHTMLFileContent;- tagLibrary = settings.tagGroups;- }- console.log("Loaded settings from local storage: "+JSON.stringify(tagLibrary));- } catch(ex) {- console.log("Loading settings from local storage failed due exception: "+ex);- }+ function extractAllTags() {+ var allTags = [];+ if (tagLibrary === undefined) {+ return allTags;}-- function extractAllTags() {- var allTags = [];- if(tagLibrary === undefined) {- return allTags;- }- for(var i=0; i < tagLibrary.length; i++) {- for(var j=0; j < tagLibrary[i].children.length; j++) {- if(tagLibrary[i].children[j].type === "plain") {- allTags.push(tagLibrary[i].children[j].title);- }- }+ for (var i = 0; i < tagLibrary.length; i++) {+ for (var j = 0; j < tagLibrary[i].children.length; j++) {+ if (tagLibrary[i].children[j].type === "plain") {+ allTags.push(tagLibrary[i].children[j].title);}- return allTags;+ }}+ return allTags;+ }- $(document).ready(init);+ $(document).ready(init);-}());\ No newline at end of file+}());diff --git a/data/cordova/cordova.api.js b/data/cordova/cordova.api.jsindex 0fb1ceebb..686eb9dde 100644--- a/data/cordova/cordova.api.js+++ b/data/cordova/cordova.api.js@@ -1,681 +1,737 @@/* Copyright (c) 2012-2014 The TagSpaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that+ * Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. *//* global define */-define(function (require, exports, module) {- "use strict";+define(function(require, exports, module) {+ "use strict";- console.log("Loading ioapi.cordova.js..");-- var TSCORE = require("tscore");- var TSPOSTIO = require("tspostioapi");-- var attachFastClick = require('cordova/fastclick.min');- attachFastClick(document.body);+ console.log("Loading ioapi.cordova.js..");- var fsRoot = undefined;+ var TSCORE = require("tscore");+ var TSPOSTIO = require("tspostioapi");- var urlFromIntent;+ var attachFastClick = require('cordova/fastclick/fastclick.min');+ attachFastClick(document.body);- document.addEventListener("deviceready", onDeviceReady, false);+ var fsRoot = undefined;- // Cordova loaded and can be used- function onDeviceReady() {- console.log("Devive Ready:"); // "+device.platform+" - "+device.version);+ var urlFromIntent;- // Redifining the back button- document.addEventListener("backbutton", function(e){- TSCORE.FileOpener.closeFile();- $('.modal').modal('hide');- e.preventDefault();- }, false);-- window.plugins.webintent.getUri(function(url) {- urlFromIntent = url;- });+ document.addEventListener("deviceready", onDeviceReady, false);- getFileSystem();- }+ // Cordova loaded and can be used+ function onDeviceReady() {+ console.log("Devive Ready:"); // "+device.platform+" - "+device.version);- var handleStartParameters = function() {- if(urlFromIntent !== undefined && urlFromIntent.length > 0) {- console.log("Intent URL: "+urlFromIntent);- var filePath = decodeURIComponent(urlFromIntent);- TSCORE.FileOpener.openFileOnStartup(filePath);- }- };-- function getFileSystem() {- window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,- function (fileSystem) { // success get file system- fsRoot = fileSystem.root;- console.log("Filesystem Details: " + JSON.stringify(fsRoot));- handleStartParameters();- },- function (evt) { // error get file system- console.log("File System Error: " + evt.target.error.code);- }+ // Redifining the back button+ document.addEventListener("backbutton", function(e) {+ TSCORE.FileOpener.closeFile();+ $('.modal').modal('hide');+ e.preventDefault();+ }, false);++ window.plugins.webintent.getUri(function(url) {+ urlFromIntent = url;+ });++ getFileSystem();+ }++ var handleStartParameters = function() {+ if (urlFromIntent !== undefined && urlFromIntent.length > 0) {+ console.log("Intent URL: " + urlFromIntent);+ var filePath = decodeURIComponent(urlFromIntent);+ TSCORE.FileOpener.openFileOnStartup(filePath);+ }+ };++ function getFileSystem() {+ window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,+ function(fileSystem) { // success get file system+ fsRoot = fileSystem.root;+ console.log("Filesystem Details: " + JSON.stringify(fsRoot));+ handleStartParameters();+ },+ function(evt) { // error get file system+ console.log("File System Error: " + evt.target.error.code);+ }+ );+ }++ // TODO recursively calling callback not really working+ function scanDirectory(entries) {+ var i;+ for (i = 0; i < entries.length; i++) {+ if (entries[i].isFile) {+ console.log("File: " + entries[i].name);+ anotatedDirListing.push({+ "name": entries[i].name,+ "isFile": entries[i].isFile,+ "size": "", // TODO+ "lmdt": "", //+ "path": entries[i].fullPath+ });+ } else {+ var directoryReader = entries[i].createReader();+ pendingRecursions++;+ directoryReader.readEntries(+ scanDirectory,+ function(error) {+ console.log("Error reading dir entries: " + error.code);+ });+ }+ }+ pendingRecursions--;+ console.log("Pending recursions: " + pendingRecursions);+ if (pendingRecursions <= 0) {+ TSPOSTIO.createDirectoryIndex(anotatedDirListing);+ }+ }++ var anotatedDirListing;+ var pendingRecursions = 0;+ var createDirectoryIndex = function(dirPath) {+ dirPath = dirPath + "/"; // TODO make it platform independent+ dirPath = normalizePath(dirPath);+ console.log("Creating index for directory: " + dirPath);+ anotatedDirListing = [];+ pendingRecursions = 0;+ fsRoot.getDirectory(dirPath, {+ create: false,+ exclusive: false+ },+ function(dirEntry) {+ var directoryReader = dirEntry.createReader();++ // Get a list of all the entries in the directory+ pendingRecursions++;+ directoryReader.readEntries(+ scanDirectory,+ function(error) { // error get file system+ console.log("Dir List Error: " + error.code);+ });+ },+ function(error) {+ console.log("Getting dir: " + dirPath + " failed with error code: " + error.code);+ }+ );+ };++ function generateDirectoryTree(entries) {+ var tree = {};+ var i;+ for (i = 0; i < entries.length; i++) {+ if (entries[i].isFile) {+ console.log("File: " + entries[i].name);+ tree["children"].push({+ "name": entries[i].name,+ "isFile": entries[i].isFile,+ "size": "", // TODO size and lmtd+ "lmdt": "", //+ "path": entries[i].fullPath+ });+ } else {+ var directoryReader = entries[i].createReader();+ pendingCallbacks++;+ directoryReader.readEntries(+ generateDirectoryTree,+ function(error) {+ console.log("Error reading dir entries: " + error.code);+ });+ }+ }+ pendingCallbacks--;+ console.log("Pending recursions: " + pendingCallbacks);+ if (pendingCallbacks <= 0) {+ TSPOSTIO.createDirectoryTree(anotatedTree);}+ }++ var anotatedTree = undefined;+ var pendingCallbacks = 0;+ var createDirectoryTree = function(dirPath) {+ console.log("Creating directory index for: " + dirPath);+ //TSCORE.showAlertDialog("Creating directory tree is not supported on Android yet.");++ };- // TODO recursively calling callback not really working- function scanDirectory(entries) {- var i;- for (i = 0; i < entries.length; i++) {- if (entries[i].isFile) {- console.log("File: " + entries[i].name);- anotatedDirListing.push({- "name": entries[i].name,- "isFile": entries[i].isFile,- "size": "", // TODO- "lmdt": "", //- "path": entries[i].fullPath+ function normalizePath(path) {+ if (path.indexOf(fsRoot.fullPath) >= 0) {+ path = path.substring(fsRoot.fullPath.length + 1, path.length);+ }+ return path;+ }++ 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?pVer=' + cVer,+ type: 'GET'+ })+ .done(function(data) {+ TSPOSTIO.checkNewVersion(data);+ })+ .fail(function(data) {+ console.log("AJAX failed " + data);+ });+ };++ var listSubDirectories = function(dirPath) {+ console.log("Listing sub directories of: " + dirPath);+ // directory path format DCIM/Camera/ !+ dirPath = dirPath + "/"; // TODO make it platform independent+ dirPath = normalizePath(dirPath);+ console.log("Listing sub directories of : " + dirPath + " normalized.");+ TSCORE.showLoadingAnimation();++ fsRoot.getDirectory(dirPath, {+ create: false,+ exclusive: false+ },+ function(dirEntry) {+ var directoryReader = dirEntry.createReader();++ // Get a list of all the entries in the directory+ directoryReader.readEntries(+ function(entries) {+ var i;+ var anotatedDirList = [];+ for (i = 0; i < entries.length; i++) {+ if (entries[i].isDirectory) {+ anotatedDirList.push({+ "name": entries[i].name,+ "path": entries[i].fullPath});- } else {- var directoryReader = entries[i].createReader();- pendingRecursions++;- directoryReader.readEntries(- scanDirectory,- function (error) {- console.log("Error reading dir entries: " + error.code);- });+ }}- }- pendingRecursions--;- console.log("Pending recursions: " + pendingRecursions);- if(pendingRecursions <= 0) {- TSPOSTIO.createDirectoryIndex(anotatedDirListing);- }- }-- var anotatedDirListing;- var pendingRecursions = 0;- var createDirectoryIndex = function(dirPath) {- dirPath = dirPath+"/"; // TODO make it platform independent- dirPath = normalizePath(dirPath);- console.log("Creating index for directory: "+dirPath);- anotatedDirListing = [];- pendingRecursions = 0;- fsRoot.getDirectory(dirPath, {create: false, exclusive: false},- function (dirEntry) {- var directoryReader = dirEntry.createReader();-- // Get a list of all the entries in the directory- pendingRecursions++;- directoryReader.readEntries(- scanDirectory,- function (error) { // error get file system- console.log("Dir List Error: " + error.code);- }- );- },- function (error) {- console.log("Getting dir: "+dirPath+" failed with error code: " + error.code);- }- );- };-- function generateDirectoryTree(entries) {- var tree = {};- var i;- for (i = 0; i < entries.length; i++) {- if (entries[i].isFile) {- console.log("File: "+entries[i].name);- tree["children"].push({- "name": entries[i].name,- "isFile": entries[i].isFile,- "size": "", // TODO size and lmtd- "lmdt": "", //- "path": entries[i].fullPath- });- } else {- var directoryReader = entries[i].createReader();- pendingCallbacks++;- directoryReader.readEntries(- generateDirectoryTree,- function (error) {- console.log("Error reading dir entries: " + error.code);- } );- }- }- pendingCallbacks--;- console.log("Pending recursions: " + pendingCallbacks);- if(pendingCallbacks <= 0) {- TSPOSTIO.createDirectoryTree(anotatedTree);- }- }-- var anotatedTree = undefined;- var pendingCallbacks = 0;- var createDirectoryTree = function(dirPath) {- console.log("Creating directory index for: "+dirPath);- //TSCORE.showAlertDialog("Creating directory tree is not supported on Android yet.");-- };-- function normalizePath(path) {- if(path.indexOf(fsRoot.fullPath) >= 0) {- path = path.substring(fsRoot.fullPath.length+1, path.length);- }- return path;- }-- 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?pVer='+cVer,- type: 'GET'- })- .done(function(data) {- TSPOSTIO.checkNewVersion(data);- })- .fail(function(data) {- console.log("AJAX failed "+data);- })- ;- };-- var listSubDirectories = function (dirPath) {- console.log("Listing sub directories of: " + dirPath);- // directory path format DCIM/Camera/ !- dirPath = dirPath+"/"; // TODO make it platform independent- dirPath = normalizePath(dirPath);- console.log("Listing sub directories of : " + dirPath + " normalized.");- TSCORE.showLoadingAnimation();-- fsRoot.getDirectory(dirPath, {create: false, exclusive: false},- function (dirEntry) {- var directoryReader = dirEntry.createReader();-- // Get a list of all the entries in the directory- directoryReader.readEntries(- function (entries) {- var i;- var anotatedDirList = [];- for (i = 0; i < entries.length; i++) {- if(entries[i].isDirectory){- anotatedDirList.push({- "name": entries[i].name,- "path": entries[i].fullPath- });- }- }- //console.log("Dir content: " + JSON.stringify(entries));- TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);- }, function (error) { // error get file system- //TSPOSTIO.errorOpeningPath(dirPath);- console.log("Listing sub directories failed: " + error.code);- }- );- },- function (error) {- //TSPOSTIO.errorOpeningPath(dirPath);- console.log("Getting sub directories of : "+dirPath+" failed: " + error.code);- }- );- };-- var listDirectory = function (dirPath) {- TSCORE.showLoadingAnimation();-- /*window.resolveLocalFileSystemURL(dirPath, function(entry) {- console.log("--------"+entry.name);- }, function(e) {- console.log("-----"+e);- });*/-- // directory path format DCIM/Camera/ !- dirPath = dirPath+"/"; // TODO make it platform independent- dirPath = normalizePath(dirPath);-- console.log("Listing directory: " + dirPath);-- fsRoot.getDirectory(dirPath, {create: false, exclusive: false},- function (dirEntry) {- var directoryReader = dirEntry.createReader();- var anotatedDirList = [];- var pendingCallbacks = 0;- // Get a list of all the entries in the directory- directoryReader.readEntries(- function (entries) {- var i;- var normalizedPath;- for (i = 0; i < entries.length; i++) {- if(entries[i].isFile) {- pendingCallbacks++;- entries[i].file(- function(entry) {- anotatedDirList.push({- "name": entry.name,- "isFile": true,- "size": entry.size,- "lmdt": entry.lastModifiedDate,- "path": entry.fullPath- });- pendingCallbacks--;- console.log("File: "+entry.name+" Size: "+entry.size+ " i:"+i+" Callb: "+pendingCallbacks);- if(pendingCallbacks === 0 && i === entries.length) {- TSPOSTIO.listDirectory(anotatedDirList);- }- }, function (error) { // error get file system- console.log("Getting file meta error: " + error.code);- }- );- } else {- normalizedPath = normalizePath(entries[i].fullPath);- anotatedDirList.push({- "name": entries[i].name,- "isFile": false,- "size": "",- "lmdt": "",- "path": normalizedPath- });- console.log("Dir: "+entries[i].name+ " I:"+i+" Callb: "+pendingCallbacks);- if((pendingCallbacks === 0) && ((i+1) == entries.length)) {- TSPOSTIO.listDirectory(anotatedDirList);- }- }-- }- if(pendingCallbacks === 0) {- TSPOSTIO.listDirectory(anotatedDirList);- }- //console.log("Dir content: " + JSON.stringify(entries));-- }, function (error) { // error get file system- TSPOSTIO.errorOpeningPath(dirPath);- console.log("Dir List Error: " + error.code);- }- );- },- function (error) {- TSPOSTIO.errorOpeningPath(dirPath);- console.log("Getting dir: "+dirPath+" failed with error code: " + error.code);- }- );- };-- var deleteElement = function(filePath) {- console.log("Deleting: "+filePath);- TSCORE.showLoadingAnimation();-- var path = normalizePath(filePath);-- fsRoot.getFile(path, {create: false, exclusive: false},- function(entry) {- entry.remove(- function() {- console.log("file deleted: "+path);- TSPOSTIO.deleteElement(filePath);- },- function() {- console.log("error deleting: "+filePath);- }- );- },- function() {- console.log("error getting file");- }+ //console.log("Dir content: " + JSON.stringify(entries));+ TSPOSTIO.listSubDirectories(anotatedDirList, dirPath);+ },+ function(error) { // error get file system+ //TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Listing sub directories failed: " + error.code);+ });- };-- var deleteDirectory = function(dirPath) {- console.log("Deleting directory: "+dirPath);- TSCORE.showLoadingAnimation();-- var path = normalizePath(dirPath);-- fsRoot.getDirectory(path, {create: false, exclusive: false},- function(entry) {- entry.remove(- function() {- console.log("file deleted: "+path);- TSPOSTIO.deleteDirectory(dirPath);- },- function() {- TSPOSTIO.deleteDirectoryFailed(path);- console.log("error deleting dir: "+dirPath);+ },+ function(error) {+ //TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Getting sub directories of : " + dirPath + " failed: " + error.code);+ }+ );+ };++ var listDirectory = function(dirPath) {+ TSCORE.showLoadingAnimation();++ /*window.resolveLocalFileSystemURL(dirPath, function(entry) {+ console.log("--------"+entry.name);+ }, function(e) {+ console.log("-----"+e);+ });*/++ // directory path format DCIM/Camera/ !+ dirPath = dirPath + "/"; // TODO make it platform independent+ dirPath = normalizePath(dirPath);++ console.log("Listing directory: " + dirPath);++ fsRoot.getDirectory(dirPath, {+ create: false,+ exclusive: false+ },+ function(dirEntry) {+ var directoryReader = dirEntry.createReader();+ var anotatedDirList = [];+ var pendingCallbacks = 0;+ // Get a list of all the entries in the directory+ directoryReader.readEntries(+ function(entries) {+ var i;+ var normalizedPath;+ for (i = 0; i < entries.length; i++) {+ if (entries[i].isFile) {+ pendingCallbacks++;+ entries[i].file(+ function(entry) {+ anotatedDirList.push({+ "name": entry.name,+ "isFile": true,+ "size": entry.size,+ "lmdt": entry.lastModifiedDate,+ "path": entry.fullPath+ });+ pendingCallbacks--;+ console.log("File: " + entry.name + " Size: " + entry.size + " i:" + i + " Callb: " + pendingCallbacks);+ if (pendingCallbacks === 0 && i === entries.length) {+ TSPOSTIO.listDirectory(anotatedDirList);}+ },+ function(error) { // error get file system+ console.log("Getting file meta error: " + error.code);+ });- },- function() {- console.log("error getting directory");+ } else {+ normalizedPath = normalizePath(entries[i].fullPath);+ anotatedDirList.push({+ "name": entries[i].name,+ "isFile": false,+ "size": "",+ "lmdt": "",+ "path": normalizedPath+ });+ console.log("Dir: " + entries[i].name + " I:" + i + " Callb: " + pendingCallbacks);+ if ((pendingCallbacks === 0) && ((i + 1) == entries.length)) {+ TSPOSTIO.listDirectory(anotatedDirList);+ }+ }++ }+ if (pendingCallbacks === 0) {+ TSPOSTIO.listDirectory(anotatedDirList);}+ //console.log("Dir content: " + JSON.stringify(entries));++ },+ function(error) { // error get file system+ TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Dir List Error: " + error.code);+ });- };-- var loadTextFile = function(filePath, isPreview) {- console.log("Loading file: "+filePath);- TSCORE.showLoadingAnimation();-- filePath = normalizePath(filePath);- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- entry.file(- function(file) {- var reader = new FileReader();- reader.onloadend = function(evt) {- TSPOSTIO.loadTextFile(evt.target.result);- };- if(isPreview) {- reader.readAsText(file.slice(0,10000));- } else {- reader.readAsText(file);- }- },- function() {- console.log("error getting file: "+filePath);- }- );- },- function() {- console.log("Error getting file entry: "+filePath);- }- );- };-- var saveTextFile = function(filePath,content) {- console.log("Saving file: "+filePath);- TSCORE.showLoadingAnimation();-- // Handling the UTF8 support for text files- var UTF8_BOM = "\ufeff";-- if(content.indexOf(UTF8_BOM) === 0) {- console.log("Content beging with a UTF8 bom");- } else {- content = UTF8_BOM+content;- }+ },+ function(error) {+ TSPOSTIO.errorOpeningPath(dirPath);+ console.log("Getting dir: " + dirPath + " failed with error code: " + error.code);+ }+ );+ };++ var deleteElement = function(filePath) {+ console.log("Deleting: " + filePath);+ TSCORE.showLoadingAnimation();++ var path = normalizePath(filePath);++ fsRoot.getFile(path, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.remove(+ function() {+ console.log("file deleted: " + path);+ TSPOSTIO.deleteElement(filePath);+ },+ function() {+ console.log("error deleting: " + filePath);+ }+ );+ },+ function() {+ console.log("error getting file");+ }+ );+ };++ var deleteDirectory = function(dirPath) {+ console.log("Deleting directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ var path = normalizePath(dirPath);++ fsRoot.getDirectory(path, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.remove(+ function() {+ console.log("file deleted: " + path);+ TSPOSTIO.deleteDirectory(dirPath);+ },+ function() {+ TSPOSTIO.deleteDirectoryFailed(path);+ console.log("error deleting dir: " + dirPath);+ }+ );+ },+ function() {+ console.log("error getting directory");+ }+ );+ };++ var loadTextFile = function(filePath, isPreview) {+ console.log("Loading file: " + filePath);+ TSCORE.showLoadingAnimation();++ filePath = normalizePath(filePath);+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.file(+ function(file) {+ var reader = new FileReader();+ reader.onloadend = function(evt) {+ TSPOSTIO.loadTextFile(evt.target.result);+ };+ if (isPreview) {+ reader.readAsText(file.slice(0, 10000));+ } else {+ reader.readAsText(file);+ }+ },+ function() {+ console.log("error getting file: " + filePath);+ }+ );+ },+ function() {+ console.log("Error getting file entry: " + filePath);+ }+ );+ };++ var saveTextFile = function(filePath, content) {+ console.log("Saving file: " + filePath);+ TSCORE.showLoadingAnimation();++ // Handling the UTF8 support for text files+ var UTF8_BOM = "\ufeff";++ if (content.indexOf(UTF8_BOM) === 0) {+ console.log("Content beging with a UTF8 bom");+ } else {+ content = UTF8_BOM + content;+ }- var isFileNew = true;+ var isFileNew = true;- filePath = normalizePath(filePath);+ filePath = normalizePath(filePath);- // Checks if the file already exists- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- if(entry.isFile) {- isFileNew = false;- }- saveFile(isFileNew);+ // Checks if the file already exists+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ if (entry.isFile) {+ isFileNew = false;+ }+ saveFile(isFileNew);+ },+ function() {+ saveFile(isFileNew)+ }+ );++ function saveFile(isFileNew) {+ fsRoot.getFile(filePath, {+ create: true,+ exclusive: false+ },+ function(entry) {+ entry.createWriter(+ function(writer) {+ writer.onwriteend = function(evt) {+ TSPOSTIO.saveTextFile(fsRoot.fullPath + "/" + filePath, isFileNew);+ };+ writer.write(content);},function() {- saveFile(isFileNew)+ console.log("error creating writter file: " + filePath);}- );-- function saveFile(isFileNew) {- fsRoot.getFile(filePath, {create: true, exclusive: false},- function(entry) {- entry.createWriter(- function(writer) {- writer.onwriteend = function(evt) {- TSPOSTIO.saveTextFile(fsRoot.fullPath+"/"+filePath, isFileNew);- };- writer.write(content);- },- function() {- console.log("error creating writter file: "+filePath);- }- );- },- function() {- console.log("Error getting file entry: "+filePath);- }- );+ );+ },+ function() {+ console.log("Error getting file entry: " + filePath);}- };-- var saveBinaryFile = function(filePath,content) {- console.log("Saving file: "+filePath);- TSCORE.showLoadingAnimation();+ );+ }+ };- var isFileNew = true;+ var saveBinaryFile = function(filePath, content) {+ console.log("Saving file: " + filePath);+ TSCORE.showLoadingAnimation();- filePath = normalizePath(filePath);+ var isFileNew = true;- // Checks if the file already exists- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- if(entry.isFile) {- isFileNew = false;- }- },- function() {}- );+ filePath = normalizePath(filePath);- if(isFileNew) {- fsRoot.getFile(filePath, {create: true, exclusive: false},- function(entry) {- entry.createWriter(- function(writer) {- writer.onwriteend = function(evt) {- TSPOSTIO.saveBinaryFile(fsRoot.fullPath+"/"+filePath);- };- var dataView = new Int8Array(content);- writer.write(dataView.buffer);- },- function() {- console.log("error creating writter file: "+filePath);- }- );- },- function() {- console.log("Error getting file entry: "+filePath);- }- );- } else {- TSCORE.showAlertDialog("File Already Exists.");+ // Checks if the file already exists+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ if (entry.isFile) {+ isFileNew = false;}- };-- var createDirectory = function(dirPath) {- console.log("Creating directory: "+dirPath);- TSCORE.showLoadingAnimation();-- dirPath = normalizePath(dirPath);-- fsRoot.getDirectory(dirPath, {create: true, exclusive: false},- function (dirEntry) {- TSPOSTIO.createDirectory(dirPath);- },- function (error) {- console.log("Creating directory failed: "+dirPath+" failed with error code: " + error.code);- }- );- };-- var copyFile = function(filePath, newFilePath) {- filePath = normalizePath(filePath);- var newFileName = newFilePath.substring(newFilePath.lastIndexOf('/')+1);- var newFileParentPath = normalizePath(newFilePath.substring(0, newFilePath.lastIndexOf('/')));- // TODO check if the newFilePath exist or causes issues by copying- fsRoot.getDirectory(newFileParentPath, {create: false, exclusive: false},- function (parentDirEntry) {- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- entry.copyTo(- parentDirEntry,- newFileName,- function() {- console.log("File copy: target: "+newFilePath+" source: "+entry.fullPath);- TSPOSTIO.copyFile(entry.fullPath, newFilePath);- },- function() {- console.log("error copying: "+filePath);- }- );- },- function() {- console.log("Error getting file: "+filePath);- }- );+ },+ function() {}+ );++ if (isFileNew) {+ fsRoot.getFile(filePath, {+ create: true,+ exclusive: false+ },+ function(entry) {+ entry.createWriter(+ function(writer) {+ writer.onwriteend = function(evt) {+ TSPOSTIO.saveBinaryFile(fsRoot.fullPath + "/" + filePath);+ };+ var dataView = new Int8Array(content);+ writer.write(dataView.buffer);},- function (error) {- console.log("Getting dir: "+newFileParentPath+" failed with error code: " + error.code);+ function() {+ console.log("error creating writter file: " + filePath);}+ );+ },+ function() {+ console.log("Error getting file entry: " + filePath);+ }+ );+ } else {+ TSCORE.showAlertDialog("File Already Exists.");+ }+ };++ var createDirectory = function(dirPath) {+ console.log("Creating directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ dirPath = normalizePath(dirPath);++ fsRoot.getDirectory(dirPath, {+ create: true,+ exclusive: false+ },+ function(dirEntry) {+ TSPOSTIO.createDirectory(dirPath);+ },+ function(error) {+ console.log("Creating directory failed: " + dirPath + " failed with error code: " + error.code);+ }+ );+ };++ var copyFile = function(filePath, newFilePath) {+ filePath = normalizePath(filePath);+ var newFileName = newFilePath.substring(newFilePath.lastIndexOf('/') + 1);+ var newFileParentPath = normalizePath(newFilePath.substring(0, newFilePath.lastIndexOf('/')));+ // TODO check if the newFilePath exist or causes issues by copying+ fsRoot.getDirectory(newFileParentPath, {+ create: false,+ exclusive: false+ },+ function(parentDirEntry) {+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.copyTo(+ parentDirEntry,+ newFileName,+ function() {+ console.log("File copy: target: " + newFilePath + " source: " + entry.fullPath);+ TSPOSTIO.copyFile(entry.fullPath, newFilePath);+ },+ function() {+ console.log("error copying: " + filePath);+ }+ );+ },+ function() {+ console.log("Error getting file: " + filePath);+ });- };-- var renameFile = function(filePath, newFilePath) {- filePath = normalizePath(filePath);- var newFileName = newFilePath.substring(newFilePath.lastIndexOf('/')+1);- var newFileParentPath = normalizePath(newFilePath.substring(0, newFilePath.lastIndexOf('/')));- // TODO check if the newFilePath exist or causes issues by renaming- fsRoot.getDirectory(newFileParentPath, {create: false, exclusive: false},- function (parentDirEntry) {- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- entry.moveTo(- parentDirEntry,- newFileName,- function() {- console.log("File renamed to: "+newFilePath+" Old name: "+entry.fullPath);- TSPOSTIO.renameFile(entry.fullPath, newFilePath);- },- function() {- console.log("error renaming: "+filePath);- }- );- },- function() {- console.log("Error getting file: "+filePath);- }- );- },- function (error) {- console.log("Getting dir: "+newFileParentPath+" failed with error code: " + error.code);- }+ },+ function(error) {+ console.log("Getting dir: " + newFileParentPath + " failed with error code: " + error.code);+ }+ );+ };++ var renameFile = function(filePath, newFilePath) {+ filePath = normalizePath(filePath);+ var newFileName = newFilePath.substring(newFilePath.lastIndexOf('/') + 1);+ var newFileParentPath = normalizePath(newFilePath.substring(0, newFilePath.lastIndexOf('/')));+ // TODO check if the newFilePath exist or causes issues by renaming+ fsRoot.getDirectory(newFileParentPath, {+ create: false,+ exclusive: false+ },+ function(parentDirEntry) {+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.moveTo(+ parentDirEntry,+ newFileName,+ function() {+ console.log("File renamed to: " + newFilePath + " Old name: " + entry.fullPath);+ TSPOSTIO.renameFile(entry.fullPath, newFilePath);+ },+ function() {+ console.log("error renaming: " + filePath);+ }+ );+ },+ function() {+ console.log("Error getting file: " + filePath);+ });- };-- var renameDirectory = function(dirPath, newDirName) {- var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;- TSCORE.showLoadingAnimation();-- dirPath = normalizePath(dirPath);- var newDirParentPath = normalizePath(newDirPath.substring(0, newDirPath.lastIndexOf('/')));- // TODO check if the newFilePath exist or cause issues by renaming- fsRoot.getDirectory(newDirParentPath, {create: false, exclusive: false},- function (parentDirEntry) {- fsRoot.getDirectory(dirPath, {create: false, exclusive: false},- function(entry) {- entry.moveTo(- parentDirEntry,- newDirName,- function() {- console.log("Directory renamed to: "+newDirPath+" Old name: "+entry.fullPath);- TSPOSTIO.renameDirectory(entry.fullPath, newDirPath);- },- function() {- console.log("error renaming: "+dirPath);- }- );- },- function() {- console.log("Error getting directory: "+dirPath);- }- );- },- function (error) {- console.log("Getting dir: "+newDirParentPath+" failed with error code: " + error.code);- }+ },+ function(error) {+ console.log("Getting dir: " + newFileParentPath + " failed with error code: " + error.code);+ }+ );+ };++ var renameDirectory = function(dirPath, newDirName) {+ var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + newDirName;+ TSCORE.showLoadingAnimation();++ dirPath = normalizePath(dirPath);+ var newDirParentPath = normalizePath(newDirPath.substring(0, newDirPath.lastIndexOf('/')));+ // TODO check if the newFilePath exist or cause issues by renaming+ fsRoot.getDirectory(newDirParentPath, {+ create: false,+ exclusive: false+ },+ function(parentDirEntry) {+ fsRoot.getDirectory(dirPath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ entry.moveTo(+ parentDirEntry,+ newDirName,+ function() {+ console.log("Directory renamed to: " + newDirPath + " Old name: " + entry.fullPath);+ TSPOSTIO.renameDirectory(entry.fullPath, newDirPath);+ },+ function() {+ console.log("error renaming: " + dirPath);+ }+ );+ },+ function() {+ console.log("Error getting directory: " + dirPath);+ });- };-- var selectDirectory = function() {- console.log("Open select directory dialog.");- //file:///storage/emulated/0/DCIM/Camera/- TSCORE.showDirectoryBrowserDialog(fsRoot.fullPath);- };-- var selectFile = function() {- console.log("Operation selectFile not supported.");- };-- var checkAccessFileURLAllowed = function() {- console.log("checkAccessFileURLAllowed function not relevant for Android..");- };-- var openDirectory = function(dirPath) {- TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openContainingDirectoryAlert"));- //dirPath = normalizePath(dirPath);- //window.open(dirPath,"_blank", "location=no");- };-- var openFile = function(filePath) {- console.log("Opening natively: "+filePath);- window.plugins.fileOpener.open(filePath);- //window.open(filePath,"_blank", "location=no");- };-- var sendFile = function(filePath) {- console.log("Sending file: "+filePath);- window.plugins.fileOpener.send(filePath);- };-- var openExtensionsDirectory = function() {- TSCORE.showAlertDialog("Open extensions directory functionality not supported on Android!");- };-- var getFileProperties = function(filePath) {- filePath = normalizePath(filePath);- var fileProperties = {};- fsRoot.getFile(filePath, {create: false, exclusive: false},- function(entry) {- if(entry.isFile) {- entry.file(- function(file) {- fileProperties.path = entry.fullPath;- fileProperties.size = file.size;- fileProperties.lmdt = file.lastModifiedDate;- fileProperties.mimetype = file.type;- TSPOSTIO.getFileProperties(fileProperties);- },- function() {- console.log("Error retrieving file properties of "+filePath);- }- );- } else {- console.log("Error getting file properties. "+filePath+" is directory");- }+ },+ function(error) {+ console.log("Getting dir: " + newDirParentPath + " failed with error code: " + error.code);+ }+ );+ };++ var selectDirectory = function() {+ console.log("Open select directory dialog.");+ //file:///storage/emulated/0/DCIM/Camera/+ TSCORE.showDirectoryBrowserDialog(fsRoot.fullPath);+ };++ var selectFile = function() {+ console.log("Operation selectFile not supported.");+ };++ var checkAccessFileURLAllowed = function() {+ console.log("checkAccessFileURLAllowed function not relevant for Android..");+ };++ var openDirectory = function(dirPath) {+ TSCORE.showAlertDialog($.i18n.t("ns.dialogs:openContainingDirectoryAlert"));+ //dirPath = normalizePath(dirPath);+ //window.open(dirPath,"_blank", "location=no");+ };++ var openFile = function(filePath) {+ console.log("Opening natively: " + filePath);+ window.plugins.fileOpener.open(filePath);+ //window.open(filePath,"_blank", "location=no");+ };++ var sendFile = function(filePath) {+ console.log("Sending file: " + filePath);+ window.plugins.fileOpener.send(filePath);+ };++ var openExtensionsDirectory = function() {+ TSCORE.showAlertDialog("Open extensions directory functionality not supported on Android!");+ };++ var getFileProperties = function(filePath) {+ filePath = normalizePath(filePath);+ var fileProperties = {};+ fsRoot.getFile(filePath, {+ create: false,+ exclusive: false+ },+ function(entry) {+ if (entry.isFile) {+ entry.file(+ function(file) {+ fileProperties.path = entry.fullPath;+ fileProperties.size = file.size;+ fileProperties.lmdt = file.lastModifiedDate;+ fileProperties.mimetype = file.type;+ TSPOSTIO.getFileProperties(fileProperties);},function() {- console.log("error getting file");- }- );- };-- // Bring the TagSpaces window on top of the windows- var focusWindow = function() {- console.log("Focusing window is not implemented yet.");- };-- exports.focusWindow = focusWindow;- exports.createDirectory = createDirectory;- exports.copyFile = copyFile;- exports.renameFile = renameFile;- exports.renameDirectory = renameDirectory;- exports.loadTextFile = loadTextFile;- exports.saveTextFile = saveTextFile;- exports.saveBinaryFile = saveBinaryFile;- exports.listDirectory = listDirectory;- exports.listSubDirectories = listSubDirectories;- exports.deleteElement = deleteElement;- exports.deleteDirectory = deleteDirectory;- exports.createDirectoryIndex = createDirectoryIndex;- exports.createDirectoryTree = createDirectoryTree;- exports.selectDirectory = selectDirectory;- exports.openDirectory = openDirectory;- exports.openFile = openFile;- exports.sendFile = sendFile;- exports.selectFile = selectFile;- exports.openExtensionsDirectory = openExtensionsDirectory;- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;- exports.checkNewVersion = checkNewVersion;- exports.getFileProperties = getFileProperties;- exports.handleStartParameters = handleStartParameters;--});\ No newline at end of file+ console.log("Error retrieving file properties of " + filePath);+ }+ );+ } else {+ console.log("Error getting file properties. " + filePath + " is directory");+ }+ },+ function() {+ console.log("error getting file");+ }+ );+ };++ // Bring the TagSpaces window on top of the windows+ var focusWindow = function() {+ console.log("Focusing window is not implemented yet.");+ };++ exports.focusWindow = focusWindow;+ exports.createDirectory = createDirectory;+ exports.copyFile = copyFile;+ exports.renameFile = renameFile;+ exports.renameDirectory = renameDirectory;+ exports.loadTextFile = loadTextFile;+ exports.saveTextFile = saveTextFile;+ exports.saveBinaryFile = saveBinaryFile;+ exports.listDirectory = listDirectory;+ exports.listSubDirectories = listSubDirectories;+ exports.deleteElement = deleteElement;+ exports.deleteDirectory = deleteDirectory;+ exports.createDirectoryIndex = createDirectoryIndex;+ exports.createDirectoryTree = createDirectoryTree;+ exports.selectDirectory = selectDirectory;+ exports.openDirectory = openDirectory;+ exports.openFile = openFile;+ exports.sendFile = sendFile;+ exports.selectFile = selectFile;+ exports.openExtensionsDirectory = openExtensionsDirectory;+ exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;+ exports.checkNewVersion = checkNewVersion;+ exports.getFileProperties = getFileProperties;+ exports.handleStartParameters = handleStartParameters;++});diff --git a/data/web/dropbox.api.js b/data/web/dropbox.api.jsindex cafb0135e..6314d55c3 100644--- a/data/web/dropbox.api.js+++ b/data/web/dropbox.api.js@@ -1,240 +1,241 @@/* Copyright (c) 2012-2014 The TagSpaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that+ * Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. */-define(function (require, exports, module) {- "use strict";-- console.log("Loading ioapi.dropbox.js..");--/* stat format-- file-{"_json":{"revision":9,"rev":"90068aeb1","thumb_exists":false,"bytes":1268,"modified":"Sat, 30 Jan 2010 12:32:43 +0000","client_mtime":"Sat, 30 Jan 2010 12:32:43 +0000","path":"/Getting Started.rtf","is_dir":false,"icon":"page_white_text","root":"dropbox","mime_type":"application/rtf","size":"1.2 KB"},"path":"/Getting Started.rtf","name":"Getting Started.rtf","isFolder":false,"isFile":true,"isRemoved":false,"typeIcon":"page_white_text","modifiedAt":"2010-01-30T12:32:43.000Z","clientModifiedAt":"2010-01-30T12:32:43.000Z","inAppFolder":false,"size":1268,"humanSize":"1.2 KB","hasThumbnail":false,"versionTag":"90068aeb1","contentHash":null,"mimeType":"application/rtf"}-- directory-{"_json":{"revision":354,"rev":"1620068aeb1","thumb_exists":false,"bytes":0,"modified":"Tue, 19 Nov 2013 16:32:05 +0000","path":"/23","is_dir":true,"icon":"folder","root":"dropbox","size":"0 bytes"},"path":"/23","name":"23","isFolder":true,"isFile":false,"isRemoved":false,"typeIcon":"folder","modifiedAt":"2013-11-19T16:32:05.000Z","clientModifiedAt":null,"inAppFolder":false,"size":0,"humanSize":"0 bytes","hasThumbnail":false,"versionTag":"1620068aeb1","contentHash":null,"mimeType":"inode/directory"}-*/-- var fsRoot;-- var TSCORE = require("tscore");- var TSPOSTIO = require("tspostioapi");- require('dropbox');-- var init = function() {- if (!fsRoot) {- if(window.location.hash.length < 1) {- fsRoot = new Dropbox.Client({- key: "t174lonmydtl9mk",- sandbox: false- });- fsRoot.authDriver(new Dropbox.AuthDriver.ChromeExtension({receiverPath: "index.html", rememberUser: true}));- //fsRoot.authDriver(new Dropbox.AuthDriver.Popup({rememberUser: true}));- fsRoot.authenticate(function (err, fsRoot) {- if (err) {- console.log("Auth Error: " + err);- }- });- } else {- // #access_token=p00H94aHbVkAAAAAAAAAAbITvnyzGGMSw5EUYfbpH9V5lSeiK7QmoEIbyvn6uYMw&token_type=bearer&uid=4360164&state=oas_ho7adxkp_0.pd8q6hqf1zs8xgvi- var locationHash = location.hash.substr(1);- var dboxToken = locationHash.substr(locationHash.indexOf('access_token=')).split('&')[0].split('=')[1];- //console.log("Token: "+dboxToken);- fsRoot = new Dropbox.Client({- key: "t174lonmydtl9mk",- sandbox: false,- token: dboxToken- });- }- }- };--- // TODO recursivly calling callback not working- function scanDirectory(dirPath, index) {-- }-- // TODO recursivly calling callback not working- function generateDirectoryTree(dirPath) {-- }-- 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?pVer='+cVer,- type: 'GET'- })- .done(function(data) {- TSPOSTIO.checkNewVersion(data);- })- .fail(function(data) {- console.log("AJAX failed "+data);- })- ;- };-- var listDirectory = function (dirPath) {- TSCORE.showLoadingAnimation();-- dirPath = dirPath+"/"; // TODO make it platform independent-- console.log("Listing directory: " + dirPath);-- fsRoot.readdir(dirPath, function (err, contents, dirStat, stats) {- var i;-- if (!err) {- var anotatedDirList = [];- for (i = 0; i < stats.length; i++) {- console.log("File: "+stats[i].name);- anotatedDirList.push({- "name": stats[i].name,- "isFile": stats[i].isFile,- "size": stats[i].size,- "lmdt": stats[i].modifiedAt,- "path": stats[i].path- });- }- //console.log("Dir content: " + JSON.stringify(entries));- TSPOSTIO.listDirectory(anotatedDirList);- } else {- TSPOSTIO.errorOpeningPath();- console.log("Dir List Error: " + err);- }+define(function(require, exports, module) {+ "use strict";++ console.log("Loading ioapi.dropbox.js..");++ /* stat format+ - file+ {"_json":{"revision":9,"rev":"90068aeb1","thumb_exists":false,"bytes":1268,"modified":"Sat, 30 Jan 2010 12:32:43 +0000","client_mtime":"Sat, 30 Jan 2010 12:32:43 +0000","path":"/Getting Started.rtf","is_dir":false,"icon":"page_white_text","root":"dropbox","mime_type":"application/rtf","size":"1.2 KB"},"path":"/Getting Started.rtf","name":"Getting Started.rtf","isFolder":false,"isFile":true,"isRemoved":false,"typeIcon":"page_white_text","modifiedAt":"2010-01-30T12:32:43.000Z","clientModifiedAt":"2010-01-30T12:32:43.000Z","inAppFolder":false,"size":1268,"humanSize":"1.2 KB","hasThumbnail":false,"versionTag":"90068aeb1","contentHash":null,"mimeType":"application/rtf"}+ - directory+ {"_json":{"revision":354,"rev":"1620068aeb1","thumb_exists":false,"bytes":0,"modified":"Tue, 19 Nov 2013 16:32:05 +0000","path":"/23","is_dir":true,"icon":"folder","root":"dropbox","size":"0 bytes"},"path":"/23","name":"23","isFolder":true,"isFile":false,"isRemoved":false,"typeIcon":"folder","modifiedAt":"2013-11-19T16:32:05.000Z","clientModifiedAt":null,"inAppFolder":false,"size":0,"humanSize":"0 bytes","hasThumbnail":false,"versionTag":"1620068aeb1","contentHash":null,"mimeType":"inode/directory"}+ */++ var fsRoot;++ var TSCORE = require("tscore");+ var TSPOSTIO = require("tspostioapi");+ require('dropbox');++ var init = function() {+ if (!fsRoot) {+ if (window.location.hash.length < 1) {+ fsRoot = new Dropbox.Client({+ key: "t174lonmydtl9mk",+ sandbox: false+ });+ fsRoot.authDriver(new Dropbox.AuthDriver.ChromeExtension({+ receiverPath: "index.html",+ rememberUser: true+ }));+ //fsRoot.authDriver(new Dropbox.AuthDriver.Popup({rememberUser: true}));+ fsRoot.authenticate(function(err, fsRoot) {+ if (err) {+ console.log("Auth Error: " + err);+ }});- };-- var deleteElement = function(path) {- console.log("Deleting: "+path);- TSCORE.showLoadingAnimation();-- fsRoot.unlink(path, function (err, stat) {- if(err) {- console.log("Error deleting path: "+err);- } else {- console.log("Element deleted: "+stat.path);- TSPOSTIO.deleteElement(path);- }- });- };-- var createDirectoryIndex = function(dirPath) {- console.log("Creating index for directory: "+dirPath);- TSCORE.showLoadingAnimation();-- TSCORE.showAlertDialog("Creating directory index is not supported on Android yet.");-/* var directoryIndex = [];- directoryIndex = scanDirectory(dirPath, directoryIndex);- console.log(JSON.stringify(directoryIndex));- TSPOSTIO.createDirectoryIndex(directoryIndex); */- };-- var createDirectoryTree = function(dirPath) {- console.log("Creating directory index for: "+dirPath);- TSCORE.showLoadingAnimation();-- TSCORE.showAlertDialog("Creating directory tree is not supported on Android yet.");-/* var directoyTree = generateDirectoryTree(dirPath);- //console.log(JSON.stringify(directoyTree));- TSPOSTIO.createDirectoryTree(directoyTree);*/- };-- var loadTextFile = function(filePath) {- console.log("Loading file: "+filePath);- TSCORE.showLoadingAnimation();-- fsRoot.readFile(filePath, function (err, data, stat) {- if(err) {- console.log("Error loading file: "+err);- } else {- TSPOSTIO.loadTextFile(data);- }- });- };-- var saveTextFile = function(filePath,content) {- console.log("Saving file: "+filePath);- TSCORE.showLoadingAnimation();-- fsRoot.writeFile(filePath, content, function (err, stat) {- if(err) {- console.log("Error creating/saving file: "+err);- } else {- TSPOSTIO.saveTextFile(stat.path);- }- });- };-- var createDirectory = function(dirPath) {- console.log("Creating directory: "+dirPath);- TSCORE.showLoadingAnimation();-- fsRoot.mkdir(dirPath, function (err, stat) {- if(err) {- console.log("Error creating directory: "+err);- } else {- console.log("Directory created: "+stat.path);- TSPOSTIO.createDirectory(dirPath);- }- });- };-- var renameFile = function(filePath, newFilePath) {- console.log("Renaming file from: "+filePath+" to: "+newFilePath);- TSCORE.showLoadingAnimation();-- fsRoot.move(filePath, newFilePath, function (err, stat) {- if(err) {- console.log("Error renaming: "+err);- } else {- console.log("File renamed to: "+stat.path);- TSPOSTIO.renameFile(filePath, stat.path);- }+ } else {+ // #access_token=p00H94aHbVkAAAAAAAAAAbITvnyzGGMSw5EUYfbpH9V5lSeiK7QmoEIbyvn6uYMw&token_type=bearer&uid=4360164&state=oas_ho7adxkp_0.pd8q6hqf1zs8xgvi+ var locationHash = location.hash.substr(1);+ var dboxToken = locationHash.substr(locationHash.indexOf('access_token=')).split('&')[0].split('=')[1];+ //console.log("Token: "+dboxToken);+ fsRoot = new Dropbox.Client({+ key: "t174lonmydtl9mk",+ sandbox: false,+ token: dboxToken});- };-- var selectDirectory = function() {- console.log("Operation selectDirectory not supported in the Dropbox mode yet!");- TSCORE.showAlertDialog("Selecting directory not supported in the Dropbox mode yet, please type the desired directory path manually in textbox!");- };-- var selectFile = function() {- console.log("Operation selectFile not supported in the Dropbox mode!");- };-- var checkAccessFileURLAllowed = function() {- console.log("checkAccessFileURLAllowed function not relevant in the Dropbox mode!");- };-- var openDirectory = function(dirPath) {- TSCORE.showAlertDialog("Select file functionality not supported in the Dropbox mode! "+dirPath);- };-- var openExtensionsDirectory = function() {- TSCORE.showAlertDialog("Open extensions directory functionality not supported in the Dropbox mode!");- };-- var getFileProperties = function(filePath) {- console.log("getFileProperties not implemented for dropbox "+filePath);- };-- exports.init = init;-- exports.createDirectory = createDirectory;- exports.renameFile = renameFile;- exports.loadTextFile = loadTextFile;- exports.saveTextFile = saveTextFile;- exports.listDirectory = listDirectory;- exports.deleteElement = deleteElement;- exports.createDirectoryIndex = createDirectoryIndex;- exports.createDirectoryTree = createDirectoryTree;- exports.selectDirectory = selectDirectory;- exports.openDirectory = openDirectory;- exports.selectFile = selectFile;- exports.openExtensionsDirectory = openExtensionsDirectory;- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;- exports.checkNewVersion = checkNewVersion;- exports.getFileProperties = getFileProperties;--});\ No newline at end of file+ }+ }+ };++ // TODO recursivly calling callback not working+ function scanDirectory(dirPath, index) {++ }++ // TODO recursivly calling callback not working+ function generateDirectoryTree(dirPath) {++ }++ 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?pVer=' + cVer,+ type: 'GET'+ })+ .done(function(data) {+ TSPOSTIO.checkNewVersion(data);+ })+ .fail(function(data) {+ console.log("AJAX failed " + data);+ });+ };++ var listDirectory = function(dirPath) {+ TSCORE.showLoadingAnimation();++ dirPath = dirPath + "/"; // TODO make it platform independent++ console.log("Listing directory: " + dirPath);++ fsRoot.readdir(dirPath, function(err, contents, dirStat, stats) {+ var i;++ if (!err) {+ var anotatedDirList = [];+ for (i = 0; i < stats.length; i++) {+ console.log("File: " + stats[i].name);+ anotatedDirList.push({+ "name": stats[i].name,+ "isFile": stats[i].isFile,+ "size": stats[i].size,+ "lmdt": stats[i].modifiedAt,+ "path": stats[i].path+ });+ }+ //console.log("Dir content: " + JSON.stringify(entries));+ TSPOSTIO.listDirectory(anotatedDirList);+ } else {+ TSPOSTIO.errorOpeningPath();+ console.log("Dir List Error: " + err);+ }+ });+ };++ var deleteElement = function(path) {+ console.log("Deleting: " + path);+ TSCORE.showLoadingAnimation();++ fsRoot.unlink(path, function(err, stat) {+ if (err) {+ console.log("Error deleting path: " + err);+ } else {+ console.log("Element deleted: " + stat.path);+ TSPOSTIO.deleteElement(path);+ }+ });+ };++ var createDirectoryIndex = function(dirPath) {+ console.log("Creating index for directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ TSCORE.showAlertDialog("Creating directory index is not supported on Android yet.");+ /* var directoryIndex = [];+ directoryIndex = scanDirectory(dirPath, directoryIndex);+ console.log(JSON.stringify(directoryIndex));+ TSPOSTIO.createDirectoryIndex(directoryIndex); */+ };++ var createDirectoryTree = function(dirPath) {+ console.log("Creating directory index for: " + dirPath);+ TSCORE.showLoadingAnimation();++ TSCORE.showAlertDialog("Creating directory tree is not supported on Android yet.");+ /* var directoyTree = generateDirectoryTree(dirPath);+ //console.log(JSON.stringify(directoyTree));+ TSPOSTIO.createDirectoryTree(directoyTree);*/+ };++ var loadTextFile = function(filePath) {+ console.log("Loading file: " + filePath);+ TSCORE.showLoadingAnimation();++ fsRoot.readFile(filePath, function(err, data, stat) {+ if (err) {+ console.log("Error loading file: " + err);+ } else {+ TSPOSTIO.loadTextFile(data);+ }+ });+ };++ var saveTextFile = function(filePath, content) {+ console.log("Saving file: " + filePath);+ TSCORE.showLoadingAnimation();++ fsRoot.writeFile(filePath, content, function(err, stat) {+ if (err) {+ console.log("Error creating/saving file: " + err);+ } else {+ TSPOSTIO.saveTextFile(stat.path);+ }+ });+ };++ var createDirectory = function(dirPath) {+ console.log("Creating directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ fsRoot.mkdir(dirPath, function(err, stat) {+ if (err) {+ console.log("Error creating directory: " + err);+ } else {+ console.log("Directory created: " + stat.path);+ TSPOSTIO.createDirectory(dirPath);+ }+ });+ };++ var renameFile = function(filePath, newFilePath) {+ console.log("Renaming file from: " + filePath + " to: " + newFilePath);+ TSCORE.showLoadingAnimation();++ fsRoot.move(filePath, newFilePath, function(err, stat) {+ if (err) {+ console.log("Error renaming: " + err);+ } else {+ console.log("File renamed to: " + stat.path);+ TSPOSTIO.renameFile(filePath, stat.path);+ }+ });+ };++ var selectDirectory = function() {+ console.log("Operation selectDirectory not supported in the Dropbox mode yet!");+ TSCORE.showAlertDialog("Selecting directory not supported in the Dropbox mode yet, please type the desired directory path manually in textbox!");+ };++ var selectFile = function() {+ console.log("Operation selectFile not supported in the Dropbox mode!");+ };++ var checkAccessFileURLAllowed = function() {+ console.log("checkAccessFileURLAllowed function not relevant in the Dropbox mode!");+ };++ var openDirectory = function(dirPath) {+ TSCORE.showAlertDialog("Select file functionality not supported in the Dropbox mode! " + dirPath);+ };++ var openExtensionsDirectory = function() {+ TSCORE.showAlertDialog("Open extensions directory functionality not supported in the Dropbox mode!");+ };++ var getFileProperties = function(filePath) {+ console.log("getFileProperties not implemented for dropbox " + filePath);+ };++ exports.init = init;++ exports.createDirectory = createDirectory;+ exports.renameFile = renameFile;+ exports.loadTextFile = loadTextFile;+ exports.saveTextFile = saveTextFile;+ exports.listDirectory = listDirectory;+ exports.deleteElement = deleteElement;+ exports.createDirectoryIndex = createDirectoryIndex;+ exports.createDirectoryTree = createDirectoryTree;+ exports.selectDirectory = selectDirectory;+ exports.openDirectory = openDirectory;+ exports.selectFile = selectFile;+ exports.openExtensionsDirectory = openExtensionsDirectory;+ exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;+ exports.checkNewVersion = checkNewVersion;+ exports.getFileProperties = getFileProperties;++});diff --git a/data/web/web.api.js b/data/web/web.api.jsindex 14ff8de5f..7bb09cbdc 100644--- a/data/web/web.api.js+++ b/data/web/web.api.js@@ -1,303 +1,301 @@/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.- * Use of this source code is governed by a AGPL3 license that+ * Use of this source code is governed by a AGPL3 license that* can be found in the LICENSE file. */define(function(require, exports, module) {-"use strict";-- // Activating browser specific exports modul- console.log("Loading web.js..");-- var TSCORE = require("tscore");- var TSPOSTIO = require("tspostioapi");-- require("webdavlib");-- var davClient;-- function connectDav() {- console.log("Connecting webdav...");- var useHTTPS = false;- if(location.href.indexOf("https") === 0) {- useHTTPS = true;- }- davClient = new nl.sara.webdav.Client(location.hostname, useHTTPS, location.port);- }+ "use strict";- window.setTimeout(connectDav(), 2000);-- function listDirectory(dirPath) {- console.log("Listing directory: "+dirPath);-- dirPath = encodeURI(dirPath + "/");-- davClient.propfind(- dirPath, //encodeURI(dirPath),- function( status, data ) {- console.log("Dirlist Status: "+status);- //console.log("Dirlist Content: "+JSON.stringify(data._responses));- var anotatedDirList = [],- dirList = data._responses,- fileName,- isDir,- filesize,- lmdt;-- for (var entry in dirList) {- var path = dirList[entry].href;- if(dirPath.toLowerCase() !== path.toLowerCase()) {- isDir = false;- filesize = undefined;- lmdt = undefined;- //console.log(dirList[entry]._namespaces["DAV:"]);- if (typeof dirList[entry]._namespaces["DAV:"].getcontentlength === 'undefined') {- isDir = true;- } else {- filesize = dirList[entry]._namespaces["DAV:"].getcontentlength;- lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;- }- fileName = getNameForPath(path);- anotatedDirList.push({- "name": fileName,- "isFile": !isDir,- "size": filesize,- "lmdt": lmdt,- "path": decodeURI(path)- });- }- }- TSPOSTIO.listDirectory(anotatedDirList);- },- 1 //1 , davClient.INFINITY- );+ // Activating browser specific exports modul+ console.log("Loading web.js..");++ var TSCORE = require("tscore");+ var TSPOSTIO = require("tspostioapi");++ require("webdavlib");++ var davClient;++ function connectDav() {+ console.log("Connecting webdav...");+ var useHTTPS = false;+ if (location.href.indexOf("https") === 0) {+ useHTTPS = true;}+ davClient = new nl.sara.webdav.Client(location.hostname, useHTTPS, location.port);+ }- function getNameForPath(path) {- if(path.lastIndexOf("/") == path.length-1) {- path = path.substring(0,path.lastIndexOf("/"));+ window.setTimeout(connectDav(), 2000);++ function listDirectory(dirPath) {+ console.log("Listing directory: " + dirPath);++ dirPath = encodeURI(dirPath + "/");++ davClient.propfind(+ dirPath, //encodeURI(dirPath),+ function(status, data) {+ console.log("Dirlist Status: " + status);+ //console.log("Dirlist Content: "+JSON.stringify(data._responses));+ var anotatedDirList = [],+ dirList = data._responses,+ fileName,+ isDir,+ filesize,+ lmdt;++ for (var entry in dirList) {+ var path = dirList[entry].href;+ if (dirPath.toLowerCase() !== path.toLowerCase()) {+ isDir = false;+ filesize = undefined;+ lmdt = undefined;+ //console.log(dirList[entry]._namespaces["DAV:"]);+ if (typeof dirList[entry]._namespaces["DAV:"].getcontentlength === 'undefined') {+ isDir = true;+ } else {+ filesize = dirList[entry]._namespaces["DAV:"].getcontentlength;+ lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;+ }+ fileName = getNameForPath(path);+ anotatedDirList.push({+ "name": fileName,+ "isFile": !isDir,+ "size": filesize,+ "lmdt": lmdt,+ "path": decodeURI(path)+ });+ }}- var encodedName = path.substring(path.lastIndexOf("/")+1, path.length);- return decodeURI(encodedName);- }+ TSPOSTIO.listDirectory(anotatedDirList);+ },+ 1 //1 , davClient.INFINITY+ );+ }- function isDirectory(path) {- return path.lastIndexOf("/") == path.length-1;+ function getNameForPath(path) {+ if (path.lastIndexOf("/") == path.length - 1) {+ path = path.substring(0, path.lastIndexOf("/"));}+ var encodedName = path.substring(path.lastIndexOf("/") + 1, path.length);+ return decodeURI(encodedName);+ }- var createDirectoryIndex = function(dirPath) {- console.log("Creating index for directory: "+dirPath);- TSCORE.showLoadingAnimation();-- var directoryIndex = [];- TSPOSTIO.createDirectoryIndex(directoryIndex);- };-- var createDirectoryTree = function(dirPath) {- console.log("Creating directory index for: "+dirPath);- TSCORE.showLoadingAnimation();-- var directoyTree = [];- //console.log(JSON.stringify(directoyTree));- TSPOSTIO.createDirectoryTree(directoyTree);- };-- var createDirectory = function(dirPath) {- console.log("Creating directory: "+dirPath);- davClient.mkcol(- encodeURI(dirPath),- function( status, data, headers ) {- console.log("Directory Creation Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.createDirectory(dirPath);- }- );- };-- var copyFile = function(filePath, newFilePath) {- console.log("Copying file: "+filePath+" to "+newFilePath);- davClient.copy(- encodeURI(filePath),- function( status, data, headers ) {- console.log("Copy File Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.copyFile(filePath, newFilePath);- },- encodeURI(newFilePath),- davClient.FAIL_ON_OVERWRITE- );- };-- var renameFile = function(filePath, newFilePath) {- console.log("Renaming file: "+filePath+" to "+newFilePath);- davClient.move(- encodeURI(filePath),- function( status, data, headers ) {- console.log("Rename File Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.renameFile(filePath, newFilePath);- },- encodeURI(newFilePath),- davClient.FAIL_ON_OVERWRITE- );- };-- var renameDirectory = function(dirPath, newDirName) {- var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + encodeURIComponent(newDirName);- console.log("Renaming directory: "+dirPath+" to "+newDirPath);- davClient.move(- encodeURI(dirPath),- function( status, data, headers ) {- console.log("Rename Directory Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.renameDirectory(dirPath, newDirPath);- },- encodeURI(newDirPath),- davClient.FAIL_ON_OVERWRITE- );- };-- var loadTextFile = function(filePath) {- console.log("Loading file: "+filePath);- davClient.get(- encodeURI(filePath),- function( status, data, headers ) {- console.log("Loading File Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.loadTextFile(data);- }- //,customHeaders- );- //TODO Perform file locking and unlocking- };-- var saveTextFile = function(filePath,content,overWrite) {- console.log("Saving file: "+filePath); //+" content: "+content);-- var isNewFile = false; // = !pathUtils.existsSync(filePath);- davClient.propfind( encodeURI(filePath), function( status, data ) {- console.log("Check file exists: Status / Content: "+status+" / "+data);- if(parseInt(status) === 404) {- isNewFile = true;- }- davClient.put(- encodeURI(filePath),- function( status, data, headers ) {- console.log("Creating File Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.saveTextFile(filePath, isNewFile);- },- content,- 'application/octet-stream'- );- },1+ function isDirectory(path) {+ return path.lastIndexOf("/") == path.length - 1;+ }++ var createDirectoryIndex = function(dirPath) {+ console.log("Creating index for directory: " + dirPath);+ TSCORE.showLoadingAnimation();++ var directoryIndex = [];+ TSPOSTIO.createDirectoryIndex(directoryIndex);+ };++ var createDirectoryTree = function(dirPath) {+ console.log("Creating directory index for: " + dirPath);+ TSCORE.showLoadingAnimation();++ var directoyTree = [];+ //console.log(JSON.stringify(directoyTree));+ TSPOSTIO.createDirectoryTree(directoyTree);+ };++ var createDirectory = function(dirPath) {+ console.log("Creating directory: " + dirPath);+ davClient.mkcol(+ encodeURI(dirPath),+ function(status, data, headers) {+ console.log("Directory Creation Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.createDirectory(dirPath);+ }+ );+ };++ var copyFile = function(filePath, newFilePath) {+ console.log("Copying file: " + filePath + " to " + newFilePath);+ davClient.copy(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Copy File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.copyFile(filePath, newFilePath);+ },+ encodeURI(newFilePath),+ davClient.FAIL_ON_OVERWRITE+ );+ };++ var renameFile = function(filePath, newFilePath) {+ console.log("Renaming file: " + filePath + " to " + newFilePath);+ davClient.move(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Rename File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.renameFile(filePath, newFilePath);+ },+ encodeURI(newFilePath),+ davClient.FAIL_ON_OVERWRITE+ );+ };++ var renameDirectory = function(dirPath, newDirName) {+ var newDirPath = TSCORE.TagUtils.extractParentDirectoryPath(dirPath) + TSCORE.dirSeparator + encodeURIComponent(newDirName);+ console.log("Renaming directory: " + dirPath + " to " + newDirPath);+ davClient.move(+ encodeURI(dirPath),+ function(status, data, headers) {+ console.log("Rename Directory Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.renameDirectory(dirPath, newDirPath);+ },+ encodeURI(newDirPath),+ davClient.FAIL_ON_OVERWRITE+ );+ };++ var loadTextFile = function(filePath) {+ console.log("Loading file: " + filePath);+ davClient.get(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Loading File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.loadTextFile(data);+ }+ //,customHeaders+ );+ //TODO Perform file locking and unlocking+ };++ var saveTextFile = function(filePath, content, overWrite) {+ console.log("Saving file: " + filePath); //+" content: "+content);++ var isNewFile = false; // = !pathUtils.existsSync(filePath);+ davClient.propfind(encodeURI(filePath), function(status, data) {+ console.log("Check file exists: Status / Content: " + status + " / " + data);+ if (parseInt(status) === 404) {+ isNewFile = true;+ }+ davClient.put(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.saveTextFile(filePath, isNewFile);+ },+ content,+ 'application/octet-stream');- };-- var saveBinaryFile = function(filePath,content) {- console.log("Saving binary file: "+filePath); //+" content: "+content);- var isNewFile = false;- davClient.propfind( encodeURI(filePath), function( status, data ) {- console.log("Check file exists: Status / Content: "+status+" / "+data);- if(parseInt(status) === 404) {- isNewFile = true;- }- if(isNewFile) {- davClient.put(- encodeURI(filePath),- function( status, data, headers ) {- console.log("Creating File Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.saveBinaryFile(filePath, isNewFile);- },- content,- 'application/octet-stream'- );- } else {- TSCORE.showAlertDialog("File Already Exists.");- }- },1);- };-- var deleteElement = function(path) {- console.log("Deleting: "+path);- davClient.remove(- encodeURI(path),- function( status, data, headers ) {- console.log("Directory/File Deletion Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.deleteElement(path);- }- );- };-- var deleteDirectory = function(path) {- console.log("Deleting directory: "+path);- davClient.remove(- encodeURI(path),- function( status, data, headers ) {- console.log("Directory/File Deletion Status/Content/Headers: "+status+" / "+data+" / "+headers);- TSPOSTIO.deleteDirectory(path);- }- );- };-- var checkAccessFileURLAllowed = function() {- console.log("checkAccessFileURLAllowed function not relevant for webdav..");- };-- var checkNewVersion = function() {- console.log("Checking for new version not relevant fot the webdav version");- };-- var selectDirectory = function() {- TSCORE.showAlertDialog("Select directory is still not implemented in the webdav edition");- };-- var openDirectory = function(dirPath) {- console.log("openDirectory function not relevant for webdav..");- };-- var openFile = function(filePath) {- console.log("openFile function not relevant for webdav..");- };-- var selectFile = function() {- console.log("selectFile function not relevant for webdav..");- };-- var openExtensionsDirectory = function() {- console.log("openExtensionsDirectory function not relevant for webdav..");- };-- var getFileProperties = function(filePath) {- davClient.propfind( encodeURI(filePath), function( status, data ) {- console.log("Properties Status / Content: "+status+" / "+JSON.stringify(data._responses));- var fileProperties = {};- for (var entry in data._responses) {- fileProperties.path = filePath;- fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;- fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;- }- TSPOSTIO.getFileProperties(fileProperties);- },1+ }, 1);+ };++ var saveBinaryFile = function(filePath, content) {+ console.log("Saving binary file: " + filePath); //+" content: "+content);+ var isNewFile = false;+ davClient.propfind(encodeURI(filePath), function(status, data) {+ console.log("Check file exists: Status / Content: " + status + " / " + data);+ if (parseInt(status) === 404) {+ isNewFile = true;+ }+ if (isNewFile) {+ davClient.put(+ encodeURI(filePath),+ function(status, data, headers) {+ console.log("Creating File Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.saveBinaryFile(filePath, isNewFile);+ },+ content,+ 'application/octet-stream');- };-- // Bring the TagSpaces window on top of the windows- var focusWindow = function() {- window.focus();- };-- exports.focusWindow = focusWindow;- exports.createDirectory = createDirectory;- exports.copyFile = copyFile;- exports.renameFile = renameFile;- exports.renameDirectory = renameDirectory;- exports.loadTextFile = loadTextFile;- exports.saveTextFile = saveTextFile;- exports.saveBinaryFile = saveBinaryFile;- exports.listDirectory = listDirectory;- exports.deleteElement = deleteElement;- exports.deleteDirectory = deleteDirectory;- exports.createDirectoryIndex = createDirectoryIndex;- exports.createDirectoryTree = createDirectoryTree;- exports.selectDirectory = selectDirectory;- exports.openDirectory = openDirectory;- exports.openFile = openFile;- exports.selectFile = selectFile;- exports.openExtensionsDirectory = openExtensionsDirectory;- exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;- exports.checkNewVersion = checkNewVersion;- exports.getFileProperties = getFileProperties;-});\ No newline at end of file+ } else {+ TSCORE.showAlertDialog("File Already Exists.");+ }+ }, 1);+ };++ var deleteElement = function(path) {+ console.log("Deleting: " + path);+ davClient.remove(+ encodeURI(path),+ function(status, data, headers) {+ console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.deleteElement(path);+ }+ );+ };++ var deleteDirectory = function(path) {+ console.log("Deleting directory: " + path);+ davClient.remove(+ encodeURI(path),+ function(status, data, headers) {+ console.log("Directory/File Deletion Status/Content/Headers: " + status + " / " + data + " / " + headers);+ TSPOSTIO.deleteDirectory(path);+ }+ );+ };++ var checkAccessFileURLAllowed = function() {+ console.log("checkAccessFileURLAllowed function not relevant for webdav..");+ };++ var checkNewVersion = function() {+ console.log("Checking for new version not relevant fot the webdav version");+ };++ var selectDirectory = function() {+ TSCORE.showAlertDialog("Select directory is still not implemented in the webdav edition");+ };++ var openDirectory = function(dirPath) {+ console.log("openDirectory function not relevant for webdav..");+ };++ var openFile = function(filePath) {+ console.log("openFile function not relevant for webdav..");+ };++ var selectFile = function() {+ console.log("selectFile function not relevant for webdav..");+ };++ var openExtensionsDirectory = function() {+ console.log("openExtensionsDirectory function not relevant for webdav..");+ };++ var getFileProperties = function(filePath) {+ davClient.propfind(encodeURI(filePath), function(status, data) {+ console.log("Properties Status / Content: " + status + " / " + JSON.stringify(data._responses));+ var fileProperties = {};+ for (var entry in data._responses) {+ fileProperties.path = filePath;+ fileProperties.size = data._responses[entry]._namespaces["DAV:"].getcontentlength;+ fileProperties.lmdt = data._responses[entry]._namespaces["DAV:"].getlastmodified._xmlvalue[0].data;+ }+ TSPOSTIO.getFileProperties(fileProperties);+ }, 1);+ };++ // Bring the TagSpaces window on top of the windows+ var focusWindow = function() {+ window.focus();+ };++ exports.focusWindow = focusWindow;+ exports.createDirectory = createDirectory;+ exports.copyFile = copyFile;+ exports.renameFile = renameFile;+ exports.renameDirectory = renameDirectory;+ exports.loadTextFile = loadTextFile;+ exports.saveTextFile = saveTextFile;+ exports.saveBinaryFile = saveBinaryFile;+ exports.listDirectory = listDirectory;+ exports.deleteElement = deleteElement;+ exports.deleteDirectory = deleteDirectory;+ exports.createDirectoryIndex = createDirectoryIndex;+ exports.createDirectoryTree = createDirectoryTree;+ exports.selectDirectory = selectDirectory;+ exports.openDirectory = openDirectory;+ exports.openFile = openFile;+ exports.selectFile = selectFile;+ exports.openExtensionsDirectory = openExtensionsDirectory;+ exports.checkAccessFileURLAllowed = checkAccessFileURLAllowed;+ exports.checkNewVersion = checkNewVersion;+ exports.getFileProperties = getFileProperties;+});