Stackedit/js/blogger-provider.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2013-05-27 19:45:33 +00:00
define([
"underscore",
"utils",
"google-helper"
], function(_, utils, googleHelper) {
2013-04-15 21:15:15 +00:00
2013-05-04 00:05:58 +00:00
var PROVIDER_BLOGGER = "blogger";
2013-04-15 21:15:15 +00:00
var bloggerProvider = {
providerId: PROVIDER_BLOGGER,
providerName: "Blogger",
defaultPublishFormat: "html",
publishPreferencesInputIds: ["blogger-url"]
2013-04-15 21:15:15 +00:00
};
bloggerProvider.publish = function(publishAttributes, title, content, callback) {
googleHelper.uploadBlogger(
publishAttributes.blogUrl,
publishAttributes.blogId,
publishAttributes.postId,
2013-04-22 22:35:29 +00:00
publishAttributes.labelList,
title,
content,
2013-04-20 00:14:20 +00:00
function(error, blogId, postId) {
if(error) {
callback(error);
return;
}
publishAttributes.blogId = blogId;
publishAttributes.postId = postId;
callback();
2013-04-15 21:15:15 +00:00
}
);
2013-04-15 21:15:15 +00:00
};
bloggerProvider.newPublishAttributes = function(event) {
var publishAttributes = {};
2013-05-25 18:13:59 +00:00
var blogUrl = utils.getInputTextValue("#input-publish-blogger-url", event);
2013-04-22 22:35:29 +00:00
if(blogUrl !== undefined) {
2013-05-25 18:13:59 +00:00
publishAttributes.blogUrl = utils.checkUrl(blogUrl);
2013-04-22 22:35:29 +00:00
}
2013-05-25 18:13:59 +00:00
publishAttributes.postId = utils.getInputTextValue("#input-publish-postid");
2013-04-22 22:35:29 +00:00
publishAttributes.labelList = [];
2013-05-25 18:13:59 +00:00
var labels = utils.getInputTextValue("#input-publish-labels");
2013-04-22 22:35:29 +00:00
if(labels !== undefined) {
2013-05-27 19:45:33 +00:00
publishAttributes.labelList = _.chain(
labels.split(",")
).map(function(label) {
return utils.trim(label);
}).compact().value();
2013-04-22 22:35:29 +00:00
}
2013-04-15 21:15:15 +00:00
if(event.isPropagationStopped()) {
return undefined;
}
return publishAttributes;
};
return bloggerProvider;
});