2013-02-26 01:54:02 +00:00
|
|
|
$(window).load(function() {
|
2013-02-26 05:23:31 +00:00
|
|
|
var currentPin;
|
|
|
|
|
|
|
|
|
|
function createPin() {
|
|
|
|
|
var template = Handlebars.compile($('#pins-template').html());
|
|
|
|
|
var html = template({
|
|
|
|
|
pins: [{
|
|
|
|
|
submitter: currentUser,
|
|
|
|
|
image: {
|
|
|
|
|
standard: {
|
|
|
|
|
image: $('#pin-form-image-url').val()
|
|
|
|
|
},
|
|
|
|
|
thumbnail: {
|
|
|
|
|
image: $('#pin-form-image-url').val()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
description: $('#pin-form-description').val(),
|
2013-02-27 06:03:05 +00:00
|
|
|
tags: cleanTags($('#pin-form-tags').val())
|
2013-02-26 05:23:31 +00:00
|
|
|
}]
|
|
|
|
|
});
|
|
|
|
|
currentPin = html;
|
|
|
|
|
return html
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function createPreview() {
|
|
|
|
|
$('#pin-form-image-preview').html(createPin());
|
|
|
|
|
$('#pin-form-image-preview .pin').css('width', '200px');
|
|
|
|
|
$('#pin-form-image-preview .pin .text').css('width', '140px');
|
|
|
|
|
var pinHeight = $('#pin-form-image-preview .pin').height();
|
|
|
|
|
if (pinHeight > 305)
|
|
|
|
|
$('#pin-form .modal-body').css('height', String(pinHeight)+'px');
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 01:54:02 +00:00
|
|
|
function createPinForm() {
|
|
|
|
|
var template = Handlebars.compile($('#pin-form-template').html());
|
|
|
|
|
var html = template();
|
|
|
|
|
$('body').append(html);
|
|
|
|
|
$('#pin-form-image-url').bind('propertychange keyup input paste', function() {
|
2013-02-26 05:23:31 +00:00
|
|
|
createPreview();
|
|
|
|
|
});
|
|
|
|
|
$('#pin-form-description').bind('propertychange keyup input paste', function() {
|
|
|
|
|
createPreview();
|
|
|
|
|
});
|
|
|
|
|
$('#pin-form-tags').bind('propertychange keyup input paste', function() {
|
|
|
|
|
createPreview();
|
2013-02-26 01:54:02 +00:00
|
|
|
});
|
2013-02-26 23:20:50 +00:00
|
|
|
|
|
|
|
|
function getURLParameter(name) {
|
|
|
|
|
return decodeURI(
|
|
|
|
|
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
if (getURLParameter('pin-image-url') != 'null') {
|
|
|
|
|
$('#pin-form-image-url').val(getURLParameter('pin-image-url'));
|
|
|
|
|
createPreview();
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 01:54:02 +00:00
|
|
|
$('#pin-form-submit').click(function(e) {
|
2013-02-27 06:03:05 +00:00
|
|
|
var tags = cleanTags($('#pin-form-tags').val());
|
2013-02-26 01:54:02 +00:00
|
|
|
$.ajax({
|
|
|
|
|
type: "post",
|
|
|
|
|
url: "/api/v1/pin/",
|
|
|
|
|
contentType: 'application/json',
|
|
|
|
|
data: JSON.stringify({
|
2013-02-26 05:23:31 +00:00
|
|
|
submitter: '/api/v1/user/'+currentUser.id+'/',
|
2013-02-26 01:54:02 +00:00
|
|
|
url: $('#pin-form-image-url').val(),
|
|
|
|
|
description: $('#pin-form-description').val(),
|
|
|
|
|
tags: tags
|
2013-02-26 05:23:31 +00:00
|
|
|
}),
|
|
|
|
|
success: function() {
|
|
|
|
|
$('#pins').prepend(currentPin);
|
|
|
|
|
},
|
|
|
|
|
error: function() {
|
|
|
|
|
alert("Something went wrong. :(");
|
|
|
|
|
}
|
2013-02-26 01:54:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#pin-form-close').click(function() {
|
|
|
|
|
$('#pin-form').remove();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#pin-form').remove();
|
|
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#pin-form-close').click(function() {
|
|
|
|
|
$('#pin-form').remove();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-26 23:20:50 +00:00
|
|
|
if ($('#display-pin-form').length >= 1) createPinForm();
|
|
|
|
|
|
2013-02-26 01:54:02 +00:00
|
|
|
$('#call-pin-form').click(function() {
|
|
|
|
|
createPinForm();
|
|
|
|
|
});
|
|
|
|
|
});
|