PageSourceSearch

https://nichehacks.com/wp-content/plugins/powerkit/modules/pintere…/js/public-powerkit-pin-it.js?ver=2.9.1

js nichehacks.com collected 2026-09-24 10:30:45 UTC 4,698 bytes, 174 lines download raw bytes

1/**
2 * Pin It
3 */
4( function( $ ) {
5
6	$.fn.powerkitPinIt = function() {
7
8		$( this ).each( function() {
9
10			if ( $( this ).hasClass( 'pk-pin-it-ready' ) ) {
11				return;
12			}
13
14			var width  = $( this ).attr( 'width' );
15			var height = $( this ).attr( 'height' );
16
17			if ( typeof width === 'undefined' ) {
18				width = $( this ).width();
19			}
20
21			if ( typeof height === 'undefined' ) {
22				height = $( this ).height();
23			}
24
25			if ( !( parseInt( width ) > 120 && parseInt( height ) > 120 ) ) {
26				$( this ).addClass( 'pk-pin-it-ready' );
27				return;
28			}
29
30			var container = $( this ).parent(),
31				postURL = $( location ).attr( 'href' ),
32				pinURL;
33
34			if ( $( container ).is( 'a' ) ) {
35
36				var imagehref = $( container ).attr( 'href' );
37
38				if ( typeof imagehref !== 'undefined' && imagehref.match( /\.(gif|jpeg|jpg|png|webp)/ ) ) {
39					pinURL = imagehref;
40				}
41
42				if ( !( $( container ).closest( 'figure' ).length ) ) {
43					$( container ).wrap( '<figure class="pk-pin-it-container"></figure>' );
44				}
45
46				container = $( container ).parent();
47
48			} else {
49
50				if ( !( $( container ).is( 'figure' ) || $( container ).closest( 'figure' ).length ) ) {
51					$( this ).wrap( '<figure class="pk-pin-it-container"></figure>' );
52				}
53
54				container = $( this ).parent();
55
56			}
57
58			if ( !$( this ).closest( 'figure' ).hasClass( 'pk-pin-it-container' ) ) {
59				$( this ).closest( 'figure' ).addClass( 'pk-pin-it-container' );
60			}
61
62			if ( ! pinURL ) {
63				if ( $( this ).is( 'img' ) ) {
64					pinURL = ( typeof $( this ).data( 'pk-src' ) !== 'undefined' ) ? $( this ).data( 'pk-src' ) : $( this ).attr( 'src' );
65				} else {
66					pinURL = ( typeof $( container ).find( 'img' ).data( 'src' ) !== 'undefined' ) ? $( container ).find( 'img' ).data( 'src' ) : $( container ).find( 'img' ).attr( 'src' );
67				}
68			}
69
70			pinURL = encodeURIComponent( pinURL );
71			postURL = encodeURIComponent( postURL );
72
73			var figure = container;
74
75			if ( ! $( container ).is( 'figure' ) ) {
76				figure = $( container ).closest( 'figure' );
77			}
78
79			// Get caption text.
80			var imgDescription = $( figure ).find( 'img' ).data( 'pin-description' );
81
82			if ( !imgDescription ) {
83				imgDescription = $( figure ).find( '.wp-caption-text' ).text();
84			}
85
86			if ( !imgDescription ) {
87				imgDescription = $( figure ).find( 'figcaption' ).text();
88			}
89
90			if ( !imgDescription ) {
91				imgDescription = $( figure ).find( 'img' ).attr( 'alt' );
92			}
93
94			if ( imgDescription ) {
95				// Add attribute to share URL.
96				imgDescription = '&amp;description=' + encodeURIComponent( imgDescription );
97			}
98
99			// Img classes.
100			var imgClasses = [ 'alignnone', 'aligncenter', 'alignleft', 'alignright' ];
101
102			imgClasses.forEach( function( el ) {
103				if ( $( container ).find( 'img' ).hasClass( el ) ) {
104					$( container ).find( 'img' ).removeClass( el );
105					$( container ).find( 'img' ).closest( 'figure' ).addClass( el );
106
107					// Add width to figure.
108					var imgWidth = $( container ).find( 'img' ).attr( 'width' );
109
110					if ( parseInt( imgWidth ) !== 'NaN' ) {
111						$( container ).find( 'img' ).closest( 'figure' ).width( imgWidth );
112					}
113				}
114			} );
115
116			// Add func PintIt.
117			var addPowerkitPintIt = function( container ) {
118				if ( ! $( container ).find( '.pk-pin-it' ).length ) {
119					$( '<a class="pk-pin-it" href="http://www.pinterest.com/pin/create/bookmarklet/?url=' + postURL + '&amp;media=' + pinURL + imgDescription + '&is_video=false" target="_blank"><span>Pin</span><span><i class="pk-icon pk-icon-pinterest"></i></span></a>' )
120						.appendTo( container )
121						.addClass( 'pk-pin-it-visible' );
122				}
123			}
124
125			// PintIt Mode.
126			if ( powerkit_pinit_localize.only_hover ) {
127
128				$( container ).mousemove(function(){
129					addPowerkitPintIt( this );
130				});
131
132				$( container ).mouseleave(function(){
133					var $this = this;
134
135					$( $this ).children( '.pk-pin-it' ).fadeOut( 200, function(){
136						$( $this ).children( '.pk-pin-it' ).remove();
137					});
138				});
139
140			} else {
141				addPowerkitPintIt( container );
142			}
143
144			$( this ).addClass( 'pk-pin-it-ready' );
145		} );
146	};
147
148
149	function initPowerkitPinIt() {
150
151		// Exclude.
152		var filterPowerkitPinIt = function() {
153			var exclude = powerkit_pinit_localize.exclude_selectors;
154			if ( exclude ) {
155				if ( $( this ).closest( exclude ).length > 0 ) {
156					return false;
157				}
158			}
159			return true;
160		}
161
162		// Init.
163		$( powerkit_pinit_localize.image_selectors ).imagesLoaded( function() {
164			$( powerkit_pinit_localize.image_selectors ).filter( filterPowerkitPinIt ).powerkitPinIt();
165		} );
166	}
167
168	$( document ).ready( function() {
169		initPowerkitPinIt();
170		$( document.body ).on( 'post-load image-load', function() {
171			initPowerkitPinIt();
172		} );
173	} );
174} )( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.