
    <div class="contents">
		<form name="input_form" id="input_form" action="/web/mypage/bookmark" method="post">
		<div class="mypage_right">
			<div class="mypage_right_top">
				<span class="mypage_title">북마크함 </span>
				<span class="srch">
					<span><input type="text" name="search_keyword" id="search_keyword" value="<?=$search_keyword?>" placeholder="북마크 검색" onkeypress="list_search(event);"><a href="javascript:list_search_proc();"><img src="/img/web/mypage_serch_icon.gif" alt="검색하기"></a></span>
				</span>
				<span style="margin-left:10px;">총 <span class="beachblue"><?=number_format($total_count)?></span>개</span>
			</div>
			<div class="bookmark_add">
				<span class="url"><input type="text" placeholder="URL 입력" name="bookmark_url" id="bookmark_url" style="width:440px"></span>
	            <span class="bttn"><span><a href="javascript:bookmark_add();" class="btn btn-success br5">북마크 추가</a></span></span>
	            <span class="bttn2"><span><a href="javascript:bookmark_edit();" class="btn btn-default br5 fr arrow_down" id="bookmark_edit_btn">편집</a></span></span>
			</div>
			<div class="bookmark_header" id="bookmark_edit_header" style="display:none">
				<span style="margin-right:20px;"><input name="allcheck" id="allcheck" type="checkbox"></span>
				<span style="margin-right:20px;">총 <span class="beachblue" id="bookmark_del_count">0</span>개 선택</span>
				<span><a href="javascript:bookmark_arr_del();" class="btn btn-default br15">삭제</a></span>
				<span class="fr"><a href="javascript:bookmark_edit()"><img src="/img/web/photo_close.png" style="padding:18px 20px 0 0"></a></span>
			</div>
			<div class="mypage_list" id="bookmark_list">
		<?

		if(count($list)==0){
			echo '<div style="min-height:300px;padding-left:43%" class="mypage_list_cont">등록된 북마크가 없습니다.</div>';
		} else {

			foreach ($list as $val) {
				switch ($val['content_type']) {
					case '1':	$view_url = '/web/news/news_view/'.$val['idx']; 	$share_id_name = "news_".$val['idx'];
								break;
					case '2': 	$view_url = '/web/news/column_view/'.$val['idx']; 	$share_id_name = "column_".$val['idx'];
								break;
					case '3': 	$view_url = '/web/life/life_view/'.$val['idx'];		$share_id_name = "life_".$val['idx'];
								break;
				}

				$title = $val['title'];
				$bookmark_date	= $val['bookmark_date'];
				$bookmark_date_txt = substr($bookmark_date, 0, 10);
				$bookmark_date_txt = str_replace('-', '.', $bookmark_date_txt);

				$title_txt = mb_strimwidth($title, '0', '80', '..', 'utf-8');
				$content = strip_tags($val['content']);
               	$content_txt = mb_strimwidth($content, '0', '200', '..', 'utf-8');

				$share_title 	= str_replace("'", "\\'", $title);
				$share_title  	= str_replace('"', '\\"', $share_title);
				$share_content  = mb_strimwidth($content, '0', '250', '..', 'utf-8');
				$share_content  = htmlspecialchars($share_content);
				$share_content  = str_replace("'", "\\'", $share_content);
				$share_content  = str_replace('”', '"', $share_content);

				$main_img = $val['main_img'];

		?>
				<div class="mypage_list_cont">
					<input type="hidden" name="content_<?=$share_id_name?>" id="content_<?=$share_id_name?>" value="<?=$share_content?>">
					<input type="hidden" name="title_<?=$share_id_name?>" id="title_<?=$share_id_name?>" value="<?=$share_title?>">
					<input type="hidden" name="copy_url_<?=$share_id_name?>" id="copy_url_<?=$share_id_name?>" value="<?=WWW_CROSSMAP?><?=$view_url?>">
					<input type="hidden" name="img_url_l<?=$share_id_name?>" id="img_url_<?=$share_id_name?>" value="<?=WWW_CROSSMAP?><?=$main_img?>">
					<div class="btn-input bookmark_checkbox" style="display:none"><input type="checkbox" name="is_del[]" value="<?=$val['bookmark_idx']?>" onclick="bookmark_del_count();"></div>
					<div class="art-img" onclick="location.href='<?=$view_url?>'" style="cursor:pointer;width:89px;height:61px;background:url('<?=$val['main_img']?>') no-repeat center; background-size:cover;"></div>
					<div class="art-info">
						<h2 class="art-title"><a href="<?=$view_url?>"><?=$title_txt?></a><span class="beachblue"><span class="company"><span class="beachblue"><?=$val['content_name']?></span></span></span></h2>
						<p class="art-link"><a href="<?=$view_url?>"><?=WWW_CROSSMAP?><?=$view_url?></a></p>
						<p class="art-sum"><span id="content_<?=$val['bookmark_idx']?>" style="display:none"><a href="<?=$view_url?>"><?=$content_txt?></a></span></p>
					</div>
					<div class="art-menu fr">
	                    <div style="padding-bottom:5px; float:right">
	                    	<span><a href="javascript:;"  class="btn btn-default br5" onclick="share_box(this);" id="share_box_btn<?=$val['bookmark_idx']?>" style="border-radius:5px 0 0 5px !important;float:left;padding: 5px 6px 5px 9px;" strA="<?=$share_id_name?>"><img src="/img/web/img_upload.gif"></a></span>
							<span><a href="javascript:bookmark_del('<?=$val['bookmark_idx']?>')" class="btn btn-default br5" style="border-radius:0 5px 5px 0 !important; border-left:0 !important;padding: 5px 6px"><img src="/img/web/img_x.gif"></a></span>
	                    </div>
						<div class="date" style="padding:15px 0 10px;text-align:right; padding-right:5px; font-size:12px"><?=$bookmark_date_txt?></div>
						<div class="bttn2"><span><a href="javascript:content_more('<?=$val['bookmark_idx']?>')" class="btn btn-default br5 fr arrow_down" id="arrow_img_<?=$val['bookmark_idx']?>">자세히</a></span></div>
					</div>
				</div>
		<?	}

		}

		?>
			</div>
		</div>
		</form>
	</div>

