Stackedit/js/gist-provider.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-04-29 23:19:54 +00:00
define(["jquery", "core", "github-helper"], function($, core, githubHelper) {
2013-05-04 00:05:58 +00:00
var PROVIDER_GIST = "gist";
2013-04-29 23:19:54 +00:00
var gistProvider = {
providerId: PROVIDER_GIST,
2013-05-04 00:05:58 +00:00
providerName: "Gist",
sharingAttributes: ["gistId", "filename"]
2013-04-29 23:19:54 +00:00
};
gistProvider.publish = function(publishAttributes, title, content, callback) {
2013-05-04 00:05:58 +00:00
githubHelper.uploadGist(publishAttributes.gistId, publishAttributes.filename, publishAttributes.isPublic,
2013-04-29 23:19:54 +00:00
title, content, function(error, gistId) {
if(error) {
callback(error);
return;
}
publishAttributes.gistId = gistId;
callback();
}
);
};
gistProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
2013-05-02 00:02:57 +00:00
publishAttributes.gistId = $("#input-publish-gist-id").val() || undefined;
2013-04-29 23:19:54 +00:00
publishAttributes.filename = core.getInputValue($("#input-publish-filename"), event);
publishAttributes.isPublic = $("#input-publish-gist-public").is(":checked");
if(event.isPropagationStopped()) {
return undefined;
}
return publishAttributes;
};
2013-05-04 00:05:58 +00:00
gistProvider.importPublic = function(importParameters, callback) {
githubHelper.downloadGist(importParameters.gistId, importParameters.filename, callback);
};
2013-04-29 23:19:54 +00:00
return gistProvider;
});