в оригинале все выглядит так
HTML:
<div class="item border">
<img src="img/shop/zont1.png" width="200">
<p><b>Зонт1</b> | Цена: 1200 руб</p>
<div class="sum_but">
<span class="plus">+</span>
<input value="1" maxlength="2" name="" id='' type="text" class="mam">
<span class="minus">-</span>
</div>
<button class="border" onclick="cart.addToCart(this, '001', 'Зонт1', '1200', '')">Купить</button>
</div>
JS - обработчик:
function WICard(obj)
{
this.widjetX = 0;
this.widjetY = 0;
this.widjetObj;
this.widjetPos;
this.cardID = "";
this.DATA = {};
this.IDS = [];
this.objNAME = obj;
this.CONFIG = {};
this.IMG = "...";
this.init = function(widjetID, config)
{
this.CONFIG = config || {};
try {
this.DATA = JSON.parse(localStorage.getItem(widjetID)); // code to try
//console.log("TRY - OK");
if ($.isEmptyObject(this.DATA))
{
this.DATA = {};
}
}
catch (e)
{
this.DATA = {};
//onsole.log("TRY - BED");
}
try {
this.IDS = JSON.parse(localStorage.getItem(widjetID + "_ids"));
if ($.isEmptyObject(this.IDS))
{
this.IDS = [];
}
}
catch (e)
{
this.IDS = [];
}
//console.log(this.DATA);
this.cardID = widjetID;
$("body").append("<div class='bird' id='"+widjetID +"_bird'></div>");
this.widjetObj = $("#" + widjetID);
this.widjetPos = this.widjetObj.position();
if ($.isEmptyObject(this.DATA))
{
this.widjetObj.html("Корзина пуста");
}
else
{
this.reCalc();
this.renderBasketTable();
}
}
/***********************************************************************************************
* example: onclick="cart.addToCart(this, '2', 'Name of comic 2', '25500')
**********************************************************************************************/
$('button').click(function() {
num = $(this).parent().find('input').val();
alert(num);
})
this.addToCart = function(curObj, id, name, price, num)
{
id = ( $.isNumeric(id) ) ? "ID" + id.toString() : id;
var goodieLine = {"id" : id, "name" : name, "price": price, "num" : num, "url" : document.location.href};
if ($.isEmptyObject(this.DATA))
{
this.DATA[id] = goodieLine;
this.IDS.push(id);
}
else
for(var idkey in this.DATA)
{
if($.inArray(id, this.IDS) === -1)
{
this.DATA[id] = goodieLine;
this.IDS.push(id)
}
else
if (idkey == id)
{
this.DATA[idkey].num += num;
}
}
localStorage.setItem(this.cardID, JSON.stringify(this.DATA));
localStorage.setItem(this.cardID + "_ids", JSON.stringify(this.IDS));
this.reCalc();
this.renderBasketTable();
var bird = $("#" + this.cardID + "_bird");
var pos = $(curObj).position();
bird.offset({ top: pos.top, left: pos.left});
bird.html(price);
bird.show();
bird.animate(
{
'left': this.widjetPos.left,
'top': this.widjetPos.top
}
,
{
'duration': 500,
complete: function()
{
bird.offset({ top: -300, left: -300});
}
});
if (this.CONFIG.showAfterAdd)
{
cart.showWinow('bcontainer', 1);
}
}