/** * cerkl_awp.js v1.0.1 * Cerkl Automated Personalized Web. * * Copyright 2016, Cerkl * */ cerkl_awp = function(params) { // var DOMAIN = 'http://staging-cerkl.gopagoda.io'; var DOMAIN = 'https://cerkl.com'; // var DOMAIN = 'http://localhost/cerkl'; var VERSION = '1.0.1'; var that; var attrs; var jQuery; var vid; var link = '
'; //currently serves as an externally-unmodifiable wrapper var cookie_email = null, drop_name= 'Aptly {{display_name}}
';
cookie_id = null;
(function(){
that = params.div;
attrs = {
organization_id: null,
wide: false,
image_size: 'sm',
image_type: 'sq',
item_width: '300px',
headline: {
font_size: '.9em',
font_weight: 'bolder'
},
for_you: {
enabled: true,
style: '
';
getData(true);
}
});
})
var open_dialog = function(uri, name, options, closeCallback) {
var win = window.open(uri, name, options);
win_log_interval = window.setInterval(function() {
try {
if (win == null || win.closed) {
window.clearInterval(win_log_interval);
closeCallback(win);
}
}
catch (e) {
}
}, 1000);
return win;
};
jQuery('.c_awp_btn_toggle_login').click(function(e){
e.preventDefault();
if (win_log_interval != null) window.clearInterval(win_log_interval);
if (cookie_id == null){
cookie_id = request_new_id(function(data){
if (data==null){
}else{
open_dialog(DOMAIN + '/awp/account.php?cerkl_u_c=' + cookie_id, 'c_awp_win', 'width=550px,height=400px', function(win){
getData(true);
})
}
});
}else{
open_dialog(DOMAIN + '/awp/account.php?cerkl_u_c=' + cookie_id, 'c_awp_win', 'width=550px,height=400px', function(win){
getData(true);
});
}
})
jQuery('.c_awp_btn_register').data('r_type', 'l');
jQuery('.c_awp_btn_settings').click(function(e){
jQuery(this).parents('.dropdown').toggleClass('open');
e.stopPropagation();
});
jQuery(document).click(function(e){
jQuery('.c_awp_btn_settings').parents('.dropdown').removeClass('open');
})
jQuery('.c_awp_btn_register').click(function(e){
if (jQuery(this).text().trim()=='Register'){
jQuery(this).data('r_type', 'r');
jQuery('#c_awp_modal_login h1').text('Register Account');
jQuery('#c_awp_p_full_name').fadeIn();
jQuery('.c_awp_btn_submit').text('Create');
jQuery(this).text('Already Registered')
}else{
c_awp_reset_login();
}
jQuery('.c_awp_modal input:visible:first').focus();
});
jQuery('.c_awp_btn_toggle').click(function(e){
if (jQuery('.c_awp_modal-backdrop').length == 0){
var backdrop = jQuery('');
jQuery(document).find("body").append(backdrop);
}
jQuery('.c_awp_modal-backdrop').addClass('in');
jQuery('#' + jQuery(this).attr('data-target')).addClass('in').show();
jQuery('#' + jQuery(this).attr('data-target')).click(function(e){
jQuery('.c_awp_modal').removeClass('in').hide();
jQuery('.c_awp_modal-backdrop').removeClass('in');
})
jQuery('.c_awp_modal-dialog').click(function(e){
e.stopPropagation();
})
jQuery('.c_awp_modal input:visible:first').focus();
});
jQuery('button[data-dismiss="c_awp_modal"]').click(function(e){
jQuery('.c_awp_modal').removeClass('in').hide();
jQuery('.c_awp_modal-backdrop').removeClass('in');
})
//called inside a JQuery ready context
jQuery(".c_awp_item").not('.c_awp_hidden').click(function (e){
var that = jQuery(this);
var ue = jQuery(this).attr('data-ue');
var url = jQuery(this).attr('href');
if (ue.trim() != ""){
e.preventDefault();
jQuery.ajax({
url: DOMAIN + "/awp/" + VERSION + "/cerkl_awp.php?callback=?&action=c&cerkl_ue=" + ue,
dataType: 'jsonp',
error: function (jqXHR, textStatus) {
window.location.href=url;
},
success: function(data) {
if (data.length>0){
if(url.indexOf('?') !== -1){
url += '&cerkl_ue=' + data;
}else{
url += '?cerkl_ue=' + data;
}
}
window.location.href=url;
}
});
}
//alert(jQuery(this).find('.c_awp_headline').text() + ' was clicked;');
});
function resize_image(){
var wrapper_width = jQuery('.c_awp_item_wrapper:first()').width();
if (attrs.image_type == 'rect'){
jQuery('.c_awp_item_wrapper .c_awp_story_img').css('height', wrapper_width * .65);
}else{
jQuery('.c_awp_item_wrapper .c_awp_story_img').css('height', wrapper_width );
}
}
jQuery(window).resize(function(e){
resize_image();
})
resize_image();
}
function getData(r){
if (r==undefined) r = false;
cookie_email = getCookie("cerkl_e_c");
cookie_id = getCookie("cerkl_u_c");
var thru_email = null;
var thru_id = null;
var jsonp_url;
if(attrs.email != undefined){
if(cookie_email !== null){
if(cookie_email == attrs.email){
thru_email = attrs.email;
thru_id = cookie_id;
} else {
thru_email = attrs.email;
}
}else{
if(cookie_id !== null){
thru_email = attrs.email;
thru_id = cookie_id;
} else{
thru_email = attrs.email;
}
}
} else{
if(cookie_id !== null){
if(cookie_email !== null){
thru_email = cookie_email;
thru_id = cookie_id;
} else{
thru_id = cookie_id;
}
} else{
//pass nothing
}
}
var append="";
if (thru_email !== null) append += "&email=" + thru_email;
if (thru_id !== null) append += "&user_id=" + thru_id;
var action = (r ? 'r' : 'v');
if (attrs.organization_id !== null) append += "&organization_id=" + params.organization_id; else return;
if (attrs.popular.enabled==false) append += "&popular=false";
if (attrs.newest.enabled==false) append += "&newest=false";
if (attrs.last.enabled==false) append += "&last=false";
jsonp_url = DOMAIN + "/awp/" + VERSION + "/cerkl_awp.php?callback=?&action=" + action + append;
//jsonp(jsonp_url);
jQuery.ajax({
url: jsonp_url,
dataType: 'jsonp',
error: function (jqXHR, textStatus) {
},
success: function(response) {
process(response);
}
});
}
function setCookie(cname, cvalue, exdays) {
//independent of jquery
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var append = "; expires="+ d.toUTCString() + "; path=/";
document.cookie = cname + "=" + cvalue + "; " + append;
}
function getCookie(cname) {
//independent of jquery
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i = 0; i
';
return html_now;
}
return "";
}
html += section(for_you_news,attrs.for_you);
html += section(popular_news,attrs.popular);
html += section(newest_news,attrs.newest);
html += section(last_news,attrs.last);
if (html == '') {
html += '