Revision: 34982
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 31, 2010 17:54 by nuwak
Initial Code
var buyed_once = false;
$(function(){
//запиÑываем данные по корзине Ñлева
num = getCardNum();
hr = window.location.href ;
root = hr.substr(0,hr.indexOf('test.zhempodvorye.ru'))+"test.zhempodvorye.ru";
$(".middle-content").append("\
<div class=right onclick='window.location.href=\""+root+"/test.zhempodvorye.ru/default.htm\"'>\
<div class=basket style='cursor:pointer'>\
<div class=block-title>Сундучок</div>\
<p>Товаров: <strong>"+num+" шт</strong></p>\
<p><strong><a href='#' onclick='clearCart();location.href=location.href' style='font-size:14px;color:white'>ОчиÑтить корзину</a></strong></p>\
</div>\
</div>");
/*
//запиÑываем запиÑи из общей таблицы
$('#example tbody tr td a').each(function(i){
href = $(this).attr('href');
id = href.substr(href.lastIndexOf('/')+1);
if(getCookie(id)=='null'){
setCookie(id,$(this).parent().parent().html(),null,'../../');
}
}); */
//защита
$('form.ajax-cart-form').attr('action',location.href+'#');
//Ñкрываем кнопку
href = location.href;
id = href.substr(href.lastIndexOf('/')+1);
if(exists(id))
clear_buy_button();
//при покупке
$('form.ajax-cart-form').submit(function(){
var cnt = $('#edit-qty').val();
var body1 = $("body").html();
var match = body1.match(/<A class=model href=\"(.*?)\"/gi);
if (!match){
var match = body1.match(/\"model\">(.*?)<\/a/);
}
if (match){
var match1 = match[0].match(/href=\"(.*?)\"/);
id2 = match1[1].substr(match1[1].lastIndexOf('/')+1);
}else{
id2 = 0;
}
var ssize = 0;
//ЕÑли еÑть обÑзательное поле
if($('.required').size()>0&&buyed_once==false){
if($('.required').val()==''){
alert('Укажите размер');
return false;
}
ssize = $('.required option[selected]').text();
buyed_once = true;
//alert(ssize);
}
h = location.href;
id = h.substring(h.lastIndexOf('/')+1);
card = getCookie('card');
var use_1 = true;
var use_2 = true;
if(exists(id)){
use_1 = false;
if (id2>0){
if (exists(id2)){
return false;
}
}else{
return false;
}
}else{
if (id2>0){
if (exists(id2)){
use_2 = false;
}
}else{
use_2 = false;
}
}
if (use_1){
if(card!=null&&card!=""){
card=card+'-'+id;
}else{
card = id;
}
}
if (use_2){
if(card!=null&&card!=""){
card=card+'-'+id2;
}else{
card = id2;
}
}
clear_buy_button();
setCookie('card',card,null,'/');
if (use_1){
var p1 = $('.catalogue-img img:eq(0)').attr('src');
p1 = '../'+str_replace(p1,'../','');
h = str_replace(p1,'../default.htm','');
color = $('#color_zp option:selected').text();
$('#color_zp_span').remove();
html = $('#attr-goods').html();
html+='<span id="color_zp_span">'+color+'</span>';
if(ssize!=0){
html+='<br><strong>Размер:</strong> '+ssize;
}
html+='<br><strong>КоличеÑтво:</strong> '+cnt;
setCookie(id,$.trim("<td><img src='"+h+"'></td><td>"+html),null,'/');
}
if (use_2){
var p2 = $('.catalogue-img img:eq(1)').attr('src');
p2 = '../'+str_replace(p2,'../','');
h2 = str_replace(p2,'../default.htm','');
color = $('#color_zp2 option:selected').text();
$('#color_zp_span2').remove();
html = $('#attr-goods2').html();
html+='<span id="color_zp_span2">'+color+'</span>';
if(ssize!=0){
html+='<br><strong>Размер:</strong> '+ssize;
}
html+='<br><strong>КоличеÑтво:</strong> '+cnt;
setCookie(id2,$.trim("<td><img src='"+h2+"'></td><td>"+html),null,'/');
}
return false;
});
});
function clearCart(){
card = getCookie('card');
if(card!=null&&card!=''){
if(card.indexOf('-')==-1)
card = [card];
else
card = card.split('-');
for(i=0;i<card.length;i++){
setCookie(card[i],'',null,'/');
}
setCookie('card','',null,'/');
}
}
function getCardNum(){
c = getCookie('card');
if(c!=''&&c!=null)
a = c.split('-').length;
else
a = 0;
return a;
}
function clear_buy_button(){
$('form.ajax-cart-form input[type=submit]').parent().html('<br><span style="font-weight:bold;font-size:18px" class="ok">Куплено</span>');
}
function setCookie (name, value, expires, path, domain, secure) {
expires = 'Mon, 01-Jan-2020 00:00:00 GMT';
document.cookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function getCookie(name) {
var cookie = " " + document.cookie;
var search = " " + name + "=";
var setStr = null;
var offset = 0;
var end = 0;
if (cookie.length > 0) {
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(";", offset)
if (end == -1) {
end = cookie.length;
}
setStr = unescape(cookie.substring(offset, end));
}
}
return(setStr);
}
function str_replace(haystack, needle, replacement) {
var temp = haystack.split(needle);
return temp.join(replacement);
}
function exists(id){
q = getCookie('card');
if(q&&q!='null'&&q.indexOf(id)!=-1)
return true;
return false;
}
$(document).ready(
function() {
if ($.browser.msie && ($.browser.version == "6.0")) {
$("div.footer-designer a").hover(
function() {
$(this).find("strong").addClass("hover");
},
function() {
$(this).find("strong").removeClass("hover");
}
);
}
var curRel = 1;
var curZIndex = 100;
$("div.form-item select").each(
function() {
var curSelect = $(this);
curSelect.parent().css("z-index", curZIndex--);
// curSelect.attr("rel", curRel++).niceSelect();
}
);
$("div.catalogue-field select").each(
function() {
var curSelect = $(this);
curSelect.parent().parent().css("z-index", curZIndex--);
// curSelect.attr("rel", curRel++).niceSelect();
}
);
}
);
function delCard(id){
if(exists(id)){
q = getCookie('card');
if(q.indexOf('-')==-1)
q = [q];
else
q = q.split('-');
newC = [];
for(i=0;i<q.length;i++){
if(q[i]!=id)
newC[newC.length] = q[i];
}
setCookie('card',newC.join("-"),null,'/');
setCookie(id,'',null,'/');
window.location.replace( window.location.href);
}
}
Initial URL
Initial Description
Initial Title
Скрипт офлайн корзины
Initial Tags
Initial Language
jQuery