Skip to content

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

tighter integration of requirejs

uggrock0fdda44b30af
diff --git a/data/index.html b/data/index.html
index a683124fc..149126c4c 100644
--- a/data/index.html
+++ b/data/index.html
@@ -9,21 +9,12 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" type="image/x-icon" href="icons/icon16.png">
<title>TagSpaces</title>
-
<link rel="stylesheet" type="text/css" href="libs/jqueryui/custom-theme/jquery-ui-1.9.1.custom.css">
<link rel="stylesheet" type="text/css" href="libs/jquerylayout/layout-default-latest.css">
<link rel="stylesheet" type="text/css" href="libs/dynatree/skin-vista/ui.dynatree.css">
<link rel="stylesheet" type="text/css" href="libs/jsoneditor/jsoneditor.css">
<link rel="stylesheet" type="text/css" href="libs/datatables/css/jquery.dataTables.css">
<link rel="stylesheet/less" type="text/css" href="css/tagspaces.less">
-
- <script type="text/javascript" src="libs/less/less-1.3.1.min.js"></script>
- <script type="text/javascript" src="libs/jquery/jquery-1.8.3.min.js"></script>
- <script type="text/javascript" src="libs/jqueryui/jquery-ui-1.9.2.custom.min.js"></script>
- <script type="text/javascript" src="libs/jquerylayout/jquery.layout-latest.min.js"></script>
- <script type="text/javascript" src="libs/dynatree/jquery.dynatree.min.js"></script>
- <script type="text/javascript" src="libs/jsoneditor/jsoneditor.js"></script>
- <script type="text/javascript" src="libs/datatables/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" data-main="loader" src="libs/requirejs/require.js"></script>
</head>
<body>
diff --git a/data/js/basicviews.ui.js b/data/js/basicviews.ui.js
index 9761c5a6a..ad2b33a07 100644
--- a/data/js/basicviews.ui.js
+++ b/data/js/basicviews.ui.js
@@ -1,6 +1,16 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
+/*
+define([
+ 'require',
+ 'exports',
+ 'module',
+ 'datatables',
+// 'css!datatablescss'
+],function(require, exports, module) {
+"use strict";
+*/
console.debug("Loading BasicViewsUI...");
var BasicViewsUI = (typeof BasicViewsUI == 'object' && BasicViewsUI != null) ? BasicViewsUI : {};
@@ -96,14 +106,11 @@ BasicViewsUI.initFileTagViews = function() {
}
BasicViewsUI.initThumbView = function() {
-// Managing the selection of files in the thumb view
+ // Managing the selection of files in the thumb view
$( "#selectableFiles" ).selectable({
stop: function() {
UIAPI.selectedFiles = [];
$( ".ui-selected", this ).each(function() {
- // var index = $( "#selectableFiles li" ).index( this );
- // console.debug( "Selected #:" + ( index + 1 ) );
- // console.debug( "Selected file: "+$( "#selectableFiles li" )[index].innerHTML);
UIAPI.selectedFiles.push($(this).attr("title"));
});
console.debug("Selected files: "+UIAPI.selectedFiles);
@@ -596,4 +603,7 @@ BasicViewsUI.initDialogs = function() {
}
}
});
-}
\ No newline at end of file
+}
+
+//return BasicViewsUI;
+//});
\ No newline at end of file
diff --git a/data/js/directories.ui.js b/data/js/directories.ui.js
index 8bd0e1ede..6dc214949 100644
--- a/data/js/directories.ui.js
+++ b/data/js/directories.ui.js
@@ -205,7 +205,7 @@ DirectoriesUI.initFavorites = function() {
$( "#favoritesList" ).menu();
$( "#favoritesList" ).menu("disable");
- $( "#favoritesList" ).html("");
+ $( "#favoritesList" ).empty();
var favoritesList = TSSETTINGS.Settings["tagspacesList"]
var menuHTML = undefined;
diff --git a/data/js/fileviewer.ui.js b/data/js/fileviewer.ui.js
index 6ee2f4981..d007aa622 100644
--- a/data/js/fileviewer.ui.js
+++ b/data/js/fileviewer.ui.js
@@ -1,19 +1,21 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
-define(function(require, exports, module) {
-"use strict";
+//define(function(require, exports, module) {
+//"use strict";
console.debug("Loading FileViewer...");
+var FileViewer = (typeof FileViewer == 'object' && FileViewer != null) ? FileViewer : {};
+
var tsEditor = undefined;
-exports.updateTextEditorContent = function(fileContent) {
+FileViewer.updateTextEditorContent = function(fileContent) {
console.debug("Updating edtitor"); // with data: "+fileContent);
tsEditor.setContent(fileContent);
}
-exports.openFile = function(fileName) {
+FileViewer.openFile = function(fileName) {
console.debug("Opening file: "+fileName);
var openedFilePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;
@@ -51,7 +53,7 @@ exports.openFile = function(fileName) {
}
}
-exports.editFile = function(fileName) {
+FileViewer.editFile = function(fileName) {
console.debug("Editing file: "+filePath);
var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;
var fileExt = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length).toLowerCase();
@@ -75,14 +77,15 @@ exports.editFile = function(fileName) {
}
}
-this.constructFileViewerUI = function(fileName, filePath) {
+FileViewer.constructFileViewerUI = function(fileName, filePath) {
// Adding tag buttons to the filetoolbox
var tags = TSAPI.extractTags(fileName);
+ // TODO remove html()
$( "#fileTitle" ).html(TSAPI.extractTitle(fileName));
// Generate tag buttons
- $( "#fileTags" ).html("");
+ $( "#fileTags" ).empty();
for (var i=0; i < tags.length; i++) {
$( "#fileTags" ).append('<button title="Opens context menu for '+tags[i]+'" tag="'+tags[i]+'" filename="'+fileName+'" class="tagButton">'+tags[i]+'</button>');
};
@@ -93,7 +96,7 @@ this.constructFileViewerUI = function(fileName, filePath) {
});
// Clear filetoolbox
- $( "#filetoolbox" ).html("");
+ $( "#filetoolbox" ).empty();
// TODO Fullscreen disabled due a fullscreen issue
//this.addFullScreenButton("#filetoolbox");
@@ -110,7 +113,7 @@ this.constructFileViewerUI = function(fileName, filePath) {
}
-this.initTagSuggestionMenu = function(fileName, tags) {
+FileViewer.initTagSuggestionMenu = function(fileName, tags) {
// Adding buttons for creating tags according to the suggested tags
var suggTags = TSAPI.suggestTags(fileName);
@@ -135,7 +138,7 @@ this.initTagSuggestionMenu = function(fileName, tags) {
});
}
-this.addEditButton = function(container, fileName) {
+FileViewer.addEditButton = function(container, fileName) {
// TODO implement disabled check
var buttonDisabled = false;
$( ""+container ).append('<button id="editDocument">Edit</button>');
@@ -151,7 +154,7 @@ this.addEditButton = function(container, fileName) {
});
}
-this.addOpenInWindowButton = function(container, filePath) {
+FileViewer.addOpenInWindowButton = function(container, filePath) {
$( ""+container ).append('<button id="openInNewWindow">Open in new tab</button>');
$( "#openInNewWindow" ).button({
text: false,
@@ -165,7 +168,7 @@ this.addOpenInWindowButton = function(container, filePath) {
});
}
-this.addCloseButton = function(container) {
+FileViewer.addCloseButton = function(container) {
$( ""+container ).append('<button id="closeOpenedFile">Close</button>');
$( "#closeOpenedFile" ).button({
text: false,
@@ -182,7 +185,7 @@ this.addCloseButton = function(container) {
}
-this.addFullScreenButton = function(container) {
+FileViewer.addFullScreenButton = function(container) {
$( ""+container ).append('<button id="startFullscreen">Fullscreen</button>');
$( "#startFullscreen" ).button({
text: false,
@@ -208,7 +211,7 @@ this.addFullScreenButton = function(container) {
});
}
-this.addTagSuggestionButton = function(container) {
+FileViewer.addTagSuggestionButton = function(container) {
$( ""+container ).append('<button id="openTagSuggestionMenu">Tag Suggestion</button>');
$( "#openTagSuggestionMenu" ).button({
text: false,
@@ -231,4 +234,4 @@ this.addTagSuggestionButton = function(container) {
});
}
-});
\ No newline at end of file
+//});
\ No newline at end of file
diff --git a/data/js/ioapi.chrome.js b/data/js/ioapi.chrome.js
index 3b288fcb7..a2108fc36 100644
--- a/data/js/ioapi.chrome.js
+++ b/data/js/ioapi.chrome.js
@@ -2,7 +2,6 @@
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
// Activating browser specific IOAPI modul
-if( $.browser.webkit) {
console.debug("Loading IOapiChrome.js..");
IOAPI = (typeof IOAPI == 'object' && IOAPI != null) ? IOAPI : {};
@@ -132,4 +131,3 @@ IOAPI.deleteElement = function(path) {
IOAPI.plugin.removeFile(path)
}
-}
\ No newline at end of file
diff --git a/data/js/ioapi.mozilla.js b/data/js/ioapi.mozilla.js
index 47f2f65bf..f5fe4ad2b 100644
--- a/data/js/ioapi.mozilla.js
+++ b/data/js/ioapi.mozilla.js
@@ -2,7 +2,6 @@
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
// Activating browser specific IOAPI modul
-if( $.browser.mozilla) {
console.debug("Loading IOapiMozilla.js..");
@@ -110,5 +109,3 @@ IOAPI.deleteElement = function(path) {
}});
document.documentElement.dispatchEvent(event);
}
-
-}
\ No newline at end of file
diff --git a/data/js/main.js b/data/js/main.js
index a7dd55fde..a0a67930a 100644
--- a/data/js/main.js
+++ b/data/js/main.js
@@ -1,9 +1,90 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
-console.debug("Loading LayoutUI...");
+define([
+ 'jquery',
+ 'jquerylayout',
+ 'jqueryui',
+ 'dynatree',
+ 'datatables',
+ 'jsoneditor',
+ 'less'
+], function($){
+"use strict";
-$(document).ready(function () {
+var layoutContainer = undefined;
+
+var initUI = function(){
+ console.debug("Initializing UI...");
+/*
+ var FileViewer = undefined;
+ var TagsUI = undefined;
+ var BasicViewsUI = undefined;
+ var SettingsUI = undefined;
+// var IOAPI = undefined;
+ var UIAPI = undefined;
+*/
+ var editor = undefined; // Needed for JSON Editor
+
+ // Setting up the communication between the extension and tagspace app
+ if( $.browser.mozilla) {
+ require([
+ "js/messaging.mozilla",
+ "js/ioapi.mozilla"
+ ]);
+ } else if ($.browser.chrome) {
+ require([
+ "js/ioapi.chrome"
+ ]);
+ }
+
+ require([
+ "js/fileviewer.ui",
+ "js/tags.ui",
+ "js/basicviews.ui",
+ "js/settings.ui",
+ "js/misc.ui",
+ "js/settings.api",
+ "js/tagspace.api",
+ "js/directories.ui",
+ ],
+ function() {
+ TagsUI.initContextMenus();
+ TagsUI.initDialogs();
+ TagsUI.initTagTree();
+
+ BasicViewsUI.initContextMenus();
+ BasicViewsUI.initFileTagViews();
+ BasicViewsUI.initDialogs();
+ BasicViewsUI.initButtons();
+ BasicViewsUI.initThumbView();
+
+ DirectoriesUI.initDialogs();
+ DirectoriesUI.initButtons();
+ DirectoriesUI.initDirectoryTree();
+
+ SettingsUI.initButtons();
+ SettingsUI.initDialogs();
+ SettingsUI.initJSONEditor();
+
+ TSSETTINGS.loadSettingsLocalStorage();
+
+ // By empty local storage and a mozilla browser, trying to load from mozilla preferences
+ if(TSSETTINGS.Settings == undefined && $.browser.mozilla) {
+ setTimeout(IOAPI.loadSettings, 1000); // executes initUI and updateSettingMozillaPreferences by success
+ console.debug("Loading setting with from mozilla pref execured with delay...");
+ }
+
+ if(TSSETTINGS.Settings == undefined) {
+ TSSETTINGS.Settings = TSSETTINGS.DefaultSettings;
+ }
+
+ UIAPI.initUI();
+ });
+}
+
+var initLayout = function(){
+ console.debug("Initializing Layout...");
layoutContainer = $('#container').layout(
{
fxName: "none"
@@ -94,4 +175,12 @@ $(document).ready(function () {
// Hide Document Viewer by default
layoutContainer.toggle("east");
-});
\ No newline at end of file
+}
+
+return {
+ initializeUI: initUI,
+ initializeLayout: initLayout
+};
+
+});
+
diff --git a/data/js/messaging.mozilla.js b/data/js/messaging.mozilla.js
index ccdf4bb50..8d9b1aedc 100644
--- a/data/js/messaging.mozilla.js
+++ b/data/js/messaging.mozilla.js
@@ -16,6 +16,9 @@ document.documentElement.addEventListener("addon-message1", function(event) {
try {
console.debug("Loading settings...: "+JSON.stringify(message.content));
TSSETTINGS.updateSettingMozillaPreferences(message.content);
+
+ // Reloads the UI
+ UIAPI.initUI();
} catch (ex) {
console.debug("Exception while getting setting from firefox failed "+ex)
}
diff --git a/data/js/misc.ui.js b/data/js/misc.ui.js
index c57c2550e..b4719482c 100644
--- a/data/js/misc.ui.js
+++ b/data/js/misc.ui.js
@@ -1,6 +1,17 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
+/*
+define([
+ 'require',
+ 'exports',
+ 'module',
+ 'jsoneditor',
+// 'css!jsoneditorcss'
+],function(require, exports, module) {
+*/
+//"use strict";
+
console.debug("Loading MiscUI...");
var UIAPI = (typeof UIAPI == 'object' && UIAPI != null) ? UIAPI : {};
@@ -171,9 +182,6 @@ UIAPI.initRiverView = function(viewType) {
for (var i=0; i < UIAPI.fileList.length; i++) {
if(i > 10) break;
tagsHTML = "";
-// for (var j=0; j < tags.length; j++) {
-// tagsHTML +='<button id="'+tags[j]+'" title="Open tag menu" class="tagButton">'+tags[j]+'</button>';
-// };
var fileName = UIAPI.fileList[i][0];
var filePath = UIAPI.currentPath+UIAPI.getDirSeparator()+fileName;
tagsHTML += '<iframe id="idFrameViewer" style="width: 100%; height: 150px;" src="'+'file:///'+filePath+'" />';
@@ -331,6 +339,7 @@ UIAPI.handleElementActivation = function() {
UIAPI.initUI = function() {
try {
console.debug("Initializing UI...");
+ // TODO remove html()
$("#appVersion").html("["+TSSETTINGS.Settings["appVersion"]+"]");
DirectoriesUI.initFavorites();
@@ -353,6 +362,9 @@ UIAPI.reloadUI = function() {
location.reload();
}
+//return UIAPI;
+//});
+
/**
* Sorting
switch (UIAPI.fileSortCriteria) {
diff --git a/data/js/settings.api.js b/data/js/settings.api.js
index 82b799f01..4a62e0025 100644
--- a/data/js/settings.api.js
+++ b/data/js/settings.api.js
@@ -291,9 +291,6 @@ TSSETTINGS.updateSettingMozillaPreferences = function(settings) {
console.debug('Default settings loaded(Firefox)!');
}
TSSETTINGS.saveSettings();
-
- // Reloads the UI
- UIAPI.initUI();
}
TSSETTINGS.loadSettingsLocalStorage = function() {
diff --git a/data/js/settings.ui.js b/data/js/settings.ui.js
index d14768c70..1a7f139d0 100644
--- a/data/js/settings.ui.js
+++ b/data/js/settings.ui.js
@@ -1,6 +1,17 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
+/*
+define([
+ 'require',
+ 'exports',
+ 'module',
+ 'jsoneditor',
+// 'css!jsoneditorcss'
+],function(require, exports, module) {
+// TODO
+//"use strict";
+*/
console.debug("Loading SettingsUI...");
var SettingsUI = (typeof SettingsUI == 'object' && SettingsUI != null) ? SettingsUI : {};
@@ -100,4 +111,7 @@ SettingsUI.initDialogs = function() {
editor.set(TSSETTINGS.Settings);
}
});
-}
\ No newline at end of file
+}
+
+//return SettingsUI;
+//});
\ No newline at end of file
diff --git a/data/js/tags.ui.js b/data/js/tags.ui.js
index 53150e522..831c7b53d 100644
--- a/data/js/tags.ui.js
+++ b/data/js/tags.ui.js
@@ -1,12 +1,21 @@
/* Copyright (c) 2012 The Tagspaces Authors. All rights reserved.
* Use of this source code is governed by a AGPL3 license that
* can be found in the LICENSE file. */
-define(function(require, exports, module) {
+/*
+define([
+ 'require',
+ 'exports',
+ 'module',
+ 'dynatree',
+// 'css!dynatreecss'
+],function(require, exports, module) {
"use strict";
-
+*/
console.debug("Loading TagsUI...");
-exports.initContextMenus = function() {
+var TagsUI = (typeof TagsUI == 'object' && TagsUI != null) ? TagsUI : {};
+
+TagsUI.initContextMenus = function() {
// $( "#tagSuggestionsMenu" ).menu({
// select: function( event, ui ) {
@@ -101,7 +110,7 @@ exports.initContextMenus = function() {
});
}
-exports.initDialogs = function() {
+TagsUI.initDialogs = function() {
var newDirName = $( "#dirname" );
@@ -298,14 +307,13 @@ exports.initDialogs = function() {
});
}
-exports.updateTagGroups = function() {
+TagsUI.updateTagGroups = function() {
console.debug("Updating TagGroups tree..."); //+JSON.stringify(TSSETTINGS.Settings["tagGroups"]));
$("#tagGroups").dynatree("getRoot").removeChildren();
$("#tagGroups").dynatree("getRoot").addChild(TSSETTINGS.Settings["tagGroups"]);
}
-
-exports.initTagTree = function() {
+TagsUI.initTagTree = function() {
// Init the tag tree / taggroups module
$("#tagGroups").dynatree({
clickFolderMode: 1,
@@ -347,7 +355,7 @@ exports.initTagTree = function() {
});
}
-exports.openTagMenu = function(tagButton, tag, fileName) {
+TagsUI.openTagMenu = function(tagButton, tag, fileName) {
BasicViewsUI.clearSelectedFiles();
$(tagButton).parent().parent().toggleClass("selectedRow");
@@ -368,4 +376,4 @@ exports.openTagMenu = function(tagButton, tag, fileName) {
return false;*/
}
-});
\ No newline at end of file
+//});
\ No newline at end of file
diff --git a/data/loader.js b/data/loader.js
index afdcb5fb4..91027906b 100644
--- a/data/loader.js
+++ b/data/loader.js
@@ -3,66 +3,63 @@
* can be found in the LICENSE file. */
console.debug("Loading Loader...");
-// Init layout
-require(["js/layout.ui"]);
+require.config({
+ map: {
+ '*': {
+ 'css': 'libs/requirecss/css'
+ }
+ },
+ paths: {
+ jquery: 'libs/jquery/jquery-1.8.3.min',
+ jquerylayout: 'libs/jquerylayout/jquery.layout-latest.min',
+ jquerylayoutcss: 'libs/jquerylayout/layout-default-latest',
+ jqueryui: 'libs/jqueryui/jquery-ui-1.9.2.custom.min',
+ jqueryuicss: 'libs/jqueryui/custom-theme/jquery-ui-1.9.1.custom',
+ dynatree: 'libs/dynatree/jquery.dynatree.min',
+ dynatreecss: 'libs/dynatree/skin-vista/ui.dynatree',
+ datatables: 'libs/datatables/js/jquery.dataTables.min',
+ datatablescss: 'libs/datatables/css/jquery.dataTables',
+ jsoneditor: 'libs/jsoneditor/jsoneditor',
+ jsoneditorcss: 'libs/jsoneditor/jsoneditor',
+ less: 'libs/less/less-1.3.1.min',
+ },
+ shim: {
+ 'jquerylayout': {
+ deps: [
+ 'jquery'
+ ]
+ },
+ 'jqueryui': {
+ deps: [
+ 'jquery'
+ ]
+ },
+ 'dynatree': {
+ deps: [
+ 'jquery'
+ ]
+ },
+ 'datatables': {
+ deps: [
+ 'jquery'
+ ]
+ },
+/* less: {
+ deps: [
+ 'css!jquerylayoutcss',
+ 'css!jqueryuicss',
+ 'css!dynatreecss',
+ 'css!datatablescss',
+ 'css!jsoneditorcss'
+ ]
+ },*/
+ }
+});
-// Setting up the communication between the extension and tagspace app
-if( $.browser.mozilla) {
- require(["js/messaging.mozilla"]);
-}
-
-FileViewer = undefined;
-TagsUI = undefined;
-//BasicViewsUI = undefined;
-
-jQuery(function($) {
- require([
- "js/fileviewer.ui",
- "js/tags.ui",
- "js/basicviews.ui.js",
- "js/misc.ui.js",
- "js/ioapi.chrome.js",
- "js/ioapi.mozilla.js",
- "js/settings.api.js",
- "js/tagspace.api.js",
- "js/directories.ui.js",
- "js/settings.ui.js"
- ],
- function(viewer,tags) {
- FileViewer = viewer;
-
- TagsUI = tags;
- TagsUI.initContextMenus();
- TagsUI.initDialogs();
- TagsUI.initTagTree();
-
- //BasicViewsUI = basicviews;
- BasicViewsUI.initContextMenus();
- BasicViewsUI.initFileTagViews();
- BasicViewsUI.initDialogs();
- BasicViewsUI.initButtons();
- BasicViewsUI.initThumbView();
-
- DirectoriesUI.initDialogs();
- DirectoriesUI.initButtons();
- DirectoriesUI.initDirectoryTree();
-
- SettingsUI.initButtons();
- SettingsUI.initDialogs();
- SettingsUI.initJSONEditor();
-
- TSSETTINGS.loadSettingsLocalStorage();
-
- // By empty local storage and a mozilla browser, trying to load from mozilla preferences
- if(TSSETTINGS.Settings == undefined && $.browser.mozilla) {
- setTimeout(IOAPI.loadSettings, 1000); // executes initUI and updateSettingMozillaPreferences by success
- console.debug("Loading setting with from mozilla pref execured with delay...");
- }
-
- if(TSSETTINGS.Settings == undefined) {
- TSSETTINGS.Settings = TSSETTINGS.DefaultSettings;
- }
-
- UIAPI.initUI();
- });
-});
\ No newline at end of file
+// Init Application
+require(['js/main'],
+ function(Main) {
+ $(document).ready(Main.initializeLayout());
+ Main.initializeUI();
+ }
+);
\ No newline at end of file