$(function() { /*================================================================ 情報 ================================================================*/ var allList = [ { id: "341", life: "23", url:"index.php?act=staff&id=341", img:"user_data/1664.jpg", nen:"平成11年式", soukou:"68000", title:"キャリィトラック白239 スズキ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "804", life: "65", url:"index.php?act=staff&id=804", img:"user_data/5538.jpg", nen:"平成26年式", soukou:"96970", title:"ミラココア茶1725 ダイハツ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "793", life: "59", url:"index.php?act=staff&id=793", img:"user_data/5533.jpg", nen:"平成22年式", soukou:"68434", title:"ラパンLブルー1705 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "792", life: "63", url:"index.php?act=staff&id=792", img:"user_data/5534.jpg", nen:"平成25年式", soukou:"77761", title:"デイズ銀1743 ニッサン", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "784", life: "63", url:"index.php?act=staff&id=784", img:"user_data/4927.jpg", nen:"平成24年式", soukou:"110019", title:"タントエグゼ茶1672 ダイハツ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "776", life: "66", url:"index.php?act=staff&id=776", img:"user_data/4925.jpg", nen:"平成24年式", soukou:"18728", title:"ピクシスクリーム1666 トヨタ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "669", life: "55", url:"index.php?act=staff&id=669", img:"user_data/4512.jpg", nen:"平成23年式", soukou:"106144", title:"ライフ銀1599 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "668", life: "49", url:"index.php?act=staff&id=668", img:"user_data/4511.jpg", nen:"平成14年式", soukou:"155736", title:"スクラムトラックダンプ白339 マツダ", sold:"", new:"", tag: ["","販売中","","AT",""], description: "tesut" }, { id: "662", life: "65", url:"index.php?act=staff&id=662", img:"user_data/4478.jpg", nen:"平成21年式", soukou:"31130", title:"サンバートラック銀338 スバル", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "658", life: "55", url:"index.php?act=staff&id=658", img:"user_data/4482.jpg", nen:"平成23年式", soukou:"95347", title:"ステラ青1598 スバル", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "657", life: "58", url:"index.php?act=staff&id=657", img:"user_data/4483.jpg", nen:"平成21年式", soukou:"58402", title:"クリッパーバン白337 ニッサン", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "651", life: "54", url:"index.php?act=staff&id=651", img:"user_data/4433.jpg", nen:"平成18年式", soukou:"94286", title:"アクティトラック白332 ホンダ", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "648", life: "59", url:"index.php?act=staff&id=648", img:"user_data/4435.jpg", nen:"平成25年式", soukou:"118500", title:"エブリーバン白329 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "632", life: "59", url:"index.php?act=staff&id=632", img:"user_data/4407.jpg", nen:"平成20年式", soukou:"65340", title:"キャリィトラック白328 スズキ", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "631", life: "38", url:"index.php?act=staff&id=631", img:"user_data/4397.jpg", nen:"平成16年式", soukou:"144158", title:"サンバー白 スバル", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "629", life: "48", url:"index.php?act=staff&id=629", img:"user_data/4398.jpg", nen:"平成17年式", soukou:"109234", title:"クリッパーバン白333 ニッサン", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "626", life: "64", url:"index.php?act=staff&id=626", img:"user_data/4389.jpg", nen:"平成22年式", soukou:"98000", title:"タントエグゼ黒1577 ダイハツ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "623", life: "45", url:"index.php?act=staff&id=623", img:"user_data/4384.jpg", nen:"平成19年式", soukou:"155801", title:"ミニキャブトラック白 ミツビシ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "622", life: "79", url:"index.php?act=staff&id=622", img:"user_data/4375.jpg", nen:"平成26年式", soukou:"50741", title:"ムーブコンテ紫1631 ダイハツ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "617", life: "68", url:"index.php?act=staff&id=617", img:"user_data/4225.jpg", nen:"平成25年式", soukou:"97338", title:"N-ONE白1562 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "616", life: "55", url:"index.php?act=staff&id=616", img:"user_data/4207.jpg", nen:"平成23年式", soukou:"95272", title:"MRワゴン茶1561 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "613", life: "53", url:"index.php?act=staff&id=613", img:"user_data/4185.jpg", nen:"平成18年式", soukou:"100400", title:"エブリイワゴン白 スズキ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "598", life: "52", url:"index.php?act=staff&id=598", img:"user_data/4023.jpg", nen:"平成23年式", soukou:"108258", title:"ライフ銀1541 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "595", life: "66", url:"index.php?act=staff&id=595", img:"user_data/3951.jpg", nen:"平成25年式", soukou:"101000", title:"ハイゼットカーゴ白303 ダイハツ", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "556", life: "57", url:"index.php?act=staff&id=556", img:"user_data/3694.jpg", nen:"平成24年式", soukou:"106395", title:"モコベージュ1486 ニッサン", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "555", life: "59", url:"index.php?act=staff&id=555", img:"user_data/3749.jpg", nen:"平成23年式", soukou:"72531", title:"ミラココアベージュ1526 ダイハツ ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "551", life: "57", url:"index.php?act=staff&id=551", img:"user_data/3726.jpg", nen:"平成23年式", soukou:"123980", title:"モコ茶1520 ニッサン", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "549", life: "57", url:"index.php?act=staff&id=549", img:"user_data/3619.jpg", nen:"平成24年式", soukou:"111488", title:"モコピンク1521 ニッサン", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "539", life: "54", url:"index.php?act=staff&id=539", img:"user_data/3603.jpg", nen:"平成21年式", soukou:"87203", title:"ライフ赤1524 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "533", life: "49", url:"index.php?act=staff&id=533", img:"user_data/3525.jpg", nen:"平成23年式", soukou:"91100", title:"アルト白361 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "523", life: "59", url:"index.php?act=staff&id=523", img:"user_data/3452.jpg", nen:"平成20年式", soukou:"116000", title:"パレット白1440 スズキ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "522", life: "59", url:"index.php?act=staff&id=522", img:"user_data/3869.jpg", nen:"平成23年式", soukou:"108934", title:"ライフ銀1455 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "517", life: "59", url:"index.php?act=staff&id=517", img:"user_data/3543.jpg", nen:"平成22年式", soukou:"86494", title:"ムーブコンテLゴールド1525 ダイハツ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "514", life: "63", url:"index.php?act=staff&id=514", img:"user_data/3311.jpg", nen:"平成24年式", soukou:"96000", title:"トッポ黒1657 ミツビシ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "500", life: "55", url:"index.php?act=staff&id=500", img:"user_data/3029.jpg", nen:"平成21年式", soukou:"111464", title:"ムーブコンテローズ1417 ダイハツ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "498", life: "64", url:"index.php?act=staff&id=498", img:"user_data/3030.jpg", nen:"平成23年式", soukou:"110996", title:"モコ茶1400 ニッサン", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "496", life: "62", url:"index.php?act=staff&id=496", img:"user_data/3039.jpg", nen:"平成23年式", soukou:"114891", title:"ラパンピンク1399 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "477", life: "55", url:"index.php?act=staff&id=477", img:"user_data/2542.jpg", nen:"平成21年式", soukou:"77000", title:"ムーブコンテグレー1330 ダイハツ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "474", life: "44", url:"index.php?act=staff&id=474", img:"user_data/2551.jpg", nen:"平成21年式", soukou:"223800", title:"ハイゼットカーゴ銀266 ダイハツ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "435", life: "48", url:"index.php?act=staff&id=435", img:"user_data/2367.jpg", nen:"平成22年式", soukou:"120767", title:"アイ白1340 ミツビシ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "421", life: "98", url:"index.php?act=staff&id=421", img:"user_data/2380.jpg", nen:"平成26年式", soukou:"9700", title:"リクエスト車両 ハイゼットトラック銀 ダイハツ", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "407", life: "53", url:"index.php?act=staff&id=407", img:"user_data/2172.jpg", nen:"平成23年式", soukou:"61810", title:"ムーブコンテ青1341 ダイハツ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "404", life: "49", url:"index.php?act=staff&id=404", img:"user_data/2378.jpg", nen:"平成20年式", soukou:"90699", title:"モコ白1311 ニッサン", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "402", life: "46", url:"index.php?act=staff&id=402", img:"user_data/2267.jpg", nen:"平成23年式", soukou:"97277", title:"アルト白269 スズキ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "399", life: "55", url:"index.php?act=staff&id=399", img:"user_data/3877.jpg", nen:"平成23年式", soukou:"115568", title:"ライフ銀1379 ホンダ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "392", life: "55", url:"index.php?act=staff&id=392", img:"user_data/2271.jpg", nen:"平成17年式", soukou:"130256", title:"サンバートラック白284 スバル", sold:"", new:"", tag: ["新着","販売中","MT","",""], description: "tesut" }, { id: "359", life: "62", url:"index.php?act=staff&id=359", img:"user_data/2108.jpg", nen:"平成24年式", soukou:"103394", title:"モコ白1347 ニッサン", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "327", life: "ご予算♪", url:"index.php?act=staff&id=327", img:"user_data/750.jpg", nen:"ご希望に応じて♪", soukou:"ご希望による♪", title:"リクエストプラン!!", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "323", life: "35", url:"index.php?act=staff&id=323", img:"user_data/592.jpg", nen:"平成17年式", soukou:"131000", title:"サンバー銀248 スバル", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "40", life: "39", url:"index.php?act=staff&id=40", img:"user_data/601.jpg", nen:"平成23年式", soukou:"116000", title:"ミニキャブ白237 ミツビシ", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "24", life: "23", url:"index.php?act=staff&id=24", img:"user_data/1096.jpg", nen:"平成20年式", soukou:"125913", title:"キャリィトラック白256 スズキ", sold:"", new:"", tag: ["新着","","MT","","売り切れ"], description: "tesut" }, { id: "861", life: "59", url:"index.php?act=staff&id=861", img:"./img/nophoto.png", nen:"平成26年式", soukou:"96340", title:"デイズ白 ニッサン", sold:"", new:"", tag: ["新着","販売中","","AT",""], description: "tesut" }, { id: "642", life: "59", url:"index.php?act=staff&id=642", img:"./img/nophoto.png", nen:"平成20年式", soukou:"90617", title:"リクエスト車両 ミニキャブトラック白 ミツビシ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, { id: "520", life: "42", url:"index.php?act=staff&id=520", img:"./img/nophoto.png", nen:"平成17年式", soukou:"127000", title:"リクエスト車両 ハイゼットカーゴ白 ダイハツ", sold:"", new:"", tag: ["新着","","","AT","売り切れ"], description: "tesut" }, ]; /*================================================================ スクリプトはじまり ================================================================*/ function init() { //イベント登録 $(".filter_life select").on("change", onFilterChange); $(".filter_tag input").on("change", onFilterChange); $(".filter_keyword button").on("click", onFilterChange); //最初は全て出力 refleshHtml(allList); } /*================================================================ HTML出力 ================================================================*/ function refleshHtml(list) { var outputHtml = ''; //出力する内容をoutputHtmlに格納 if (list.length > 0) { _.each(list, function(line, i) { outputHtml += '

' + line.title + '

'; outputHtml += '' + line.title + ''; outputHtml += '' + line.new + '' + line.sold + ''; outputHtml += '

価格 ' + line.life + '万円

'; outputHtml += '

年式: ' + line.nen + '

'; outputHtml += '

走行: 約 ' + line.soukou + 'km

'; outputHtml += '
'; }); } else { outputHtml += '

条件に当てはまる車を検索できませんでした。

'; } //HTML出力(フェードインアニメーションつき) $('.productArea').html(outputHtml); $('.productArea .product').css({opacity: 0}).each(function(i){$(this).delay(100 * i).animate({opacity:1}, 300); }); //検索件数表示 $('.productCntArea').html('

' + allList.length + '件中' + list.length + '件を表示しています。

'); } /*================================================================ 絞り込み条件を変更した時 ================================================================*/ function onFilterChange(e) { var filterFncs = []; var result = []; //セレクトボックスの値を引数に指定した関数filterByLifeをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByLife(list, $('.filter_life select').val()); } ); //チェックボックスの値を引数に指定した関数filterByTagをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByTag(list, $('.filter_tag input:checked')); } ); //キーワードの値を引数に指定した関数filterByKeywordをfilterFuncs配列に格納 filterFncs.push( function(list) { return filterByKeyword(list, _.escape($('.filter_keyword input').val())); } ); //FilterFuncs配列内の関数をバケツリレーみたいに1つずつ実行して結果をresult配列に格納 result = _.reduce(filterFncs, function(list, fnc) { return fnc(list); }, allList); //絞り込んだ結果を出力 refleshHtml(result); } /*================================================================ 絞り込み[1] セレクトボックス絞り込み関数 ================================================================*/ function filterByLife(list, value) { //絞り込み指定がない場合はリターン if (value == "") { return list; } //選択したセレクトボックスとlifeがマッチするかでフィルタリング return _.filter(list, function(item) { switch (value) { case '1': return item.life <= 10; case '2': return 10 < item.life && item.life <= 20; case '3': return 20 < item.life && item.life <= 30; case '4': return 30 < item.life && item.life <= 40; case '5': return 40 < item.life && item.life <= 50; case '6': return 50 < item.life; } }); } /*================================================================ 絞り込み[2] チェックボックス絞り込み関数 ================================================================*/ function filterByTag(list, value) { //絞り込み指定がない場合はリターン if (value.length == 0) { return list; } //選択した属性(チェックボックス)とtagがマッチするかでフィルタリング return _.filter(list, function(item) { var isMatch = false; //配列同士の比較 _.each(value, function(chkItem, i) { _.each(item.tag, function(tagItem, i) { if (tagItem === $(chkItem).val()) { isMatch = true; } }); }); return isMatch; }); } /*================================================================ 絞り込み[3] テキストボックス絞り込み関数 ================================================================*/ function filterByKeyword(list, value) { //絞り込み指定がない場合はリターン if (value == "") { return list; } //検索キーワードを配列に格納(スペースがある場合は複数格納) var freeAry = [];  var val = value.replace(/ /g, " "); searchAry = val.split(" "); //入力したキーワードがtitleもしくdescriptionにマッチするかでフィルタリング return _.filter(list, function(item) { var isMatch = false; _.each(searchAry, function(data, i) { if (item.title.indexOf(data) != -1 || item.description.indexOf(data) != -1) { isMatch = true; } }); return isMatch; }); } /*================================================================ スクリプトはじめ ================================================================*/ init(); });