/*! * mega.jquery.posts.timeline.js * Copyright (c) 2016 MegaThemes - http://www.megathemes.com * License: MIT */ jQuery(document).ready( function($) { var megaTL = (function () { var megaTL = function () { this.json = {}; var self = this; self.onLoad(self); self.onClick(self); } megaTL.prototype = { calcHeight: function ($this, data, height, offset) { var circle = height + offset + 20; var margin = 0; if (( circle - data.circle ) < 0 ) { var margin = data.circle - circle; $this.css('margin-top', margin + 20 ); } data.circle = circle + margin + 20; return $this.outerHeight(true); }, onLoad: function (self) { $(window).on('load',function() { if ( !$('body').hasClass('mobile')) $('.ys-timeline-posts ul.left').each(function() { var data = {'lHeight': 0, 'rHeight': 1, 'circle': 0, 'rCircle': 1, 'top': 30}; $(this).children('li').each(function() { //$(this).children('img.thumb').on('load',function() { data = self.process(self, this, data); //}); }); $(this).parent().attr({ 'data-left-height': data.lHeight, 'data-right-height': data.rHeight, 'data-circle': data.circle }); }); }); }, process: function (self, el, data) { var $this = $(el); //$this.children('img').appendTo("body"); $this.removeClass('hidden'); var heightz = $this.outerHeight(true); var wrapper = $this.closest('.wrapper'); var offset = $this.children('img').height(); if ( data.lHeight > data.rHeight ) { if ( wrapper.width() > 700 ) { if ( $('body').hasClass('ltr')) { $this.appendTo(wrapper.children('.right')); //var circle = data.rHeight + offset + 20; } } else { if ( !$('body').hasClass('ltr')) $this.appendTo(wrapper.children('.right')); } data.rHeight += self.calcHeight($this, data, data.rHeight, offset); } else { if ( !$('body').hasClass('ltr')) $this.appendTo(wrapper.children('.right')); data.lHeight += self.calcHeight($this, data, data.lHeight, offset); } if ( offset > 0 ) { $this.find('i').css('top', offset + 20); } return data; }, onClick: function (self) { $(document).on('click', 'a.more:not(.disabled)', function( event ) { event.preventDefault(); var $this = $(this); $.ajax( { url: mega.ajax, type: 'POST', data: { action: 'timeline_ajax', nounce: $(this).attr('data-nounce'), instance: $(this).attr('data-instance'), page: $(this).attr('data-page') }, success: function( html ) { var parent = $this.parent();//$('.ys-timeline-posts'); var timeline = parent.children('.wrapper'); var more = parent.children('.more'); more.attr('data-page', parseInt(more.attr('data-page')) + 1); var data = { 'lHeight': parseInt( timeline.attr('data-left-height')), 'rHeight': parseInt( timeline.attr('data-right-height')), 'circle': parseInt( timeline.attr('data-circle')), 'rCircle': 1, 'top': 30 }; var time = 0; $(html).each(function() { var $this = $(this); setTimeout(function() { var li = $this.appendTo(timeline.children('ul.left')); li.removeClass('hidden'); if ( li.children('img').length ) { Holder.run({ images: li.children('img')[0] }); } if ( !$('body').hasClass('mobile')) { data = self.process(self, li, data); timeline.attr({ 'data-left-height': data.lHeight, 'data-right-height': data.rHeight, 'data-circle': data.circle }); } li.hide().show(500); //.animate({ opacity: 1 }, 500); li.addClass('popAnimation').delay(500).queue(function() {$(this).removeClass('popAnimation');}); }, time); time += 1100; }); } }); }); } }; return megaTL; })(); new megaTL(); });