File: /home/dailygoldindex/public_html/wp-content/themes/jnews/assets/js/sidefeed.js
!function(e){"use strict";function t(){var t=e("#jeg_sidecontent");if(t.length){var a,n,i,o=e(".jeg_header.full").outerHeight()||0,s=e(".jeg_stickybar"),d=0,r=0;!function(){var t=e(".sidecontent_postwrapper");if(t.length){t.jScrollPane({mouseWheelSpeed:50});var a=t.data("jsp"),n=1==jnewsoption.admin_bar?32:0;e(window).on("resize load",(function(){e(window).width()>1024?t.css("height",e(window).height()-e(".jeg_side_heading").outerHeight()-n):(e("#jeg_sidecontent").css("height",e(window).height()-e(".jeg_navbar_mobile_wrapper").outerHeight()),t.css("height",e(window).height()-e(".jeg_side_heading").outerHeight()-e(".jeg_navbar_mobile_wrapper").outerHeight())),a.reinitialise()}))}}();var c=function(){r=e(window).scrollTop(),d=1==jnewsoption.admin_bar?32:0,s.length&&(a=s.css("-webkit-transform")||s.css("-moz-transform")||s.css("-ms-transform")||s.css("-o-transform")||s.css("transform"),n=a.replace(/[^0-9\-.,]/g,"").split(","),i=n[13]||n[5]),r>o?(t.addClass("fixed"),e(".jeg_header").hasClass("full")&&i>0&&s.length&&(d+=s.outerHeight())):(t.removeClass("fixed"),d=o+d),t.css({top:d})};e(window).width()>1024?e(window).on("scroll load",c):e(window).off("scroll load",c)}}window.jnews.sidefeed=window.jnews.sidefeed||{},window.jnews.sidefeed={init:function(){var t=this;t.container=e("#jeg_sidecontent"),t.container.length&&(t.variable=window.side_feed,t.xhr=null,t.xhr_cache=[],t.lock_action=!1,t.current_post_id=jnewsoption.postid,t.min_prev_sidefeed=5,t.post_xhr=null,t.post_xhr_cache=[],t.tab=t.container.find(".jeg_side_tabs > li"),t.menu=t.container.find(".jeg_filter_menu a"),t.loadbutton=t.container.find(".sidefeed_loadmore button"),t.sidefeed=t.container.find(".jeg_sidefeed"),t.overlay_loader=t.container.find(".jeg_sidefeed_overlay"),t.sectionwrap=e(".post-wrapper"),t.postoverlay=e(".post-ajax-overlay"),t.bind_autoload(),t.bind_tab(),t.bind_menu(),t.bind_load_button(),jnewsoption.sidefeed_ajax&&t.bind_ajax())},load_first_item:function(){var t=this.sidefeed.find(".jeg_post").first();t&&e(t).find("a.ajax").trigger("click")},load_ajax:function(t,a,n){var i=this;"append"===t?e(i.sidefeed).append(n.content):"replace"===t&&i.sidefeed.html(n.content),i.after_ajax_request(t,a,n)},cache_get:function(e){for(var t=this,a=JSON.stringify(e),n=0;n<t.xhr_cache.length;n++)if(t.xhr_cache[n].param==a)return t.xhr_cache[n].result;return!1},cache_save:function(e,t){var a=JSON.stringify(e);this.xhr_cache.push({param:a,result:t})},before_ajax_request:function(t){var a=this;"append"===t?a.loadbutton.addClass("btn-loading").text(e(a.loadbutton).data("loading")):"replace"===t&&a.overlay_loader.show(),a.lock_action=!0},after_ajax_request:function(t,a,n){var i=this;i.loadbutton.removeClass("btn-end").text(e(i.loadbutton).data("loadmore")),n.next?i.loadbutton.text(e(i.loadbutton).data("loadmore")):i.loadbutton.addClass("btn-end").text(e(i.loadbutton).data("end")),"append"===t?i.loadbutton.removeClass("loading"):"replace"===t&&(i.overlay_loader.hide(),i.load_first_item(),i.active_state_feed(i.current_post_id)),i.lock_action=!1,i.cache_save(a,n),i.reinitialize_view()},load_content:function(t){var a=this;a.before_ajax_request(t);var n={action:"jnews_newsfeed_load",data:a.variable},i=a.cache_get(n);a.xhr&&a.xhr.abort(),i?a.load_ajax(t,n,i):a.xhr=e.ajax({url:jnews_ajax_url,type:"post",dataType:"json",data:n,success:e.proxy(a.load_ajax,a,t,n)})},bind_autoload:function(){var t=this;e(document).on("jnews-autoload-change-id",(function(e,a){t.current_post_id=a,t.active_state_feed(a)}))},bind_tab:function(){var t=this;t.tab.on("click",(function(a){a.preventDefault(),t.lock_action||(t.tab.removeClass("active"),e(this).addClass("active"),t.variable.sort_by=e(this).data("sort"),t.variable.paged=1,t.load_content("replace"))}))},bind_menu:function(){var t=this;t.menu.on("click",(function(a){a.preventDefault(),t.lock_action||(t.menu.removeClass("active"),e(this).addClass("active"),t.variable.include_category=e(this).data("id"),t.variable.paged=1,t.load_content("replace"))}))},bind_load_button:function(){var e=this;e.loadbutton.on("click",(function(t){t.preventDefault(),e.lock_action||e.loadbutton.hasClass("btn-end")||(e.variable.paged=e.variable.paged+1,e.load_content("append"))}))},bind_ajax:function(){var t=this;jnewsoption.isblog&&window.history&&window.history.pushState&&t.ajax_dispatch(),window.history.pushState&&!jnewsoption.ismobile&&e(window).on("popstate",e.proxy(t.popstate,t))},popstate:function(e){var t=this;if(void 0!==e.originalEvent){var a=e.originalEvent.state,n=location.href;"sidefeed"===a.type&&(t.current_post_id=a.postid,t.active_state_feed(t.current_post_id),t.do_request(n,!0))}},ajax_dispatch:function(){var t=this;t.sidefeed.on("click","a.ajax",(function(a){a.preventDefault();var n=e(this).parents(".jeg_post"),i=e(n).data("id"),o=e(this).attr("href");i==t.current_post_id||(e("body").removeClass("menu-active").removeClass("push-content-right"),t.current_post_id=i,t.set_side_active(n),t.do_request(o,!1))}))},do_request:function(t,a){var n=this;n.postoverlay.fadeIn(500,(function(){e(document).trigger("jnews-sidefeed-ajax-begin"),n.sectionwrap.height(e(window).height()),n.sectionwrap.find(".post-wrap").remove(),e("html, body").scrollTop(0),n.fetch_content(t,n.current_post_id,a)}))},active_state_feed:function(e){var t=this;t.sidefeed.find(".jeg_post").removeClass("active");var a=t.sidefeed.find(".jeg_post[data-id="+e+"]").addClass("active");t.load_sidefeed_content(a),t.scroll_to_view(a)},load_sidefeed_content:function(e){for(var t=0;t<this.min_prev_sidefeed;t++)e.length&&(e=e.next());0===e.length&&this.try_load_sidefeed_content()},try_load_sidefeed_content:function(){this.loadbutton.trigger("click")},close_curtain:function(){this.postoverlay.fadeOut(500),this.sectionwrap.css({height:"auto"})},fetch_content:function(t,a,n){var i=this;null!==i.post_xhr&&i.post_xhr.abort(),i.post_xhr=e.ajax({url:t,type:"get",dataType:"html",success:function(e){n||window.history.pushState({postid:a,type:"sidefeed"},"",t),jnews.ajax_analytic.update(t,a),i.set_meta_data(e),i.setup_content(e,a)},timeout:function(){window.location=t}})},set_side_active:function(t){var a=this;a.sidefeed.find(".jeg_post").removeClass("active"),e(t).addClass("active"),a.load_sidefeed_content(t),a.scroll_to_view(t)},reinitialize_view:function(){e(".sidecontent_postwrapper").data("jsp").reinitialise(),setTimeout((function(){window.dispatchEvent(new Event("resize"))}),500)},scroll_to_view:function(t){if(e(t).length){var a=e(".sidecontent_postwrapper"),n=a.data("jsp"),i=e(t).position().top,o=a.height(),s=i+e(".jspPane").position().top,d=e(t).height();if(s<0||s>o-d){var r=0;r=s<0?i-20:i-o+d+50,n.scrollTo(0,r)}}},set_meta_data:function(t){var a=e(t).filter("title").text(),n=e(t).filter("meta[name=keyword]").attr("content"),i=e(t).filter("meta[name=description]").attr("content");e("meta[name=description]").attr("content",i),e("meta[name=keyword]").attr("content",n),document.title=a},setup_content:function(t,a){var n=e(t).find(".post-wrap");this.sectionwrap.append(n);var i=e(t).find("#post-body-class").attr("class");e("body").attr("class",i),this.close_curtain(),e(document).trigger("jnews-sidefeed-ajax",[a]),e(document).trigger("jnews-ajax-load",[n])}},e(document).on("ready",(function(){t(),jnews.sidefeed.init()}))}(jQuery);