diff --git a/js/extensions/document-selector.js b/js/extensions/document-selector.js new file mode 100644 index 00000000..8bfe60b9 --- /dev/null +++ b/js/extensions/document-selector.js @@ -0,0 +1,65 @@ +define( [ "jquery", "underscore" ], function($) { + + var documentSelector = { + extensionId: "documentSelector", + extensionName: "Document selector", + settingsBloc: [ + '
Builds the "Open document" dropdown menu.
' + ].join("") + }; + + var fileSystemDescriptor = undefined; + documentSelector.onFileSystemLoaded = function(fileSystemDescriptorParameter) { + fileSystemDescriptor = fileSystemDescriptorParameter; + }; + + var fileDesc = undefined; + var updateSelector = function() { + var sortedDescriptor = _.sortBy(fileSystemDescriptor, function(fileDesc) { + return fileDesc.title.toLowerCase(); + }); + + function composeTitle(fileDesc) { + var result = []; + var syncAttributesList = _.values(fileDesc.syncLocations); + var publishAttributesList = _.values(fileDesc.publishLocations); + var attributesList = syncAttributesList.concat(publishAttributesList); + _.chain(attributesList).sortBy(function(attributes) { + return attributes.provider; + }).each(function(attributes) { + result.push(''); + }); + result.push(" "); + result.push(fileDesc.title); + return result.join(""); + } + + $("#file-selector li:not(.stick)").empty(); + _.each(sortedDescriptor, function(fileDescToPrint) { + var a = $("").html(composeTitle(fileDescToPrint.index)); + var li = $("Responsible for showing the document title in the navigation bar.
' + ].join("") + }; + + var layout = undefined; + documentTitle.onLayoutCreated = function(layoutParameter) { + layout = layoutParameter; + }; + + var fileDesc = undefined; + var updateTitle = function(fileDescParameter) { + if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) { + return; + } + + function composeTitle(fileDesc) { + var result = []; + var syncAttributesList = _.values(fileDesc.syncLocations); + var publishAttributesList = _.values(fileDesc.publishLocations); + var attributesList = syncAttributesList.concat(publishAttributesList); + _.chain(attributesList).sortBy(function(attributes) { + return attributes.provider; + }).each(function(attributes) { + result.push(''); + }); + result.push(" "); + result.push(fileDesc.title); + return result.join(""); + } + + var title = fileDesc.title; + document.title = "StackEdit - " + title; + $("#file-title").html(composeTitle(fileDesc)); + $(".file-title").text(title); + $("#file-title-input").val(title); + + if(layout !== undefined) { + // Use defer to make sure UI has been updated + _.defer(layout.resizeAll); + } + }; + + documentTitle.onFileSelected = function(fileDescParameter) { + fileDesc = fileDescParameter; + updateTitle(fileDescParameter); + }; + + documentTitle.onTitleChanged = updateTitle; + documentTitle.onSyncExportSuccess = updateTitle; + documentTitle.onSyncRemoved = updateTitle; + documentTitle.onNewPublishSuccess = updateTitle; + documentTitle.onPublishRemoved = updateTitle; + + return documentTitle; + +}); \ No newline at end of file diff --git a/js/extensions/manage-publication.js b/js/extensions/manage-publication.js new file mode 100644 index 00000000..f56929cf --- /dev/null +++ b/js/extensions/manage-publication.js @@ -0,0 +1,65 @@ +define( [ "jquery", "underscore" ], function($) { + + var managePublication = { + extensionId: "managePublication", + extensionName: "Manage Publication", + settingsBloc: [ + 'Populates the "Manage publication" dialog box.
' + ].join("") + }; + + var fileManager = undefined; + manageSynchronization.onFileManagerCreated = function(fileManagerParameter) { + fileManager = fileManagerParameter; + }; + + var fileDesc = undefined; + var lineTemplate = [ + 'Populates the "Manage synchronization" dialog box.
' + ].join("") + }; + + var fileManager = undefined; + manageSynchronization.onFileManagerCreated = function(fileManagerParameter) { + fileManager = fileManagerParameter; + }; + + var fileDesc = undefined; + var lineTemplate = [ + 'Adds a "Share document" button in the navigation bar.
' + ].join("") + }; + + var fileDesc = undefined; + var lineTemplate = [ + '' + ].join(""); + var refreshDocumentSharing = function(fileDescParameter) { + if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) { + return; + } + + var linkList = $("#link-container .link-list").empty(); + $("#link-container .no-link").show(); + + var attributesList = _.values(fileDesc.publishLocations); + _.each(attributesList, function(attributes) { + if(attributes.sharingLink) { + var lineElement = $(_.template(lineTemplate, { + link: attributes.sharingLink + })); + lineElement.click(function(event) { + event.stopPropagation(); + }); + linkList.append(lineElement); + $("#link-container .no-link").hide(); + } + }); + }; + + sharingButton.onFileSelected = function(fileDescParameter) { + fileDesc = fileDescParameter; + refreshDocumentSharing(fileDescParameter); + }; + + sharingButton.onNewPublishSuccess = refreshDocumentSharing; + sharingButton.onPublishRemoved = refreshDocumentSharing; + + return sharingButton; + +}); \ No newline at end of file