-
-
Save taizooo/115532 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
models.register( { | |
name: 'HatenaDiary', | |
ICON: 'http://d.hatena.ne.jp/favicon.ico', | |
POST_URL : 'http://d.hatena.ne.jp', | |
check : function(ps){ | |
return (/(regular|photo|quote|link)/).test(ps.type) && !ps.file; | |
}, | |
converters: { | |
getTitle: function(ps){ | |
return Hatena.reprTags(ps.tags) + '[' + ps.type + ']' | |
//return Hatena.reprTags(ps.tags) + '[' + ps.type + ']'+ (ps.page || '') | |
}, | |
renderingTemplates: { | |
regular: '<p>{ps.description}</p>', | |
photo: '<p><blockquote class="tombloo_photo" cite={ps.pageUrl} title={ps.page}><img src={ps.itemUrl} /></blockquote></p>', | |
link: '<p><div class="tombloo_link"><a href={ps.pageUrl} title={ps.page}>{ps.page}</a></div></p>', | |
quote: '<p><blockquote class="tombloo_quote" cite={ps.pageUrl} title={ps.page}>{ps.body}</blockquote></p>', | |
}, | |
__noSuchMethod__: function(name, args){ | |
var ps = args[0]; | |
return { | |
title: (name == 'regular') ? ps.item : this.getTitle(ps), | |
//title: (name == 'regular') ? '' : this.getTitle(ps), | |
body: eval( this.renderingTemplates[name] ).toString() | |
}; | |
}, | |
}, | |
post : function(params){ | |
var content; | |
var self = this; | |
return models.Hatena.getToken().addCallback(function(token){ | |
content = self.converters[params.type](params); | |
content.rkm = token; | |
return models.Hatena.getCurrentUser(); | |
}).addCallback(function(id){ | |
var endpoint = [self.POST_URL, id, ''].join('/'); | |
return request( endpoint, { | |
redirectionLimit : 0, | |
referrer : endpoint, | |
sendContent : content | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment