mirror of
https://github.com/pinry/pinry.git
synced 2025-11-13 16:45:41 +01:00
Greatly improved bookmarklet pinning functionality, much better pin form
This commit is contained in:
@@ -3,6 +3,10 @@ body {
|
|||||||
background: #eee;
|
background: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#bookmarklet {
|
#bookmarklet {
|
||||||
cursor: move;
|
cursor: move;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ $(document).ready(function() {
|
|||||||
});
|
});
|
||||||
$(image).click(function() {
|
$(image).click(function() {
|
||||||
var popUrl = getFormUrl()+imageUrl;
|
var popUrl = getFormUrl()+imageUrl;
|
||||||
window.open(popUrl, '', 'width=600,height=500,toolbar=0,menubar=0');
|
window.open(popUrl, '', 'width=590,height=439,toolbar=0,menubar=0');
|
||||||
$('#pinry-images').remove();
|
$('#pinry-images').remove();
|
||||||
});
|
});
|
||||||
return $('#pinry-images').append(image);
|
return $('#pinry-images').append(image);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ function cleanTags(tags) {
|
|||||||
tags = tags.split(',');
|
tags = tags.split(',');
|
||||||
for (var i in tags) tags[i] = tags[i].trim();
|
for (var i in tags) tags[i] = tags[i].trim();
|
||||||
}
|
}
|
||||||
return tags
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -26,3 +26,21 @@ function getPinData(pinId) {
|
|||||||
var apiUrl = '/api/v1/pin/'+pinId+'/?format=json';
|
var apiUrl = '/api/v1/pin/'+pinId+'/?format=json';
|
||||||
return $.get(apiUrl);
|
return $.get(apiUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function postPinData(data) {
|
||||||
|
return $.ajax({
|
||||||
|
type: "post",
|
||||||
|
url: "/api/v1/pin/",
|
||||||
|
contentType: 'application/json',
|
||||||
|
data: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getUrlParameter(name) {
|
||||||
|
var decode = decodeURI(
|
||||||
|
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
|
||||||
|
);
|
||||||
|
if (decode == 'null') return null;
|
||||||
|
else return decode;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,97 +1,103 @@
|
|||||||
|
/**
|
||||||
|
* Pin Form for Pinry
|
||||||
|
* Descrip: This is for creation new pins on everything, the bookmarklet, on the
|
||||||
|
* site and even editing pins in some limited situations.
|
||||||
|
* Authors: Pinry Contributors
|
||||||
|
* Updated: Feb 27th, 2013
|
||||||
|
* Require: jQuery, Pinry JavaScript Helpers
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
$(window).load(function() {
|
$(window).load(function() {
|
||||||
var currentPin;
|
var currentPin;
|
||||||
|
// Start Helper Functions
|
||||||
|
function getFormData() {
|
||||||
|
return {
|
||||||
|
submitter: currentUser,
|
||||||
|
url: $('#pin-form-image-url').val(),
|
||||||
|
description: $('#pin-form-description').val(),
|
||||||
|
tags: cleanTags($('#pin-form-tags').val())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function createPin() {
|
function createPinPreviewFromForm() {
|
||||||
var template = Handlebars.compile($('#pins-template').html());
|
var context = {pins: [{
|
||||||
var html = template({
|
|
||||||
pins: [{
|
|
||||||
submitter: currentUser,
|
submitter: currentUser,
|
||||||
image: {
|
image: {thumbnail: {image: $('#pin-form-image-url').val()}},
|
||||||
standard: {
|
|
||||||
image: $('#pin-form-image-url').val()
|
|
||||||
},
|
|
||||||
thumbnail: {
|
|
||||||
image: $('#pin-form-image-url').val()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
description: $('#pin-form-description').val(),
|
description: $('#pin-form-description').val(),
|
||||||
tags: cleanTags($('#pin-form-tags').val())
|
tags: cleanTags($('#pin-form-tags').val())
|
||||||
}]
|
}]},
|
||||||
});
|
html = renderTemplate('#pins-template', context),
|
||||||
currentPin = html;
|
preview = $('#pin-form-image-preview');
|
||||||
return html
|
preview.html(html);
|
||||||
|
preview.find('.pin').width(200);
|
||||||
|
preview.find('.pin .text').width(140);
|
||||||
|
if (preview.height() > 305)
|
||||||
|
$('#pin-form .modal-body').height(preview.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
function createPreview() {
|
function dismissModal(modal) {
|
||||||
$('#pin-form-image-preview').html(createPin());
|
modal.modal('hide');
|
||||||
$('#pin-form-image-preview .pin').css('width', '200px');
|
setTimeout(function() {
|
||||||
$('#pin-form-image-preview .pin .text').css('width', '140px');
|
modal.remove();
|
||||||
var pinHeight = $('#pin-form-image-preview .pin').height();
|
}, 200);
|
||||||
if (pinHeight > 305)
|
|
||||||
$('#pin-form .modal-body').css('height', String(pinHeight)+'px');
|
|
||||||
}
|
}
|
||||||
|
// End Helper Functions
|
||||||
|
|
||||||
|
|
||||||
|
// Start View Functions
|
||||||
function createPinForm() {
|
function createPinForm() {
|
||||||
var template = Handlebars.compile($('#pin-form-template').html());
|
$('body').append(renderTemplate('#pin-form-template', ''));
|
||||||
var html = template();
|
var modal = $('#pin-form'),
|
||||||
$('body').append(html);
|
formFields = [$('#pin-form-image-url'), $('#pin-form-description'),
|
||||||
$('#pin-form-image-url').bind('propertychange keyup input paste', function() {
|
$('#pin-form-tags')],
|
||||||
createPreview();
|
pinFromUrl = getUrlParameter('pin-image-url');
|
||||||
});
|
modal.modal('show');
|
||||||
$('#pin-form-description').bind('propertychange keyup input paste', function() {
|
for (var i in formFields) {
|
||||||
createPreview();
|
formFields[i].bind('propertychange keyup input paste', function() {
|
||||||
});
|
createPinPreviewFromForm()
|
||||||
$('#pin-form-tags').bind('propertychange keyup input paste', function() {
|
});
|
||||||
createPreview();
|
|
||||||
});
|
|
||||||
|
|
||||||
function getURLParameter(name) {
|
|
||||||
return decodeURI(
|
|
||||||
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (getURLParameter('pin-image-url') != 'null') {
|
if (pinFromUrl) {
|
||||||
$('#pin-form-image-url').val(getURLParameter('pin-image-url'));
|
$('#pin-form-image-url').val(pinFromUrl);
|
||||||
createPreview();
|
$('.navbar').css('display', 'none');
|
||||||
|
modal.css({
|
||||||
|
'margin-top': -35,
|
||||||
|
'margin-left': -281
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('#pin-form-submit').click(function(e) {
|
$('#pin-form-submit').click(function(e) {
|
||||||
var tags = cleanTags($('#pin-form-tags').val());
|
e.preventDefault();
|
||||||
$.ajax({
|
var data = {
|
||||||
type: "post",
|
|
||||||
url: "/api/v1/pin/",
|
|
||||||
contentType: 'application/json',
|
|
||||||
data: JSON.stringify({
|
|
||||||
submitter: '/api/v1/user/'+currentUser.id+'/',
|
submitter: '/api/v1/user/'+currentUser.id+'/',
|
||||||
url: $('#pin-form-image-url').val(),
|
url: $('#pin-form-image-url').val(),
|
||||||
description: $('#pin-form-description').val(),
|
description: $('#pin-form-description').val(),
|
||||||
tags: tags
|
tags: cleanTags($('#pin-form-tags').val())
|
||||||
}),
|
|
||||||
success: function() {
|
|
||||||
$('#pins').prepend(currentPin);
|
|
||||||
},
|
},
|
||||||
error: function() {
|
promise = postPinData(data);
|
||||||
alert("Something went wrong. :(");
|
promise.success(function() {
|
||||||
}
|
if (pinFromUrl) return window.close();
|
||||||
|
$('#pins').prepend(currentPin);
|
||||||
|
dismissModal(modal);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#pin-form-close').click(function() {
|
|
||||||
$('#pin-form').remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#pin-form').remove();
|
|
||||||
|
|
||||||
e.preventDefault();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#pin-form-close').click(function() {
|
$('#pin-form-close').click(function() {
|
||||||
$('#pin-form').remove();
|
if (pinFromUrl) return window.close();
|
||||||
|
dismissModal(modal);
|
||||||
});
|
});
|
||||||
|
createPinPreviewFromForm();
|
||||||
|
}
|
||||||
|
// End View Functions
|
||||||
|
|
||||||
|
|
||||||
|
// Start Init
|
||||||
|
window.pinForm = function() {
|
||||||
|
createPinForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($('#display-pin-form').length >= 1) createPinForm();
|
if (getUrlParameter('pin-image-url')) {
|
||||||
|
|
||||||
$('#call-pin-form').click(function() {
|
|
||||||
createPinForm();
|
createPinForm();
|
||||||
});
|
}
|
||||||
|
// End Init
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
<ul class="nav pull-right">
|
<ul class="nav pull-right">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<li>{% include "includes/bookmarklet_link.html" %}</li>
|
<li>{% include "includes/bookmarklet_link.html" %}</li>
|
||||||
<li><a href="#" id="call-pin-form">New Pin</a></li>
|
<li><a onclick="pinForm()">New Pin</a></li>
|
||||||
<li><a href="{% url 'core:logout' %}">Logout</a></li>
|
<li><a href="{% url 'core:logout' %}">Logout</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="{% url 'core:login' %}">Login</a></li>
|
<li><a href="{% url 'core:login' %}">Login</a></li>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% verbatim %}
|
{% verbatim %}
|
||||||
<script id="pin-form-template" type="text/x-handlebars-template">
|
<script id="pin-form-template" type="text/x-handlebars-template">
|
||||||
<div class="modal" id="pin-form">
|
<div class="modal hide fade" id="pin-form">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<h3>New Pin</h3>
|
<h3>New Pin</h3>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user