TagSpaces is an offline, open source, document manager with tagging support
Tag suggestion working again.
uggrockba14ae1c8b21
diff --git a/data/js/fileviewer.ui.js b/data/js/fileviewer.ui.jsindex 79fe01c08..002c4cbd9 100644--- a/data/js/fileviewer.ui.js+++ b/data/js/fileviewer.ui.js@@ -28,6 +28,8 @@ FileViewer.openFile = function(filePath) {UIAPI.openFileViewer();+ this.initTagSuggestionMenu(filePath);+$( "#viewer" ).empty();if(!viewerExt) {$( "#viewer" ).text("File type not supported for viewing.");@@ -140,40 +142,49 @@ FileViewer.constructFileViewerUI = function(filePath) {this.addOpenInWindowButton("#filetoolbox", filePath);- // TODO Tag suggestion disabled due menu init issue- this.initTagSuggestionMenu(filePath, tags);this.addTagSuggestionButton("#filetoolbox");this.addCloseButton("#filetoolbox");}-FileViewer.initTagSuggestionMenu = function(filePath, tags) {+FileViewer.initTagSuggestionMenu = function(filePath) {+ var tags = TSAPI.extractTags(filePath);+var suggTags = TSAPI.suggestTags(filePath);var tsMenu = $( "#tagSuggestionsMenu" );- tsMenu.menu();-// tsMenu.menu("disable");- tsMenu.empty();++ $( "#tagSuggestionsMenu" ).empty();++ var suggestionMenuEmpty = true;// Adding context menu entries for creating tags according to the suggested tagsfor (var i=0; i < suggTags.length; i++) {// Ignoring the tags already assigned to a fileif(tags.indexOf(suggTags[i]) < 0) {- tsMenu.append($('<li>', {name: suggTags[i]}).append($('<a>', {+ $( "#tagSuggestionsMenu" ).append($('<li>', {name: suggTags[i]}).append($('<a>', {href: "javascript:void(0);",title: "Add tag "+suggTags[i]+" to current file",+ tagname: suggTags[i],filepath: filePath,text: "Tag with '"+suggTags[i]+"'"- })));+ })+ .click(function() {+ var tagName = $(this).attr( "tagname" );+ var filePath = $(this).attr( "filepath" );+ console.debug("Tag suggestion clicked: "+tagName);+ TSAPI.writeTagsToFile(filePath, [tagName]);+ return false;+ })+ ));+ suggestionMenuEmpty = false;}- };-- tsMenu.menu({- select: function( event, ui ) {- var tagName = ui.item.attr( "name" );- TSAPI.writeTagsToFile(filePath, [tagName]);- }- });+ };++ // Showing dropdown menu only if the context menus is not empty+ if(!suggestionMenuEmpty) {+ $( "#openTagSuggestionMenu" ).dropdown( 'attach' , '#tagSuggestionsMenu' );+ }}FileViewer.addTagSuggestionButton = function(container) {@@ -185,7 +196,6 @@ FileViewer.addTagSuggestionButton = function(container) {},disabled: false})- .dropdown( 'attach' , '#tagSuggestionsMenu' );}FileViewer.addEditButton = function(container, filePath) {diff --git a/data/js/tagspace.api.js b/data/js/tagspace.api.jsindex 0ce4c20a9..e745628d6 100644--- a/data/js/tagspace.api.js+++ b/data/js/tagspace.api.js@@ -31,6 +31,21 @@ TSAPI.extractFileExtension = function(filePath) {return ext;}+TSAPI.extractTitle = function(filePath) {+ console.debug("Extracting title from: "+filePath);+ fileName = TSAPI.extractFileName(filePath);++ var beginTagContainer = fileName.indexOf(TSAPI.beginTagContainer);+ var indexExtensionSepartor = fileName.lastIndexOf(".");+ if( (indexExtensionSepartor <= 0) || (indexExtensionSepartor < beginTagContainer) ) {+ return fileName.trim();+ } else if( beginTagContainer < 0 ) {+ return fileName.slice(0,indexExtensionSepartor).trim();+ } else if( beginTagContainer >= 0 ) {+ return fileName.slice(0,beginTagContainer).trim();+ }+}+TSAPI.formatFileSize = function(fileSize) {// TODO implement format file sizereturn fileSize;@@ -86,20 +101,6 @@ TSAPI.extractTags = function(filePath) {return cleanedTags;}-TSAPI.extractTitle = function(filePath) {- console.debug("Extracting title from: "+filePath);- fileName = TSAPI.extractFileName(filePath);-- var beginTagContainer = fileName.indexOf(TSAPI.beginTagContainer);- var indexExtensionSepartor = fileName.lastIndexOf(".");- if( (indexExtensionSepartor <= 0) || (indexExtensionSepartor < beginTagContainer) ) {- return fileName.trim();- } else if( beginTagContainer < 0 ) {- return fileName.slice(0,indexExtensionSepartor).trim();- } else if( beginTagContainer >= 0 ) {- return fileName.slice(0,beginTagContainer).trim();- }-}TSAPI.suggestTags = function(filePath) {console.debug("Suggesting tags for: "+filePath);diff --git a/data/loader.js b/data/loader.jsindex 34e4220c9..f27e7274f 100644--- a/data/loader.js+++ b/data/loader.js@@ -11,8 +11,6 @@ require.config({},paths: {jquery: 'libs/jquery/jquery-1.8.3',- dynatree: 'libs/dynatree/jquery.dynatree.min',- dynatreecss: 'libs/dynatree/skin-vista/ui.dynatree',jqueryui: 'libs/jqueryui/jquery.ui.core',jqueryuiwidget: 'libs/jqueryui/jquery.ui.widget',jqueryuimouse: 'libs/jqueryui/jquery.ui.mouse',