Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/modules/shortcod.../js
File: slideshow-shortcode.js
/* global jetpackSlideshowSettings */
[0] Fix | Delete
[1] Fix | Delete
function JetpackSlideshow( element, transition, autostart ) {
[2] Fix | Delete
this.element = element;
[3] Fix | Delete
this.images = [];
[4] Fix | Delete
this.controls = {};
[5] Fix | Delete
this.transition = transition || 'fade';
[6] Fix | Delete
this.autostart = autostart;
[7] Fix | Delete
}
[8] Fix | Delete
[9] Fix | Delete
JetpackSlideshow.prototype.showLoadingImage = function ( toggle ) {
[10] Fix | Delete
if ( toggle ) {
[11] Fix | Delete
this.loadingImage_ = document.createElement( 'div' );
[12] Fix | Delete
this.loadingImage_.className = 'jetpack-slideshow-loading';
[13] Fix | Delete
var img = document.createElement( 'img' );
[14] Fix | Delete
img.src = jetpackSlideshowSettings.spinner;
[15] Fix | Delete
this.loadingImage_.appendChild( img );
[16] Fix | Delete
this.loadingImage_.appendChild( this.makeZeroWidthSpan() );
[17] Fix | Delete
this.element.append( this.loadingImage_ );
[18] Fix | Delete
} else if ( this.loadingImage_ ) {
[19] Fix | Delete
this.loadingImage_.parentNode.removeChild( this.loadingImage_ );
[20] Fix | Delete
this.loadingImage_ = null;
[21] Fix | Delete
}
[22] Fix | Delete
};
[23] Fix | Delete
[24] Fix | Delete
JetpackSlideshow.prototype.init = function () {
[25] Fix | Delete
this.showLoadingImage( true );
[26] Fix | Delete
[27] Fix | Delete
var self = this;
[28] Fix | Delete
// Set up DOM.
[29] Fix | Delete
for ( var i = 0; i < this.images.length; i++ ) {
[30] Fix | Delete
var imageInfo = this.images[ i ];
[31] Fix | Delete
var img = document.createElement( 'img' );
[32] Fix | Delete
img.src = imageInfo.src;
[33] Fix | Delete
img.title = typeof imageInfo.title !== 'undefined' ? imageInfo.title : '';
[34] Fix | Delete
img.alt = typeof imageInfo.alt !== 'undefined' ? imageInfo.alt : '';
[35] Fix | Delete
img.setAttribute( 'itemprop', 'image' );
[36] Fix | Delete
img.nopin = 'nopin';
[37] Fix | Delete
var caption = document.createElement( 'div' );
[38] Fix | Delete
caption.className = 'jetpack-slideshow-slide-caption';
[39] Fix | Delete
caption.setAttribute( 'itemprop', 'caption description' );
[40] Fix | Delete
caption.innerHTML = imageInfo.caption;
[41] Fix | Delete
var container = document.createElement( 'div' );
[42] Fix | Delete
container.className = 'jetpack-slideshow-slide';
[43] Fix | Delete
container.setAttribute( 'itemprop', 'associatedMedia' );
[44] Fix | Delete
container.setAttribute( 'itemscope', '' );
[45] Fix | Delete
container.setAttribute( 'itemtype', 'https://schema.org/ImageObject' );
[46] Fix | Delete
[47] Fix | Delete
// Hide loading image once first image has loaded.
[48] Fix | Delete
if ( i === 0 ) {
[49] Fix | Delete
if ( img.complete ) {
[50] Fix | Delete
// IE, image in cache
[51] Fix | Delete
setTimeout( function () {
[52] Fix | Delete
self.finishInit_();
[53] Fix | Delete
}, 1 );
[54] Fix | Delete
} else {
[55] Fix | Delete
img.addEventListener( 'load', function () {
[56] Fix | Delete
self.finishInit_();
[57] Fix | Delete
} );
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
container.appendChild( img );
[61] Fix | Delete
// I'm not sure where these were coming from, but IE adds
[62] Fix | Delete
// bad values for width/height for portrait-mode images
[63] Fix | Delete
img.removeAttribute( 'width' );
[64] Fix | Delete
img.removeAttribute( 'height' );
[65] Fix | Delete
container.appendChild( this.makeZeroWidthSpan() );
[66] Fix | Delete
container.appendChild( caption );
[67] Fix | Delete
this.element.append( container );
[68] Fix | Delete
}
[69] Fix | Delete
};
[70] Fix | Delete
[71] Fix | Delete
JetpackSlideshow.prototype.makeZeroWidthSpan = function () {
[72] Fix | Delete
var emptySpan = document.createElement( 'span' );
[73] Fix | Delete
emptySpan.className = 'jetpack-slideshow-line-height-hack';
[74] Fix | Delete
// Having a NBSP makes IE act weird during transitions, but other
[75] Fix | Delete
// browsers ignore a text node with a space in it as whitespace.
[76] Fix | Delete
if ( -1 !== window.navigator.userAgent.indexOf( 'MSIE ' ) ) {
[77] Fix | Delete
emptySpan.appendChild( document.createTextNode( ' ' ) );
[78] Fix | Delete
} else {
[79] Fix | Delete
emptySpan.innerHTML = '&nbsp;';
[80] Fix | Delete
}
[81] Fix | Delete
return emptySpan;
[82] Fix | Delete
};
[83] Fix | Delete
[84] Fix | Delete
JetpackSlideshow.prototype.finishInit_ = function () {
[85] Fix | Delete
this.showLoadingImage( false );
[86] Fix | Delete
[87] Fix | Delete
var self = this;
[88] Fix | Delete
if ( this.images.length > 1 ) {
[89] Fix | Delete
this.renderControls_();
[90] Fix | Delete
[91] Fix | Delete
// Initialize Cycle instance.
[92] Fix | Delete
jQuery( this.element ).cycle( {
[93] Fix | Delete
fx: this.transition,
[94] Fix | Delete
prev: this.controls.prev,
[95] Fix | Delete
next: this.controls.next,
[96] Fix | Delete
timeout: jetpackSlideshowSettings.speed,
[97] Fix | Delete
slideExpr: '.jetpack-slideshow-slide',
[98] Fix | Delete
onPrevNextEvent: function () {
[99] Fix | Delete
return self.onCyclePrevNextClick_.apply( self, arguments );
[100] Fix | Delete
},
[101] Fix | Delete
} );
[102] Fix | Delete
[103] Fix | Delete
var slideshow = this.element;
[104] Fix | Delete
[105] Fix | Delete
if ( ! this.autostart ) {
[106] Fix | Delete
jQuery( slideshow ).cycle( 'pause' );
[107] Fix | Delete
this.controls.stop.classList.remove( 'running' );
[108] Fix | Delete
this.controls.stop.classList.add( 'paused' );
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
this.controls.stop.addEventListener( 'click', function ( event ) {
[112] Fix | Delete
var button = event.currentTarget;
[113] Fix | Delete
[114] Fix | Delete
if ( button === event.target ) {
[115] Fix | Delete
event.preventDefault();
[116] Fix | Delete
[117] Fix | Delete
if ( ! button.classList.contains( 'paused' ) ) {
[118] Fix | Delete
jQuery( slideshow ).cycle( 'pause' );
[119] Fix | Delete
button.classList.remove( 'running' );
[120] Fix | Delete
button.classList.add( 'paused' );
[121] Fix | Delete
} else {
[122] Fix | Delete
button.classList.add( 'running' );
[123] Fix | Delete
button.classList.remove( 'paused' );
[124] Fix | Delete
jQuery( slideshow ).cycle( 'resume', true );
[125] Fix | Delete
}
[126] Fix | Delete
}
[127] Fix | Delete
} );
[128] Fix | Delete
} else if ( this.element.children.length ) {
[129] Fix | Delete
this.element.children[ 0 ].style.display = 'block';
[130] Fix | Delete
this.element.style.position = 'relative';
[131] Fix | Delete
}
[132] Fix | Delete
this.initialized_ = true;
[133] Fix | Delete
};
[134] Fix | Delete
[135] Fix | Delete
JetpackSlideshow.prototype.renderControls_ = function () {
[136] Fix | Delete
if ( this.controlsDiv_ ) {
[137] Fix | Delete
return;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
var controlsDiv = document.createElement( 'div' );
[141] Fix | Delete
controlsDiv.className = 'jetpack-slideshow-controls';
[142] Fix | Delete
[143] Fix | Delete
var controls = [ 'prev', 'stop', 'next' ];
[144] Fix | Delete
for ( var i = 0; i < controls.length; i++ ) {
[145] Fix | Delete
var controlName = controls[ i ];
[146] Fix | Delete
var label_name = 'label_' + controlName;
[147] Fix | Delete
var a = document.createElement( 'a' );
[148] Fix | Delete
[149] Fix | Delete
a.href = '#';
[150] Fix | Delete
a.className = 'button-' + controlName;
[151] Fix | Delete
a.setAttribute( 'aria-label', jetpackSlideshowSettings[ label_name ] );
[152] Fix | Delete
a.setAttribute( 'role', 'button' );
[153] Fix | Delete
[154] Fix | Delete
controlsDiv.appendChild( a );
[155] Fix | Delete
this.controls[ controlName ] = a;
[156] Fix | Delete
}
[157] Fix | Delete
this.element.append( controlsDiv );
[158] Fix | Delete
this.controlsDiv_ = controlsDiv;
[159] Fix | Delete
};
[160] Fix | Delete
[161] Fix | Delete
JetpackSlideshow.prototype.onCyclePrevNextClick_ = function ( isNext, i /*, slideElement*/ ) {
[162] Fix | Delete
// If blog_id not present don't track page views
[163] Fix | Delete
if ( ! jetpackSlideshowSettings.blog_id ) {
[164] Fix | Delete
return;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
var postid = this.images[ i ].id;
[168] Fix | Delete
var stats = new Image();
[169] Fix | Delete
stats.src =
[170] Fix | Delete
document.location.protocol +
[171] Fix | Delete
'//pixel.wp.com/g.gif?host=' +
[172] Fix | Delete
encodeURIComponent( document.location.host ) +
[173] Fix | Delete
'&rand=' +
[174] Fix | Delete
Math.random() +
[175] Fix | Delete
'&blog=' +
[176] Fix | Delete
jetpackSlideshowSettings.blog_id +
[177] Fix | Delete
'&subd=' +
[178] Fix | Delete
jetpackSlideshowSettings.blog_subdomain +
[179] Fix | Delete
'&user_id=' +
[180] Fix | Delete
jetpackSlideshowSettings.user_id +
[181] Fix | Delete
'&post=' +
[182] Fix | Delete
postid +
[183] Fix | Delete
'&ref=' +
[184] Fix | Delete
encodeURIComponent( document.location );
[185] Fix | Delete
};
[186] Fix | Delete
[187] Fix | Delete
( function () {
[188] Fix | Delete
function jetpack_slideshow_init() {
[189] Fix | Delete
document.querySelectorAll( '.jetpack-slideshow-noscript' ).forEach( function ( element ) {
[190] Fix | Delete
element.remove();
[191] Fix | Delete
} );
[192] Fix | Delete
document.querySelectorAll( '.jetpack-slideshow' ).forEach( function ( container ) {
[193] Fix | Delete
if ( container.dataset.processed === 'true' ) {
[194] Fix | Delete
return;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
// Extract data attributes manually
[198] Fix | Delete
var transition = container.dataset.trans;
[199] Fix | Delete
var autostart = container.dataset.autostart === 'true';
[200] Fix | Delete
var gallery = JSON.parse( container.dataset.gallery || '[]' );
[201] Fix | Delete
[202] Fix | Delete
var slideshow = new JetpackSlideshow( container, transition, autostart );
[203] Fix | Delete
slideshow.images = gallery;
[204] Fix | Delete
slideshow.init();
[205] Fix | Delete
[206] Fix | Delete
container.dataset.processed = 'true';
[207] Fix | Delete
} );
[208] Fix | Delete
}
[209] Fix | Delete
[210] Fix | Delete
document.addEventListener( 'DOMContentLoaded', jetpack_slideshow_init );
[211] Fix | Delete
document.body.addEventListener( 'post-load', jetpack_slideshow_init );
[212] Fix | Delete
} )();
[213] Fix | Delete
[214] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function