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 = $("
  • ").append(a); + if (fileDescToPrint === fileDesc) { + li.addClass("disabled"); + } else { + a.prop("href", "#").click(function() { + fileManager.selectFile(fileDescToPrint); + }); + } + $("#file-selector").append(li); + }); + }; + + documentSelector.onFileSelected = function(fileDescParameter) { + fileDesc = fileDescParameter; + updateSelector(); + }; + + documentSelector.onTitleChanged = updateSelector; + documentSelector.onSyncExportSuccess = updateSelector; + documentSelector.onSyncRemoved = updateSelector; + documentSelector.onNewPublishSuccess = updateSelector; + documentSelector.onPublishRemoved = updateSelector; + + return documentSelector; + +}); \ No newline at end of file diff --git a/js/extensions/document-title.js b/js/extensions/document-title.js new file mode 100644 index 00000000..82049794 --- /dev/null +++ b/js/extensions/document-title.js @@ -0,0 +1,62 @@ +define( [ "jquery", "underscore" ], function($) { + + var documentTitle = { + extensionId: "documentTitle", + extensionName: "Document title", + settingsBloc: [ + '

    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 = [ + '
    ', + '', + '', + '', + '', + '
    '].join(""); + var removeButtonTemplate = '
    '; + var refreshDialog = function(fileDescParameter) { + if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) { + return; + } + + var publishAttributesList = _.values(fileDesc.publishLocations); + $(".msg-no-publish, .msg-publish-list").addClass("hide"); + var publishList = $("#manage-publish-list").empty(); + if (publishAttributesList.length > 0) { + $(".msg-publish-list").removeClass("hide"); + } else { + $(".msg-no-publish").removeClass("hide"); + } + _.each(publishAttributesList, function(publishAttributes) { + publishAttributes = _.extend({}, publishAttributes); + if(publishAttributes.password) { + publishAttributes.password = "********"; + } + var publishDesc = JSON.stringify(publishAttributes).replace(/{|}|"/g, ""); + var lineElement = $(_.template(lineTemplate, { + provider: providerMap[publishAttributes.provider], + publishDesc: publishDesc + })); + lineElement.append($(removeButtonTemplate).click(function() { + fileManager.removePublish(publishIndex); + })); + publishList.append(lineElement); + }); + }; + + managePublication.onFileSelected = function(fileDescParameter) { + fileDesc = fileDescParameter; + refreshDialog(fileDescParameter); + }; + + managePublication.onNewPublishSuccess = refreshDialog; + managePublication.onPublishRemoved = refreshDialog; + + return managePublication; + +}); \ No newline at end of file diff --git a/js/extensions/manage-synchronization.js b/js/extensions/manage-synchronization.js new file mode 100644 index 00000000..b192cbf0 --- /dev/null +++ b/js/extensions/manage-synchronization.js @@ -0,0 +1,61 @@ +define( [ "jquery", "underscore" ], function($) { + + var manageSynchronization = { + extensionId: "manageSynchronization", + extensionName: "Manage Synchronization", + settingsBloc: [ + '

    Populates the "Manage synchronization" dialog box.

    ' + ].join("") + }; + + var fileManager = undefined; + manageSynchronization.onFileManagerCreated = function(fileManagerParameter) { + fileManager = fileManagerParameter; + }; + + var fileDesc = undefined; + var lineTemplate = [ + '
    ', + '', + '', + '', + '', + '
    '].join(""); + var removeButtonTemplate = ''; + var refreshDialog = function(fileDescParameter) { + if(fileDescParameter !== undefined && fileDescParameter !== fileDesc) { + return; + } + + var syncAttributesList = _.values(fileDesc.syncLocations); + $(".msg-no-sync, .msg-sync-list").addClass("hide"); + var syncList = $("#manage-sync-list").empty(); + if (syncAttributesList.length > 0) { + $(".msg-sync-list").removeClass("hide"); + } else { + $(".msg-no-sync").removeClass("hide"); + } + _.each(syncAttributesList, function(syncAttributes) { + var syncDesc = syncAttributes.id || syncAttributes.path; + var lineElement = $(_.template(lineTemplate, { + provider: providerMap[syncAttributes.provider], + syncDesc: syncDesc + })); + lineElement.append($(removeButtonTemplate).click(function() { + fileManager.removeSync(syncAttributes); + })); + syncList.append(lineElement); + }); + }; + + manageSynchronization.onFileSelected = function(fileDescParameter) { + fileDesc = fileDescParameter; + refreshDialog(fileDescParameter); + }; + + manageSynchronization.onSyncExportSuccess = refreshDialog; + manageSynchronization.onSyncRemoved = refreshDialog; + + return manageSynchronization; + +}); \ No newline at end of file diff --git a/js/extensions/sharing-button.js b/js/extensions/sharing-button.js new file mode 100644 index 00000000..f798467c --- /dev/null +++ b/js/extensions/sharing-button.js @@ -0,0 +1,52 @@ +define( [ "jquery", "underscore" ], function($) { + + var sharingButton = { + extensionId: "sharingButton", + extensionName: "Sharing button", + optional: true, + settingsBloc: [ + '

    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