Advertisement
GochiSiyan

float video js

Aug 23rd, 2021
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. (function($){
  2. 'use strict'
  3.  
  4. window.jnews.floating_video = window.jnews.floating_video || {}
  5.  
  6. window.jnews.floating_video = {
  7. container: null,
  8. element: null,
  9. wrapper: null,
  10. videoBottom: null,
  11. closeButton: null,
  12. closed: false,
  13. ww: null,
  14.  
  15. following: false,
  16. position: 'bottom_right',
  17.  
  18. sidebar: null,
  19. offset: null,
  20. width: null,
  21. left: null,
  22.  
  23. init: function (container) {
  24. if (container !== undefined) {
  25. this.container = container
  26. } else {
  27. this.container = $('body')
  28. }
  29.  
  30. this.element = $(this.container).find('.jeg_featured.featured_video')
  31.  
  32. if (this.element.length) {
  33. this.following = this.element.attr('data-following')
  34. this.position = this.element.attr('data-position')
  35.  
  36. if (this.following === '1') {
  37. this.wrapper = $(this.element).find('.jeg_featured_video_wrapper')
  38. this.closeButton = $(this.element).find('.floating_close')
  39. this.resize()
  40.  
  41. $(window).on('scroll', this.scroll.bind(this))
  42. $(window).on('ready resize', this.resize.bind(this))
  43. $(this.closeButton).on('click', this.close.bind(this))
  44. }
  45. }
  46. },
  47. unbind: function () {
  48. $(window).off('scroll', this.scroll.bind(this))
  49. $(window).off('ready resize', this.resize.bind(this))
  50. $(this.closeButton).off('click', this.close.bind(this))
  51. },
  52. close: function () {
  53. this.closed = true
  54. this.element.removeClass('floating')
  55. },
  56. resize: function () {
  57. if (this.element.length) {
  58. this.videoBottom = this.element.outerHeight() + this.element.offset().top
  59. this.ww = $(window).width()
  60. this.sidebar = $('.jeg_sidebar')
  61. }
  62.  
  63. if (this.sidebar.length > 0) {
  64. this.offset = this.sidebar.offset()
  65. this.width = this.sidebar.width()
  66. this.left = parseInt(this.sidebar.css('padding-left')) + parseInt(this.sidebar.css('margin-left'))
  67. }
  68. },
  69. scroll: function () {
  70. if (!this.closed && this.following === '1') {
  71. var windowScrollTop = $(window).scrollTop()
  72.  
  73. if (windowScrollTop > this.videoBottom) {
  74. this.element.addClass('floating')
  75.  
  76. if (this.position === 'sidebar' && this.sidebar.length > 0) {
  77. this.wrapper.width(this.width + 20).css({
  78. top: 100,
  79. left: this.offset.left + this.left - 10,
  80. })
  81. }
  82. } else {
  83. this.element.removeClass('floating')
  84. this.wrapper.removeAttr('style')
  85. }
  86. }
  87. },
  88. }
  89.  
  90. $(document).on('jnews-ajax-load', function(event, element) {
  91. jnews.floating_video.init(element)
  92. })
  93.  
  94. $(document).on('ready', function() {
  95. jnews.floating_video.init()
  96. });
  97.  
  98. })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement