Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- 'use strict'
- window.jnews.floating_video = window.jnews.floating_video || {}
- window.jnews.floating_video = {
- container: null,
- element: null,
- wrapper: null,
- videoBottom: null,
- closeButton: null,
- closed: false,
- ww: null,
- following: false,
- position: 'bottom_right',
- sidebar: null,
- offset: null,
- width: null,
- left: null,
- init: function (container) {
- if (container !== undefined) {
- this.container = container
- } else {
- this.container = $('body')
- }
- this.element = $(this.container).find('.jeg_featured.featured_video')
- if (this.element.length) {
- this.following = this.element.attr('data-following')
- this.position = this.element.attr('data-position')
- if (this.following === '1') {
- this.wrapper = $(this.element).find('.jeg_featured_video_wrapper')
- this.closeButton = $(this.element).find('.floating_close')
- this.resize()
- $(window).on('scroll', this.scroll.bind(this))
- $(window).on('ready resize', this.resize.bind(this))
- $(this.closeButton).on('click', this.close.bind(this))
- }
- }
- },
- unbind: function () {
- $(window).off('scroll', this.scroll.bind(this))
- $(window).off('ready resize', this.resize.bind(this))
- $(this.closeButton).off('click', this.close.bind(this))
- },
- close: function () {
- this.closed = true
- this.element.removeClass('floating')
- },
- resize: function () {
- if (this.element.length) {
- this.videoBottom = this.element.outerHeight() + this.element.offset().top
- this.ww = $(window).width()
- this.sidebar = $('.jeg_sidebar')
- }
- if (this.sidebar.length > 0) {
- this.offset = this.sidebar.offset()
- this.width = this.sidebar.width()
- this.left = parseInt(this.sidebar.css('padding-left')) + parseInt(this.sidebar.css('margin-left'))
- }
- },
- scroll: function () {
- if (!this.closed && this.following === '1') {
- var windowScrollTop = $(window).scrollTop()
- if (windowScrollTop > this.videoBottom) {
- this.element.addClass('floating')
- if (this.position === 'sidebar' && this.sidebar.length > 0) {
- this.wrapper.width(this.width + 20).css({
- top: 100,
- left: this.offset.left + this.left - 10,
- })
- }
- } else {
- this.element.removeClass('floating')
- this.wrapper.removeAttr('style')
- }
- }
- },
- }
- $(document).on('jnews-ajax-load', function(event, element) {
- jnews.floating_video.init(element)
- })
- $(document).on('ready', function() {
- jnews.floating_video.init()
- });
- })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement