Skip to content

Instantly share code, notes, and snippets.

@tshafer
Last active January 30, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tshafer/6c329527ca94deb85bebac05e23e2206 to your computer and use it in GitHub Desktop.
Save tshafer/6c329527ca94deb85bebac05e23e2206 to your computer and use it in GitHub Desktop.
//Sample JavaScript implementation
var w = window,
sf = w.$sf,
sfAPI = sf && sf.ext,
myPubCookieValue = "",
settingCookie = false;
//Register the status update listener
function register_content() {
var e;
try {
if (sf) sf.register(970, 90, status_update_handler);
} catch (e) {
console.log("no sf -- > "+ e.message);
sf = null;
}
}
function status_update_handler(status, data) {
console.log(status);
console.log(data);
if (status == "write-cookie") {
myPubCookieValue = data.info;
//now do whatever here since the write was successful
} else if (status == "failed" && data.cmd == "write-cookie") {
//data.cmd contains original command sent
//data.reason contains a description of failure
//data.info contains the object of information sent to host
settingCookie = false;
//cookie not allowed to be set
} else if (status == "read-cookie") {
if(data !== true) {
window.setTimeout(function(){
expandAd();
}, 1000);
window.setTimeout(function(){
collapseAd();
}, 5000);
}
}
}
function get_host_cookie() {
var e;
try {
if (sfAPI && sfAPI.supports("read-cookie")) {
fetchingCookie = sfAPI.cookie("washingtonian-dropdown-ad");
}
} catch (e) {
fetchingCookie = false;
}
}
function set_host_cookie(newVal) {
var e, cookieData = {value:newVal,expires:new Date(2020, 11, 1)};
try {
if (sfAPI && sfAPI.supports("write-cookie")) {
settingCookie = sfAPI.cookie("washingtonian-dropdown-ad", cookieData);
}
} catch (e) {
settingCookie = false;
}
}
function expandAd(){
var g, ex;
try {
g = sfAPI.geom();
ex = g && g.exp;
var config = {
push: false,
t: 0,
l: 0,
r: 0,
b: 200
};
sfAPI.expand(config);
} catch (e) {
//do not expand, not enough room
}
}
function collapseAd(){
sfAPI.collapse();
}
var isOpen = false;
function adtoggle(){
if(isOpen === false) {
expandAd();
isOpen = true;
} else {
collapseAd();
isOpen = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment