Merge branch 'bitly'

This commit is contained in:
Sacha Greif 2013-07-04 12:06:41 +09:00
commit 7a92f405f8
10 changed files with 52 additions and 6 deletions

View file

@ -1420,13 +1420,13 @@ form .control-group, .accounts-dialog .control-group {
margin-left: 150px;
position: relative; }
/* line 19, ../sass/modules/_forms.scss */
form .control-group .controls .get-title-link, .accounts-dialog .control-group .controls .get-title-link {
form .control-group .controls .inline-link, .accounts-dialog .control-group .controls .inline-link {
position: absolute;
display: block;
top: 2px;
right: 8px; }
/* line 24, ../sass/modules/_forms.scss */
form .control-group .controls .get-title-link.loading, .accounts-dialog .control-group .controls .get-title-link.loading {
form .control-group .controls .inline-link.loading, .accounts-dialog .control-group .controls .inline-link.loading {
background: url(/img/loading.gif) center center no-repeat;
height: 22px;
width: 18px;

View file

@ -25,6 +25,7 @@ Setting = FormModel.extend({
clickyId:'',
goSquaredId: '',
embedlyId: '',
bitlyToken: '',
footerCode: '',
extraCode: '',
notes: ''
@ -40,6 +41,7 @@ Setting = FormModel.extend({
this.overwriteTitle('mixpanelId', '<a href="http://mixpanel.com/">Mixpanel</a> ID');
this.overwriteTitle('clickyId', '<a href="http://getclicky.com/">Clicky</a> ID');
this.overwriteTitle('goSquaredId', '<a href="http://gosquared.com/">GoSquared</a> ID');
this.overwriteTitle('bitlyToken', '<a href="https://bitly.com/a/oauth_apps">Bitly</a> Token');
this.overwriteTitle('logoUrl', 'Logo URL');
this.overwriteType('footerCode', 'textarea');
this.overwriteType('extraCode', 'textarea');

View file

@ -16,7 +16,7 @@ form, .accounts-dialog{
.controls{
margin-left:150px;
position:relative;
.get-title-link{
.inline-link{
position:absolute;
display:block;
top:2px;

View file

@ -14,6 +14,12 @@
<label class="control-label post-form-url">URL</label>
<div class="controls"><input id="url" type="text" value="{{url}}" /></div>
</div>
{{#if shorten}}
<div class="control-group">
<label class="control-label post-form-url">Short URL</label>
<div class="controls"><input id="short-url" type="text" value="{{shortUrl}}" /></div>
</div>
{{/if}}
<div class="control-group">
<label class="control-label post-form-body">Body</label>
<div class="controls" id="editor"><textarea id="body" value="" class="input-xlarge">{{body}}</textarea></div>

View file

@ -51,7 +51,10 @@ Template.post_edit.helpers({
},
hasStatusRejected: function(){
return this.status == STATUS_REJECTED ? 'checked' : '';
},
},
shorten: function(){
return !!getSetting('bitlyToken');
}
});
Template.post_edit.rendered = function(){
@ -78,6 +81,7 @@ Template.post_edit.events = {
var post = Posts.findOne(selectedPostId);
var categories = [];
var url = $('#url').val();
var shortUrl = $('#short-url').val();
var status = parseInt($('input[name=status]:checked').val());
$('input[name=category]:checked').each(function() {
@ -88,6 +92,7 @@ Template.post_edit.events = {
var properties = {
headline: $('#title').val(),
shortUrl: shortUrl,
body: instance.editor.exportFile(),
categories: categories,
};

View file

@ -8,7 +8,7 @@
</div>
<div class="control-group">
<label class="control-label">Title</label>
<div class="controls"><input id="title" type="text" value="" /><a href="#" class="get-title-link">Suggest title</a></div>
<div class="controls"><input id="title" type="text" value="" /><a href="#" class="get-title-link inline-link">Suggest title</a></div>
</div>
<div class="control-group">
<label class="control-label">Message</label>

View file

@ -36,6 +36,7 @@ Template.post_submit.events = {
var title= $('#title').val();
var url = $('#url').val();
var shortUrl = $('#short-url').val();
var body = instance.editor.exportFile();
var categories=[];
var sticky=!!$('#sticky').attr('checked');
@ -50,6 +51,7 @@ Template.post_submit.events = {
var properties = {
headline: title
, body: body
, shortUrl: shortUrl
, categories: categories
, sticky: sticky
, submitted: submitted
@ -95,4 +97,5 @@ Template.post_submit.events = {
$(".get-title-link").removeClass("loading");
}
}
};

View file

@ -16,7 +16,6 @@ Template.posts_list.helpers({
return this.fetch();
},
postsReady: function() {
console.log('checking postsReady', this.ready(), this);
return this.ready();
},
allPostsLoaded: function(){

View file

@ -44,6 +44,23 @@ Meteor.methods({
throw new Meteor.Error(605, 'Sorry, you cannot submit more than '+maxPostsPer24Hours+' posts per day');
}
// shorten URL
if(!this.isSimulation && (token=getSetting('bitlyToken'))){
var shortenResponse = Meteor.http.get(
"https://api-ssl.bitly.com/v3/shorten?",
{
timeout: 5000,
params:{
"format": "json",
"access_token": token,
"longUrl": post.url
}
}
);
if(shortenResponse.statusCode == 200)
post.shortUrl = shortenResponse.data.data.url
}
post = _.extend(post, {
headline: headline,
body: body,

View file

@ -78,6 +78,20 @@ slugify = function(text) {
text = text.toLowerCase();
return text;
}
getShortUrl = function(url, func){
$.getJSON(
"https://api-ssl.bitly.com/v3/shorten?callback=?",
{
"format": "json",
"access_token": getSetting('bitlyToken'),
"longUrl": url
},
function(response){
func(response.data.url);
}
);
}
// ---------------------------------- String Helper Functions ----------------------------------- //
cleanUp = function(s){
return stripHTML(s);