From f5ef3a0c2b8793c41c0af0a2debc53885a53cec0 Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Mon, 25 Feb 2013 04:34:49 +0000 Subject: [PATCH] Get bookmarklet mostly setup --- pinry/static/js/bookmarklet.js | 54 +++++++++++++++++++++++++++++++++++ pinry/static/js/pinry.js | 7 +++++ pinry/templates/core/base.html | 1 + pinry/templates/pins/bookmarklet.html | 7 +++++ 4 files changed, 69 insertions(+) create mode 100644 pinry/static/js/bookmarklet.js create mode 100644 pinry/templates/pins/bookmarklet.html diff --git a/pinry/static/js/bookmarklet.js b/pinry/static/js/bookmarklet.js new file mode 100644 index 0000000..12e91a0 --- /dev/null +++ b/pinry/static/js/bookmarklet.js @@ -0,0 +1,54 @@ +if (!jQuery) { + var head = document.getElementsByTagName('head')[0]; + var script = document.createElement('script'); + script.src = '//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js'; + head.appendChild(script); +} + +$(document).ready(function() { + function createPage() { + var documentHeight = $(document).height(); + + $('body').append('
'); + $('.pinry-images').css({ + 'position': 'absolute', + 'z-index': '9001', + 'background': 'rgba(255, 255, 255, 0.7)', + 'top': '0', + 'left': '0', + 'right': '0', + 'height': documentHeight + }); + } + + function template(imageUrl) { + var wrapper = document.createElement('div'); + wrapper.class = 'pinry-image-wrapper'; + image = document.createElement('img'); + image.src = imageUrl; + image = $(image).css({ + 'max-width': '200px', + }); + wrapper = $(wrapper); + wrapper.append(image); + wrapper.css({ + 'display': 'inline-block', + 'padding': '15px', + 'cursor': 'pointer' + }); + wrapper.click(function() { + alert('Added'); + $('.pinry-images').remove(); + }); + return wrapper; + } + + createPage(); + + var images = $('body').find('img'); + for (var i=0; i < images.length; i++) { + var image = images.eq(i); + var imageHtml = template(image.attr('src')); + $('.pinry-images').append(imageHtml); + } +}); diff --git a/pinry/static/js/pinry.js b/pinry/static/js/pinry.js index df57e27..ab660ff 100644 --- a/pinry/static/js/pinry.js +++ b/pinry/static/js/pinry.js @@ -1,6 +1,13 @@ $(window).load(function() { /** + * Setup our bookmarklet href + */ + var bookmarkletUrl = 'http://'+document.location.hostname+'/static/js/bookmarklet.js'; + var bookmarklet = "javascript:void((function(d){var s=d.createElement('script');s.src='"+bookmarkletUrl+"?'+Math.random()*9001;d.body.appendChild(s)})(document));"; + $('.bookmarklet-link').attr('href', bookmarklet); + + /** * tileLayout will simply tile/retile the block/pin container when run. This * was put into a function in order to adjust frequently on screen size * changes. diff --git a/pinry/templates/core/base.html b/pinry/templates/core/base.html index abf53a9..a10c4ad 100644 --- a/pinry/templates/core/base.html +++ b/pinry/templates/core/base.html @@ -23,6 +23,7 @@