Germano Guerrini avatar Germano Guerrini committed 278a428

Even more customizable.

Comments (0)

Files changed (2)

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,popupX:100,popupY:100,popupHeight:580,popupWidth:730,popupName:"pinterest"},r=e.extend(n,t);var i=function(e){var t=e.position();var n=e.width();var 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){e.css({opacity:1,"-webkit-transition":"opacity .5s ease-out","-moz-transition":"opacity .5s ease-out",transition:"opacity .5s ease-out"})};var o=function(e){e.css({opacity:.75,"-webkit-transition":"opacity .5s ease-out","-moz-transition":"opacity .5s ease-out",transition:"opacity .5s ease-out"})};return this.each(function(){var t=e(this),n="pin_me_wrapper",u="http://pinterest.com/pin/create/button/",a="img"+r.imageSelector,f=e('<img src="'+r.buttonUrl+'" />'),l=e('<span class="'+n+'" />');t.find(a).wrap(l);e("."+n).on("mouseenter mouseleave",function(t){if(t.type=="mouseenter"){var n=e(this).children(a).first();var l=n.attr(r.imageMediaAttribute),c=n.attr(r.imageDescriptionAttribute);var h={url:document.URL,media:l,description:c};var p=i(n);f.css({position:"absolute",top:p.top,left:p.left,opacity:.75,cursor:"pointer"});f.on("click",function(t){var n=u+"?"+e.param(h),i="screenX="+r.popupX+",screenY="+r.popupY+",width="+r.popupWidth+",height="+r.popupHeight;window.open(n,r.popupName,i)});f.on("mouseover mouseout",function(t){if(t.type=="mouseover"){s(e(this))}else{o(e(this))}});f.appendTo(e(this))}else{f.off();f.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:".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",function(t){var n=o+"?"+e.param(h),i="screenX="+r.popupX+",screenY="+r.popupY+",width="+r.popupWidth+",height="+r.popupHeight;window.open(n,r.popupName,i)});a.on("mouseover mouseout",function(t){var n=e(this);if(t.type=="mouseover"){r.buttonOnMouseOverFunction(n,f)}else{r.buttonOnMouseOutFunction(n,f)}});a.appendTo(n)}else{a.off();a.remove()}return false})})};e.pinMe=function(t){return e("body").pinMe(t)}})(jQuery)
                 buttonHeight: 25,
                 buttonAlignment: 'top-left',
                 buttonPadding: 5,
+                buttonWillShowFunction: function(button) {
+                    button.css({
+                        opacity: 0.75
+                    });
+                },
+                buttonOnMouseOverFunction: function(button, image) {
+                    button.css({
+                        opacity: 1.0,
+                        '-webkit-transition': 'opacity .25s ease-out',
+                        '-moz-transition': 'opacity .25s ease-out',
+                        transition: 'opacity .25s ease-out'
+                    });
+                    image.css({
+                        opacity:0.75,
+                        '-webkit-transition': 'opacity .25s ease-out',
+                        '-moz-transition': 'opacity .25s ease-out',
+                        transition: 'opacity .25s ease-out'
+                    });
+                },
+                buttonOnMouseOutFunction: function(button, image) {
+                    button.css({
+                        opacity: 0.75,
+                        '-webkit-transition': 'opacity .25s ease-out',
+                        '-moz-transition': 'opacity .25s ease-out',
+                        transition: 'opacity .25s ease-out'}
+                    );
+                    image.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,
             settings = $.extend(defaults, options);
         
         var getButtonPosition = function(image) {
-            var imagePosition = image.position();
-            var imageWidth = image.width();
-            var imageHeight = image.height();
+            var imagePosition = image.position(),
+                imageWidth = image.width(),
+                imageHeight = image.height();
+            
             switch (settings.buttonAlignment) {
                 case 'top-right':
                     return {
             }
         };
         
-        var buttonMouseOver = function(button) {
-            button.css({
-                opacity: 1.0,
-                '-webkit-transition': 'opacity .5s ease-out',
-                '-moz-transition': 'opacity .5s ease-out',
-                transition: 'opacity .5s ease-out'
-            });
-        }
-        
-        var buttonMouseOut = function(button) {
-            button.css({
-                opacity: 0.75,
-                '-webkit-transition': 'opacity .5s ease-out',
-                '-moz-transition': 'opacity .5s ease-out',
-                transition: 'opacity .5s ease-out'}
-            );
-        }
+        var getImageAbsoluteUrl = function(image) {
+            var value = image.attr(settings.imageMediaAttribute);
+            // These controls should be safe enough.
+            // If not, the image is likely broken anyway.
+            if (!value.match("^http://")) {
+                var separator = (value.substr(0,1) === "/") ? "" : "/";
+                value = window.location.origin + separator + value;
+            }
+            return value;
+        };
         
         return this.each(function() {
             var element = $(this),
             element.find(fullImageSelector).wrap(wrapper);
             
             $('.' + wrapperSelector).on('mouseenter mouseleave', function(event) {
-                if (event.type == 'mouseenter') {
-                    // Gets the wrapper image again to obtain the needed parameters.
-                    var image = $(this).children(fullImageSelector).first();
-                    
-                    var imageMedia = image.attr(settings.imageMediaAttribute),
-                        imageDescription = image.attr(settings.imageDescriptionAttribute);
+                var currentWrapper = $(this);
+                if (event.type === 'mouseenter') {
+                    // Gets the wrapped image again to obtain the needed parameters.
+                    var currentImage = currentWrapper.children(fullImageSelector).first(),
+                        imageMedia = getImageAbsoluteUrl(currentImage),
+                        imageDescription = currentImage.attr(settings.imageDescriptionAttribute);
                     
                     var params = {
                         url: document.URL,
                         description: imageDescription
                     };
                     
-                    var buttonPosition = getButtonPosition(image)
+                    var buttonPosition = getButtonPosition(currentImage);
                     
                     button.css({
                         position: 'absolute',
                         top: buttonPosition.top,
                         left: buttonPosition.left,
-                        opacity: 0.75,
                         cursor: 'pointer'
                     });
                     
+                    settings.buttonWillShowFunction(button);
+                    
                     button.on('click', function(event) {
                         var url = baseUrl + '?' + $.param(params),
                             specs = 'screenX=' + settings.popupX + ',screenY=' + settings.popupY + ',width=' + settings.popupWidth + ',height=' + settings.popupHeight;
                     });
                     
                     button.on('mouseover mouseout', function(event) {
+                        var currentButton = $(this);
                         if (event.type == 'mouseover') {
-                            buttonMouseOver($(this))
+                            settings.buttonOnMouseOverFunction(currentButton, currentImage);
                         } else {
-                            buttonMouseOut($(this))
+                            settings.buttonOnMouseOutFunction(currentButton, currentImage);
                         };
                     });
                     
-                    button.appendTo($(this));
+                    button.appendTo(currentWrapper);
                 } else {
                     button.off();
                     button.remove();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.