<?
$title = '';$content='';$main_img='';
require_once(APPPATH."views/web/comm/share_box_inc.php"); ?>


<script>
// 공유하기
var share_key = '';
function share_box(e){
	var id = e.id;
	$("#share_box").toggle();
	var key = $("#"+id).attr('strA');

	$("#share_content").val($("#content_"+key).val());
	$("#share_title").val($("#title_"+key).val());
	$("#share_copy_url").val($("#copy_url_"+key).val());
	$("#share_img_url").val($("#img_url_"+key).val());
	$("#copy_url").val($("#copy_url_"+key).val());

    var popH = $("#"+id).offset().top;
	var popL = $("#"+id).offset().left;

    $('.popup_share').css('left',(popL-100)+'px');
	$('.popup_share').css('top',popH+'px');

	share_key = key;
}


// 공유하기 - 북마크
function bookmark(){
	alert("이미 북마크되었습니다.");
	return false;
}



// 스크롤
<? if($total_count <= $limit) {?>
	var more_yn = 'N';
<?} else {?>
	var more_yn = 'Y';
<?}?>
$(document).ready(function () {
  $(document).scroll(function() {
    var maxHeight = $(document).height();
    var currentScroll = $(window).scrollTop() + $(window).height();
    if (maxHeight <= currentScroll + 100) {
        if(more_yn=='Y') {
            bookmark_list_more();
        }
    }
  })
});

var bookmark_list_page = 2;
function bookmark_list_more(){
	var form_data = {
		"page"              : bookmark_list_page,
		"search_keyword"    : "<?=$search_keyword?>"
	};
	$.ajax({
        url: '/web/mypage/bookmark_list_more',
        async: false,
        type: 'POST',
        dataType: 'HTML',
		data: form_data,
		success: function (rtnHtml) {
        	var arrHtml = rtnHtml.split("|||||");
			if(arrHtml[0].trim()=='0000') {
			    more_yn = arrHtml[2];
				if (arrHtml[1] != "") {
					$("#bookmark_list").append(arrHtml[1]);
					bookmark_list_page++;
				}
			}
        },
        error: function (rtnHtml) {
            alert('데이터 로드에 실패했습니다.');
            return false;
        }
    });
}


