2013-02-27 01:58:00 +00:00
|
|
|
/**
|
|
|
|
|
* Bookmarklet for Pinry
|
|
|
|
|
* Descrip: This is trying to be as standalone a script as possible hence
|
|
|
|
|
* why it has built in helpers and such when the rest of the
|
|
|
|
|
* scripts make use of helpers.js. In the future i want to remove
|
|
|
|
|
* all dependencies on jQuery.
|
|
|
|
|
* Authors: Pinry Contributors
|
2013-03-05 22:05:04 +00:00
|
|
|
* Updated: Mar 4th, 2013
|
2013-02-27 01:58:00 +00:00
|
|
|
* Require: None (dynamically loads jQuery if needed)
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start jQuery Check
|
|
|
|
|
if (!window.jQuery) {
|
|
|
|
|
var body = document.getElementsByTagName('body')[0];
|
2013-02-25 04:34:49 +00:00
|
|
|
var script = document.createElement('script');
|
2014-05-28 15:47:55 +02:00
|
|
|
script.onload = main;
|
2013-02-25 04:34:49 +00:00
|
|
|
script.src = '//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js';
|
2013-03-03 11:06:22 -05:00
|
|
|
body.appendChild(script);
|
2014-05-28 15:47:55 +02:00
|
|
|
} else
|
|
|
|
|
jQuery(document).ready(main);
|
2013-02-27 01:58:00 +00:00
|
|
|
// End jQuery Check
|
2013-02-25 04:34:49 +00:00
|
|
|
|
2014-05-28 15:47:55 +02:00
|
|
|
function main() {
|
|
|
|
|
var $ = jQuery;
|
|
|
|
|
|
2014-05-31 13:45:10 +02:00
|
|
|
function closePinry() {
|
|
|
|
|
$('#pinry-images').add('#pinry-bookmarklet').remove();
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-28 15:47:55 +02:00
|
|
|
// Start Helper Functions
|
|
|
|
|
function getFormUrl() {
|
|
|
|
|
var hostUrl = $('#pinry-bookmarklet').attr('src').split('/')[2];
|
|
|
|
|
var formUrl = '/pins/pin-form/?pin-image-url=';
|
|
|
|
|
return 'http://'+hostUrl+formUrl;
|
|
|
|
|
}
|
|
|
|
|
// End Helper Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start View Functions
|
|
|
|
|
function pageView() {
|
|
|
|
|
var pinryImages = document.createElement('div');
|
|
|
|
|
pinryImages.id = 'pinry-images';
|
|
|
|
|
$(pinryImages).css({
|
|
|
|
|
'position': 'absolute',
|
|
|
|
|
'z-index': '9001',
|
|
|
|
|
'background': 'rgba(0, 0, 0, 0.7)',
|
|
|
|
|
'padding-top': '70px',
|
|
|
|
|
'top': '0',
|
|
|
|
|
'left': '0',
|
|
|
|
|
'right': '0',
|
|
|
|
|
'height': $(document).height(),
|
|
|
|
|
'text-align': 'center',
|
|
|
|
|
'width': '100%'
|
|
|
|
|
});
|
|
|
|
|
var pinryBar = document.createElement('div');
|
|
|
|
|
pinryBar.id = 'pinry-bar';
|
|
|
|
|
$(pinryBar).css({
|
|
|
|
|
'background': 'black',
|
|
|
|
|
'padding': '15px',
|
|
|
|
|
'position': 'absolute',
|
|
|
|
|
'z-index': '9002',
|
|
|
|
|
'width': '100%',
|
|
|
|
|
'top': 0,
|
|
|
|
|
'border-bottom': '1px solid #555',
|
|
|
|
|
'color': 'white',
|
|
|
|
|
'text-align': 'center',
|
|
|
|
|
'font-size': '22px'
|
|
|
|
|
});
|
|
|
|
|
$('body').append(pinryImages);
|
|
|
|
|
$('#pinry-images').append(pinryBar);
|
2014-05-31 13:45:10 +02:00
|
|
|
$('#pinry-bar').html('Pinry Bookmarklet').click(closePinry);
|
|
|
|
|
$(document).keyup(function (e) {
|
|
|
|
|
if (e.keyCode == 27) // ESC key
|
|
|
|
|
closePinry();
|
|
|
|
|
});
|
2014-05-28 15:47:55 +02:00
|
|
|
$(window).scrollTop(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function imageView(imageUrl) {
|
|
|
|
|
// Requires that pageView has been created already
|
2014-05-31 13:50:01 +02:00
|
|
|
var image = $('<div/>');
|
|
|
|
|
image.css({
|
2014-05-28 15:47:55 +02:00
|
|
|
'background-image': 'url('+imageUrl+')',
|
|
|
|
|
'background-position': 'center center',
|
|
|
|
|
'background-repeat': 'no-repeat',
|
2014-05-31 13:50:01 +02:00
|
|
|
'background-size': 'cover',
|
2014-05-28 15:47:55 +02:00
|
|
|
'display': 'inline-block',
|
2014-05-31 13:50:01 +02:00
|
|
|
'color': 'blue',
|
|
|
|
|
'text-shadow': 'yellow 0px 0px 2px, yellow 0px 0px 3px, yellow 0px 0px 4px',
|
2014-05-28 15:47:55 +02:00
|
|
|
'width': '200px',
|
|
|
|
|
'height': '200px',
|
|
|
|
|
'margin': '15px',
|
|
|
|
|
'cursor': 'pointer',
|
|
|
|
|
'border': '1px solid #555'
|
|
|
|
|
});
|
2014-05-31 13:50:01 +02:00
|
|
|
image.click(function() {
|
2014-05-28 16:10:08 +02:00
|
|
|
var popUrl = getFormUrl()+encodeURIComponent(imageUrl);
|
2014-05-28 15:47:55 +02:00
|
|
|
window.open(popUrl);
|
2014-05-31 13:45:10 +02:00
|
|
|
closePinry();
|
2014-05-28 15:47:55 +02:00
|
|
|
});
|
2014-05-31 13:50:01 +02:00
|
|
|
return image.appendTo('#pinry-images');
|
2014-05-28 15:47:55 +02:00
|
|
|
}
|
|
|
|
|
// End View Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start Active Functions
|
|
|
|
|
function addAllImagesToPageView() {
|
|
|
|
|
var images = $('body').find('img');
|
|
|
|
|
images.each(function() {
|
2014-05-31 13:50:01 +02:00
|
|
|
var t = $(this),
|
|
|
|
|
w = this.naturalWidth || t.width(),
|
|
|
|
|
h = this.naturalHeight || t.height();
|
|
|
|
|
if (w > 200 && h > 200)
|
|
|
|
|
imageView(this.src).text(w + '\u00D7' + h);
|
2014-05-28 15:47:55 +02:00
|
|
|
});
|
|
|
|
|
return images;
|
|
|
|
|
}
|
|
|
|
|
// End Active Functions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Start Init
|
|
|
|
|
pageView(); // Build page before we insert images
|
|
|
|
|
addAllImagesToPageView(); // Add all images on page to our new pageView
|
|
|
|
|
// End Init
|
|
|
|
|
}
|