Having problems with "position:fixed; bottom:0%;" and dropzone div's

4 views
Skip to first unread message

Masier

unread,
Oct 18, 2006, 12:33:48 AM10/18/06
to Ruby on Rails: Spinoffs
Hello, after searching through other posts I have not found this
problem.

What I am trying to do is to create a simple shopping cart. What I had
hoped was to have a div that is positioned to the bottom of the browser
window (the cart). Therefore customers can drag items into the cart as
they browse the catalogue. Nothing too tough, or so I thought. However
in the below example I can drag items from 1 - 6 into the cart without
a problem but when I scroll down to 7 - 12 and try to drop stuff into
the cart it doesn't pick it up.

What am I missing?? Any solutions or pointers in the right direction
would be greatly appreciated. I am using the current 1.6.4 release.

PS I should also mention this example is for fire fox and the like.


Example.php

____________________________________________________________________________

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"
/>
<title>Ajax Workshop 3: Shopping Cart using Script.aculo.us</title>
<script src="prototype.js" type="text/javascript"></script>
<script src="scriptaculous.js" type="text/javascript"></script>
<style media="screen" type="text/css">
body {
font-family:"Trebuchet MS";
font-size:12px;
}
#body {
position:absolute;
width:99%;
height:99%;
background-color:#ffffff;
overflow:auto;
}

#cart {
background-color:#FFFF66;
border:dashed gray 1px;
height:100px;
width:500px;
padding:5px;
margin-top:10px;
overflow: auto;
position: fixed;
bottom:0%;
}
#products {
background-color:#FFF;
border:dashed gray 1px;
height:100px;
width:500px;
padding:5px;
}
#productstoscroll {
position:absolute;
top:1200px;
background-color:#FFF;
border:dashed gray 1px;
height:100px;
width:500px;
padding:5px;
}
#spaceforcart {
position:absolute;
top:1310px;
height:100px;
width:1px;
padding:1px;
visibility: hidden;
}
.box {
background-color:#CCFF33;
border:solid gray 1px;
margin:10px;
padding:4px;
width:50px;
height:50px;
float:left;
cursor:pointer;
position: static;

}
#loading {
display:none;
float:right;
}
#clearCart {
color:blue;
text-decoration:underline;
cursor:pointer;
float:right;
}
#clearCart:hover {
background-color:#CCFFCC;
color:#000099;
}
</style>
<script language="javascript" type="text/javascript">
function addProduct(element, dropon, event) {
sendData(element.id);
}
function sendData (prod) {
var url = 'cart.php';
var rand = Math.random(9999);
var pars = 'product_id=' + prod + '&rand=' + rand;
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
}
function clearCart () {
var url = 'cart.php';
var rand = Math.random(9999);
var pars = 'clear=true&rand=' + rand;
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
}
function clearProduct (id) {
var url = 'cart.php';
var rand = Math.random(9999);
var pars = 'clearProduct=true&id=' + id + '&rand=' + rand;
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
}
function showResponse (originalRequest) {
$('loading').style.display = "none";
$('clearCart').style.display = "block";
$('cart').innerHTML = originalRequest.responseText;
}
function showLoad () {
$('clearCart').style.display = "none";
$('loading').style.display = "block";
}
</script>
</head>
<div id="hypv-feedback" style="position:absolute; border:1px solid
#f90; background-color:#ccc; top:0px; left:0px; padding:2px;
width:75px; height:75px; display:none;font-size:110%;">Click Me</div>
<script type="text/javascript">
Position.Window = {
//extended prototypes position to return the scrolled window
deltas
getDeltas: function() {
var deltaX = window.pageXOffset
|| document.documentElement.scrollLeft
|| document.body.scrollLeft
|| 0;
var deltaY = window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop
|| 0;
return [deltaX, deltaY];
},
//extended prototypes position to return working window's size,
copied this code from the tooltip.js library based on prototype.
size: function() {
var winWidth, winHeight, d=document;
if (typeof window.innerWidth!='undefined') {
winWidth = window.innerWidth;
winHeight = window.innerHeight;
} else {
if (d.documentElement && typeof
d.documentElement.clientWidth!='undefined' &&
d.documentElement.clientWidth!=0) {
winWidth = d.documentElement.clientWidth
winHeight = d.documentElement.clientHeight
} else {
if (d.body && typeof
d.body.clientWidth!='undefined') {
winWidth = d.body.clientWidth
winHeight = d.body.clientHeight
}
}
}
return [winWidth, winHeight];
}
}

