var counterList = 3; function ZdcEmapMultiSearchRequest(url, target, listObj, replace, typ) { if(typ == undefined) typ = 1; var ZdcEmapSearchNextObj = document.getElementById("ZdcEmapSearchNext"+target); if (ZdcEmapSearchNextObj) ZdcEmapSearchNextObj.innerHTML = "
"; ZdcEmapHttpRequestHtml(url, function(html, status){ if(status) html = " search["+status+"]"; var ZdcEmapSearchNextObj = document.getElementById("ZdcEmapSearchNext"+target); if (listObj && ZdcEmapSearchNextObj) listObj.removeChild(ZdcEmapSearchNextObj); if (replace) { listObj.innerHTML = html; } else { setTimeout(function (listObj, html) { listObj.innerHTML += html; setTimeout(ZdcEmapRefList, 100, listObj); }, 500, listObj, html); } listObj.style.visibility = "visible"; ZdcEmapRefListObj = listObj; }, false, typ); } function ZdcEmapHttpRequestHtml(url, func, nowaitmsg, typ, noref) { if(typ == undefined) typ = 1; var ZdcEmapHttpRequestObj = new ZdcEmapHttpRequest('UTF8', 'UTF8', 1); ZdcEmapHttpRequestObj.request(url, function(html,status) { if(status == 3) status = 0;//タイムアウトは無視 連続呼び出し時の動作が安定しないので if(status == 9) status = 0;//テンプレートが無い場合に対応 if(html == null) html = "";//nullは出さない if(status == 0) { func(html,status); } else { func(html,status); } },60000,typ,noref); } function ZdcEmapRefList(listObj) { if (listObj) { if (listObj.id == "ZdcEmapSearchFWList5") { if (document.querySelector('.next-url-5') && document.querySelector('.next-url-5').attributes.getNamedItem('attr-url').value.length > 0) { var url = document.querySelector('.next-url-5').getAttribute("attr-url"); moreContents5.setLoadUrl(url); } else if (document.querySelector('.next-url-5')) { // document.querySelector('.next-url-5').remove(); document.getElementsByClassName('next-url-5')[0].parentElement.removeChild(document.getElementsByClassName('next-url-5')[0]); } counterList--; } else if (listObj.id == "ZdcEmapSearchFWList2") { if (document.querySelector('.next-url-2') && document.querySelector('.next-url-2').attributes.getNamedItem('attr-url').value.length > 0) { var url = document.querySelector('.next-url-2').getAttribute("attr-url"); moreContents2.setLoadUrl(url); } else if (document.querySelector('.next-url-2')) { // document.querySelector('.next-url-2').remove(); document.getElementsByClassName('next-url-2')[0].parentElement.removeChild(document.getElementsByClassName('next-url-2')[0]); } counterList--; } else if (listObj.id == "ZdcEmapSearchFWList1") { if (document.querySelector('.next-url-1') && document.querySelector('.next-url-1').attributes.getNamedItem('attr-url').value.length > 0) { var url = document.querySelector('.next-url-1').getAttribute("attr-url"); moreContents1.setLoadUrl(url); } else if (document.querySelector('.next-url-1')) { // document.querySelector('.next-url-1').remove(); document.getElementsByClassName('next-url-1')[0].parentElement.removeChild(document.getElementsByClassName('next-url-1')[0]); } counterList--; } setTimeout(function() { window.moreContents5.reload(); window.moreContents2.reload(); window.moreContents1.reload(); }, 100); } else if (ZdcEmapRefListObj) { ZdcEmapRefListObj.innerHTML = ZdcEmapRefListObj.innerHTML + ' '; ZdcEmapRefListObj.offsetLeft; ZdcEmapRefListObj = null; } } function MoreContents(target, opts) { var hospitalList = target; var that = this; this.elem = hospitalList; if (this.elem.classList.contains("error-stop")) { counterList--; if (counterList <= 0) { setTimeout(function() { hideLoadingBox(); }, 500); } // Stop search return; } this.window = window; this.window.queueDataLoad = []; this.elem.getElementsByClassName("p-search-result__inner")[0].setAttribute('data-inner', opts.group); this.elem.getElementsByClassName("p-search-result__inner")[0].parentElement.setAttribute('data-outer', opts.group); this.elem.getElementsByClassName("p-search-results__btn")[0].setAttribute('data-btn', opts.group); this.elem.getElementsByClassName("p-search-results__btn")[1].setAttribute('data-btn', opts.group); this.items = this.elem.querySelectorAll('[data-list="item"]'); this.result = this.elem.querySelectorAll('[data-result="' + opts.group + '"]')[0]; this.moreOpen = this.elem.querySelectorAll('[data-btn="' + opts.group + '"]')[0]; this.moreClose = this.elem.querySelectorAll('[data-btn="' + opts.group + '"]')[1]; this.outer = this.elem.querySelectorAll('[data-outer="' + opts.group + '"]')[0]; this.inner = this.elem.querySelectorAll('[data-inner="' + opts.group + '"]')[0]; this.maxCurrent = this.items.length; this.showClass = 'is-show'; this.openClass = 'is-open'; this.currentNum = 0; this.showNum = Number(opts.initialView); this.initialView = Number(opts.initialView); this.open = false; this.eventLoaded = false; this.opts = opts; this.init(); } MoreContents.prototype.init = function () { this.setInitialView(); if (this.items.length && !this.eventLoaded) { this.eventLoaded = true; this.moreOpen.addEventListener('click', this.action.bind(this), false); this.moreClose.addEventListener('click', this.action.bind(this), false); } this.elem.classList.remove('is-no-result'); this.getHeight(this.open); if (counterList <= 0) { setTimeout(function() { hideLoadingBox(); }, 500); } }; MoreContents.prototype.setInitialView = function () { this.currentNum += this.initialView; this.showContent(); }; MoreContents.prototype.action = function () { this.open = !this.open; if (this.open) { this.moreOpen.style.display = 'none'; } this.getHeight(this.open); }; MoreContents.prototype.getHeight = function (open) { if (open) { this.showContent(); this.elem.classList.add(this.openClass); this.outer.style.height = this.inner.clientHeight + "px"; if (this.items.length) { this.result.innerHTML = this.maxCurrent + ' 件中 ' + this.items.length + '件を表示中'; } } else { this.closeContent(); this.elem.classList.remove(this.openClass); this.showResult(); this.outer.style.height = this.inner.clientHeight + "px"; } }; MoreContents.prototype.showResult = function () { if (this.items.length) { if (this.items.length > 3 || this.maxCurrent > 3) { this.result.innerHTML = this.maxCurrent + ' 件中 1-3件を表示中'; this.moreOpen.style.display = 'block'; } else { this.result.innerHTML = this.maxCurrent + ' 件中 ' + this.items.length + '件を表示中'; this.moreOpen.style.display = 'none'; } this.elem.classList.remove('is-no-result'); } else if (this.items.length === 0) { this.moreOpen.style.display = 'none'; this.elem.classList.add('is-no-result'); } }; MoreContents.prototype.showContent = function () { var that = this; var targetNodes = Array.prototype.slice.call(this.items, 0); targetNodes.forEach(function(elem, index) { that.currentNum += that.showNum; if (index <= that.currentNum - 1) { elem.classList.add(that.showClass); } }) }; MoreContents.prototype.closeContent = function () { var that = this; var targetNodes = Array.prototype.slice.call(this.items, 0); targetNodes.forEach(function(elem, index) { that.currentNum += that.showNum; if (index <= that.currentNum - 4) { elem.classList.remove(that.showClass); } }); }; MoreContents.prototype.setLoadUrl = function (url) { if (this.elem.classList.contains("error-stop")) { // Stop search return; } var that = this; if (!this.loadUrl || this.loadUrl !== url) { this.loadUrl = url; setTimeout(function() { eval(that.loadUrl); }, 100); } if (this.inner.getElementsByClassName('next-url').length) { this.inner.getElementsByClassName('next-url')[0].parentElement.removeChild(this.inner.getElementsByClassName('next-url')[0]); } }; MoreContents.prototype.reload = function () { if (this.elem.classList.contains("error-stop")) { // Stop search return; } this.items = this.elem.querySelectorAll('[data-list="item"]'); this.maxCurrent = this.elem.querySelectorAll('[data-max]').length ? this.elem.querySelectorAll('[data-max]')[0].value : 0; this.currentNum = 0; this.showNum = this.items.length; this.initialView = Number(this.initialView); this.init(); }; $(function() { function submitError(e) { if ($.trim($("#search_fw > .p-search-aside__form").val()).length === 0) { $(".p-search-results").addClass("is-empty"); //$(".p-search-results__list").addClass("hidden").addClass("is-empty"); e.preventDefault(); return false; } return true; } $("#search_fw").bind("submit", function(e) { return submitError(e); }); $("#btnSearchFw").click(function(e) { var rs = submitError(e); if (rs) { $("#search_fw").submit(); } return rs; }); window.moreContents5 = new MoreContents(document.getElementById("hospitalList"), { initialView: 3, group: 'first', }); window.moreContents2 = new MoreContents(document.getElementById("addressList"), { initialView: 3, group: 'second' }); window.moreContents1 = new MoreContents(document.getElementById("stationList"), { initialView: 3, group: 'third' }); });