|
var sp_freqency = 14500; |
|
var sp_timeout = 1200; |
|
var popbackup = ""; |
|
|
|
var names = ["Anonymous", "Anonymous", "Anonymous", "Someone", "Someone", "Irma", "Frank", "Ella", "Liz", "Sasha", "Mariella", "Jeremy", "Virginia", "Charles", "Karina", "Vihaan", "Reyansh", "Krishna", "Akshay", "Rajesh"]; |
|
var towns = ["Portland","Hillsboro","Beaverton","Bethany","Aloha","Tigard","King City","Forest Grove","Rock Creek","Raleigh Hills","Garden Home","East Portland","Tualatin"]; |
|
|
|
var pastactions = ["Buy Healy"]; |
|
var recentactions = ["Registered Free Lesson", "Buy Healy"]; |
|
var futureactions = ["Buy Healy", "Registered Free Lesson"]; |
|
// set data for the first time |
|
fn_UpdateSocialProofData(); |
|
jQuery(".custom-social-proof").stop().slideToggle('slow'); |
|
|
|
// set interval for popping up/down |
|
var togglevar = setInterval( function() { |
|
fn_ToggleSocialProof(); |
|
}, sp_freqency); //every 14 seconds as defined by sp_freqency var |
|
|
|
// set what to do on close |
|
jQuery(".custom-close").click(function() { |
|
//Stop all timers and hide social proof |
|
clearTimeout(popbackup); |
|
clearTimeout(togglevar); |
|
jQuery(".custom-social-proof").stop().slideToggle('slow'); |
|
}); |
|
|
|
function fn_UpdateSocialProofData() { |
|
var selectedname = names[Math.floor(Math.random() * names.length)]; |
|
var selectedtown = towns[Math.floor(Math.random() * towns.length)]; |
|
|
|
// always select a recent action as a fallback |
|
var selectedaction = recentactions[Math.floor(Math.random() * recentactions.length)]; |
|
var timeperiod = fn_RecentTimeGen(); |
|
// sometimes choose something older |
|
if (fn_Percentage(33)) { |
|
selectedaction = pastactions[Math.floor(Math.random() * pastactions.length)]; |
|
timeperiod = fn_PastTimeGen(); |
|
} |
|
// sometimes choose something tomorrow |
|
if (fn_Percentage(80)) { |
|
selectedaction = futureactions[Math.floor(Math.random() * futureactions.length)]; |
|
timeperiod = fn_FutureTimeGen(); |
|
} |
|
|
|
|
|
jQuery("#sp_customername").text(selectedname); |
|
jQuery("#sp_location").text(selectedtown); |
|
jQuery("#sp_actionname").text(selectedaction); |
|
jQuery("#sp_time").text(timeperiod); |
|
// console.log("updated socialproof"); |
|
} |
|
|
|
function fn_ToggleSocialProof() { |
|
jQuery(".custom-social-proof").stop().slideToggle('slow', function() { |
|
// console.log("gone down") |
|
fn_UpdateSocialProofData(); |
|
}); |
|
// |
|
popbackup = setTimeout( function() { |
|
jQuery(".custom-social-proof").stop().slideToggle('slow'); |
|
// console.log("popped up") |
|
}, sp_timeout); |
|
} |
|
|
|
function fn_Percentage(para_percent) { |
|
if (Math.random() < para_percent/100) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
function fn_RecentTimeGen() { |
|
if (fn_Percentage(80)) { |
|
return fn_PluralReturn(15,"second","seconds") + " ago"; |
|
} |
|
return fn_PluralReturn(50,"second","seconds") + " ago"; |
|
} |
|
|
|
function fn_FutureTimeGen() { |
|
if (fn_Percentage(80)) { |
|
return fn_PluralReturn(15,"mins","mins") + " ago"; |
|
} |
|
return fn_PluralReturn(35,"mins","mins") + " ago"; |
|
} |
|
|
|
function fn_PastTimeGen() { |
|
if (fn_Percentage(80)) { |
|
return fn_PluralReturn(2,"hour","hours") + " ago"; |
|
} |
|
return fn_PluralReturn(2,"hour","hours") + " ago"; |
|
} |
|
|
|
|
|
function fn_PluralReturn(para_number,para_nonplural,para_plural) { |
|
var l_number = Math.ceil(Math.random() * para_number) |
|
if (l_number == 1) { |
|
return "" + l_number + " " + para_nonplural |
|
} |
|
return "" + l_number + " " + para_plural |
|
} |