-
Notifications
You must be signed in to change notification settings - Fork 793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPCOM Misc Sync #6900
Merged
Merged
WPCOM Misc Sync #6900
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7cfbc88
Optimize images
georgestephanis 7ee0931
SEO Tools: Replace blog sticker used for business plan check
vindl 85447cf
Partial reversion of r152512 -- it seems changing from h/w/crop to re…
georgestephanis 60d855b
Probably temporary hack to solve some image distortion issues
dllh f48cafd
Tile Galleries: Fix a divide by zero error by making sure that the nu…
enejb b6af253
Responsive Videos: Multiple changes to JS:
thomasguillot 0a3ce0c
Responsive Videos: Multiple changes to JS:
thomasguillot 3bbf060
Social Links: Enable removal of disconnected services
63f1346
Shortcodes: SoundCloud: Test visual from shortcode params, default false
ae3a795
Shortcodes: SoundCloud: Remove ineffective logic around visual default
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
101 changes: 35 additions & 66 deletions
101
modules/theme-tools/responsive-videos/responsive-videos.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,67 @@ | ||
( function( $ ) { | ||
|
||
/** | ||
* A function to help debouncing. | ||
*/ | ||
var debounce = function( func, wait ) { | ||
var resizeTimer; | ||
|
||
var timeout, args, context, timestamp; | ||
function responsiveVideos() { | ||
|
||
return function() { | ||
|
||
context = this; | ||
args = [].slice.call( arguments, 0 ); | ||
timestamp = new Date(); | ||
|
||
var later = function() { | ||
|
||
var last = ( new Date() ) - timestamp; | ||
|
||
if ( last < wait ) { | ||
timeout = setTimeout( later, wait - last ); | ||
} else { | ||
timeout = null; | ||
func.apply( context, args ); | ||
} | ||
|
||
}; | ||
|
||
if ( ! timeout ) { | ||
timeout = setTimeout( later, wait ); | ||
} | ||
|
||
}; | ||
|
||
}; | ||
|
||
/** | ||
* A function to resize videos. | ||
*/ | ||
function responsive_videos() { | ||
|
||
$( '.jetpack-video-wrapper' ).find( 'embed, iframe, object' ).each( function() { | ||
var video_element, video_width, video_height, video_ratio, video_wrapper, video_margin, container_width; | ||
var _this, videoWidth, videoHeight, videoRatio, videoWrapper, videoMargin, containerWidth; | ||
|
||
video_element = $( this ); | ||
video_margin = 0; | ||
_this = $( this ); | ||
videoMargin = 0; | ||
|
||
if ( video_element.parents( '.jetpack-video-wrapper' ).prev( 'p' ).css( 'text-align' ) === 'center' ) { | ||
video_margin = '0 auto'; | ||
if ( _this.parents( '.jetpack-video-wrapper' ).prev( 'p' ).css( 'text-align' ) === 'center' ) { | ||
videoMargin = '0 auto'; | ||
} | ||
|
||
if ( ! video_element.attr( 'data-ratio' ) ) { | ||
video_element | ||
if ( ! _this.attr( 'data-ratio' ) ) { | ||
_this | ||
.attr( 'data-ratio', this.height / this.width ) | ||
.attr( 'data-width', this.width ) | ||
.attr( 'data-height', this.height ) | ||
.css( { | ||
'display' : 'block', | ||
'margin' : video_margin | ||
'margin' : videoMargin | ||
} ); | ||
} | ||
|
||
video_width = video_element.attr( 'data-width' ); | ||
video_height = video_element.attr( 'data-height' ); | ||
video_ratio = video_element.attr( 'data-ratio' ); | ||
video_wrapper = video_element.parent(); | ||
container_width = video_wrapper.width(); | ||
videoWidth = _this.attr( 'data-width' ); | ||
videoHeight = _this.attr( 'data-height' ); | ||
videoRatio = _this.attr( 'data-ratio' ); | ||
videoWrapper = _this.parent(); | ||
containerWidth = videoWrapper.width(); | ||
|
||
if ( video_ratio === 'Infinity' ) { | ||
video_width = '100%'; | ||
if ( videoRatio === 'Infinity' ) { | ||
videoWidth = '100%'; | ||
} | ||
|
||
video_element | ||
_this | ||
.removeAttr( 'height' ) | ||
.removeAttr( 'width' ); | ||
|
||
if ( video_width > container_width ) { | ||
video_element | ||
.width( container_width ) | ||
.height( container_width * video_ratio ); | ||
if ( videoWidth > containerWidth ) { | ||
_this | ||
.width( containerWidth ) | ||
.height( containerWidth * videoRatio ); | ||
} else { | ||
video_element | ||
.width( video_width ) | ||
.height( video_height ); | ||
_this | ||
.width( videoWidth ) | ||
.height( videoHeight ); | ||
} | ||
|
||
} ); | ||
|
||
} | ||
|
||
/** | ||
* Load responsive_videos(). | ||
* Trigger resize to make sure responsive_videos() is loaded after IS. | ||
*/ | ||
$( window ).load( responsive_videos ).resize( debounce( responsive_videos, 100 ) ).trigger( 'resize' ); | ||
$( document ).on( 'post-load', responsive_videos ); | ||
$( document ).ready( function() { | ||
$( window ) | ||
.on( 'load.jetpack', responsiveVideos ) | ||
.on( 'resize.jetpack', function() { | ||
clearTimeout( resizeTimer ); | ||
resizeTimer = setTimeout( responsiveVideos, 500 ); | ||
} ) | ||
.on( 'post-load.jetpack', responsiveVideos ) | ||
.resize(); | ||
} ); | ||
|
||
} )( jQuery ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for adding the namespace 👍