Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. jQuery(document).ready(function($){
  2.  
  3. // Fix video ratio
  4. function fix_video_ratio(dom){
  5. var providers = ['youtube.com', 'vimeo.com', 'dailymotion.com', 'viddler.com'];
  6. if ( !dom )
  7. dom = 'body';
  8. for ( var p = 0; p < providers.length; p++ ){
  9. var videos = $(dom).find('iframe[src*="'+providers[p]+'"]');
  10. if ( videos.size() > 0 )
  11. videos.each(function(){
  12. if ( !$(this).parent().is('.video-keep-ratio-wrap') && parseInt($(this).attr('width')) > $(this).parent().width() ){
  13. var ratio = parseInt($(this).attr('height')) / parseInt($(this).attr('width'));
  14. $(this).wrap('<div class="video-keep-ratio-wrap"></div>');
  15. $(this).parent().css('padding-bottom', (ratio*100)+'%');
  16. }
  17. });
  18. }
  19. }
  20. fix_video_ratio();
  21.  
  22. $(window).resize(function(){
  23. fix_video_ratio();
  24. });
  25.  
  26.  
  27. /* Attach ajaxComplete on activity loading */
  28. $(document).ajaxComplete(function(e, xhr, settings){
  29. if(settings.data){
  30. if ( settings.data.match(/action=(activity_get_older_updates|.+?_filter)/i) ){
  31. // this is activity loading, finding the loaded list by looking at response
  32. var rgx = /id=["'](activity-\d+)["']/ig;
  33. var activity_ids = xhr.responseJSON.contents.match(rgx);
  34. if ( activity_ids ){
  35. setTimeout(function(){
  36. $.each(activity_ids, function(index, activity_id){
  37. var id = activity_id.replace(rgx, '$1'),
  38. el = $('#'+id).get(0);
  39. if ( FB )
  40. FB.XFBML.parse(el);
  41. fix_video_ratio(el);
  42. });
  43. }, 1000);
  44. }
  45. }
  46. }
  47. });
  48.  
  49. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement