TagSpaces is an offline, open source, document manager with tagging support
utilizing promises for loading of perspective extensions
uggrock4813bc2b36db
diff --git a/data/ext/perspectiveGrid/extension.js b/data/ext/perspectiveGrid/extension.jsindex 347cbdfe0..cc07c4d01 100644--- a/data/ext/perspectiveGrid/extension.js+++ b/data/ext/perspectiveGrid/extension.js@@ -19,22 +19,27 @@ define(function(require, exports, module) {var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;var UI;+ var extensionLoaded;var init = function() {console.log("Initializing perspective " + extensionID);- require([- extensionDirectory + '/perspectiveUI.js',- "text!" + extensionDirectory + '/toolbar.html',- "css!" + extensionDirectory + '/extension.css',- ], function(extUI, toolbarTPL) {- var toolbarTemplate = Handlebars.compile(toolbarTPL);- UI = new extUI.ExtUI(extensionID);- UI.buildUI(toolbarTemplate);- platformTuning();- if (isCordova) {- TSCORE.reLayout();- }- $('#' + extensionID + 'Container [data-i18n]').i18n();++ extensionLoaded = new Promise(function(resolve, reject) {+ require([+ extensionDirectory + '/perspectiveUI.js',+ "text!" + extensionDirectory + '/toolbar.html',+ "css!" + extensionDirectory + '/extension.css',+ ], function(extUI, toolbarTPL) {+ var toolbarTemplate = Handlebars.compile(toolbarTPL);+ UI = new extUI.ExtUI(extensionID);+ UI.buildUI(toolbarTemplate);+ platformTuning();+ if (isCordova) {+ TSCORE.reLayout();+ }+ $('#' + extensionID + 'Container [data-i18n]').i18n();+ resolve(true);+ });});};@@ -50,17 +55,13 @@ define(function(require, exports, module) {var load = function() {console.log("Loading perspective " + extensionID);- if (UI === undefined) {- window.setTimeout(function() {- UI.reInit();- }, 1000);- } else {+ extensionLoaded.then(function() {UI.reInit();- }+ });};var clearSelectedFiles = function() {- if (UI !== undefined) {+ if(UI) {UI.clearSelectedFiles();UI.handleElementActivation();}diff --git a/data/ext/perspectiveImageSwiper/extension.js b/data/ext/perspectiveImageSwiper/extension.jsindex 6c8167cc5..96fc9c26d 100644--- a/data/ext/perspectiveImageSwiper/extension.js+++ b/data/ext/perspectiveImageSwiper/extension.js@@ -24,36 +24,37 @@ define(function(require, exports, module) {var homeScreen;var template;var UI;+ var extensionLoaded;var init = function() {console.log("Initializing perspective " + extensionID);$viewContainer = $("#" + extensionID + "Container").empty();-- require([- extensionDirectory + "/perspectiveUI.js",- "text!" + extensionDirectory + "/galleryTMPL.html",- "css!" + extensionDirectory + "/gallery.css",- "css!" + extensionDirectory + "/dist/photoswipe.css",- "css!" + extensionDirectory + "/dist/default-skin/default-skin.css"- ], function(perspectiveUI, tmpl) {- UI = perspectiveUI;- template = tmpl;- UI.initUI(extensionDirectory);- });++ extensionLoaded = new Promise(function(resolve, reject) {+ require([+ extensionDirectory + "/perspectiveUI.js",+ "text!" + extensionDirectory + "/galleryTMPL.html",+ "css!" + extensionDirectory + "/gallery.css",+ "css!" + extensionDirectory + "/dist/photoswipe.css",+ "css!" + extensionDirectory + "/dist/default-skin/default-skin.css"+ ], function(perspectiveUI, tmpl) {+ UI = perspectiveUI;+ template = tmpl;+ UI.initUI(extensionDirectory);+ resolve(true);+ }+ );+ });};var load = function() {console.log("Loading perspective " + extensionID);$viewContainer.children().remove();- if (UI) {+ extensionLoaded.then(function(){UI.load($viewContainer, template, TSCORE.fileList);TSCORE.hideLoadingAnimation();- } else {- window.setTimeout(function() {- load();- }, 1000);- }+ })};var clearSelectedFiles = function() {};diff --git a/data/ext/perspectiveList/extension.js b/data/ext/perspectiveList/extension.jsindex a969c6162..c956b7ddc 100644--- a/data/ext/perspectiveList/extension.js+++ b/data/ext/perspectiveList/extension.js@@ -19,61 +19,64 @@ define(function(require, exports, module) {var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;var UI;+ var extensionLoaded;function init() {console.log("Initializing perspective " + extensionID);- require([- "css!" + extensionDirectory + '/extension.css',- extensionDirectory + '/datatables/jquery.dataTables.min.js',- 'libs/filesaver.js/FileSaver.js'- ], function() {++ extensionLoaded = new Promise(function(resolve, reject) {require([- extensionDirectory + '/perspectiveUI.js',- "text!" + extensionDirectory + '/toolbar.html',- extensionDirectory + '/datatables/natural.js',- ], function(extUI, toolbarTPL) {-- var toolbarTemplate = Handlebars.compile(toolbarTPL);- UI = new extUI.ExtUI(extensionID);- UI.buildUI(toolbarTemplate);-- // TODO refactor translations- var translation = $.i18n.t("ns.perspectiveList:fileExtension");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('File Ext.')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:fileTitle");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('Title')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:fileTags");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('Tags')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:fileSize");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('Size')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:fileLDTM");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('Last Modified')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:filePath");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('File Path')").text(translation);- }- translation = $.i18n.t("ns.perspectiveList:fileName");- if (translation.length > 0) {- $('#' + extensionID + 'Container').find("th:contains('File Name')").text(translation);- }-- if (isCordova) {- TSCORE.reLayout();- }-- $('#' + extensionID + 'Container [data-i18n]').i18n();-- platformTuning();+ "css!" + extensionDirectory + '/extension.css',+ extensionDirectory + '/datatables/jquery.dataTables.min.js',+ 'libs/filesaver.js/FileSaver.js'+ ], function() {+ require([+ extensionDirectory + '/perspectiveUI.js',+ "text!" + extensionDirectory + '/toolbar.html',+ extensionDirectory + '/datatables/natural.js',+ ], function(extUI, toolbarTPL) {++ var toolbarTemplate = Handlebars.compile(toolbarTPL);+ UI = new extUI.ExtUI(extensionID);+ UI.buildUI(toolbarTemplate);++ // TODO refactor translations+ var translation = $.i18n.t("ns.perspectiveList:fileExtension");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('File Ext.')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:fileTitle");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('Title')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:fileTags");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('Tags')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:fileSize");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('Size')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:fileLDTM");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('Last Modified')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:filePath");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('File Path')").text(translation);+ }+ translation = $.i18n.t("ns.perspectiveList:fileName");+ if (translation.length > 0) {+ $('#' + extensionID + 'Container').find("th:contains('File Name')").text(translation);+ }+ $('#' + extensionID + 'Container [data-i18n]').i18n();++ if (isCordova) {+ TSCORE.reLayout();+ }+ platformTuning();+ resolve(true);+ });});});}@@ -93,17 +96,13 @@ define(function(require, exports, module) {var load = function() {console.log("Loading perspective " + extensionID);- if (UI === undefined) {- window.setTimeout(function() {- UI.reInit();- }, 1000);- } else {+ extensionLoaded.then(function() {UI.reInit();- }+ });};var clearSelectedFiles = function() {- if (UI !== undefined) {+ if(UI) {UI.clearSelectedFiles();UI.handleElementActivation();}