From b225379703e33a19273e191cda5cfbc31037fc08 Mon Sep 17 00:00:00 2001 From: benweet Date: Sun, 28 Sep 2014 19:34:30 +0100 Subject: [PATCH] Reimplemented sharing module --- public/res/providers/downloadProvider.js | 2 +- public/res/providers/gdriveProviderBuilder.js | 2 +- public/res/providers/gistProvider.js | 2 +- public/res/sharing.js | 94 +++++++++++-------- 4 files changed, 56 insertions(+), 44 deletions(-) diff --git a/public/res/providers/downloadProvider.js b/public/res/providers/downloadProvider.js index 181f8725..50bcdcf9 100644 --- a/public/res/providers/downloadProvider.js +++ b/public/res/providers/downloadProvider.js @@ -9,7 +9,7 @@ define([ ], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) { var downloadProvider = new Provider("download"); - downloadProvider.sharingAttributes = [ + downloadProvider.viewerSharingAttributes = [ "url" ]; diff --git a/public/res/providers/gdriveProviderBuilder.js b/public/res/providers/gdriveProviderBuilder.js index 06b57b95..94a29828 100644 --- a/public/res/providers/gdriveProviderBuilder.js +++ b/public/res/providers/gdriveProviderBuilder.js @@ -21,7 +21,7 @@ define([ var gdriveProvider = new Provider(providerId, providerName); gdriveProvider.defaultPublishFormat = "template"; gdriveProvider.exportPreferencesInputIds = [ - providerId + "-parentid", + providerId + "-parentid" ]; function createSyncIndex(id) { diff --git a/public/res/providers/gistProvider.js b/public/res/providers/gistProvider.js index 3d774ab7..5262d2e8 100644 --- a/public/res/providers/gistProvider.js +++ b/public/res/providers/gistProvider.js @@ -8,7 +8,7 @@ define([ gistProvider.publishPreferencesInputIds = [ "gist-public" ]; - gistProvider.sharingAttributes = [ + gistProvider.viewerSharingAttributes = [ "gistId", "filename" ]; diff --git a/public/res/sharing.js b/public/res/sharing.js index 1fb3218f..f372f672 100644 --- a/public/res/sharing.js +++ b/public/res/sharing.js @@ -27,63 +27,75 @@ define([ isOffline = isOfflineParam; }); - sharing.getViewerLink = function(attributes) { + sharing.getEditorParams = function(attributes) { + var provider = providerMap[attributes.provider.providerId]; + if(provider === undefined) { + return; + } + var params = { + provider: provider.providerId + }; + if(!provider.editorSharingAttributes) { + return; + } + _.each(provider.editorSharingAttributes, function(attributeName) { + params[attributeName] = attributes[attributeName]; + }); + return params; + }; + + sharing.getViewerParams = function(attributes) { var provider = providerMap[attributes.provider.providerId]; - // Don't create link if provider is not compatible for sharing if(provider === undefined || // Or document is not published in markdown format attributes.format != "markdown") { return; } - var url = [ - constants.MAIN_URL, - 'viewer#!provider=', - provider.providerId - ]; - _.each(provider.sharingAttributes, function(attributeName) { - url.push('&'); - url.push(attributeName); - url.push('='); - url.push(encodeURIComponent(attributes[attributeName])); + var params = { + provider: provider.providerId + }; + if(!provider.viewerSharingAttributes) { + return; + } + _.each(provider.viewerSharingAttributes, function(attributeName) { + params[attributeName] = attributes[attributeName]; }); - attributes.sharingLink = url.join(''); - callback(); + return params; }; eventMgr.addListener("onReady", function() { - if(window.viewerMode === false) { - return; - } // Check parameters to see if we have to download a shared document var providerId = utils.getURLParameter("provider"); - if(providerId === undefined) { - providerId = "download"; - } - var provider = providerMap[providerId]; - if(provider === undefined) { - return; - } - var importParameters = {}; - _.each(provider.sharingAttributes, function(attributeName) { - var parameter = utils.getURLParameter(attributeName); - if(!parameter) { - importParameters = undefined; + if(window.viewerMode) { + if(providerId === undefined) { + providerId = "download"; + } + var provider = providerMap[providerId]; + if(provider === undefined) { return; } - importParameters[attributeName] = parameter; - }); - if(importParameters === undefined) { - return; - } - $("#preview-contents, .navbar .file-title-navbar").hide(); - provider.importPublic(importParameters, function(error, title, content) { - $("#preview-contents, .navbar .file-title-navbar").show(); - if(error) { + var importParameters = {}; + _.each(provider.viewerSharingAttributes, function(attributeName) { + var parameter = utils.getURLParameter(attributeName); + if(!parameter) { + importParameters = undefined; + return; + } + importParameters[attributeName] = parameter; + }); + if(importParameters === undefined) { return; } - var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true); - fileMgr.selectFile(fileDesc); - }); + $("#preview-contents, .navbar .file-title-navbar").hide(); + provider.importPublic(importParameters, function(error, title, content) { + $("#preview-contents, .navbar .file-title-navbar").show(); + if(error) { + return; + } + var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true); + fileMgr.selectFile(fileDesc); + }); + } }); return sharing;