Skip to content

Commit

Permalink
Second pass at responsive videos.
Browse files Browse the repository at this point in the history
Ensure that responsive JS code loads when a user is logged out.

See #77 (comment)
  • Loading branch information
r-a-y committed Dec 7, 2015
1 parent 667518e commit d58ceb1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
29 changes: 0 additions & 29 deletions assets/js/hooks-wp-fee.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,35 +693,6 @@ jQuery(document).ready( function($) {
$window.scrollTo( wtop + 60 );
}
}

// @link https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php
responsive_iframes = function() {
$allVideos = $(".entry-content iframe"),
$fluidEl = $(".entry-content");

$allVideos.each(function() {
$(this)
// jQuery .data does not work on object/embed elements
.attr('data-aspectRatio', $(this).height() / $(this).width() )
.removeAttr('height')
.removeAttr('width');

});

$(window).resize(function() {

var newWidth = $fluidEl.width();
$allVideos.each(function() {

var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.attr('data-aspectRatio'));

});

}).resize();
}
});


35 changes: 34 additions & 1 deletion assets/js/single.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
( function( $ ){
var $description,
$description_char_ratio,
$description_char_count;
$description_char_count,
$allVideos,
$fluidEl;

$( document ).ready( function(){
$( 'body' ).removeClass( 'no-js' ).addClass( 'js' );

responsive_iframes();

if ( 'undefined' !== typeof CACSP_Potential_Readers && $.isFunction( $.fn.select2 ) ) {
$( '#cacsp-group-selector' ).select2( {
placeholder: SocialPaperI18n.group_placeholder
Expand Down Expand Up @@ -75,4 +79,33 @@
$description_char_ratio.addClass( class_to_add );
}

// @link https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php
responsive_iframes = function() {
$allVideos = $(".entry-content iframe"),
$fluidEl = $(".entry-content");

$allVideos.each(function() {
$(this)
// jQuery .data does not work on object/embed elements
.attr('data-aspectRatio', $(this).height() / $(this).width() )
.removeAttr('height')
.removeAttr('width');

});

$(window).resize(function() {

var newWidth = $fluidEl.width();
$allVideos.each(function() {

var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.attr('data-aspectRatio'));

});

}).resize();
}

}( jQuery ) );

0 comments on commit d58ceb1

Please sign in to comment.