' + jQuery.VideoPress.error.messages.age + "
"); } else { jQuery.VideoPress.video.play(container_el); } }, allowedDomain: function (allowed_domains) { if ( jQuery.type(allowed_domains)==="array" ) { if ( jQuery.inArray( top.document.location.hostname, allowed_domains )===-1 ) { return false; } } return true; } }, video:{ flash:{ // Protocol and domain for player_uri and expressinstall set in video.play() player_uri: ( 'https:' == location.protocol ? 'https://v0.wordpress.com' : 'http://s0.videopress.com' ) + "/player.swf?v=1.04", min_version:"10.0.0", params:{wmode:"direct",quality:"autohigh",seamlesstabbing:"true",allowfullscreen:"true",allowscriptaccess:"always",overstretch:"true"}, expressinstall: ( 'https:' == location.protocol ? 'https://v0.wordpress.com' : 'http://s0.videopress.com' ) + "/playerProductInstall.swf", embedCallback: function(event) { if ( event.success===false ) { jQuery("#" + event.id).html("" + jQuery.VideoPress.error.messages.flash + "
"); } } }, types:{mp4:'video/mp4; codecs="avc1.64001E, mp4a.40.2"',ogv:'video/ogg; codecs="theora, vorbis"'}, canPlay:function () { if ( jQuery.VideoPress.support.flash() ) { jQuery.VideoPress.video.playerSupport = "flash"; } else if ( jQuery.VideoPress.support.html5Video() ) { if ( jQuery.VideoPress.support.html5Video( jQuery.VideoPress.video.types.mp4 ) ) { jQuery.VideoPress.video.playerSupport = "mp4"; } else if ( jQuery.VideoPress.support.html5Video( jQuery.VideoPress.video.types.ogv ) ) { jQuery.VideoPress.video.playerSupport = "ogv"; } else { jQuery.VideoPress.video.playerSupport = "html5"; } } else { jQuery.VideoPress.video.playerSupport = ""; } }, prepare: function ( guid, config, count ) { var video = jQuery.VideoPress.data[guid][count]; if ( config.container === undefined || jQuery.type(video)!=="object" ) { return; } var width = 0; if ( config.width !== undefined ) { width = config.width; } else { config.container.width(); } var height = 0; if ( config.height !== undefined ) { height = config.height; } else { config.container.height(); } var div_id = "#v-" + guid + '-' + count; var parent_width = jQuery( div_id ).parent().width(); var diffw = 0; var diffh = 0; var ratio = 0; if ( width > parent_width ) { diffw = width - parent_width + 11; ratio = ( width * 1.0 ) / ( height * 1.0 ); diffh = diffw / ratio; width -= diffw; height -= Math.round( diffh ); } if ( width < 60 || height < 60 ) { width = 400; height = 300; } jQuery.VideoPress.data[guid][count].dimensions = {}; if( 0 == ratio ) { jQuery.VideoPress.data[guid][count].dimensions.width = width; jQuery.VideoPress.data[guid][count].dimensions.height = height; } else { jQuery.VideoPress.data[guid][count].dimensions.width = width - 7; jQuery.VideoPress.data[guid][count].dimensions.height = height - Math.round( 7 / ratio ); jQuery( div_id ).width( width ); jQuery( div_id ).height( height + 50 ); jQuery( div_id + "-placeholder" ).width( jQuery.VideoPress.data[guid][count].dimensions.width ); jQuery( div_id + "-placeholder" ).height( jQuery.VideoPress.data[guid][count].dimensions.height ); jQuery( div_id + "-placeholder img.videopress-poster" ).width( jQuery.VideoPress.data[guid][count].dimensions.width ); jQuery( div_id + "-placeholder img.videopress-poster" ).height( jQuery.VideoPress.data[guid][count].dimensions.height ); } config.container.data( "guid", guid ); config.container.data( "count", count ); if ( jQuery.VideoPress.video.playerSupport === undefined ) { jQuery.VideoPress.video.canPlay(); } if ( config.freedom===true && jQuery.type(video.ogv)==="string" ) { jQuery.VideoPress.video.insert( config.container, guid, count, video, "ogv", jQuery.VideoPress.data[guid][count].dimensions.width, jQuery.VideoPress.data[guid].dimensions.height ); config.container.data( "player", "ogv" ); } else if ( jQuery.VideoPress.video.playerSupport === "flash" ) { config.container.data( "player", "flash" ); config.container.append( '' + jQuery.VideoPress.error.messages.incompatible + '
'); return false; } return true; }, insert: function( container_el, guid, count, video_data, video_type, width, height ) { var video_id = "v-" + guid + "-" + count + "-video"; var video_el = jQuery(""); video_el.attr( "id", video_id ); video_el.attr( "width", width ); video_el.attr( "height", height ); video_el.attr( "poster", video_data.poster ); if ( video_type==="ogv" ) { video_el.attr( "preload", "metadata" ); } else { video_el.attr( "preload", "none" ); } video_el.attr( "controls", "true" ); video_el.attr( "x-webkit-airplay", "allow" ); if ( video_type==="mp4" && video_data.mp4!==undefined && jQuery.type(video_data.mp4.uri)==="string" ) { video_el.attr( "src", video_data.mp4.uri ); } else if ( video_type==="ogv" && video_data.ogv!==undefined && jQuery.type(video_data.ogv.uri)==="string" ) { video_el.attr( "src", video_data.ogv.uri ); } else { // Purposely omit source type attribute since the browser does not seem to support specifics such as canPlayType if ( video_data.mp4!==undefined && jQuery.type(video_data.mp4.uri)==="string" ) { video_el.append( '' + jQuery.VideoPress.error.messages.incompatible + "
" ); video_el.hide(); container_el.append( video_el ); video_el=null; video_id=null; }, play: function( container_el ) { var player = container_el.data( "player" ); if ( player===undefined ) { player="flash"; } var guid = container_el.data( "guid" ); var count = container_el.data( "count" ); if ( player === "flash" ) { jQuery( "#" + container_el.attr("id") + "-placeholder", container_el ).remove(); var player_uri = jQuery.VideoPress.video.flash.player_uri; var expressinstall = jQuery.VideoPress.video.flash.expressinstall; swfobject.embedSWF( player_uri, "v-" + guid + "-" + count + "-video", jQuery.VideoPress.data[guid][count].dimensions.width, jQuery.VideoPress.data[guid][count].dimensions.height, jQuery.VideoPress.video.flash.min_version, expressinstall, {guid:guid,autoPlay:"true",isDynamicSeeking:"true",hd:jQuery.VideoPress.data[guid][count].hd}, jQuery.VideoPress.video.flash.params, null, jQuery.VideoPress.video.flash.embedCallback ); } else if ( jQuery.inArray( player, ["html5", "mp4", "ogv"] ) ) { var video_el = jQuery("video", container_el); if ( video_el ) { jQuery( "#" + container_el.attr("id") + "-placeholder", container_el ).remove(); if ( player==="html5" ) { player = "mp4"; } jQuery.VideoPress.video.playHTML5( video_el, guid, player ); } } else { jQuery( "#" + container_el.attr("id") + "-placeholder", container_el ).remove(); container_el.append( 'Unable to play video. No suitable player.
' ); } var play_event = new CustomEvent( 'videopress_play_video', { 'detail': { 'video_id': guid } } ); window.dispatchEvent( play_event ); }, playHTML5: function( video_el, guid, filetype ) { video_el.show(); video_el[0].load(); /* It seems load() sometimes does not work, but play() will trigger load. * Tried attaching play() to a data event but data might not load * So we trigger play() even if there is not enough data loaded to begin playback */ video_el[0].play(); jQuery.VideoPress.analytics.played(guid, filetype); video_el.bind( "error stalled", function(e) { var message = jQuery.VideoPress.error.messages.error; try { // provide a more detailed error message if a failure reason is communicated switch (e.target.error.code) { case e.target.error.MEDIA_ERR_NETWORK: message = jQuery.VideoPress.error.messages.network; break; case e.target.error.MEDIA_ERR_DECODE: case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED: message = jQuery.VideoPress.error.messages.incapable + " " + filetype.toUpperCase() + "."; break; default: break; } } catch( err ){} // provide an opportunity to silence an error with an empty string if ( message.length > 0 ) { video_el.html( '' + message + "
" ); } message=null; } ); video_el.bind( "durationchange", {guid:guid}, function( event ) { var duration = jQuery(event.target).attr("duration"); if ( jQuery.type(duration)==="number" ) { jQuery.VideoPress.data[event.data.guid].duration = duration; } duration=null; } ); /* Only record stats after video data has loaded * If html5 video seems to work but we could not match on a specific codec descriptor then there may be multiple source elements. Browser chooses a source at runtime in source order. We check the loaded video filetype instead of assuming MP4. */ video_el.one( "loadeddata", {guid:guid, filetype:filetype}, function( event ){ var filetype = event.data.filetype; var loaded_file = jQuery(event.target).attr("currentSrc"); if ( jQuery.type(loaded_file)==="string" && loaded_file.length > 3 ) { var ext = loaded_file.substr( loaded_file.lastIndexOf(".") + 1 ).toLowerCase(); if ( jQuery.inArray( ext, ["mp4","ogv"] ) ) { filetype = ext; } ext=null; } video_el.bind( "play", {guid:event.data.guid,filetype:filetype}, function( event ) { jQuery.VideoPress.analytics.played(event.data.guid, event.data.filetype); } ); video_el.bind( "timeupdate", {guid:event.data.guid,filetype:filetype}, function( event ) { var target = jQuery(event.target); jQuery.VideoPress.analytics.watched( event.data.guid, event.data.filetype, target.attr("currentTime"), target.attr("initialTime") ); target=null; } ); video_el.bind( "ended", {guid:event.data.guid,filetype:filetype}, function( event ) { jQuery.VideoPress.analytics.watched( event.data.guid, event.data.filetype, jQuery.VideoPress.data[guid].duration, jQuery(event.target).attr("initialTime") ); } ); } ); } } }}); ; ( function () { function TiledGalleryCollection() { this.galleries = []; this.findAndSetupNewGalleries(); } TiledGalleryCollection.prototype.findAndSetupNewGalleries = function () { var self = this; var unresizedGalleries = document.querySelectorAll( '.tiled-gallery.tiled-gallery-unresized' ); Array.prototype.forEach.call( unresizedGalleries, function ( el ) { self.galleries.push( new TiledGallery( el ) ); } ); }; TiledGalleryCollection.prototype.resizeAll = function () { Array.prototype.forEach.call( this.galleries, function ( gallery ) { gallery.resize(); } ); }; function TiledGallery( galleryElem ) { this.gallery = galleryElem; this.addCaptionEvents(); // Resize when initialized to fit the gallery to window dimensions this.resize(); // Displays the gallery and prevents it from being initialized again this.gallery.classList.remove( 'tiled-gallery-unresized' ); } /** * Selector for all resizeable elements inside a Tiled Gallery */ TiledGallery.prototype.resizeableElementsSelector = '.gallery-row, .gallery-group, .tiled-gallery-item img'; /** * Story */ TiledGallery.prototype.addCaptionEvents = function () { // Hide captions var galleryCaptions = this.gallery.querySelectorAll( '.tiled-gallery-caption' ); Array.prototype.forEach.call( galleryCaptions, function ( el ) { el.style.display = 'none'; } ); var mouseHoverHandler = function ( e ) { var itemEl = e.target.closest( '.tiled-gallery-item' ); var displayValue = 'mouseover' === e.type ? 'block' : 'none'; if ( itemEl ) { var itemCaption = itemEl.querySelector( '.tiled-gallery-caption' ); if ( itemCaption ) { itemCaption.style.display = displayValue; } } }; // Add hover effects to bring the caption up and down for each item this.gallery.addEventListener( 'mouseover', mouseHoverHandler ); this.gallery.addEventListener( 'mouseout', mouseHoverHandler ); }; TiledGallery.prototype.getExtraDimension = function ( el, attribute, mode ) { if ( mode === 'horizontal' ) { var left = attribute === 'border' ? 'borderLeftWidth' : attribute + 'Left'; var right = attribute === 'border' ? 'borderRightWidth' : attribute + 'Right'; return ( parseInt( el.style[ left ], 10 ) || 0 ) + ( parseInt( el.style[ right ], 10 ) || 0 ); } else if ( mode === 'vertical' ) { var top = attribute === 'border' ? 'borderTopWidth' : attribute + 'Top'; var bottom = attribute === 'border' ? 'borderBottomWidth' : attribute + 'Bottom'; return ( parseInt( el.style[ top ], 10 ) || 0 ) + ( parseInt( el.style[ bottom ], 10 ) || 0 ); } else { return 0; } }; TiledGallery.prototype.resize = function () { // Resize everything in the gallery based on the ratio of the current content width // to the original content width; var originalWidth = parseInt( this.gallery.dataset.originalWidth, 10 ); var currentWidth = parseFloat( getComputedStyle( this.gallery.parentNode, null ).width.replace( 'px', '' ) ); var resizeRatio = Math.min( 1, currentWidth / originalWidth ); var self = this; var resizableElements = this.gallery.querySelectorAll( this.resizeableElementsSelector ); Array.prototype.forEach.call( resizableElements, function ( el ) { var marginWidth = self.getExtraDimension( el, 'margin', 'horizontal' ); var marginHeight = self.getExtraDimension( el, 'margin', 'vertical' ); var paddingWidth = self.getExtraDimension( el, 'padding', 'horizontal' ); var paddingHeight = self.getExtraDimension( el, 'padding', 'vertical' ); var borderWidth = self.getExtraDimension( el, 'border', 'horizontal' ); var borderHeight = self.getExtraDimension( el, 'border', 'vertical' ); // Take all outer dimensions into account when resizing so that images // scale with constant empty space between them var outerWidth = parseInt( el.dataset.originalWidth, 10 ) + paddingWidth + borderWidth + marginWidth; var outerHeight = parseInt( el.dataset.originalHeight, 10 ) + paddingHeight + borderHeight + marginHeight; // Subtract margins so that images don't overflow on small browser windows el.style.width = Math.floor( resizeRatio * outerWidth ) - marginWidth + 'px'; el.style.height = Math.floor( resizeRatio * outerHeight ) - marginHeight + 'px'; } ); }; /** * Resizing logic */ var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame; function attachResizeInAnimationFrames( tiledGalleries ) { var resizing = false; var resizeTimeout = null; function handleFrame() { tiledGalleries.resizeAll(); if ( resizing ) { requestAnimationFrame( handleFrame ); } } window.addEventListener( 'resize', function () { clearTimeout( resizeTimeout ); if ( ! resizing ) { requestAnimationFrame( handleFrame ); } resizing = true; resizeTimeout = setTimeout( function () { resizing = false; }, 15 ); } ); } function attachPlainResize( tiledGalleries ) { window.addEventListener( 'resize', function () { tiledGalleries.resizeAll(); } ); } /** * Ready, set... */ function ready( fn ) { if ( document.readyState !== 'loading' ) { fn(); } else { document.addEventListener( 'DOMContentLoaded', fn ); } } ready( function () { var tiledGalleries = new TiledGalleryCollection(); document.body.addEventListener( 'is.post-load', function () { tiledGalleries.findAndSetupNewGalleries(); } ); if ( typeof jQuery === 'function' ) { jQuery( document ).on( 'page-rendered.wpcom-newdash', function () { tiledGalleries.findAndSetupNewGalleries(); } ); } // Chrome is a unique snow flake and will start lagging on occasion // It helps if we only resize on animation frames // // For other browsers it seems like there is no lag even if we resize every // time there is an event if ( window.chrome && requestAnimationFrame ) { attachResizeInAnimationFrames( tiledGalleries ); } else { attachPlainResize( tiledGalleries ); } if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) { wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function ( placement ) { if ( wp.isJetpackWidgetPlaced( placement, 'gallery' ) ) { tiledGalleries.findAndSetupNewGalleries(); } } ); } } ); } )(); ; ( function () { 'use strict'; if ( typeof window.wpcom === 'undefined' ) { window.wpcom = {}; } if ( window.wpcom.carousel ) { return; } var prebuilt_widths = jetpackCarouselStrings.widths; var pageviews_stats_args = jetpackCarouselStrings.stats_query_args; var findFirstLargeEnoughWidth = function ( original_w, original_h, dest_w, dest_h ) { var inverse_ratio = original_h / original_w; for ( var i = 0; i < prebuilt_widths.length; ++i ) { if ( prebuilt_widths[ i ] >= dest_w || prebuilt_widths[ i ] * inverse_ratio >= dest_h ) { return prebuilt_widths[ i ]; } } return original_w; }; var removeResizeFromImageURL = function ( url ) { return removeArgFromURL( url, 'resize' ); }; var removeArgFromURL = function ( url, arg ) { var re = new RegExp( '[\\?&]' + arg + '(=[^?&]+)?' ); if ( url.match( re ) ) { return url.replace( re, '' ); } return url; }; var addWidthToImageURL = function ( url, width ) { width = parseInt( width, 10 ); // Give devices with a higher devicePixelRatio higher-res images (Retina display = 2, Android phones = 1.5, etc) if ( 'undefined' !== typeof window.devicePixelRatio && window.devicePixelRatio > 1 ) { width = Math.round( width * window.devicePixelRatio ); } url = addArgToURL( url, 'w', width ); url = addArgToURL( url, 'h', '' ); return url; }; var addArgToURL = function ( url, arg, value ) { var re = new RegExp( arg + '=[^?&]+' ); if ( url.match( re ) ) { return url.replace( re, arg + '=' + value ); } else { var divider = url.indexOf( '?' ) !== -1 ? '&' : '?'; return url + divider + arg + '=' + value; } }; var stat = function ( names ) { if ( typeof names !== 'string' ) { names = names.join( ',' ); } new Image().src = window.location.protocol + '//pixel.wp.com/g.gif?v=wpcom-no-pv' + '&x_carousel=' + names + '&baba=' + Math.random(); }; var pageview = function ( post_id ) { new Image().src = window.location.protocol + '//pixel.wp.com/g.gif?host=' + encodeURIComponent( window.location.host ) + '&ref=' + encodeURIComponent( document.referrer ) + '&rand=' + Math.random() + '&' + pageviews_stats_args + '&post=' + encodeURIComponent( post_id ); }; var generateImgSrc = function ( srcItem, max ) { var origSize = srcItem.getAttribute( 'data-orig-size' ) || ''; var src = srcItem.getAttribute( 'src' ) || srcItem.getAttribute( 'original' ) || srcItem.getAttribute( 'data-original' ) || srcItem.getAttribute( 'data-lazy-src' ); if ( src.indexOf( 'imgpress' ) !== -1 ) { src = srcItem.getAttribute( 'data-orig-file' ); } // Square/Circle galleries use a resize param that needs to be removed. src = removeResizeFromImageURL( src ); src = addWidthToImageURL( src, findFirstLargeEnoughWidth( origSize.width, origSize.height, max.width, max.height ) ); return src; }; window.wpcom.carousel = { findFirstLargeEnoughWidth: findFirstLargeEnoughWidth, removeResizeFromImageURL: removeResizeFromImageURL, addWidthToImageURL: addWidthToImageURL, stat: stat, pageview: pageview, generateImgSrc: generateImgSrc }; } )(); ;