PageSourceSearch

https://cherneparh.ru/wp-content/plugins/shortcodes/_inc/js/slideshow-shortcode.js?ver=20121214.1

js cherneparh.ru collected 2026-10-08 11:46:41 UTC 5,630 bytes, 187 lines download raw bytes

1function JetpackSlideshow( element, width, height, transition ) {
2	this.element = element;
3	this.images = [];
4	this.controls = {};
5	this.transition = transition || 'fade';
6
7	var currentWidth = this.element.width();
8	if ( !width || width > currentWidth )
9		width = currentWidth;
10
11	this.width = width;
12	this.height = height;
13	this.element.css( {
14		'height': this.height + 'px'
15		} );
16}
17
18JetpackSlideshow.prototype.showLoadingImage = function( toggle ) {
19	if ( toggle ) {
20		this.loadingImage_ = document.createElement( 'div' );
21		this.loadingImage_.className = 'slideshow-loading';
22		var img = document.createElement( 'img' );
23		img.src = jetpackSlideshowSettings.spinner;
24		this.loadingImage_.appendChild( img );
25		this.loadingImage_.appendChild( this.makeZeroWidthSpan() );
26		this.loadingImage_.style.lineHeight = this.height + 'px';
27		this.element.append( this.loadingImage_ );
28	} else if ( this.loadingImage_ ) {
29		this.loadingImage_.parentNode.removeChild( this.loadingImage_ );
30		this.loadingImage_ = null;
31	}
32};
33
34JetpackSlideshow.prototype.init = function() {
35	this.showLoadingImage(true);
36
37	var self = this;
38	// Set up DOM.
39	for ( var i = 0; i < this.images.length; i++ ) {
40		var imageInfo = this.images[i];
41		var img = document.createElement( 'img' );
42		img.src = imageInfo.src + '?w=' + this.width;
43		img.align = 'middle';
44		var caption = document.createElement( 'div' );
45		caption.className = 'slideshow-slide-caption';
46		caption.innerHTML = imageInfo.caption;
47		var container = document.createElement('div');
48		container.className = 'slideshow-slide';
49		container.style.lineHeight = this.height + 'px';
50
51		// Hide loading image once first image has loaded.
52		if ( i == 0 ) {
53			if ( img.complete ) {
54				// IE, image in cache
55				setTimeout( function() {
56					self.finishInit_();
57				}, 1);
58			} else {
59				jQuery( img ).load(function() {
60					self.finishInit_();
61				});
62			}
63		}
64		container.appendChild( img );
65		// I'm not sure where these were coming from, but IE adds
66		// bad values for width/height for portrait-mode images
67		img.removeAttribute('width');
68		img.removeAttribute('height');
69		container.appendChild( this.makeZeroWidthSpan() );
70		container.appendChild( caption );
71		this.element.append( container );
72	}
73};
74
75JetpackSlideshow.prototype.makeZeroWidthSpan = function() {
76	var emptySpan = document.createElement( 'span' );
77	emptySpan.className = 'slideshow-line-height-hack';
78	// Having a NBSP makes IE act weird during transitions, but other
79	// browsers ignore a text node with a space in it as whitespace.
80	if (jQuery.browser.msie) {
81		emptySpan.appendChild( document.createTextNode(' ') );
82	} else {
83		emptySpan.innerHTML = '&nbsp;';
84	}
85	return emptySpan;
86};
87
88JetpackSlideshow.prototype.finishInit_ = function() {
89	this.showLoadingImage( false );
90	this.renderControls_();
91
92	var self = this;
93	// Initialize Cycle instance.
94	this.element.cycle( {
95		fx: this.transition,
96		prev: this.controls.prev,
97		next: this.controls.next,
98		slideExpr: '.slideshow-slide',
99		onPrevNextEvent: function() {
100			return self.onCyclePrevNextClick_.apply( self, arguments );
101		}
102	} );
103
104	var slideshow = this.element;
105	jQuery( this.controls['stop'] ).click( function() {
106		var button = jQuery(this);
107		if ( ! button.hasClass( 'paused' ) ) {
108			slideshow.cycle( 'pause' );
109			button.removeClass( 'running' );
110			button.addClass( 'paused' );
111		} else {
112			button.addClass( 'running' );
113			button.removeClass( 'paused' );
114			slideshow.cycle( 'resume', true );
115		}
116		return false;
117	} );
118
119	var controls = jQuery( this.controlsDiv_ );
120	slideshow.mouseenter( function() {
121		controls.fadeIn();
122	} );
123	slideshow.mouseleave( function() {
124		controls.fadeOut();
125	} );
126
127	this.initialized_ = true;
128};
129
130JetpackSlideshow.prototype.renderControls_ = function() {
131	if ( this.controlsDiv_ )
132		return;
133
134	var controlsDiv = document.createElement( 'div' );
135	controlsDiv.className = 'slideshow-controls';
136
137	controls = [ 'prev', 'stop', 'next' ];
138	for ( var i = 0; i < controls.length; i++ ) {
139		var controlName = controls[i];
140		var a = document.createElement( 'a' );
141		a.href = '#';
142		controlsDiv.appendChild( a );
143		this.controls[controlName] = a;
144	}
145	this.element.append( controlsDiv );
146	this.controlsDiv_ = controlsDiv;
147};
148
149JetpackSlideshow.prototype.onCyclePrevNextClick_ = function( isNext, i, slideElement ) {
150	// If blog_id not present don't track page views
151	if ( ! jetpackSlideshowSettings.blog_id )
152		return;
153
154	var postid = this.images[i].id;
155	var stats = new Image();
156	stats.src = document.location.protocol +
157		'//stats.wordpress.com/g.gif?host=' +
158		escape( document.location.host ) +
159		'&rand=' + Math.random() +
160		'&blog=' + jetpackSlideshowSettings.blog_id +
161		'&subd=' + jetpackSlideshowSettings.blog_subdomain +
162		'&user_id=' + jetpackSlideshowSettings.user_id +
163		'&post=' + postid +
164		'&ref=' + escape( document.location );
165};
166
167( function ( $ ) {
168	function jetpack_slideshow_init() {
169		$( '.jetpack-slideshow-noscript' ).remove();
170
171		$( '.jetpack-slideshow' ).each( function () {
172			var container = $( this );
173
174			if ( container.data( 'processed' ) )
175				return;
176
177			var slideshow = new JetpackSlideshow( container, container.data( 'width' ), container.data( 'height' ), container.data( 'trans' ) );
178			slideshow.images = container.data( 'gallery' );
179			slideshow.init();
180
181			container.data( 'processed', true );
182		} );
183	}
184
185	$( document ).ready( jetpack_slideshow_init );
186	$( 'body' ).on( 'post-load', jetpack_slideshow_init );
187} )( 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.