Stackedit/js/blogger-provider.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2013-04-21 00:07:27 +00:00
define(["jquery", "core", "google-helper"], function($, core, 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-04-22 22:35:29 +00:00
var blogUrl = core.getInputValue($("#input-publish-blogger-url"), event);
if(blogUrl !== undefined) {
publishAttributes.blogUrl = core.checkUrl(blogUrl);
}
2013-04-28 22:33:17 +00:00
publishAttributes.postId = $("#input-publish-postid").val() || undefined;
2013-04-22 22:35:29 +00:00
publishAttributes.labelList = [];
2013-04-28 22:33:17 +00:00
var labels = $("#input-publish-labels").val() || undefined;
2013-04-22 22:35:29 +00:00
if(labels !== undefined) {
publishAttributes.labelList = _.chain(labels.split(","))
.map(function(label) {
return core.trim(label);
}).compact().value();
}
2013-04-15 21:15:15 +00:00
if(event.isPropagationStopped()) {
return undefined;
}
return publishAttributes;
};
return bloggerProvider;
});