Commits

Germano Guerrini committed 7d56f24

Added a README and the button image.

  • Participants
  • Parent commits 43ed12e

Comments (0)

Files changed (2)

File jquery.pinme.compressed.js

-(function(e){"use strict";e.fn.pinMe=function(t){var n={imageSelector:".pin_me",imageMediaAttribute:"src",imageDescriptionAttribute:"data-pin-description",buttonUrl:"pinit.png",buttonWidth:49,buttonHeight:25,buttonAlignment:"top-left",buttonPadding:5,buttonWillShowFunction:function(e){e.css({opacity:.75})},buttonOnMouseOverFunction:function(e,t){e.css({opacity:1,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"});t.css({opacity:.75,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"})},buttonOnMouseOutFunction:function(e,t){e.css({opacity:.75,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"});t.css({opacity:1,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"})},popupX:100,popupY:100,popupHeight:580,popupWidth:730,popupName:"pinterest"},r=e.extend(n,t);var i=function(e){var t=e.position(),n=e.width(),i=e.height();switch(r.buttonAlignment){case"top-right":return{top:t.top+r.buttonPadding,left:t.left+n-r.buttonWidth-r.buttonPadding};case"bottom-right":return{top:t.top+i-r.buttonHeight-r.buttonPadding,left:t.left+n-r.buttonWidth-r.buttonPadding};case"bottom-left":return{top:t.top+i-r.buttonHeight-r.buttonPadding,left:t.left+r.buttonPadding};default:return{top:t.top+r.buttonPadding,left:t.left+r.buttonPadding}}};var s=function(e){var t=e.attr(r.imageMediaAttribute);if(!t.match("^http://")){var n=t.substr(0,1)==="/"?"":"/";t=window.location.origin+n+t}return t};return this.each(function(){var t=e(this),n="pin_me_wrapper",o="http://pinterest.com/pin/create/button/",u="img"+r.imageSelector,a=e('<img src="'+r.buttonUrl+'" />'),f=e('<span class="'+n+'" />');t.find(u).wrap(f);e("."+n).on("mouseenter mouseleave",function(t){var n=e(this);if(t.type==="mouseenter"){var f=n.children(u).first(),l=s(f),c=f.attr(r.imageDescriptionAttribute);var h={url:document.URL,media:l,description:c};var p=i(f);a.css({position:"absolute",top:p.top,left:p.left,cursor:"pointer"});r.buttonWillShowFunction(a);a.on("click mouseover mouseout",function(t){var n=e(this);if(t.type==="click"){var i=o+"?"+e.param(h),s="screenX="+r.popupX+",screenY="+r.popupY+",width="+r.popupWidth+",height="+r.popupHeight;window.open(i,r.popupName,s)}else if(t.type==="mouseover"){r.buttonOnMouseOverFunction(n,f)}else if(t.type==="mouseout"){r.buttonOnMouseOutFunction(n,f)}});a.appendTo(n)}else{a.off();a.remove()}return false})})};e.pinMe=function(t){return e("body").pinMe(t)}})(jQuery)
+(function(e){"use strict";e.fn.pinMe=function(t){var n={imageSelector:".pinme",imageMediaAttribute:"src",imageDescriptionAttribute:"data-pin-description",buttonUrl:"img/pinit.png",buttonWidth:49,buttonHeight:25,buttonAlignment:"top-left",buttonPadding:5,buttonWillShowFunction:function(e){e.css({opacity:.75})},buttonOnMouseOverFunction:function(e,t){e.css({opacity:1,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"});t.css({opacity:.75,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"})},buttonOnMouseOutFunction:function(e,t){e.css({opacity:.75,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"});t.css({opacity:1,"-webkit-transition":"opacity .25s ease-out","-moz-transition":"opacity .25s ease-out",transition:"opacity .25s ease-out"})},popupX:100,popupY:100,popupHeight:580,popupWidth:730,popupName:"pinterest"},r=e.extend(n,t);var i=function(e){var t=e.position(),n=e.width(),i=e.height();switch(r.buttonAlignment){case"top-right":return{top:t.top+r.buttonPadding,left:t.left+n-r.buttonWidth-r.buttonPadding};case"bottom-right":return{top:t.top+i-r.buttonHeight-r.buttonPadding,left:t.left+n-r.buttonWidth-r.buttonPadding};case"bottom-left":return{top:t.top+i-r.buttonHeight-r.buttonPadding,left:t.left+r.buttonPadding};default:return{top:t.top+r.buttonPadding,left:t.left+r.buttonPadding}}};var s=function(e){var t=e.attr(r.imageMediaAttribute);if(!t.match("^http://")){var n=t.substr(0,1)==="/"?"":"/";t=window.location.origin+n+t}return t};return this.each(function(){var t=e(this),n="http://pinterest.com/pin/create/button/",o="img"+r.imageSelector,u=e('<img src="'+r.buttonUrl+'" id="pinme_button" />'),a="pinme_wrapper",f=e('<span class="'+a+'" />');t.find(o).wrap(f);e("."+a).on("mouseenter mouseleave",function(t){var a=e(this);if(t.type==="mouseenter"){var f=a.children(o).first(),l=s(f),c=f.attr(r.imageDescriptionAttribute);var h={url:document.URL,media:l,description:c};var p=i(f);u.css({position:"absolute",top:p.top,left:p.left,cursor:"pointer"});r.buttonWillShowFunction(u);u.on("click mouseover mouseout",function(t){var i=e(this);if(t.type==="click"){var s=n+"?"+e.param(h),o="screenX="+r.popupX+",screenY="+r.popupY+",width="+r.popupWidth+",height="+r.popupHeight;window.open(s,r.popupName,o)}else if(t.type==="mouseover"){r.buttonOnMouseOverFunction(i,f)}else if(t.type==="mouseout"){r.buttonOnMouseOutFunction(i,f)}});u.appendTo(a)}else{u.off();u.remove()}return false})})};e.pinMe=function(t){return e("body").pinMe(t)}})(jQuery)

File jquery.pinme.js

+/*
+        jQuery pin me plugin
+        --
+        Adds a pin it button to single images to easily share them on Pinterest.
+        --
+        Author  : Germano Guerrini
+        Version : 1.0
+*/
 (function ($) {
     'use strict';
     
     $.fn.pinMe = function(options) {
         var defaults = {
-                imageSelector: '.pin_me',
+                imageSelector: '.pinme',
                 imageMediaAttribute: 'src',
                 imageDescriptionAttribute: 'data-pin-description',
-                buttonUrl: 'pinit.png',
+                buttonUrl: 'img/pinit.png',
                 buttonWidth: 49,
                 buttonHeight: 25,
                 buttonAlignment: 'top-left',
         
         return this.each(function() {
             var element = $(this),
-                wrapperSelector = 'pin_me_wrapper',
                 baseUrl = 'http://pinterest.com/pin/create/button/',
                 fullImageSelector = 'img' + settings.imageSelector,
-                button = $('<img src="' + settings.buttonUrl + '" />'),
+                button = $('<img src="' + settings.buttonUrl + '" id="pinme_button" />'),
+                wrapperSelector = 'pinme_wrapper',
                 wrapper = $('<span class="' + wrapperSelector + '" />');
             
             // Wraps all images so that we can use mouseenter and mouseleave