//템플릿로드 function loadTemplate(url, func) { var xhr = (window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP")); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { if (typeof func === 'function') func(xhr.responseText); } } xhr.open("GET", url, true); xhr.send(); } //퀵메뉴 $(function () { $(window).scroll(function () { var windowH = $(window).height(), scrollY = $(window).scrollTop(); $('.quick').each(function () { var elPosition = $(this).offset().top; if (scrollY > elPosition - windowH) { $('.quick>div').addClass('actives') } else { $('.quick>div').removeClass('actives') } }) }); }); //팝업 닫기 function popUpClose(id, location, func) { location = typeof location !== 'undefined' ? location : 'reload'; func = typeof func !== 'undefined' ? func : ''; $('#' + id).css('display', 'none'); if (location == 'reload') { window.location.reload(); } else if (location == 'referrer') { history.back(); } else if (location == 'N') { if (typeof func === 'function') func(response); } else { window.location.href = location; } } //맨위로 버튼 $(function () { $(window).scroll(function () { if ($(this).scrollTop() > 500) { $('.go-top').fadeIn(); } else { $('.go-top').fadeOut(); } }); $(".go-top").click(function () { $('html, body').animate({ scrollTop: 0 }, 400); return false; }); }); //page copy $('*[data-event="copy_page"]').click(function () { var tempElem = document.createElement('textarea'); var html = ''; var target = $(this).attr('data-target'); if (target != undefined && target != '') { html = $('#' + target).clone(); } else { html = $(this).clone(); } if (html.length > 0) { html = html[0].outerHTML; html = html.replace('data-event="copy_code"', ''); html = html.replace('id="' + target + '"', ''); html = formatFactory(html) tempElem.value = html; document.body.appendChild(tempElem); tempElem.select(); document.execCommand("copy"); document.body.removeChild(tempElem); alert('Success copy this code.'); } else { alert('Html code is empty.') } }); //html code copy $('*[data-event="copy_code"]').click(function () { var tempElem = document.createElement('textarea'); var html = ''; var target = $(this).attr('data-target'); if (target != undefined && target != '') { html = $('#' + target).clone(); } else { html = $(this).clone(); } if (html.length > 0) { html = html[0].outerHTML; html = html.replace('data-event="copy_code"', ''); html = html.replace('id="' + target + '"', ''); html = formatFactory(html) tempElem.value = html; document.body.appendChild(tempElem); tempElem.select(); document.execCommand("copy"); document.body.removeChild(tempElem); alert('Success copy this code.'); } else { alert('Html code is empty.') } }); //code copy $('*[data-event="copy_clipboard"]').click(function () { //data-clipboard-text var tempElem = document.createElement('textarea'); var code = ''; var target = $(this).attr('data-target'); var currentText = $(this).html(); //attr data-clipboard-text 복사할 텍스트 에서 가져온다 code = $(this).attr('data-clipboard-text'); // Create a temporary element to copy the code to clipboard tempElem.value = code; document.body.appendChild(tempElem); tempElem.select(); document.execCommand("copy"); document.body.removeChild(tempElem); // Show tooltip var tooltipElem = $('
doneSuccess
'); $(this).text(''); $(this).append(tooltipElem); setTimeout(function () { tooltipElem.remove(); $(this).html(currentText); }.bind(this), 2000); }); //html formater function formatFactory(html) { function parse(html, tab = 0) { var tab; var html = $.parseHTML(html); var formatHtml = new String(); function setTabs() { var tabs = new String(); for (i = 0; i < tab; i++) { tabs += '\t'; } return tabs; }; $.each(html, function (i, el) { if (el.nodeName == '#text') { if (($(el).text().trim()).length) { formatHtml += setTabs() + $(el).text().trim() + '\n'; } } else { var innerHTML = $(el).html().trim(); $(el).html(innerHTML.replace('\n', '').replace(/ +(?= )/g, '')); if ($(el).children().length) { $(el).html('\n' + parse(innerHTML, (tab + 1)) + setTabs()); var outerHTML = $(el).prop('outerHTML').trim(); formatHtml += setTabs() + outerHTML + '\n'; } else { var outerHTML = $(el).prop('outerHTML').trim(); formatHtml += setTabs() + outerHTML + '\n'; } } }); return formatHtml; }; return parse(html.replace(/(\r\n|\n|\r)/gm, " ").replace(/ +(?= )/g, '')); }; // Function to Convert rgb to rgba function rgb2rgba(rgb, opacity) { var rgbaValue = 'rgba(' + rgb.split('(')[1].split(')')[0].split(',').join(', ') + ', ' + opacity + ')'; return rgbaValue; } //change rgba function changeRgba(rgba, opacity) { var rgbaValue = 'rgba(' + rgba.split('(')[1].split(')')[0].split(',').join(', ') + ', ' + opacity + ')'; return rgbaValue; } //반복 스타일 생성 function createStyleForeach(dom, style, defaultValue, value, math = "+") { var onlyNumDefault = defaultValue.replace(/[^0-9]/g, ''); var onlyNumValue = value.replace(/[^-0-9]/g, ''); var onlyUnitDefault = defaultValue.replace(/[^a-z]/gi, ''); //ms // var thisStyle = defaultValue; for (var i = 0; i < $(dom).length; i++) { // 배열 arr의 모든 요소의 인덱스(index)를 출력함. var li = $(dom)[i]; if (i == 0) { $(li).css(style, defaultValue); continue; } // console.log(onlyNumValue); var newNum = parseInt(onlyNumDefault) + (parseInt(onlyNumValue) * i); var newStyle = newNum + onlyUnitDefault; // var newStyle = `calc(${thisStyle} ${math} ${value})`; // console.log(newStyle); $(li).css(style, newStyle); // thisStyle = $(li).css(style); } } // 스크롤 고정 컨텐츠 함수 function fixedScrollAdd(id) { var fixedScroll = id + ' .fixed-item'; var imageScroll = id + ' .scroll-item'; var imageScrollValue = $(imageScroll).offset().top; var fixedScrollHeight = $(fixedScroll).height(); $(window).scroll(function () { var scrollTop = $(window).scrollTop(); console.log(scrollTop); if (scrollTop > imageScrollValue) { $(fixedScroll).addClass('fixed'); } else { $(fixedScroll).removeClass('fixed'); } var fixedScrollBottom = $(fixedScroll).offset().top + fixedScrollHeight; var imageScrollBottom = $(imageScroll).offset().top + $(imageScroll).height(); if (fixedScrollBottom > imageScrollBottom) { $(fixedScroll).removeClass('fixed'); $(id + ' .fixed-area').addClass('fixed-end'); } else { $(id + ' .fixed-area').removeClass('fixed-end'); } }); } //복사 function copyText() { $('.copy').click(function () { var text = $(this).text().trim(); // 앞뒤 공백 제거 var $temp = $("