var shopDataRequest = new XMLHttpRequest(); // 店舗・観光地情報の保持クラス var shopData = function shopData (categoryId, shopId, shopName, summary, featuredName, featuredDescription, otherDescription, address, latitude, longitude, image, rating, review, order_id,romaji) { this.categoryId = categoryId; this.shopId = shopId; this.shopName = shopName; this.summary = summary; this.featuredName = featuredName; this.featuredDescription = featuredDescription; this.otherDescription = otherDescription; this.address = address; this.latitude = latitude; this.longitude = longitude; this.image = image; this.rating = rating; this.review = review; this.order_id = order_id; this.romaji = romaji; }; // カテゴリー情報csvの読み込み function readShopDataCsv(file_name) { shopDataRequest.onreadystatechange = shopDataReadyStateChange; shopDataRequest.open("GET", file_name, false); shopDataRequest.send(null); } // カテゴリー情報csvの読み込み実行コールバック function shopDataReadyStateChange() { if(shopDataRequest.readyState == 4) { if(shopDataRequest.status != 200) { // 通信失敗ならローカルのデータを取得 shopDataConnectError = true; getLocalShopData(); return; } // 通信成功なら受信したデータを格納 shopDataCount = 0; var csv = $.csv(",", "", "\n")(shopDataRequest.responseText); notopflg = false; $(csv).each(function(){ if (notopflg) { if (this.length == 15) { // 店舗情報が正常取得できたならリストに格納し、ローカルストレージに情報を細んする for (i = 0; i < 15; i++) { this[i] = this[i].replace(/\/\[,\]\//g, ',').replace(/\"\"/g, "\""); } var eachCsvShopData = new shopData(this[0], this[1], this[2], this[3], this[4], this[5], this[6], this[7], this[8], this[9], this[10], this[11], this[12], this[13], this[14], this[15]); shopDataList[shopDataCount] = eachCsvShopData; shopDataCount++; localStorage.setItem(shopDataKey + keysDelimiter + categoryId + shopDataDelimiter + this[1], JSON.stringify(eachCsvShopData)); } } else { notopflg = true; } }); } } // ローカルストレージからの店舗情報取得 function getLocalShopData() { dataCount = 0; for(i = 0; i < localStorage.length; i++){ localStorageKey = localStorage.key(i); firstSplit = localStorageKey.split(keysDelimiter); if (firstSplit[0] == shopDataKey) { secondSplit = firstSplit[1].split(shopDataDelimiter); if (secondSplit[0] == categoryId) { var eachLocalShopData = JSON.parse(localStorage.getItem(localStorageKey)); shopDataList[dataCount] = eachLocalShopData; dataCount++; } } } } // 店舗情報を五十音順にソートする // 現在は未使用 // function shopDataSort() { // shopDataList.sort(function(a, b) { // return ( a.shopName > b.shopName ? 1 : -1); // }); // }