script function xxx id value arr for arr length if arr attr id arr val

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<script>
function xxx(id, value, arr)
{
for (i=0; i<arr.length; i++)
{
if (arr[i].attr == id && arr[i].value == value)
return true;
}
return false;
}
//-----------------------------
$(document).ready()
{
var maxpage=<?php echo $maxpage;?>;
var loading=false;
var clear=true;
$("#filform").on("change","input[type=checkbox]", function()
{
var ch = $("#filform").find("input[type=checkbox]:checked");
var check=new Array();
ch.each(function()
{
var value=$(this).val();
var attr=$(this).parent().find("input[type=checkbox]").attr("name");
attr=attr.replace(/[^0-9]/g,"");
check.push({"attr":attr, "value":value});
});
if(clear==true)
{
$("#pageid").val(1);
}
var param=$("#filform").serialize();
$.ajax(
{
type: "POST",
url: "/php/ajax/filter.php",
data: param,
dataType: "JSON",
success: function(data)
{
$("ul.filter").empty();
if(clear==true)
{
$("div.productrow").empty();
}
$("<p>").attr("class","params").html("Параметры").appendTo("ul.filter");
$("<p>").attr("id","filteroff").html("Сбросить фильтр").appendTo("ul.filter");
var i=1;
$(data[0]).each(function()
{
var li=$("<li>");
var id=this.id;
var at=this.attr;
var atval=this.value;
$("<span>").attr("class","f_name").html(at).appendTo(li);
var div=$("<div>").attr("class","filterbox").appendTo(li);
$(atval).each(function(val, el)
{
if (xxx(id,el,check))
$("<input>").attr({"type":"checkbox", "id":"p_"+i+"","name":"param["+id+"][]","value":""+el+"","checked":"checked"}).appendTo(div);
else
$("<input>").attr({"type":"checkbox", "id":"p_"+i+"","name":"param["+id+"][]","value":""+el+""}).appendTo(div);
$("<label>").attr("for","p_"+i+"").html(el).append("<br>").appendTo(div);
i++;
});
$(li).appendTo("ul.filter");
});
$(data[1]).each(function()
{
var div=$("<div>").attr("class","productleft").hide();
var a=$("<a>").attr({"href":"/catalog/goods"+this.id+".html", "target":"_blank"});
$("<h3>").html(this.name).appendTo(a);
$("<img>").attr("src","/img/catalog/small/"+this.preview).appendTo(a);
$("<p>").html("Цена: <span>"+this.price+" руб.</span>").appendTo(a);
if(this.status ==1)
{
$("<img>").attr({"class":"new","src":"/img/new.png"}).appendTo(a);
}
a.appendTo(div);
div.appendTo("div.productrow").fadeIn();
});
maxpage=data[2];
loading = false;
clear=true;
if(parseInt($("#pageid").val()) == maxpage)
{
$("#bottom").hide();
}
else
$("#bottom").show();
}
});
});
$("ul.filter").on("click", "#filteroff", function()
{
if($("#filform").find("input[type=checkbox]:checked").length>0)
{
$("input[type=checkbox]").removeAttr("checked");
$("<input>").attr("type","checkbox").css("display","none").appendTo("#filform").change().remove();
}
});
$("#bottom").click(function ()
{
if(loading == false)
{
var val=parseInt($("#pageid").val())+1;
if(val>maxpage){ return false;}
clear=false;
$("#pageid").val(val);
loading=true;
$("<input>").attr("type","checkbox").css("display","none").appendTo("#filform").change().remove();
}
});
$("#sort1").click(function()
{
$("#sorttype").val(1);
$(this).css({"color":"#e31281"});
$("#sort2").css({"color":"#000"});
$("<input>").attr("type","checkbox").css("display","none").appendTo("#filform").change().remove();
});
$("#sort2").click(function()
{
$("#sorttype").val(2);
$(this).css({"color":"#e31281"});
$("#sort1").css({"color":"#000"});
$("<input>").attr("type","checkbox").css("display","none").appendTo("#filform").change().remove();
});
if(parseInt($("#pageid").val()) == maxpage)
{
$("#bottom").hide();
}
else
$("#bottom").show();
}
</script>