';
} else {
html += '';
}
html += ' ';
html += ' ';
html += ' ';
html += ' ';
html += ' BY';
html += ' ' + p.post_author + '';
html += ' ';
html += '
';
//html += ' ' + postContent + '
';
html += ' ';
html += ' ';
html += '';
return html;
}
function initGoogleAD() {
if ($('.post.excerpt').length >= 3) {
$( ".post.excerpt:nth(2)" ).after(html2);
}
}
function fillPosts(data) {
var className = 'post excerpt';
if (syncADPosts) {
if (!$('.gg_iframe').last().hasClass('loaded')) {
className = 'post excerpt pending';
}
}
_pf_log("fillPosts, className=" + className);
var contentWidth = $('#content').outerWidth() - 20;
var healthHtml = '';
var googleHtml = '';
if (isMobile) {
googleHtml = "googletag.cmd.push(function() { googletag.defineSlot('/70071061/yl-xk/336*280-01-wap', [336, 280], 'div-gpt-ad-1538124262845-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); });googletag.cmd.push(function() { googletag.display('div-gpt-ad-1538124262845-0'); });
";
} else {
googleHtml = "googletag.cmd.push(function() { googletag.defineSlot('/70071061/yl-xk/728*90-01-pc', [728, 90], 'div-gpt-ad-1538124592869-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); }); googletag.cmd.push(function() { googletag.display('div-gpt-ad-1538124592869-0'); });
";
}
var googleHtml2 = replaceAll2(googleHtml, "script2", "script");
_pf_log("adgoogle, googleHtml2=" + googleHtml2);
var adxHtml = '';
if (isMobile) {
adxHtml = "googletag.cmd.push(function() { googletag.defineSlot('/70071061/yl-xk/336*280-02-wap', [336, 280], 'div-gpt-ad-1538124381854-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices();});googletag.cmd.push(function() { googletag.display('div-gpt-ad-1538124381854-0'); });
";
} else {
adxHtml = "googletag.cmd.push(function() { googletag.defineSlot('/70071061/yl-xk/728*90-02-pc', [728, 90], 'div-gpt-ad-1538124636993-0').addService(googletag.pubads()); googletag.pubads().enableSingleRequest(); googletag.enableServices(); });googletag.cmd.push(function() { googletag.display('div-gpt-ad-1538124636993-0'); });
";
}
var adxHtml2 = replaceAll2(adxHtml, "script2", "script");
var fillHtml = "";
var posts = data.posts;
var isHealthAdFilled = false;
if (posts != null) {
for (var i = 0; i < posts.length; i++) {
var p = posts[i];
if (!isValidPost(p)) {
_pf_log('invalid post, ignored, p.ID=' + p.ID + ', p.post_title=' + p.post_title);
continue;
}
var postHtml = getPostHtml(p, className);
postIndex++;
_pf_log("fillPosts, internal, postID=" + p.ID + " ,postTitle=" + p.post_title);
fillHtml += postHtml;
if (postIndex == 2) {
fillHtml += googleHtml2;
try {
_pf_event('adx-impl', 'impl', 'cat');
_pf_log("ga adx-impl cat");
} catch(err) {
}
}
if (postIndex == 8) {
fillHtml += adxHtml2;
isHealthAdFilled = true;
try {
_pf_event('adx-impl', 'impl', 'cat');
_pf_log("ga adx-impl cat");
} catch(err) {
}
}
}
}
if (fillHtml.length > 0) {
if ($('.sponsoredlinks').length > 0) {
$('.sponsoredlinks').last().after(fillHtml);
} else if ($('.post.excerpt').length > 0) {
$('.post.excerpt').last().after(fillHtml);
} else if ($('#content .postsby').length > 0) {
$('#content .postsby').last().after(fillHtml);
_pf_log('fill after postsby');
} else if ($('#content #searchform').length > 0) {
$('#content #searchform').last().after(fillHtml);
} else if ($('#pf-search-button').length > 0) {
$('#pf-search-button').last().after(fillHtml);
} else {
$('#content').html(fillHtml);
_pf_log('fill all');
}
}
// Page view
try {
if (isHealthAdFilled) {
if (typeof ga == "function") ga('send', 'event', 'health-ad-cat-impl');
_pf_log("ga event for health-ad-cat-impl");
}
} catch(err) {
}
_pf_event('post', 'reload', location.href);
_pf_log("ga event for reload");
}
// check count of posts?
var lastPostCount = 0;
$(window).scroll(function(event){
var scrollHeight = $(window).scrollTop();
var windowHeight = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
// NOT working for some case
// windowHeight = $(window).height();
var documentHeight = $(document).height();
if(scrollHeight + windowHeight > documentHeight - BOTTOM_DISTANCE) {
var postCount = $(".post.excerpt").length;
if (lastPostCount != postCount) {
_pf_log("lastPostCount mimatch, prev=" + lastPostCount + ", current=" + postCount);
lastPostCount = postCount;
_pf_log("fire event");
_pf_log("bottom event, scrollHeight=" + scrollHeight + ", windowHeight=" + windowHeight + ", documentHeight=" + documentHeight);
if($('.post.excerpt').length > 0){
$('.post.excerpt').last().after("Loading more ... ...
");
_pf_log('add loading more');
}
// Load posts
loadPosts();
} else {
//_pf_log("skip event");
}
}
var selector = '#content #searchform';
if (searchFormTop == 0) {
searchFormTop = $(selector).offset().top + 100;
_pf_log("searchFormTop=" + searchFormTop);
maxScrollHeight = searchFormTop + 200;
}
// _pf_log('handle search form class, scrollHeight=' + scrollHeight);
if ($(selector).length == 1) {
if (scrollHeight > maxScrollHeight) {
$(selector).last().addClass('pending');
//_pf_log("add pending for searchform");
} else {
$(selector).last().removeClass('pending');
//_pf_log("remove pending for searchform");
}
}
});
$("#pf-search-button").click(function(){
var html = '';
$("#pf-search-button").after(html);
$("#pf-search-button").remove();
});
$(document).on("click", ".post.excerpt .readMore a", function() {
try {
var index = $(this).attr('index');
if (index > 12) {
index = 12;
}
//_pf_log("post read-more click, index=" + index);
if (typeof ga == "function") ga('send', 'event', 'post-readmore-click-' + index);
_pf_log("ga event for post read-more click, index=" + index);
} catch(err) {
}
});
$(document).on("click", ".post.excerpt .title a", function() {
try {
var index = $(this).attr('index');
if (index > 12) {
index = 12;
}
//_pf_log("post title click, index=" + index);
if (typeof ga == "function") ga('send', 'event', 'post-title-click-' + index);
_pf_log("ga event for post title click, index=" + index);
} catch(err) {
}
});
$(document).on("click", ".post.excerpt .health-ad-anchor", function() {
try {
if (typeof ga == "function") ga('send', 'event', 'health-ad-cat-click');
_pf_log("ga event for health-ad-cat-click");
} catch(err) {
}
});
$(window).resize(function(){
_pf_log('window resize');
resetWidth();
});
$(window).on("orientationchange", function() {
_pf_log('window orientationchange');
resetWidth();
});
});
})();