From a5b4a6220f4bf777c8fc393a9b31d2fe5fdfb77a Mon Sep 17 00:00:00 2001 From: Owen Leonard Date: Fri, 14 Mar 2008 11:45:16 -0500 Subject: [PATCH] Trying to fancy up the process of adding items to cart. Unfinished. Signed-off-by: Joshua Ferraro --- .../opac-tmpl/prog/en/includes/masthead.inc | 2 +- koha-tmpl/opac-tmpl/prog/en/js/basket.js | 69 ++++++++++++------- koha-tmpl/opac-tmpl/prog/en/js/script.js | 48 +++---------- 3 files changed, 56 insertions(+), 63 deletions(-) diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc index 47e028e57b..521c5147c7 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/masthead.inc @@ -1,6 +1,6 @@ diff --git a/koha-tmpl/opac-tmpl/prog/en/js/basket.js b/koha-tmpl/opac-tmpl/prog/en/js/basket.js index 1b6303865a..19759ffce2 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/basket.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/basket.js @@ -8,6 +8,7 @@ var CGIBIN = "/cgi-bin/koha/"; var nameCookie = "bib_list"; var valCookie = readCookie(nameCookie); +function getBasketCount(){ if(valCookie){ var arrayRecords = valCookie.split("/"); if(arrayRecords.length > 0){ @@ -18,6 +19,9 @@ if(valCookie){ } else { var basketcount = ""; } +return basketcount; +} +var bCount = getBasketCount(); function writeCookie(name, val, wd) { if (wd) { @@ -94,7 +98,7 @@ function addRecord(val, selection,NoMsgAlert) { if ( ! valCookie ) { // empty basket valCookie = val + '/'; write = 1; - updateBasket(1,document); + updateBasket(1); } else { // is this record already in the basket ? @@ -117,7 +121,7 @@ function addRecord(val, selection,NoMsgAlert) { else { valCookie += val + '/'; write = 1; - updateBasket(arrayRecords.length,document); + updateBasket(arrayRecords.length); } } @@ -179,7 +183,6 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t break; } } - var msg = ""; if (nbAdd) { if (i > nbAdd) { @@ -197,9 +200,16 @@ function addSelRecords(valSel) { // function for adding a selection of biblios t msg = MSG_NO_RECORD_ADDED+" ("+MSG_NRECORDS_IN_BASKET+") !"; } } - alert(msg); + $("#cartDetails").html(msg); + cartOverlay.show(); + alert(nbAdd); + newtotal = nbAdd + Number($('#basket span').html()); + setTimeout("cartOverlay.hide(updateCart("+newtotal+"))",5000); } +function updateCart(newtotal){ +$('#cartDetails').html(_("Your cart contains ")+newtotal+_(" items")); +} function selRecord(num, status) { var str = document.myform.records.value @@ -241,7 +251,7 @@ function delSelRecords() { if (rep) { delCookie(nameCookie); document.location = "about:blank"; - updateBasket(0,top.opener.document); + updateBasket(0,top.opener); window.close(); } else { return; @@ -258,7 +268,7 @@ function delSelRecords() { var valCookie = readCookie(nameCookie, 1); strCookie = nameCookie + "=" + valCookie; var arrayRecords = valCookie.split("/"); - updateBasket(arrayRecords.length-1,top.opener.document); + updateBasket(arrayRecords.length-1,top.opener); document.location = CGIBIN + "opac-basket.pl?" + strCookie; } else { @@ -297,7 +307,7 @@ function delBasket() { if (rep) { delCookie(nameCookie); document.location = "about:blank"; - updateBasket(0,top.opener.document); + updateBasket(0,top.opener); window.close(); } } @@ -311,7 +321,7 @@ function quit() { delSelRecords(); } } - updateBasket(arrayRecords.length-1,top.opener.document); + updateBasket(arrayRecords.length-1,top.opener); window.close(); } @@ -356,22 +366,14 @@ function showLess() { } function updateBasket(updated_value,target) { - if(typeof document.getElementById != "undefined") { - if(target.getElementById('basket')){ - target.getElementById('basket').innerHTML = ""+updated_value+""; - } - if(target.getElementById('cartDetails')){ - target.getElementById('cartDetails').innerHTML = _("Your cart contains ")+updated_value+_(" items"); - } - } else if (typeof document.layers != "undefined") { - target.layers['basket'].open(); - target.layers['basket'].write(" ("+updated_value+")"); - target.layers['basket'].close(); - } else if(typeof document.all != "undefined" && typeof -document.getElementById == "undefined") { - target.all['basket'].innerHTML = " ("+updated_value+")"; - } - var basketcount = updated_value; + if(target){ + target.$('#basket').html(""+updated_value+""); + target.$('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items")); + } else { + $('#basket').html(""+updated_value+""); + $('#cartDetails').html(_("Your cart contains ")+updated_value+_(" items")); + } + var bCount = updated_value; } function openBiblio(dest,biblionumber) { @@ -402,3 +404,22 @@ function vShelfAdd() { } } } + +YAHOO.util.Event.onContentReady("cartDetails", function () { + $("#cartDetails").css("display","block").css("visibility","hidden"); + $("#cmspan").html("\"\" Cart"); + if(bCount){ updateBasket(bCount) } +}); + +function cartMenuInit() { + $('#cartmenulink').click(function(){ + openBasket(); return false; + }); + // Build cartOverlay based on markup + cartOverlay = new YAHOO.widget.Overlay("cartDetails", { context:["cartmenulink","tr","br"], visible:false,width:"200px",effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} } ); + cartOverlay.render(); + YAHOO.util.Event.addListener("cartmenulink", "mouseover", cartOverlay.show, cartOverlay, true); + YAHOO.util.Event.addListener("cartmenulink", "mouseout", cartOverlay.hide, cartOverlay, true); + YAHOO.util.Event.addListener("cartmenulink", "click", cartOverlay.hide, cartOverlay, true); +} +YAHOO.util.Event.addListener(window, "load", cartMenuInit); \ No newline at end of file diff --git a/koha-tmpl/opac-tmpl/prog/en/js/script.js b/koha-tmpl/opac-tmpl/prog/en/js/script.js index cce93fc9d5..f5c2767edc 100644 --- a/koha-tmpl/opac-tmpl/prog/en/js/script.js +++ b/koha-tmpl/opac-tmpl/prog/en/js/script.js @@ -41,22 +41,20 @@ $(document).ready(function(){ window.close(); }); $("#logout").click(function(){ - alert("logging out!"); var nameCookie = "bib_list"; var valCookie = readCookie(nameCookie); if (valCookie) { // basket has contents - if(confirm("Are you sure you want to log out? The contents of your cart will be lost")){ - delBasket(); - return true; - } else { - return false; - } + alert("Deleting cart contents!!!"); + updateBasket(0,document); + delCookie(nameCookie); + return true; } else { return true; } }); }); - + +// build Change Language menus YAHOO.util.Event.onContentReady("changelanguage", function () { var oMenu = new YAHOO.widget.Menu("sublangs", { zindex: 2 }); function positionoMenu() { @@ -79,18 +77,11 @@ YAHOO.util.Event.onContentReady("changelanguage", function () { YAHOO.util.Event.addListener("showlang", "click", onYahooClick); YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionoMenu); }); + +// Build lists menu YAHOO.util.Event.onContentReady("listsmenu", function () { $("#listsmenu").css("display","block").css("visibility","hidden"); - $("#cartDetails").css("display","block").css("visibility","hidden"); - - $("#cmspan").html("\"\" Cart"); $("#listsmenulink").attr("href","#").find("span:eq(0)").append("\"\""); - $("#searchsubmit").click(function(){ - $("#searchform").submit(); - }) - - if(basketcount){ updateBasket(basketcount,document) } - var listMenu = new YAHOO.widget.Menu("listsmenu", { lazyload: true }); listMenu.render(); listMenu.cfg.setProperty("context", ["listsmenulink", "tr", "br"]); @@ -101,24 +92,5 @@ YAHOO.util.Event.onContentReady("listsmenu", function () { } YAHOO.util.Event.addListener("listsmenulink", "click", listMenu.show, null, listMenu); YAHOO.widget.Overlay.windowResizeEvent.subscribe(positionlistMenu); - - if(basketcount){ updateBasket(basketcount,document) } - - - }); - -function init() { - $('#cartmenulink').click(function(){ - openBasket(); return false; - }); - // Build cartOverlay based on markup - cartOverlay = new YAHOO.widget.Overlay("cartDetails", { context:["cartmenulink","tr","br"], - visible:false, - width:"200px", - effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.25} } ); - cartOverlay.render(); - YAHOO.util.Event.addListener("cartmenulink", "mouseover", cartOverlay.show, cartOverlay, true); - YAHOO.util.Event.addListener("cartmenulink", "mouseout", cartOverlay.hide, cartOverlay, true); - YAHOO.util.Event.addListener("cartmenulink", "click", cartOverlay.hide, cartOverlay, true); - } - YAHOO.util.Event.addListener(window, "load", init); \ No newline at end of file + }); + -- 2.39.5