</script>
<body>
<div id=body>
<div id="cart">
<div style="float:left; font-weight:bold">Shopping Cart</div>
</div>
<h1>Ajax Workshop 3: Shopping Cart using <a
href="http://script.aculo.us">Script.aculo.us</a> </h1>
<h2>Drag the products into the shopping cart</h2>
<div id="products">
<div style="float:left; font-weight:bold">Products</div>
<div id="clearCart" onclick="clearCart();">Clear Cart</div>
<div id="loading"><img src="indicator.gif" alt="loading..." /></div>
<br style="clear:both" />
<div class="box" id="product_1">1</div>
<div class="box" id="product_2">2</div>
<div class="box" id="product_3">3</div>
<div class="box" id="product_4">4</div>
<div class="box" id="product_5">5</div>
<div class="box" id="product_6">6</div>
</div>
<div id="productstoscroll">
<div style="float:left; font-weight:bold">Products</div>
<div id="clearCart" onclick="clearCart();">Clear Cart</div>
<div id="loading"><img src="indicator.gif" alt="loading..." /></div>
<br style="clear:both" />
<div class="box" id="product_7">7</div>
<div class="box" id="product_8">8</div>
<div class="box" id="product_9">9</div>
<div class="box" id="product_10">10</div>
<div class="box" id="product_11">11</div>
<div class="box" id="product_12">12</div>
</div>

<div id="spaceforcart">
<div style="float:left; font-weight:bold">Shopping Cart</div>
</div>
<script type="text/javascript">
var products = document.getElementsByClassName('box');
for (var i = 0; i < products.length; i++) {
new Draggable(products[i].id, {ghosting:true, revert:true})
}
Droppables.add('cart', {onDrop:addProduct})
</script>
</div>
</body>
</html>


___________________________________________________________________________


cart.php

____________________________________________________________________________

<?php
session_start();
function stringForJavascript($in_string) {
print "$in_string <br />";
$str = ereg_replace("[\r\n]", " \\n\\\n", $in_string);
$str = ereg_replace('"', '\\"', $str);
Return $str;
}
if (isset($_GET['clearProduct'])) {
$_SESSION['cart'][$_GET['id']]--;
if ($_SESSION['cart'][$_GET['id']] == 0) {
unset($_SESSION['cart'][$_GET['id']]);
}
foreach ($_SESSION['cart'] as $key => $value) {
print "$key = $value <span style=\"color:blue;
text-decoration:underline; cursor:pointer\"
onclick=\"clearProduct('$key');\">DELETE</span><br />";
}
sleep(1);
die;
}
if (isset($_GET['clear'])) {
unset($_SESSION['cart']);
sleep(1);
die;
}
$prodid = $_GET['product_id'];
$_SESSION['cart'][$prodid] = 1 + $_SESSION['cart'][$prodid];
foreach ($_SESSION['cart'] as $key => $value) {
print "$key = $value <span style=\"color:blue;
text-decoration:underline; cursor:pointer\"
onclick=\"clearProduct('$key');\">DELETE</span><br />";
}
sleep(1);
?>

Brian Peiris

unread,
Oct 18, 2006, 2:48:12 AM10/18/06
to rubyonrail...@googlegroups.com
It's not that the cart isn't pickup up the drop, it's just offset so the drop location is actually an invisible area above the cart.
I added two lines to the 'within' method of the Position class in prototype.js that seems to fix your problem
It's not a permanent fix, just a clue to what's going wrong. I'm sure it will break other cases

  within: function(element, x, y) {
    if (this.includeScrollOffsets)
      return this.withinIncludingScrolloffsets (element, x, y);
    this.xcomp = x;
    this.ycomp = y;
    this.offset = this.cumulativeOffset(element);
        this.offset[0]+=this.realOffset(element)[0];// ADDED THESE
        this.offset[1]+=this.realOffset (element)[1];// TWO LINES
    return (y >= this.offset[1] &&
            y <  this.offset[1] + element.offsetHeight &&
            x >= this.offset[0] &&
            x <  this.offset [0] + element.offsetWidth);
  },
--
============================
Brian Peiris
Waterloo, Ontario, Canada
brian...@gmail.com
mbmp...@uwaterloo.ca
============================

Masier

