/** 검색에서 넘어온 파라메터로 화면 초기화 */
function initSearchParam() {
// 리스트와 상세화면의 키워드폼 이름이 다름
var keywordSetF = false;
if($("#cms_keyword").length > 0) {
$("#cms_keyword").val(view_form.keyword.value);
$("#cms_keyword_current").val(view_form.keyword.value);
keywordSetF = true;
}
if($("#cms_keywordFV").length > 0) {
$("#cms_keywordFV").val(view_form.keyword.value);
keywordSetF = true;
}
if(!keywordSetF && $("#keyword").length > 0) {
$("#keyword").val(view_form.keyword.value);
$("#keyword_current").val(view_form.keyword.value);
}
// 필터가 존재할때만
if($(".filters").length > 0) {
// 페이징값
if(view_form.pageNo.value > 1) {
$(".page").val(view_form.pageNo.value);
}
// 페이지볼륨
if(view_form.pageVol.value > 1) {
var options = $("select[name=pageVol]").find("option");
for(var i=0; i < options.length; i++) {
if($(options[i]).attr("value") == view_form.pageVol.value) {
$(options[i]).attr("selected", "selected");
}
else {
$(options[i]).removeAttr("selected");
}
}
}
setFilter(view_form.media.value, $("li.filter_media"));
setFilter(view_form.horiVertChoice.value, $("li.filter_horizontal"));
setFilter(view_form.size.value, $("li.filter_size"));
setFilter(view_form.saleState.value, $("li.filter_saleState"));
setFilter(view_form.durationReg.value, $("li.filter_durationReg"));
setFilter(view_form.durationTake.value, $("li.filter_durationTake"));
}
}
function setFilter(value, filterForm) {
var findF = false;
filterForm.find("li").each(function(index) {
if($(this).attr("value") == value) {
findF = true;
}
});
if(findF) {
var itemName = "";
filterForm.find("li").each(function(index) {
if($(this).attr("value") == value) {
$(this).attr("selected", "selected");
itemName = $(this).text();
}
else {
$(this).removeAttr("selected");
}
});
var titleStr = filterForm.find("span").text();
var titleFontStr = filterForm.find("font").text();
var header = "";
if(titleStr.indexOf(":") != -1) {
// 보도사진 페이지
header = titleStr.substring(0, titleStr.indexOf(":")+2);
filterForm.find("span").text(header + itemName);
}else {
// CMS 페이지
header = titleFontStr;
filterForm.find("span").html("" + header + "
" + itemName);
}
}
else {
if(value.charAt(0) == 'C') {
value = value.substring(1);
filterForm.find("li").each(function(index) {
if($(this).hasClass("choice")) {
$(this).attr("selected", "selected");
$(this).attr("value", "C"+value);
// 날짜를 직접 설정한 경우, split 해서 startDate endDate 세팅하기
var settingDate = value.split('~');
var startDate = settingDate[0];
var endDate = settingDate[1];
// this의 자식 중 input[name=startDate], input[name=endDate] 요소를 찾음
$(this).find('input[name="startDate"]').val(startDate);
$(this).find('input[name="endDate"]').val(endDate);
}
else {
$(this).removeAttr("selected");
}
});
var titleStr = filterForm.find("span").text();
var header = titleStr.substring(0, titleStr.indexOf(":")+2);
filterForm.find("span").text(header + value);
}
}
}
/*
//날짜 입력 오늘 날짜, 입력되도록 해둠 2017.04.06 이재우
// 익스플로러에서 비정상 동작하여 사용안함 / 오늘로 이동으로 변경함
$(document).on('click', ".datepicker" , function(){
var elmnt = $(this);
$("button.ui-datepicker-current").on('click', function(){
$(elmnt).datepicker('setDate',new Date());
$(".ui-datepicker-close").click();
});
});
*/
function userBookmarkList() { // 사용자가 찜한 북마크 목록
var param = "action=list";
$.ajax({
type: "POST",
url: "bookmark.api?"+param,
dataType: "json",
success : function(data) {
$(data.result).each(function(key, val) {
var uciCode = val.uciCode;
$("#search_list ul .over_wish").each(function(idx, value) { // 가로맞춤 보기
var list_uci = $("#search_list ul .over_wish").eq(idx).attr("value");
if(list_uci == uciCode) {
$("#search_list ul .over_wish").eq(idx).addClass("on");
}
});
});
}
});
}
function checkNumber(event) {
event = event || window.event;
var keyID = (event.which) ? event.which : event.keyCode;
if( ( keyID >=48 && keyID <= 57 ) || ( keyID >=96 && keyID <= 105 )
|| (keyID == 8 || keyID == 46 || keyID == 37 || keyID == 39 || keyID == 16 || keyID == 35 || keyID == 36)
)
{
return;
}
else if(keyID == 13) {
if(event.currentTarget.name = "pageNo") {
event.currentTarget.blur();
}
else {
search();
}
}
else
{
return false;
}
}
function goPage(pageNo) {
if(pageNo < 1) {
pageNo = 1;
}
else if(pageNo > $("div .paging span.total").html()) {
pageNo = $("div .paging span.total").html();
}
$("input[name=pageNo]").val(pageNo);
search();
}
function search() {
searchInternal($("#serviceMode").length == 0);
}
function searchPage() {
var pageNo = $("input[name=pageNo]").val().match(/[0-9]/g).join("");
if(Number(pageNo) > Number($("div .paging span.total").html())) {
alert("입력이 최대 페이지보다 큽니다");
return;
}
search();
}
function searchInternal(cmsMode) {
$("#searchProgress").css("display", "block");
var fullSearch = false; // 전체매체 검색(비제휴 매체 포함)
if(cmsMode) {
fullSearch = $("#fullSearch").is(":checked");
}
var keyword = "";
if(cmsMode) {
keyword = $("#cms_keyword_current").val();
}
else {
keyword = $("#keyword_current").val();
}
keyword = $.trim(keyword);
var pageNo = $("input[name=pageNo]").val();
var transPageNo = pageNo.match(/[0-9]/g).join("");
if(pageNo != transPageNo) {
pageNo = transPageNo;
$("input[name=pageNo]").val(pageNo);
}
var pageVol = $("select[name=pageVol]").val();
var contentType = $(".filter_contentType .filter_list").find("[selected=selected]").attr("value");
var media = $(".filter_media .filter_list").find("[selected=selected]").attr("value");
var durationReg = $(".filter_durationReg .filter_list").find("[selected=selected]").attr("value");
//console.log("xx"+durationReg);
var durationTake = $(".filter_durationTake .filter_list").find("[selected=selected]").attr("value");
var colorMode = $(".filter_color .filter_list").find("[selected=selected]").attr("value");
var horiVertChoice = $(".filter_horizontal .filter_list").find("[selected=selected]").attr("value");
var portRight = $(".filter_portRight .filter_list").find("[selected=selected]").attr("value");
var includePerson = $(".filter_incPerson .filter_list").find("[selected=selected]").attr("value");
var group = $(".filter_group .filter_list").find("[selected=selected]").attr("value");
var saleState = $(".filter_saleState .filter_list").find("[selected=selected]").attr("value");
var size = $(".filter_size .filter_list").find("[selected=selected]").attr("value");
view_form.keyword.value = keyword;
view_form.pageNo.value = pageNo;
view_form.pageVol.value = pageVol;
view_form.media.value = media;
view_form.durationReg.value = durationReg;
view_form.durationTake.value = durationTake;
view_form.colorMode.value = colorMode;
view_form.horiVertChoice.value = horiVertChoice;
view_form.saleState.value = saleState;
view_form.size.value = size;
var sort = "";
// 쿠키값 여부에 따라, 변수 세팅
var contextPath = window.location.pathname.split("/")[1];
var searchParam = {
"contextPath":contextPath
,"keyword":keyword
, "pageNo":pageNo
, "pageVol":pageVol
, "contentType":contentType
, "media":media
, "durationReg":durationReg
, "durationTake":durationTake
, "colorMode":colorMode
, "horiVertChoice":horiVertChoice
, "portRight":portRight
, "includePerson":includePerson
, "group":group
, "saleState":saleState
, "size":size
, "sort":sort
, "fullSearch":fullSearch
};
console.log(searchParam);
searchKeyword = keyword; //검색결과 없는 페이지를 만들기 위한 검색어 셋팅
if(cmsMode) {
$("#cms_keyword").val(keyword);
}
else {
$("#keyword").val(keyword);
}
var html = "";
$.ajax({
type: "POST",
async: true,
dataType: "json",
data: searchParam,
timeout: 1000000,
url: searchTarget,
success : function(data) { console.log(data);
var count = data.count; // 총 갯수
var viewCnt = data.result.length; // 현재 페이지에 보여지는 목록 갯수
if(cmsMode) {
makeCmsList(data);
}
else {
makeServiceList(data);
}
$("#searchProgress").css("display", "none");
var pageVol = parseInt($("select[name='pageVol'] option:selected").val()); // 페이지당 표현단위
if(count < pageVol || viewCnt < pageVol) {
// 총 갯수 혹은 현재 페이지 목록갯수가 표현단위보다 작을 때, [다음 페이지] 숨김
$(".more").hide();
}else{
$(".more").show();
}
// 새로고침했을때, 기존 검색옵션이 존재한다면 유지시키기 기능 추가 (2024-09-25 HA.J.S)
var URLParam = "?";
if(keyword!='') { URLParam = keepingSearchParam(URLParam, 'keyword', keyword); }
if(media!=0) { URLParam = keepingSearchParam(URLParam, 'media', media); }
if(durationReg!=1) { URLParam = keepingSearchParam(URLParam, 'durationReg', durationReg); }
if(durationTake!=1) { URLParam = keepingSearchParam(URLParam, 'durationTake', durationTake); }
if(horiVertChoice!=0) { URLParam = keepingSearchParam(URLParam, 'horiVertChoice', horiVertChoice); }
if(size!=0) { URLParam = keepingSearchParam(URLParam, 'size', size); }
if(pageNo > 0 && pageNo < data.totalPage) { URLParam = keepingSearchParam(URLParam, 'pageNo', pageNo); }
if(saleState!=undefined && saleState!=6) { URLParam = keepingSearchParam(URLParam, 'saleState', saleState);}
$('select[name="pageVol"] option').each(function() {
var optionValue = $(this).val();
if(pageVol==optionValue) { URLParam = keepingSearchParam(URLParam, 'pageVol', pageVol); }
});
if(URLParam!="?") {
var newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + URLParam;
history.pushState(null, '', newUrl);
}
},
error : function(request, status, error) {
alert("code:" + request.status + "\n" + "message:" + request.responseText + "\n" + "error:" + error);
$("#searchProgress").css("display", "none");
}
});
}
var searchKeyword = '';
function makeServiceList(data) {
var html = "";
if(data.result.length > 0){
$(data.result).each(function(key, val) {
html += "
"; if(searchKeyword.length > 0) { html += ""+searchKeyword+"에 대한"; } else { html += "조건에 적합한"; } html += " 검색 결과가 없습니다."; html += "
"; html += ""; if(searchKeyword.length > 0) { html += ""+searchKeyword+"에 대한 검색 결과가 없습니다."; } else { html += "조건에 적합한 검색 결과가 없습니다."; } html += "
"; html += "