/* This is the JS for the handi holder
Author: Carolina Trejos
*/
if (typeof SPIRIVA == 'undefined')
var SPIRIVA = {};
SPIRIVA.MyFactsToGo= {};
SPIRIVA.MyFactsToGo.DefaultCopy="
What is this?
Your Tips To Go is the place to gather any interesting or useful information you'd like to save for later. It's free!
Just click the "Add"
buttonhh to place any article or tip in your Tips To Go. You'll even have the option of downloading and printing all the things you've saved as a customized PDF.
"
SPIRIVA.MyFactsToGo.ContentCopy="You have in
your Tips to Go folder.
View full list >";
SPIRIVA.MyFactsToGo.DELIM='|';
SPIRIVA.MyFactsToGo.DELIM2='^';
SPIRIVA.MyFactsToGo.CookieKey="tipJar_CookieKey";
SPIRIVA.MyFactsToGo.AlreadyHaveCopy="You have already
added this item to your
Tips to Go folder.
View full list >";
$(document)
.ready(
function() {
// BoxHH
$(".handiholder").click(function(){
window.location='/my-tips.html';
});
$(".handiholder").mouseover(function() {
openHH();
});
$(".handiholder").mouseleave(function() {
closeHH();
});
//
// count items in HH
var pathname = window.location.pathname;
var h2HH = "", pHH = "";
var appendHH = "";
var storeCookie = readCookie(SPIRIVA.MyFactsToGo.CookieKey);
//alert(storeCookie);
if (storeCookie)
{
showHHState();
} else
addToHH();
// Add Items on HH page
$("a.addHandi").live({
mouseover : function() {
onToolTip("tooltip", $(this));
},
mouseout : function() {
// Put back the title attribute's value
outToolTip("tooltip", $(this));
},
click : function() {
var tipJarId = $(this).attr('tipid');
modifyCookieHH(tipJarId);
openHH();
setTimeout("closeHH();showHHState();", "3000");
addToHH();
return false;
}
});
// Add Title of the page to HH
$(".addHandi a").click(function() {
var tipJarId = $(this).attr('tipid');
modifyCookieHH(tipJarId);
openHH();
setTimeout("closeHH();showHHState();", "3000");
addToHH();
});
// Display Tooltip, hide ToolTip, Remove Element
// Select all anchor tag with rel set to tooltip
$('.hhContent .hhMiddle a[rel=tooltip]')
.live(
{
mouseover : function() {
onToolTip("tooltip", $(this));
},
mouseout : function() {
// Put back the title attribute's
// value
outToolTip("tooltip", $(this));
},
click : function() {
removeCookie($(this).attr("tipId"));
$(this).parent().parent().next()
.remove();
$(this).parent().parent().remove();
$('#tooltip').remove();
if ($(".hhContent").length == 0) {
$('.backItemHH').css("display","none");
$(".handiholder .middle").html(SPIRIVA.MyFactsToGo.DefaultCopy);
} else {
$(".backItemHH").html(
$(".hhContent").length);
countHHItems();
}
return false;
}
});
});
function openHH() {
$(".handiholder").addClass("onmouseover");
$(".handiholder .middle").removeClass("hide");
$(".handiholder .middle").addClass("show");
$(".handiholder .bottom").addClass("bottomOn");
}
function closeHH() {
$(".handiholder").removeClass("onmouseover");
$(".handiholder .middle").removeClass("show");
$(".handiholder .middle").addClass("hide");
$(".handiholder .bottom").removeClass("bottomOn");
}
function addToHH() {
var total = parseInt(countHHItems());
$(".handiholder").append(
'' + countHHItems() + '
');
$(".backItemHH").html(total);
if (total == 0) {
$('.backItemHH').css("display", "none");
} else
$('.backItemHH').css("display", "block");
}
function modifyCookieHH(tipJarId) {
if(!containItemInCookie(tipJarId)){
var storeCookie = addRemoveFromCookie(true,tipJarId);
$(".handiholder .middle")
.html(SPIRIVA.MyFactsToGo.ContentCopy);
}else{
$(".handiholder .middle").html(SPIRIVA.MyFactsToGo.AlreadyHaveCopy);
}
}
function countHHItems() {
try{
var storeCookie = readCookie(SPIRIVA.MyFactsToGo.CookieKey);
}
catch(e){
}
var totalItems = 0;
if (storeCookie && storeCookie!="") {
storeCookie = storeCookie.split(SPIRIVA.MyFactsToGo.DELIM);
totalItems = storeCookie.length;
$(".handiholder .middle h2").addClass("hhFull");
$(".handiholder .middle h2 span").html(""+totalItems+" item"+(totalItems>1?"s":""));
}
return totalItems;
}
function removeCookie(item) {
storeCookie = addRemoveFromCookie(false,item);
if (storeCookie == "") {
$("#emptyHH").removeClass("hide");
$("#wcontentHH").addClass("hide");
}
}
function onToolTip(idElement, element) {
// Grab the title attribute's value and assign it to a variable
var tip = element.attr('title');
// Remove the title attribute's to avoid the native tooltip from the browser
element.attr('title', '');
// Append the tooltip template and its value
if (element.hasClass("addHandi")) {
$("#wrapper")
.after(
'');
} else
$("#wrapper").after(
'');
// Set the X and Y axis of the tooltip
var leftPosition = element.parent().offset().left
+ element.parent().outerWidth() - $('#' + idElement + ' p').outerWidth();
$('#' + idElement).css('top', element.parent().offset().top - 25);
$('#' + idElement).css('left', leftPosition);
// Show the tooltip with faceIn effect
/*
* $('#tooltip').fadeIn('500'); $('#tooltip').fadeTo('10',0.8);
*/
}
function outToolTip(idElement, element) {
element.attr('title', $('#' + idElement + ' p').html());
// Remove the appended tooltip template
$('#' + idElement).remove();
}
function downloadPdf() {
var cookieValue = readCookie(SPIRIVA.MyFactsToGo.CookieKey);
if (cookieValue != null) {
window.open("/download.pdf?ids=" + cookieValue);
/*window.location = "/download.pdf?ids=" + cookieValue;*/
}
}
function containItemInCookie(item){
var storeCookie = readCookie(SPIRIVA.MyFactsToGo.CookieKey);
if(storeCookie!=null){
var arrItems = storeCookie.split(SPIRIVA.MyFactsToGo.DELIM);
for(i=0;i