unread,
Oct 18, 2006, 4:30:40 AM10/18/06
to Ruby on Rails: Spinoffs
Thanks for that Brian. It works like a charm. I owe you a beer mate.

Cheers

Jason


Brian Peiris wrote:
> It's not that the cart isn't pickup up the drop, it's just offset so the
> drop location is actually an invisible area above the cart.
> I added two lines to the 'within' method of the Position class in
> prototype.js that seems to fix your problem
> It's not a permanent fix, just a clue to what's going wrong. I'm sure it
> will break other cases
>
> within: function(element, x, y) {
> if (this.includeScrollOffsets)

> return this.withinIncludingScrolloffsets(element, x, y);


> this.xcomp = x;
> this.ycomp = y;
> this.offset = this.cumulativeOffset(element);
> this.offset[0]+=this.realOffset(element)[0];// ADDED THESE

> this.offset[1]+=this.realOffset(element)[1];// TWO LINES

> ------=_Part_4925_17165085.1161154092669
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 21525
>
> It's not that the cart isn't pickup up the drop, it's just offset so the drop location is actually an invisible area above the cart.<br>I added two lines to the 'within' method of the Position class in prototype.js that seems to fix your problem
> <br>It's not a permanent fix, just a clue to what's going wrong. I'm sure it will break other cases<br><br>&nbsp; within: function(element, x, y) {<br>&nbsp;&nbsp;&nbsp; if (this.includeScrollOffsets)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return this.withinIncludingScrolloffsets
> (element, x, y);<br>&nbsp;&nbsp;&nbsp; this.xcomp = x;<br>&nbsp;&nbsp;&nbsp; this.ycomp = y;<br>&nbsp;&nbsp;&nbsp; this.offset = this.cumulativeOffset(element);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.offset[0]+=this.realOffset(element)[0];// ADDED THESE<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; this.offset[1]+=this.realOffset
> (element)[1];// TWO LINES<br>&nbsp;&nbsp;&nbsp; return (y &gt;= this.offset[1] &amp;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y &lt;&nbsp; this.offset[1] + element.offsetHeight &amp;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x &gt;= this.offset[0] &amp;&amp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x &lt;&nbsp; this.offset
> [0] + element.offsetWidth);<br>&nbsp; },<br><br><div><span class="gmail_quote">On 10/18/06, <b class="gmail_sendername">Masier</b> &lt;<a href="mailto:kno...@gmail.com">kno...@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> <br>Hello, after searching through other posts I have not found this<br>problem.<br><br>What I am trying to do is to create a simple shopping cart. What I had<br>hoped was to have a div that is positioned to the bottom of the browser
> <br>window (the cart). Therefore customers can drag items into the cart as<br>they browse the catalogue. Nothing too tough, or so I thought. However<br>in the below example I can drag items from 1 - 6 into the cart without
> <br>a problem but when I scroll down to 7 - 12 and try to drop stuff into<br>the cart it doesn't pick it up.<br><br>What am I missing?? Any solutions or pointers in the right direction<br>would be greatly appreciated. I am using the current
> 1.6.4 release.<br><br>PS I should also mention this example is for fire fox and the like.<br><br><br>Example.php<br><br>____________________________________________________________________________<br><br>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML
> 1.0 Transitional//EN&quot;<br>&quot;<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd</a>&quot;&gt;<br>&lt;html xmlns=&quot;<a href="http://www.w3.org/1999/xhtml">
> http://www.w3.org/1999/xhtml</a>&quot;&gt;<br>&lt;head&gt;<br>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;<br>/&gt;<br>&lt;title&gt;Ajax Workshop 3: Shopping Cart using <a href="http://Script.aculo.us">
> Script.aculo.us</a>&lt;/title&gt;<br>&lt;script src=&quot;prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;<br>&lt;script src=&quot;scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
> <br>&lt;style media=&quot;screen&quot; type=&quot;text/css&quot;&gt;<br>body {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-family:&quot;Trebuchet MS&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;font-size:12px;<br>}<br>#body {<br>position:absolute;<br> width:99%;<br> height:99%;
> <br> background-color:#ffffff;<br> overflow:auto;<br> }<br><br>#cart {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:#FFFF66;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border:dashed gray 1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:100px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:500px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;padding:5px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin-top:10px;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;overflow: auto;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position: fixed;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bottom:0%;<br>}<br>#products {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:#FFF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border:dashed gray 1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:100px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:500px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;padding:5px;
> <br>}<br>#productstoscroll {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position:absolute;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;top:1200px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:#FFF;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border:dashed gray 1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:100px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:500px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;padding:5px;
> <br>}<br>#spaceforcart {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position:absolute;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;top:1310px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:100px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;padding:1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;visibility: hidden;<br>}<br>.box {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:#CCFF33;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;border:solid gray 1px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;margin:10px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;padding:4px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width:50px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height:50px;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float:left;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor:pointer;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;position: static;<br><br>}<br>
> #loading {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;display:none;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float:right;<br>}<br>#clearCart {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color:blue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text-decoration:underline;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cursor:pointer;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;float:right;<br>}<br>#clearCart:hover {<br>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;background-color:#CCFFCC;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;color:#000099;<br>}<br>&lt;/style&gt;<br>&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;<br>function addProduct(element, dropon, event) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sendData(
> <a href="http://element.id">element.id</a>);<br>}<br>function sendData (prod) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var url&nbsp;&nbsp;&nbsp;&nbsp;= 'cart.php';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var rand&nbsp;&nbsp; = Math.random(9999);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var pars&nbsp;&nbsp; = 'product_id=' + prod + '&amp;rand=' + rand;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,<br>onLoading: showLoad, onComplete: showResponse} );<br>}<br>function clearCart () {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var url&nbsp;&nbsp;&nbsp;&nbsp;= 'cart.php';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var rand&nbsp;&nbsp; =
> Math.random(9999);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var pars&nbsp;&nbsp; = 'clear=true&amp;rand=' + rand;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,<br>onLoading: showLoad, onComplete: showResponse} );<br>}<br>function clearProduct (id) {
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var url&nbsp;&nbsp;&nbsp;&nbsp;= 'cart.php';<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var rand&nbsp;&nbsp; = Math.random(9999);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var pars&nbsp;&nbsp; = 'clearProduct=true&amp;id=' + id + '&amp;rand=' + rand;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
> <br>onLoading: showLoad, onComplete: showResponse} );<br>}<br>function showResponse (originalRequest) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('loading').style.display = &quot;none&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('clearCart').style.display = &quot;block&quot;;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('cart').innerHTML = originalRequest.responseText;<br>}<br>function showLoad () {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('clearCart').style.display = &quot;none&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$('loading').style.display = &quot;block&quot;;<br>}<br>
> &lt;/script&gt;<br>&lt;/head&gt;<br>&lt;div id=&quot;hypv-feedback&quot; style=&quot;position:absolute; border:1px solid<br>#f90; background-color:#ccc; top:0px; left:0px; padding:2px;<br>width:75px; height:75px; display:none;font-size:110%;&quot;&gt;Click Me&lt;/div&gt;
> <br>&lt;script type=&quot;text/javascript&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;Position.Window = {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//extended prototypes position to return the scrolled window<br>deltas<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getDeltas: function() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var deltaX =&nbsp;&nbsp;
> window.pageXOffset<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| document.documentElement.scrollLeft<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| document.body.scrollLeft<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var deltaY =&nbsp;&nbsp;window.pageYOffset<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| document.documentElement.scrollTop
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| document.body.scrollTop<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|| 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [deltaX, deltaY];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//extended prototypes position to return working window's size,<br>copied this code from the
> tooltip.js library based on prototype.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;size: function() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var winWidth, winHeight, d=document;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (typeof window.innerWidth!='undefined') {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winWidth = window.innerWidth
> ;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winHeight = window.innerHeight;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (d.documentElement &amp;&amp; typeof<br>d.documentElement.clientWidth!='undefined' &amp;&amp;<br>d.documentElement.clientWidth!=0
> ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winWidth = d.documentElement.clientWidth<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winHeight = d.documentElement.clientHeight<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (d.body &amp;&amp; typeof<br>d.body.clientWidth!='undefined'
> ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winWidth = d.body.clientWidth<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;winHeight = d.body.clientHeight<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return [winWidth, winHeight];
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&lt;/script&gt;<br>&lt;body&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=body&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;cart&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style=&quot;float:left; font-weight:bold&quot;&gt;Shopping Cart&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h1&gt;Ajax Workshop 3: Shopping Cart using &lt;a<br>href=&quot;<a href="http://script.aculo.us">http://script.aculo.us</a>&quot;&gt;<a href="http://Script.aculo.us">Script.aculo.us</a>
> &lt;/a&gt; &lt;/h1&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;h2&gt;Drag the products into the shopping cart&lt;/h2&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;products&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style=&quot;float:left; font-weight:bold&quot;&gt;Products&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;clearCart&quot; onclick=&quot;clearCart();&quot;&gt;Clear Cart&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;loading&quot;&gt;&lt;img src=&quot;indicator.gif&quot; alt=&quot;loading...&quot; /&gt;&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br style=&quot;clear:both&quot; /&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_1&quot;&gt;1&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_2&quot;&gt;2&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_3&quot;&gt;3&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_4&quot;&gt;4&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_5&quot;&gt;5&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_6&quot;&gt;6&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;productstoscroll&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style=&quot;float:left; font-weight:bold&quot;&gt;Products&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;clearCart&quot; onclick=&quot;clearCart();&quot;&gt;Clear Cart&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;loading&quot;&gt;&lt;img src=&quot;indicator.gif&quot; alt=&quot;loading...&quot; /&gt;&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;br style=&quot;clear:both&quot; /&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_7&quot;&gt;7&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_8&quot;&gt;8&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_9&quot;&gt;9&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_10&quot;&gt;10&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_11&quot;&gt;11&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div class=&quot;box&quot; id=&quot;product_12&quot;&gt;12&lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id=&quot;spaceforcart&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div style=&quot;float:left; font-weight:bold&quot;&gt;Shopping Cart&lt;/div&gt;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;<br>&lt;script type=&quot;text/javascript&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var products = document.getElementsByClassName('box');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (var i = 0; i &lt; products.length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Draggable(products[i].id, {ghosting:true, revert:true})
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Droppables.add('cart', {onDrop:addProduct})<br>&lt;/script&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br><br>___________________________________________________________________________
> <br><br><br>cart.php<br><br>____________________________________________________________________________<br><br>&lt;?php<br>session_start();<br>function stringForJavascript($in_string) {<br>&nbsp;&nbsp; print &quot;$in_string &lt;br /&gt;&quot;;
> <br>&nbsp;&nbsp; $str = ereg_replace(&quot;[\r\n]&quot;, &quot; \\n\\\n&quot;, $in_string);<br>&nbsp;&nbsp; $str = ereg_replace('&quot;', '\\&quot;', $str);<br>&nbsp;&nbsp; Return $str;<br>}<br> if (isset($_GET['clearProduct'])) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$_SESSION['cart'][$_GET['id']]--;
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ($_SESSION['cart'][$_GET['id']] == 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($_SESSION['cart'][$_GET['id']]);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach ($_SESSION['cart'] as $key =&gt; $value) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;$key = $value &lt;span style=\&quot;color:blue;
> <br>text-decoration:underline; cursor:pointer\&quot;<br>onclick=\&quot;clearProduct('$key');\&quot;&gt;DELETE&lt;/span&gt;&lt;br /&gt;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die;<br>}<br>if (isset($_GET['clear'])) {
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unset($_SESSION['cart']);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sleep(1);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;die;<br>}<br>$prodid = $_GET['product_id'];<br>$_SESSION['cart'][$prodid] = 1 + $_SESSION['cart'][$prodid];<br>foreach ($_SESSION['cart'] as $key =&gt; $value) {
> <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;$key = $value &lt;span style=\&quot;color:blue;<br>text-decoration:underline; cursor:pointer\&quot;<br>onclick=\&quot;clearProduct('$key');\&quot;&gt;DELETE&lt;/span&gt;&lt;br /&gt;&quot;;<br>}<br>
> sleep(1);<br>?&gt;<br><br><br><br></blockquote></div><br><br clear="all"><br>-- <br>============================<br>Brian Peiris<br>Waterloo, Ontario, Canada<br><a href="mailto:brian...@gmail.com">brian...@gmail.com</a><br><a href="mailto:mbmp...@uwaterloo.ca">
> mbmp...@uwaterloo.ca</a><br>============================
>
> ------=_Part_4925_17165085.1161154092669--

spyridon.v...@googlemail.com

unread,
Oct 18, 2006, 5:14:40 AM10/18/06
to Ruby on Rails: Spinoffs
i havent read through the whole post (no time :P ) but from the title i
think http://dev.subimage.com/projects/substruct/ may fit your needs.
It helped me learn a ton of stuff on eshops cart etc

Reply all
Reply to author
Forward
0 new messages