// 검색
function list_search(e){
	if (e.keyCode == 13) {
		list_search_proc();
	}
}
function list_search_proc(){
	$("#input_form").submit();
}

// 북마크
function bookmark_add(){
    if($("#bookmark_url").val()==''){
		alert("url을 입력해주세요.");
		return false;
	}

	var form_data = {
		"bookmark_url"			: $("#bookmark_url").val()
	};
	$.ajax({
        url: '/web/comm/bookmark_url_add_proc',
        async: false,
        type: 'POST',
        dataType: 'JSON',
        data: form_data,
        success: function (rtnJson) {
            if (rtnJson.code == "0000") {
            	location.href='/web/mypage/bookmark';
            } else {
                alert(rtnJson.msg);
                return false;
            }
        },
        error: function (rtnJson) {
            alert('북마크에 실패했습니다.');
            return false;
        }
    });
}

// 북마크 삭제
function bookmark_del(idx){
	if(confirm("북마크가 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		var form_data = {
			"idx"			: idx
		};
		$.ajax({
			url: '/web/comm/bookmark_del_proc',
			async: false,
			type: 'POST',
			dataType: 'JSON',
			data: form_data,
			success: function (rtnJson) {
				if (rtnJson.code == "0000") {
					location.href='/web/mypage/bookmark';
				} else {
					alert(rtnJson.msg);
					return false;
				}
			},
			error: function (rtnJson) {
				alert('북마크 삭제에 실패했습니다.');
				return false;
			}
		});
	} else {   //취소
		return;
	}
}

// 복수 삭제
function bookmark_arr_del() {
	if($("input:checkbox[name='is_del[]']").is(":checked") == false) {
		alert("삭제할 내용이 없습니다.");
		return false;
	}
	if(confirm("북마크가 삭제됩니다. 삭제하시겠습니까?") == true) {    //확인
		$("#input_form").attr("action", "/web/comm/bookmark_arr_del_proc");
		$("#input_form").submit();
	} else {   //취소
		return;
	}
}

// 편집 - 클릭시
function bookmark_edit(){
	$("#bookmark_edit_header").toggle();
	$("#bookmark_edit_btn").toggleClass('arrow_down');
	$("#bookmark_edit_btn").toggleClass('arrow_up');
	$(".bookmark_checkbox").toggle();

	var class_name = $("#bookmark_edit_btn").attr("class");
	if(class_name == 'btn btn-default br5 fr arrow_down') {
		$(".mypage_list_cont").css('padding-left', '20px');
	} else {
		$(".mypage_list_cont").css('padding-left', '0px');
	}
}

// 내용 펼치기
function content_more(key){
	$("#content_"+key).toggle();
	$("#arrow_img_"+key).toggleClass('arrow_down');
	$("#arrow_img_"+key).toggleClass('arrow_up');

	var class_name = $("#arrow_img_"+key).attr("class");
	if(class_name == 'btn btn-default br5 fr arrow_down') {
		$("#arrow_img_"+key).html('자세히');
	} else {
		$("#arrow_img_"+key).html('접기');
	}
}

// checkbox click
function bookmark_del_count(){
	var cnt = $("input[name='is_del[]']:checkbox:checked").length;
	$("#bookmark_del_count").html(cnt);
}

// checkbox all checked/unchecked
$(function(){
	$("#allcheck").click(function(){
    	if($("#allcheck").prop("checked")) {
    		$("input:checkbox[name='is_del[]']").prop('checked', true); // 전체선택하기
		} else {
      		$("input:checkbox[name='is_del[]']").prop("checked", false);
    	}
    	bookmark_del_count();

  	})
})

</script>
