var news_obj = {};
news_obj.lists = [
{
id:"a4db5f2336",
name:"Carl M. Cannon's Morning Note",
site:"politics"
},{
id:"d6a76c9ec3",
name: "RCP Daily Poll Wrap-Up",
site:"politics"
},{
id:"51f930c5ce",
name: "RCP Today",
site:"politics"
},{
id:"8c65b915a9",
name: "RCP Morning Reel",
site:"politics"
},{
id:"9da46952f0",
name: "RCP Events",
site:"politics"
},{
id:"694f73a8dc",
name: "Defense Morning Recon",
site:"defense"
},{
id:"267b89dc8a",
name: "Science News",
site:"science"
},{
id:"462961a8ae",
name: "RealClearEnergy Morning Volt",
site:"energy"
},{
id:"d519acabbf",
name: "World News",
site:"world"
},{
id:"b1b7d7c262",
name: "Sports News",
site:"sports"
},{
id:"e6d0b8ecfb",
name: "Weekend Warmup",
site:"sports"
},{
id:"8a051b373b",
name: "Education Today",
site:"education"
},{
id:"b4baf6b587",
name: "RealClearHealth Morning Scan",
site:"health"
},{
id:"0157f00278",
name: "RealClearFuture Dispatch",
site:"RealClearFuture"
},{
id:"113ee1bc69",
name: "Weekly Policy Picks",
site:"policy"
},{
id:"113ee1bc69",
name: "RealClearPolicy",
site:"policy"
},{
id:"7f0a4512a1",
name: "RealClearReligion Today",
site:"religion"
},{
id:"ea772b1135",
name: "RealClearBooks Today",
site:"books"
},{
id:"fbced764bd",
name: "RealClearHistory Today",
site:"history"
},{
id:"1f71a1eaa2",
name: "RealClearMarkets Today",
site:"markets"
},{
id:"d042379c8d",
name: "RealClearInvestigations Today",
site:"investigations"
},{
id:"7d83b1601b",
name: "RealClear Originals",
site:"politics"
}
];
news_obj.inline_found = false;
loadFormHTML();
setFormTriggers();
function loadFormHTML(){
//BUILD FORM HTML FOR PAGE. CSS IN master.css
var html_data = '
';
//html_data += '- RealClear Originals✓
';
html_data += '- Carl M. Cannon\'s Morning Note✓
';
html_data += '- RCP Daily Poll Wrap-Up✓
';
html_data += '- RCP Today ✓
';
html_data += '- RCP Morning Reel✓
';
html_data += '- RCP Events✓
';
html_data += '- RCD Morning Recon ✓
';
html_data += '- Science News✓
';
html_data += '- RealClearEnergy Morning Volt✓
';
html_data += '- World News✓
';
html_data += '- Sports News✓
';
html_data += '- Weekend Warmup✓
';
html_data += '- Education Today✓
';
html_data += '- RealClearHealth Morning Scan✓
';
html_data += '- Europe Memo✓
';
html_data += '- Mideast Memo✓
';
html_data += '- RealClearFuture Dispatch✓
';
/*html_data += '- RealClearFuture Today✓
'; */
html_data += '- Weekly Policy Picks✓
';
html_data += '- RealClearPolicy Today✓
';
html_data += '- RealClearReligion Today✓
';
html_data += '- RealClearBooks Today✓
';
html_data += '- RealClearHistory Today✓
';
html_data += '- RealClearMarkets Today✓
';
html_data += '- RealClearInvestigations Today✓
';
html_data += '
';
html_data += '';
html_data += ''
+'';
html_data += '';
//APPENDS HTML FORM INTO PARENT ELEMENT
$('.jsTag').last().parent().append(html_data);
console.log('newsletter should be written');
//GETS DATA-AUTO-CHECKS ATTRIBUTE FROM JS EMBED
var att = $('.jsTag').last().attr('data-auto-checks');
var auto_checks = [];
if(typeof att !== 'undefined') {
auto_checks = att.split("|"); //SPLITS INTO ARRAY
}
//LOOP THROUGH ALL NEWSLETTER CHECKBOXES
for (var i=0; i 1023){
var inline_sign_up_box_height = parseInt(items_height)+60;
}else{
var inline_sign_up_box_height = parseInt(items_height)+180;
}
$(this).parents('.inline_sign_up_box').css('height', inline_sign_up_box_height+'px');
news_obj.inline_found = true;
}
});
showNewsWidget();
}
function setFormTriggers(){
//$("#list_email").val('Enter your email address');
//BUTTON CLICK
$('.jsTag').last().parent().find("#btn_subscribe").click(function() {
validateForm_v2($(this).parent().parent());
});
//ENTER KEY
$('.jsTag').last().parent().find('#list_email').bind('keypress', function(e) {
if(e.keyCode==13){
validateForm_v2($(this).parent().parent());
}
});
//EMAIL FOCUS SHOW OPTIONS
$('.jsTag').last().parent().find('#list_email').focus(function(){
$(this).parent().parent().find( "#opt-in" ).slideDown();
});
}
function showNewsWidget(){
$(".jQ-news-widget").unbind('click');
$(".jQ-news-widget").click(function(){
//console.log("fired...");
var elem = $(this).parent().next(".newsletter-signup-container2");
//elem.toggle();
//console.log(elem.is(':visible'));
if( elem.is(':visible') ) {
elem.hide();
} else {
elem.show();
}
});
}
function validateForm_v2(target_parent){
var e = target_parent.find('input[name="list_email"]').val();
//console.log('here1');
//console.log(e);
if(validEmail(e)){
//console.log('here2');
target_parent.find('#think_email').html('').hide();
sendSubscribe_v2(target_parent);
}else{
//console.log('here3');
target_parent.find('#think_email').html('Please enter a valid email address.').show();
target_parent.find('#think_subscribe').html('');
}
}
function validEmail(email){
var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
return emailReg.test(email);
}
//SUBMIT FORM AND SUBSCRIBE TO EACH SELECTED NEWSLETTER
function sendSubscribe_v2(target_parent){
target_parent.find('#loader').show();
var opt_in_1 = target_parent.find("#opt-in input#opt_in_1").is(':checked');
var opt_in_2 = target_parent.find("#opt-in input#opt_in_2").is(':checked');
var api_lists = [];
target_parent.find("li.newsletter-select.selected").each(function() {
api_lists.push($(this).attr("id"));
});
if(api_lists.length>0){
$.ajax({
url: window.location.protocol+'//util.realclearpolitics.com/subscriptions/mailchimp_do_subscribe_v2.php?callback=?',
data: 'zelda='+target_parent.find("#zelda").val()+'&list_email='+target_parent.find("#list_email").val()+'&lists='+api_lists+'&optin1='+opt_in_1+'&optin2='+opt_in_2+'&loc='+target_parent.find('.jsTag').attr('data-loc')+'',
dataType: 'jsonp',
jsonpCallback: 'myData',
cache: false,
context: {
target_parent_ref: target_parent
},
success: function(y) {
var target_parent = this.target_parent_ref;
var subscribe_output = '';
api_lists_subscribed = new Array();
api_lists_already_subscribed = new Array();
for(var key in y.data.content){ //STEPS THROUGH EACH CHECKED LIST
var vars = y.data.content[key].split("|");
var status = vars[0];
var email = vars[1];
var list_id = vars[2];
var code = vars[3];
var message = vars[4];
var list_name = $('#list_'+list_id).attr('rel');
if(status!=1){
if(code==214){ //EMAIL ALREADY SUBSCRIBED TO LIST
//subscribe_output += 'Already subscribed to '+list_name+'
';
api_lists_already_subscribed.push(list_name); //APPEND TO ALREADY SUBSCRIBED LIST
}else{
//console.log(message);
subscribe_output += message;
}
}else{ //SUCCESS
api_lists_subscribed.push(list_name); //APPEND TO SUCCESS LISTS ARR
}
}
//alert(api_lists_subscribed.length);
if(api_lists_already_subscribed.length>0){
subscribe_output += 'Already subscribed to the following:
';
for ( var i = 0; i < api_lists_already_subscribed.length; i = i + 1 ) {
subscribe_output += '- • '+api_lists_already_subscribed[i]+'
';
}
subscribe_output += '
';
}
if(api_lists_subscribed.length>0){
subscribe_output += 'Confirmation email shall arrive shortly for:
';
for ( var i = 0; i < api_lists_subscribed.length; i = i + 1 ) {
subscribe_output += '- • '+api_lists_subscribed[i]+'
';
}
subscribe_output += '
';
}
target_parent.find('#loader').hide();
target_parent.find('#list_email').val('');
target_parent.find('#think_email').html(''+subscribe_output+'
').show();
if($(window).width() <= 415){
//var hight_response_ul = $('.newsletter-signup-container2').height();
//var warning_wrapper = $('.warning-wrapper').height();
//console.log(hight_response_ul);
$('.warning-wrapper ul.newsletters').css({display: 'none'});
$('.warning-wrapper #opt-in').hide();
$('warning-wrapper').css({height: '200px !important'});
}
} //END SUCCESS FUNC
}); //END AJAX
} //END IF LISTS CHECK
}