Reimplemented sharing module
This commit is contained in:
parent
d2cb92e828
commit
b225379703
@ -9,7 +9,7 @@ define([
|
|||||||
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
], function($, constants, eventMgr, utils, fileMgr, Provider, AsyncTask) {
|
||||||
|
|
||||||
var downloadProvider = new Provider("download");
|
var downloadProvider = new Provider("download");
|
||||||
downloadProvider.sharingAttributes = [
|
downloadProvider.viewerSharingAttributes = [
|
||||||
"url"
|
"url"
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ define([
|
|||||||
var gdriveProvider = new Provider(providerId, providerName);
|
var gdriveProvider = new Provider(providerId, providerName);
|
||||||
gdriveProvider.defaultPublishFormat = "template";
|
gdriveProvider.defaultPublishFormat = "template";
|
||||||
gdriveProvider.exportPreferencesInputIds = [
|
gdriveProvider.exportPreferencesInputIds = [
|
||||||
providerId + "-parentid",
|
providerId + "-parentid"
|
||||||
];
|
];
|
||||||
|
|
||||||
function createSyncIndex(id) {
|
function createSyncIndex(id) {
|
||||||
|
@ -8,7 +8,7 @@ define([
|
|||||||
gistProvider.publishPreferencesInputIds = [
|
gistProvider.publishPreferencesInputIds = [
|
||||||
"gist-public"
|
"gist-public"
|
||||||
];
|
];
|
||||||
gistProvider.sharingAttributes = [
|
gistProvider.viewerSharingAttributes = [
|
||||||
"gistId",
|
"gistId",
|
||||||
"filename"
|
"filename"
|
||||||
];
|
];
|
||||||
|
@ -27,35 +27,46 @@ define([
|
|||||||
isOffline = isOfflineParam;
|
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];
|
var provider = providerMap[attributes.provider.providerId];
|
||||||
// Don't create link if provider is not compatible for sharing
|
|
||||||
if(provider === undefined ||
|
if(provider === undefined ||
|
||||||
// Or document is not published in markdown format
|
// Or document is not published in markdown format
|
||||||
attributes.format != "markdown") {
|
attributes.format != "markdown") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var url = [
|
var params = {
|
||||||
constants.MAIN_URL,
|
provider: provider.providerId
|
||||||
'viewer#!provider=',
|
};
|
||||||
provider.providerId
|
if(!provider.viewerSharingAttributes) {
|
||||||
];
|
return;
|
||||||
_.each(provider.sharingAttributes, function(attributeName) {
|
}
|
||||||
url.push('&');
|
_.each(provider.viewerSharingAttributes, function(attributeName) {
|
||||||
url.push(attributeName);
|
params[attributeName] = attributes[attributeName];
|
||||||
url.push('=');
|
|
||||||
url.push(encodeURIComponent(attributes[attributeName]));
|
|
||||||
});
|
});
|
||||||
attributes.sharingLink = url.join('');
|
return params;
|
||||||
callback();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
eventMgr.addListener("onReady", function() {
|
eventMgr.addListener("onReady", function() {
|
||||||
if(window.viewerMode === false) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Check parameters to see if we have to download a shared document
|
// Check parameters to see if we have to download a shared document
|
||||||
var providerId = utils.getURLParameter("provider");
|
var providerId = utils.getURLParameter("provider");
|
||||||
|
if(window.viewerMode) {
|
||||||
if(providerId === undefined) {
|
if(providerId === undefined) {
|
||||||
providerId = "download";
|
providerId = "download";
|
||||||
}
|
}
|
||||||
@ -64,7 +75,7 @@ define([
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var importParameters = {};
|
var importParameters = {};
|
||||||
_.each(provider.sharingAttributes, function(attributeName) {
|
_.each(provider.viewerSharingAttributes, function(attributeName) {
|
||||||
var parameter = utils.getURLParameter(attributeName);
|
var parameter = utils.getURLParameter(attributeName);
|
||||||
if(!parameter) {
|
if(!parameter) {
|
||||||
importParameters = undefined;
|
importParameters = undefined;
|
||||||
@ -84,6 +95,7 @@ define([
|
|||||||
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
|
var fileDesc = fileMgr.createFile(title, content, undefined, undefined, true);
|
||||||
fileMgr.selectFile(fileDesc);
|
fileMgr.selectFile(fileDesc);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return sharing;
|
return sharing;
|
||||||
|
Loading…
Reference in New Issue
Block a user