-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.pinitimages.js
125 lines (86 loc) · 3.96 KB
/
jquery.pinitimages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*jshint multistr:true */
/*!
* Pintest Tumblr Images 1.0
*
* Copyright 2013, William Rainbird
* Released under the MIT license
*
* Date: Sat 16th March 2013
*/
(function( $ ){
"use strict";
$('.pinImageWrapper').live("hover",
function()
{
$(this).toggleClass("hover");
}
);
$.fn.pinterestImageButton = function( options ) {
var div = document.createElement('div'),
ref = document.getElementsByTagName('base')[0] || document.getElementsByTagName('script')[0];
div.className = 'pin-image-style';
div.innerHTML = '­<style> \
.pinImageWrapper { \
position: relative; \
} \
\
.pinImageWrapper a.pinButton { \
position: absolute; \
top: 12px; \
right: 12px; \
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";\
filter: alpha(opacity=0); \
-moz-opacity: 0; \
-khtml-opacity: 0; \
opacity: 0; \
-webkit-transition: all 0.2s ease-in-out\
} \
.pinImageWrapper.hover a.pinButton { \
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";\
filter: alpha(opacity=100); \
-moz-opacity: 1; \
-khtml-opacity: 1; \
opacity: 1; \
} \
</style>';
ref.parentNode.insertBefore(div,ref);
var pageHref = window.location.origin;
var settings = {
customSource: null
};
if ( options ) {
$.extend( settings, options );
}
return this.each(function(){
var selectors = [
"img[src*='media.tumblr.com']"
];
if (settings.customSource) {
selectors.push(settings.customSource);
}
var $allPhotos = $(this).find(selectors.join(','));
$allPhotos.each(function(){
var $photo = $(this);
var pageURL;
var imgURL = $(this).attr('src');
//get URL
$(this).parents('.post').find('a').each(function() {
var currHref = $(this).attr('href');
if(currHref.indexOf(pageHref) > -1 && currHref.indexOf("post") > -1) {
pageURL = currHref;
return false;
}
});
var pinCode = '<a data-pin-config="none" href="//pinterest.com/pin/create/button/?url=' + pageURL + '&media=' + imgURL + '" data-pin-do="buttonPin" class="pinButton" ><img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" /></a>';
var parentHref = $(this).parent().attr('href');
if(parentHref !== undefined) {
if(parentHref.indexOf("media.tumblr.com") > 0) {
$photo.closest('a').wrap('<div class="pinImageWrapper"></div>').parent('.pinImageWrapper').append(pinCode);
}
} else {
$photo.wrap('<div class="pinImageWrapper"></div>').parent('.pinImageWrapper').append(pinCode);
}
});
});
};
})( jQuery );