Commits

Germano Guerrini committed 52e3062

First Commit

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 ($) {
+    'use strict';
+    
+    $.fn.pinMe = function(options) {
+        var defaults = {
+                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'
+            },
+            settings = $.extend(defaults, options);
+        
+        var getButtonPosition = function(image) {
+            var imagePosition = image.position();
+            var imageWidth = image.width();
+            var imageHeight = image.height();
+            switch (settings.buttonAlignment) {
+                case 'top-right':
+                    return {
+                        top: imagePosition.top + settings.buttonPadding,
+                        left: imagePosition.left + imageWidth - settings.buttonWidth - settings.buttonPadding
+                    };
+                case 'bottom-right':
+                    return {
+                        top: imagePosition.top + imageHeight - settings.buttonHeight - settings.buttonPadding,
+                        left: imagePosition.left + imageWidth - settings.buttonWidth - settings.buttonPadding
+                    };
+                case 'bottom-left':
+                    return {
+                        top: imagePosition.top + imageHeight - settings.buttonHeight - settings.buttonPadding,
+                        left: imagePosition.left + settings.buttonPadding
+                    };
+                default: // 'top-left
+                    return {
+                        top: imagePosition.top + settings.buttonPadding,
+                        left: imagePosition.left + settings.buttonPadding
+                    };
+            }
+        };
+        
+        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'}
+            );
+        }
+        
+        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 + '" />'),
+                wrapper = $('<span class="' + wrapperSelector + '" />');
+            
+            // Wraps all images so that we can use mouseenter and mouseleave
+            // events, otherwise hovering on the button would trigger a mouseout.
+            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 params = {
+                        url: document.URL,
+                        media: imageMedia,
+                        description: imageDescription
+                    };
+                    
+                    var buttonPosition = getButtonPosition(image)
+                    
+                    button.css({
+                        position: 'absolute',
+                        top: buttonPosition.top,
+                        left: buttonPosition.left,
+                        opacity: 0.75,
+                        cursor: 'pointer'
+                    });
+                    
+                    button.on('click', function(event) {
+                        var url = baseUrl + '?' + $.param(params),
+                            specs = 'screenX=' + settings.popupX + ',screenY=' + settings.popupY + ',width=' + settings.popupWidth + ',height=' + settings.popupHeight;
+                        window.open(url, settings.popupName, specs);
+                    });
+                    
+                    button.on('mouseover mouseout', function(event) {
+                        if (event.type == 'mouseover') {
+                            buttonMouseOver($(this))
+                        } else {
+                            buttonMouseOut($(this))
+                        };
+                    });
+                    
+                    button.appendTo($(this));
+                } else {
+                    button.off();
+                    button.remove();
+                }
+                return false;
+            });
+        });
+    };
+    
+    $.pinMe = function(options) {
+        return $('body').pinMe(options);
+    };
+})(jQuery);
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.