var Durian = {
// OK
alert : function(msg, type) {
var layer = jQuery('#__alert__');
if (layer.length) {
Durian.alertLayer(layer, msg, type);
} else {
try {
var alert_tpl = Durian.initCommon.isMobile ? '/common/js/alert/alert.mobile.html' : '/common/js/alert/alert.html';
jQuery.ajax({
url : alert_tpl,
type : 'POST',
dataType : 'TEXT',
data : {
msg : msg,
dummy : Util.random(1, 10000)
},
success : function(html) {
var layer = jQuery('
')
.css('padding', '0 0 150px 0')
.html(html);
jQuery('body').append(layer);
Durian.alertLayer(layer, msg, type);
}
});
} catch (e) {
alert(msg);
}
}
},
alertLayer : function(layer, msg, type) {
Durian.showLayer(layer, {
center : true,
block : true
})
jQuery('#__loading_panel__').hide();
jQuery('#__alert_msg__').html(msg);
jQuery("#__alert_button_ok__").focus();
if (type=='confirm') {
jQuery("#__alert_button_cancel__").parent().css('display', 'inline-block');
}
},
alertCloseMode : -1, /* default -1: history.back(); */
alertClose : function() {
var mode = parseInt(Durian.alertCloseMode, 10);
if (isNaN(mode) && Durian.alertCloseMode!='ALERT_BACK') {
location.href = Durian.alertCloseMode;
} else {
switch (mode) {
case 1 : location.reload(); break;
case -2 : self.close(); break;
case 0 : break; // do nothing(close layer only)
case -3 :
if(opener){
opener.location.reload();
self.close();
}else{
self.close();
}
break;
case -4 : parent.self.close(); break;
case -1 :
case 'ALERT_BACK':
default : history.back(); break;
}
jQuery('#__alert__').hide();
jQuery('#__block_page__').hide();
}
},
alertCancelMode : -1, /* default -1: history.back(); */
alertCancel : function() {
var mode = parseInt(Durian.alertCancelMode, 10);
if (isNaN(mode) && Durian.alertCancelMode!='ALERT_BACK') {
location.href = Durian.alertCancelMode;
} else {
switch (mode) {
case 1 : location.reload(); break;
case -2 : self.close(); break;
case 0 : break; // do nothing(close layer only)
case -3 :
if(opener){
opener.location.reload();
self.close();
}else{
self.close();
}
break;
case -4 : parent.self.close(); break;
case -1 :
case 'ALERT_BACK':
default : history.back(); break;
}
jQuery('#__alert__').hide();
jQuery('#__block_page__').hide();
}
},
hiddenLocation : function(url){
// drawHiddenFrame
var hiddenFrame = jQuery('#__hidden_frame_for_act__');
if (hiddenFrame.length) {
}else{
hiddenFrame = jQuery('');
jQuery('body').append(hiddenFrame);
}
try{
var uri = Durian.uriParser(url);
if (uri.search!='' && uri.search.indexOf('?')>=0){
uri.search += "&__UseHiddenAct__=1";
}else{
uri.search = "?__UseHiddenAct__=1";
}
var uri_pathname = uri.pathname;
if (uri_pathname!='' && uri_pathname.substring(0,1)!='/'){ // IE는 맨앞에 /가 없다.
uri_pathname = '/'+uri_pathname;
}
url = uri.protocol + "//" + uri.host + uri_pathname + uri.search + uri.hash;
}catch(e){
url += (url.indexOf('?')>=0 ? '&' : '?') + "__UseHiddenAct__=1";
}
if (window.__hidden_frame_for_act__){
window.__hidden_frame_for_act__.location.href = url;
}else{
location.href = url;
}
},
showIf : function(obj, value) {
if (value) {
jQuery(obj).show();
} else {
jQuery(obj).hide();
}
},
showHide : function(show, hide) {
if (hide) {
jQuery(hide).each(function() {
jQuery(this).hide();
});
}
if (show) {
jQuery(show).each(function() {
jQuery(this).show();
});
}
},
showLayer : function(obj, option) {
obj = jQuery(obj);
if (option.fadein){
obj.fadeIn();
}else{
obj.show();
}
if (typeof option.style == 'string') {
obj.attr('style', option.style);
} else if (typeof option.style == 'object') {
obj.css(option.style);
}
obj.css('position', 'fixed');
if (option.center) {
if(option.left) {
var offset_left = option.left;
} else {
var offset_left = (jQuery(window).innerWidth() - obj.width()) / 2;
}
if(option.top) {
var offset_top = option.top;
} else {
var offset_top = (jQuery(window).innerHeight() - obj.height()) / 2;
}
obj.css({
left : offset_left,
top : offset_top
});
}
var key = ['left', 'top', 'width', 'height'];
for (var i=0; i');
obj.html('');
jQuery('body').append(obj);
obj.option = option;
obj.iframe = obj.find(':first-child');
// show layer
this.showLayer(obj, option);
// url
if (typeof option.url == 'string') {
obj.iframe.attr('src', option.url);
}
},
showLoading : function(msg) {
var id = '__loading_panel__';
var div = jQuery('#' + id);
if (!div.length) {
div = jQuery(' ');
div.css({
/*'position' : 'fixed',*/
'border': '#787878 solid 2px',
'padding' : '10px',
'background': 'white',
'font-size' : '12pt'
});
jQuery('body').append(div);
}
//div.html(msg);
jQuery('#__loading_msg__').html(msg);
Durian.showLayer(div, {
center : true,
block : true
});
},
hideLoading : function() {
jQuery('#__loading_panel__').hide();
jQuery('#__block_page__').hide();
},
showTooltip : function(obj, position) {
if (!jQuery) return;
if (!jQuery("#__tooltip_place__").is('div')) {
jQuery(document.body).append("");
}
var $tt = jQuery("#__tooltip_place__");
position = position || "RIGHT";
var ttt = jQuery(obj).attr('title') || jQuery(obj).attr('alt') || jQuery(obj).attr('tooltip');
if (ttt == null) return;
jQuery(obj).attr('tooltip', ttt);
jQuery(obj).removeAttr('title');
jQuery(obj).removeAttr('alt');
jQuery(obj).css('cursor', 'help');
$tt.html(ttt);
$tt.css({
'position': 'absolute',
'z-index': 1001,
'border': '#787878 solid 2px',
'padding': 5,
'background': 'lightyellow',
'font-size': '10pt'
});
var tempX = jQuery(obj).offset().left + jQuery(obj).width() + 20;
var tempY = jQuery(obj).offset().top - 10;
if (position.indexOf("BOTTOM") >= 0) {
tempY = jQuery(obj).offset().top + jQuery(obj).height() + 5;
} else if (position.indexOf("TOP") >= 0) {
tempY = jQuery(obj).offset().top - $tt.height() - 5;
} else {
tempY = jQuery(obj).offset().top - Math.ceil(Math.abs(jQuery(obj).height() - $tt.height()) / 2);
}
if (position.indexOf("LEFT") >= 0) {
tempX = jQuery(obj).offset().left - $tt.width() - 5;
} else if (position.indexOf("RIGHT") >= 0) {
tempX = jQuery(obj).offset().left + jQuery(obj).width() + 5;
} else {
tempX = jQuery(obj).offset().left - Math.ceil(Math.abs(jQuery(obj).width() - $tt.width()) / 2);
}
if (tempX < 0) {
tempX = 0;
}
if (tempY < 0) {
tempY = 0;
}
$tt.css({
'top': tempY,
'left': tempX
}).show();
},
hideTooltip : function (obj) {
if (!jQuery) return;
jQuery("#__tooltip_place__").hide();
},
uriParser : function (uri){
var parser = document.createElement('a');
parser.href = uri;
// parser.protocol; // => "http:"
// parser.hostname; // => "example.com"
// parser.port; // => "3000"
// parser.pathname; // => "/pathname/" // IE는 /없이시작됨
// parser.search; // => "?search=test"
// parser.hash; // => "#hash"
// parser.host; // => "example.com:3000"
return parser;
},
autoResizeIframe : function(iframe) {
Util.autoResizeIframe(iframe);
var obj = jQuery(iframe).parent();
if (obj.option) {
if (obj.option.center) {
var pos = jQuery(obj).getCenter();
jQuery(obj).offset(pos);
}
}
},
// iframe resizing
resizeIframe : function(iframe, height) {
iframe = (typeof iframe == 'string') ? jQuery('#' + iframe) : jQuery(iframe);
if (iframe.length) {
if (height > 0) {
iframe.css('height', height);
} else {
Util.autoResizeIframe(iframe, true, false);
//Durian.autoResizeIframe(iframe);
}
}
},
// DEPRECATED
// parent : 1 base offset
searchParentTag : function(obj, tag, offset) {
tag = tag.toLowerCase();
var count = 0;
var p = obj.parentNode;
while (p != document.body) {
if (p.tagName.toLowerCase() == tag) {
count++;
if (count == offset) {
return p;
}
}
p = p.parentNode;
}
return false;
},
// DEPRECATED
// child : 1 base offset
searchChildTag : function(obj, tag, offset) {
var list = obj.getElementsByTagName(tag);
if (typeof list[offset-1] != 'undefined') {
return list[offset-1];
} else {
return false;
}
},
// DEPRECATED
// prev : 1 base offset
searchPrevSameTag : function(obj, offset, parent) {
var tag = obj.tagName;
var list = (parent || document).getElementsByTagName(tag);
var key = -1;
for (var i=0; i -1 && key >= offset) {
return list[key - offset];
} else {
return false;
}
},
// DEPRECATED
// next : 1 base offset
searchNextSameTag : function(obj, offset, parent) {
var tag = obj.tagName;
var list = (parent || document).getElementsByTagName(tag);
var key = -1;
for (var i=0; i -1 && key + offset < list.length) {
return list[key + offset];
} else {
return false;
}
},
// DEPRECATED
searchByClassName : function(obj, className) {
var result = jQuery('.' + className, obj);
if (result.length) {
return result;
} else {
return false;
}
},
// popup window
openWin : function(name, url, x, y, sc) {
if (arguments.length > 2) {
var winl = (screen.width - x) / 2;
var wint = (screen.height - y) / 2;
var w = window.open(url, name, 'scrollbars=' + sc + ', resizable=yes, width=' + x + ', height=' + y + ', top='+wint+', left='+winl);
} else {
var w = window.open(url, name);
}
if (w) {
w.focus();
}
return w;
},
// modal window
openModalWin : function(url, x, y, resize, arg) {
if (window.showModalDialog) {
return Durian.openWin('', url, x, y, resize);
} else {
return window.showModalDialog(url, arg || self, 'dialogHeight: '+y+'px; dialogWidth: '+x+'px; edge: Raised; center: Yes; help: No; resizable: '+resize+'; status: No; scroll: No;');
}
},
// open webftp window
openWebFTP : function(imgServer) {
if (!imgServer) {
imgServer = location.href.slice(0, location.href.indexOf('/', 7));
}
x = 1024;
y = 685;
var winl = (screen.width - x) / 2;
var wint = (screen.height - y) / 2;
var w = window.open(imgServer + '/admin/?act=common.webftp&ch=pop', 'webftp', 'scrollbars=no, resizable=no, width=' + x + ', height=' + y + ', top='+wint+', left='+winl);
w.focus();
return w;
},
// clipboard copy - ZeroClipboard
attachClipCopy : function(obj, callback, endCallback) {
ZeroClipboard.setMoviePath('/common/js/ZeroClipboard/ZeroClipboard.swf');
var clip = new ZeroClipboard.Client();
clip.setHandCursor(true);
clip.addEventListener('mousedown', callback);
if (endCallback) {
clip.addEventListener('complete', endCallback);
}
clip.glue(jQuery(obj).get(0));
jQuery(obj).mouseover(function(evt) {
clip.reposition(this);
});
},
imgDefault : function(img, src) {
if (!src || /^[0-9]+$/.test(src) || img.src.search(src) > -1) {
var size = parseInt((src || img.width || img.getAttribute('width')), 10) || 100;
if (size <= 50) {
src = '/data/images/default/common/default_50.gif';
} else if (size <= 100) {
src = '/data/images/default/common/default_100.gif';
} else if (size <= 300) {
src = '/data/images/default/common/default_300.gif';
} else {
src = '/data/images/default/common/default_500.gif';
}
}
if (img.src.search(src) == -1) {
img.src = src;
}
},
formatPrice : function(value, decimal, forceSign){
var sign = '';
if ( typeof value != 'number' ) value = parseFloat(value);
if (isNaN(value)) value = 0.0;
if (decimal==null || typeof decimal == "undefined") decimal = 0;
value = value.round(decimal); //.toFixed(decimal);
if (forceSign && value > 0) sign = '+';
var parts = value.toString().split(".");
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
return sign + parts.join(".");
},
// upload
checkUploadCount : function(option) {
option = jQuery.extend(option, {});
var max = parseInt(option.max, 10) || 0;
if (!max) {
return true;
}
var count = count2 = 0;
if (typeof option.single != 'undefined' && option.single == true) {
count = !option.file_path ? 0 : 1;
count2 = !option.db_file_path ? 0 : 1;
} else {
count = option.list ? jQuery('> *', option.list).length : 0;
count2 = option.db_list ? jQuery('> *', option.db_list).length : 0;
}
var total = count + count2;
if (max <= total) {
alert('첨부파일은 최대 ' + max + '개까지 업로드 가능합니다.');
return false;
} else {
return true;
}
},
openUploadWin : function(option) {
option = jQuery.extend({
act : 'common.popup_upload2',
ch : 'pop',
upload_mode : 'FILE'
}, option || {});
var domain = 'http://' + Durian.getDomain();
var img_server = 'http://' + Durian.getImgServer();
var sub_path = Durian.getDomainSubPath();
option.domain = domain;
var query = ''.encodeQuery(option);
if (sub_path) {
return Durian.openWin('upload', img_server + sub_path + '/?' + query, 550, 400, 'yes');
} else {
return Durian.openWin('upload', img_server + '?' + query, 600, 450, 'yes');
}
},
openUploadWinSingle : function(option) {
option = jQuery.extend({
act : 'common.popup_upload',
ch : 'pop',
upload_mode : 'FILE'
}, option || {});
var domain = 'http://' + Durian.getDomain();
var img_server = 'http://' + Durian.getImgServer();
var sub_path = Durian.getDomainSubPath();
option.domain = domain;
var query = ''.encodeQuery(option);
if (sub_path) {
return Durian.openWin('upload', domain + sub_path + '/?' + query, 550, 300, 'yes');
} else {
return Durian.openWin('upload', domain + '?' + query, 520, 250, 'yes');
}
},
ajaxDeleteFile : function(option, obj) {
option = jQuery.extend({
act : 'common.upload_delete_ajax',
upload_mode : 'FILE'
}, option || {});
jQuery.ajax({
url : './',
type : 'post',
data : option,
dataType : 'JSON',
success : function(data) {
if (data.success) {
applyDeleteFile(data, obj);
} else {
alert(data.msg);
}
}
});
},
getDomain : function() {
return location.href.split('/')[2];
},
getDomainSubPath : function() {
var path = location.href.split('/')[3];
if (path == 'admin') {
return '/admin';
} else if (path == 'seller') {
return '/seller';
} else {
return '';
}
},
getBaseDomain : function() {
var domain = Durian.getDomain();
// ip
if (domain.search(/^[0-9\.]+$/) > -1) {
return domain;
}
var tmp = domain.split('.');
var l = tmp.length;
if (l > 2) {
if (tmp[l-2].search(/^(co|ne|or|pe|go|com|net|org)$/) > -1) {
return tmp.slice(-3).join('.');
} else {
return tmp.slice(-2).join('.');
}
} else {
return domain;
}
},
getImgServer : function() {
return Durian.getDomain();
},
// Editor
initEditor : function(id, externalObject) {
var skinUrl = "/common/js/smarteditor/SmartEditor2Skin.html";
var creator = "createSEditor2";
externalObject = typeof externalObject !== 'undefined' ? externalObject : null;
if(externalObject != null) {
var oEditors = externalObject;
}else{
var oEditors = [];
}
switch(typeof(id)) {
case "string" :
nhn.husky.EZCreator.createInIFrame({
oAppRef: oEditors,
elPlaceHolder: id,
sSkinURI: skinUrl,
fCreator: creator,
htParams: { fOnBeforeUnload : function(){}}
});
break;
case "object" :
if(Object.prototype.toString.call(id) === "[object Array]") {
for(var i = 0; i < id.length; i++) {
nhn.husky.EZCreator.createInIFrame({
oAppRef: oEditors,
elPlaceHolder: id[i],
sSkinURI: skinUrl,
fCreator: creator,
htParams: { fOnBeforeUnload : function(){}}
});
}
}else{
//console.log("Not support object type.");
}
break;
default :
//console.log("Not support variable type.");
}
jQuery("form").submit(function() {
var textareaId;
var textareaCnt = jQuery(".textarea").length;
if(textareaCnt > 1) {
for(var i = 0; i < textareaCnt; i++) {
textareaId = jQuery(".textarea:eq(" + i + ")").attr("id");
oEditors.getById[textareaId].exec("UPDATE_CONTENTS_FIELD", []);
}
}else if(textareaCnt == 0){
}else{
textareaId = jQuery(".textarea").attr("id");
oEditors.getById[textareaId].exec("UPDATE_CONTENTS_FIELD", []);
}
});
},
updateEditor : function(id, externalObject) {
externalObject = typeof externalObject !== 'undefined' ? externalObject : null;
if(externalObject != null) {
var oEditors = externalObject;
}else{
var oEditors = [];
}
oEditors.getById[id].exec("UPDATE_CONTENTS_FIELD", []);
if(document.getElementById(id).value == '
' || document.getElementById(id).value == '
') {
document.getElementById(id).value = '';
}
},
// upload
initUpload : function(option) {
return new Durian.SWFUpload(option);
//return new Durian.TrueUpload(option);
},
// display Image or Flash
displayImageFlash : function(url, width, height) {
if (url.search(/\.swf$/i) > -1) {
Durian.displayFlash(url, width, height);
} else {
Durian.displayImage(url, width, height);
}
},
displayImage : function(url, width, height) {
if (width && height) {
var size = 'width="' + width + '" height="' + height + '"';
} else {
var size = '';
}
var html = '';
document.write(html);
},
// displayFlash
displayFlash : function(url, width, height, id, vars, wmode, bg, scriptAccess) {
var html = Durian.getFlashHTML(url, width, height, id, vars, wmode, bg);
document.write(html);
},
getFlashHTML : function(url, width, height, id, vars, wmode, bg, scriptAccess) {
if (width && height) {
var size = 'width="' + width + '" height="' + height + '"';
} else {
var size = 'width="100%"';
}
if (!id) {
id = Util.randomId(4, 'flash');
}
if (!vars) {
vars = '';
}
if (!wmode) {
wmode = 'transparent';
}
if (!bg) {
bg = '#FFFFFF';
}
if (!scriptAccess) {
scriptAccess = 'sameDomain';
}
var html = '';
return html;
},
// block page
blockPage : function(zIndex, color) {
if (!zIndex) {
zIndex = 1000;
}
var id = '__block_page__';
var div = jQuery('#' + id);
if (!div.length) {
div = jQuery('');
div.css({
'position' : 'absolute',
'left' : '0px',
'top' : '0px',
//'border' : '1px solid red',
//'cursor' : 'not-allowed',
'zIndex' : zIndex
});
jQuery('body').append(div);
}
if (color) {
div.css({
'backgroundColor' : color,
'filter' : 'alpha(opacity=30)',
'opacity' : 0.3
});
}
div
.show()
.width(jQuery(document).width())
.height(jQuery(document).height());
},
// check if member (not secure!)
isMember : function() {
if (Util.getCookie('user_level')) {
return true;
} else {
return false;
}
},
// add bookmark
// refered to http://www.dynamicdrive.com/dynamicindex9/addbook.htm
bookmark : function(url, title) {
if (Util.isIE) {
window.external.AddFavorite(url, title);
} else if (Util.isFF && window.sidebar.addPanel) {
window.sidebar.addPanel(title, url, '');
} else if (Util.isOpera) {
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel', 'sidebar');
elem.click();
} else {
alert((navigator.userAgent.toLowerCase().indexOf('mac') != - 1 ? 'Command/Cmd' : 'CTRL') + ' + D 키를 눌러 북마크에 추가하세요.');
}
},
// apply check all checkbox
applyCheckAll : function(obj) {
jQuery(obj).each(function() {
var objAll = this;
var name = jQuery(objAll).attr('name');
var val = jQuery(objAll).val();
if (val.search(/all/i) > -1) {
var list = jQuery(objAll.form.elements[name]).filter(':checkbox:gt(0)');
} else {
var list = jQuery(objAll.form.elements[val]).filter(':checkbox');
}
jQuery(objAll).click(function() {
var flag = this.checked ? true : false;
jQuery(list).each(function() {
if(!this.disabled){
this.checked = flag;
if ( jQuery(this).checkboxradio ) {
jQuery(this).checkboxradio("refresh");
}
}
});
});
jQuery(list).click(function(evt) {
var flag = (list.length == list.filter(':checked').length);
objAll.checked = flag;
if ( jQuery(objAll).checkboxradio ) {
jQuery(objAll).checkboxradio("refresh");
}
});
});
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// init common
Durian.initCommon = {
isUser : location.href.indexOf('/admin/') == -1 ? true : false,
isSeller : location.href.indexOf('/seller/') != -1 ? true : false,
isPopup : location.href.search(/&ch=(pop|iframe)/) > -1 ? true : false,
isMobile : location.href.indexOf('/m/') == -1 ? false : true,
init : function() {
var D = Durian.initCommon;
// user
if (D.isSeller) {
D.initSeller();
// seller
} else if (D.isUser) {
D.initUser();
// admin
} else {
D.initAdmin();
}
// common
// tooltip
D.initTooltip();
// inputbox
D.initInputBox();
// mask layer
if(D.isMobile == true){
window.onorientationchange = function() {
jQuery('#__block_page__').height(jQuery('body').height());
}
}
},
// seller
initSeller : function() {
var D = Durian.initCommon;
// popup launch
D.popupCookieName = 'POPUP_SELLER';
if (!D.isPopup) {
D.initPopup();
}
},
// user
initUser : function() {
var D = Durian.initCommon;
// fly
try {
var obj_fly = ['L_TODAY_GOODS', 'L_QUICK_MENU'];
for (var i=0; i -1) {
jQuery(list[j]).on('click', D.onPopViewBBS);
}
}
}
}
} catch (e) {}
// popup launch
D.popupCookieName = 'POPUP_DATA';
if (!D.isPopup) {
D.initPopup();
}
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
// ban mouse right button and drag selection
if ((typeof SHOP_MP != 'undefined') && SHOP_MP) {
D.drag = false;
jQuery(document).on('contextmenu', function() { return false; });
jQuery(document).on('mousedown', function(evt) {
if (evt.which == 1) {
D.drag = true;
} else {
return false;
}
});
if (Util.isIE) {
jQuery(document).on('dragstart', function() { console.log('ds'); return false; });
jQuery(document).on('selectstart', function() { return false; });
} else {
jQuery(document).on('mousemove', function(evt) {
if (D.drag == true && evt.which == 1) {
window.getSelection().removeAllRanges();
}
});
jQuery(document).on('mouseup', function(evt) {
D.drag = false;
});
}
}
},
initAdmin : function() {
var D = Durian.initCommon;
// start admin auto logout if not login/logout page
if (typeof ADMIN_LOGOUT_TIME != 'undefined') {
var query = location.href.decodeQuery(true);
if (typeof query.act == 'string' && query.act.search('login.') == -1) {
D.checkAdminLogoutTime();
}
}
},
// admin auto logout
checkAdminLogoutTime : function() {
var D = Durian.initCommon;
if (D.admin_access_start && D.admin_logout_check) {
var now = new Date();
if (ADMIN_LOGOUT_TIME > 0) {
if (D.admin_logout_time - now.valueOf() <= 0) {
// goto logout
location.href = './?act=login.logout_act&auto_logout=1';
} else {
D.displayAdminLogoutTime();
}
}
// access every 5 minutes
if (now.valueOf() - D.admin_temp_access > 5 * 60000) {
D.admin_temp_access = now.valueOf();
jQuery.ajax({
url : './',
type : 'POST',
dataType : 'JSON',
data : {
act : 'login.admin_access_ajax'
},
success : function(data) {
if (data.success && data.admin_access_time) {
D.admin_logout_time = data.admin_access_time * 1000 + + ADMIN_LOGOUT_TIME * 60000;
}
}
});
}
D.admin_logout_check = setTimeout(D.checkAdminLogoutTime, 1000);
} else {
D.admin_access_start = (new Date()).valueOf();
D.admin_temp_access = D.admin_access_start;
if (ADMIN_LOGOUT_TIME > 0) {
D.admin_logout_time = D.admin_access_start + ADMIN_LOGOUT_TIME * 60000;
}
D.admin_logout_check = setTimeout(D.checkAdminLogoutTime, 1000);
}
},
displayAdminLogoutTime : function() {
// display rest logout time
var D = Durian.initCommon;
var time = Math.round((D.admin_logout_time - (new Date()).valueOf()) / 1000);
return time;
},
// popup
initPopup : function() {
var D = Durian.initCommon;
var query = location.href.parseQuery(true);
var query_param = query.act;
if (query_param) {
if (query_param == 'main' || query_param == 'main.index') {
D.getPopupListAjax();
} else {
var data = Util.getCookie(D.popupCookieName);
if (!data || data == '-1') {
D.getPopupListAjax();
} else if (data != '-1') {
D.applyPopup(data);
}
}
} else {
D.getPopupListAjax();
}
},
applyPopup : function(data) {
var D = Durian.initCommon;
var query = location.href.parseQuery(true);
var list = data.split('|^|');
for (var i=0; i 0){ // IE 9.x
width = parseInt(width)-4;
height = parseInt(height)-4;
} else if(navigator.userAgent.indexOf("Trident") > 0){ // IE 11.x
width = parseInt(width)-4;
height = parseInt(height)-4;
} else if(navigator.userAgent.indexOf("Firefox") > 0) {
width = parseInt(width)+2; // FF
}
// 팝업창 재표시 기간 레이어 영역 높이에 추가
height = parseInt(height) + 25;
var D = Durian.initCommon;
var block_name = D.popupCookieName + '_BLOCK_' + seq;
if (Util.getCookie(block_name)) {
return;
}
if(wType == '0') {
var winWidth = document.body.clientWidth;
var winX = window.screenX || window.screenLeft || 0;
}else {
var winWidth = jQuery(window).width();
var winX = jQuery(window).scrollLeft();
}
var winHeight = jQuery(window).height();
var winY = jQuery(window).scrollTop();
if(pType == '0') { // 사용자 지정 위치
if(wType == '0') {
left = (winX - winWidth) + left;
}else {
left = winX + left;
}
}else if(pType == '1') { //상단 좌측 정렬
left = '';
top = '0';
}else if(pType == '2') { //상단 중앙 정렬
left = winX + ((winWidth - width) / 2);
top = '0';
}else if(pType == '3') { //상단 우측 정렬
left = winX + (winWidth - width - 2);
top = '0';
}else if(pType == '4') { //가운데 정렬
left = winX + ((winWidth - width) / 2);
top = winY + ((winHeight - height) / 2);
}
var url = '?act=common.event_popup_view&seq=' + seq;
if (wType == '0') {
var scroll = (scroll == '0' ? 'no' : 'yes');
var win = window.open(url, 'event_' + seq, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + top + ', scrollbars=' + scroll);
if (win) {
win.focus();
}
} else if(wType == '3') { // mobile
var D = Durian.initCommon;
jQuery.ajax({
url : '/m/',
type : 'POST',
dataType : 'JSON',
data : {
act : 'common.event_popup_layer',
seq : seq
},
success : function(data) {
if (data.content) {
var id = 'layer_event_'+seq;
var div = jQuery('#' + id);
if (!div.length) {
div = jQuery('')
.html(data.content);
div.css({
'border' : '#787878 solid 1px',
'margin' : '10px',
'background' : 'white',
'font-size' : '12pt',
'left' : '0',
'top' : '0'
});
jQuery('body').append(div);
}
Durian.showLayer(div, {
block : true
});
}
}
});
} else {
var scroll = (scroll == '0' ? 'hidden' : 'scroll');
var layer_index = 1000 + parseInt(seq, 10);
var div = document.createElement('div');
var D = Durian.initCommon;
jQuery(div).attr('id', 'layer_event_' + seq);
jQuery(div).css({
'position' : 'absolute',
'width' : width ,
'height' : height,
'margin' : 0,
'left' : left + 'px',
'top' : top + 'px',
'border' : '1px solid #CCCCCC',
'backgroundColor' : '#FFFFFF',
'z-index' : layer_index,
'overflow-x' : 'hidden',
'overflow-y' : scroll
});
document.body.appendChild(div);
if (wType == '1') {
jQuery(div).draggable();
}
D.getPopupContentAjax(seq);
}
},
getPopupContentAjax : function(seq) {
var D = Durian.initCommon;
jQuery.ajax({
url : D.isSeller ? '/seller/' : '/',
type : 'POST',
dataType : 'JSON',
data : {
act : 'common.event_popup_layer',
seq : seq
},
success : function(data) {
if (data.content) {
var popup_div = jQuery('#layer_event_' + data.seq);
jQuery(popup_div).html(data.content);
}
}
});
},
closePopupLayer : function(seq, block_time) {
var div = jQuery('#layer_event_' + seq);
var block = jQuery('#chk_block_' + seq + ':checked');
if (block.length) {
var D = Durian.initCommon;
var block_name = D.popupCookieName + '_BLOCK_' + seq;
Util.setCookie(block_name, 1, block_time, '/');
}
jQuery('#__block_page__').hide();
if (div) {
div.remove();
} else {
self.close();
}
},
closePopup : function(seq) {
jQuery('#layer_event_' + seq).remove();
},
onPopupLayerMove : function(evt) {
jQuery('#' + this.object.id + '_iframe').css('visibility', 'hidden');
},
onPopupLayerEnd : function(evt) {
jQuery('#' + this.object.id + '_iframe').css('visibility', 'visible');
},
checkQueryMatch : function(base, part) {
var flag = true;
for (var key in part) {
if (typeof base[key] == 'undefined' || base[key] != part[key]) {
flag = false;
break;
}
}
return flag;
},
getPopupListAjax : function() {
var D = Durian.initCommon;
if(D.isMobile == true){
var popup_mobile = 1;
} else {
var popup_mobile = 0;
}
jQuery.ajax({
url : D.isSeller ? '/seller/' : '/',
type : 'POST',
dataType : 'TEXT',
data : {
act : 'common.event_popup_ajax',
mobile : popup_mobile
},
success : function(data) {
var D = Durian.initCommon;
if (data) {
D.applyPopup(data);
Util.setCookie(D.popupCookieName, data, 0, '/');
} else {
Util.setCookie(D.popupCookieName, -1, 0, '/');
}
}
});
},
getPopupListAjaxCallback : function(r) {
if (typeof r != 'undefined') {
var D = Durian.initCommon;
if (r) {
D.applyPopup(r);
Util.setCookie(D.popupCookieName, r, 0, '/');
} else {
Util.setCookie(D.popupCookieName, -1, 0, '/');
}
}
},
// tooltip
initTooltip : function(){
var hover = function(){
var position = "RIGHT";
if (jQuery(this).hasClass('TOP')){
position = "TOP";
}else if (jQuery(this).hasClass('BOTTOM')){
position = "BOTTOM";
}else if (jQuery(this).hasClass('LEFT')){
position = "LEFT";
}
Durian.showTooltip(this, position);
return false;
}
var out = function(){
Durian.hideTooltip();
return false;
}
jQuery('.tooltip')
.mouseenter(hover).click(hover).on("focus", hover)
.mouseleave(out).on("blur", out)
;
},
initInputBox : function(obj) {
jQuery('input[type=text], input[type=password]', obj)
.focus(function() {
jQuery(this).addClass('on');
})
.blur(function() {
jQuery(this).removeClass('on');
});
jQuery("input.number_only").css("ime-mode", "disabled");
jQuery("input.price_only").css("ime-mode", "disabled");
jQuery("input.ip_only").css("ime-mode", "disabled");
jQuery(document)
// 숫자 입력폼 이벤트 매칭
.on('keypress', "input.number_only", function(event){
var allowed_minus_sign = jQuery(this).hasClass('allow-minus-sign');
if (!(event.charCode>0||event.keyCode>0||event.which>0)){
if (window.event && (window.event.charCode>0||window.event.keyCode>0||window.event.which>0)) event = window.event;
}
var key = event.charCode>0 ? event.charCode : ( event.keyCode>0 ? event.keyCode : event.which);
if (event.charCode==0 && event.keyCode==46 && event.which==0){// FF에서 DELETE눌렀을때
return true;
}
if (key == 8/*backspcae*/ || key == 9/*tab*/
|| key == 35/*end*/ || key == 36/*home*/
|| key == 37/*<-*/ || key == 39/*->*/
|| (allowed_minus_sign && key == 45/*-*/)) {
return true;
}else if ( key < 48 || key > 57 ) {
return false;
}else return true;
})
.on('blur', "input.number_only", function(e) {
jQuery(this).val(jQuery(this).val().replace(/[^0-9]/g, ''));
})
.on('blur', "input.ip_only", function(e) {
jQuery(this).val(jQuery(this).val().replace(/[^0-9.;]/g, ''));
})
// 금액 입력폼 이벤트 매칭
.on('keypress', "input.price_only", function(event){
var allowed_minus_sign = jQuery(this).hasClass('allow-minus-sign');
if (!(event.charCode>0||event.keyCode>0||event.which>0)){
if (window.event && (window.event.charCode>0||window.event.keyCode>0||window.event.which>0)) event = window.event;
}
var key = event.charCode>0 ? event.charCode : ( event.keyCode>0 ? event.keyCode : event.which);
var dot_key = 46;
if (event.charCode==0 && event.keyCode==46 && event.which==0){// FF에서 DELETE눌렀을때
return true;
}
// 페이지내에 shopp_decimal_currency변수 선언된것이 있다면 활용한다!
if (typeof window.shopp_decimal_currency != 'undefined'){
if (window.shopp_decimal_currency=='0' || window.shopp_decimal_currency==0){
dot_key = 8; /* hack */
}
}
if (key == 8/*backspcae*/ || key == 9/*tab*/ || key == dot_key/*dot(.)*/
|| key == 35/*end*/ || key == 36/*home*/
|| key == 37/*<-*/ || key == 39/*->*/
|| (allowed_minus_sign && key == 45/*-*/)) {
return true;
}else if ( key < 48 || key > 57 ) {
return false;
}else return true;
})
.on('blur', "input.price_only", function(e) {
if (jQuery(this).val().trim()!=''){
var allowed_minus_sign = jQuery(this).hasClass('allow-minus-sign');
var pure_val = jQuery(this).val().trim();
var new_val = 0;
var ptn = /[^0-9\.]/g;
if (allowed_minus_sign){
ptn = /[^\-0-9\.]/g;
}
// 페이지내에 shopp_decimal_currency변수 선언된것이 있다면 활용한다!
if (typeof window.shopp_decimal_currency != 'undefined'){
window.shopp_decimal_currency = parseInt(window.shopp_decimal_currency, 10) || 0;
if (window.shopp_decimal_currency==0){
new_val = parseInt(jQuery(this).val().replace(ptn, ''), 10);
}else{
new_val = parseFloat(jQuery(this).val().replace(ptn, ''));
if (!isNaN(new_val)){
new_val = new_val.round(window.shopp_decimal_currency);
}
}
}else{
new_val = parseFloat(jQuery(this).val().replace(ptn, ''));
if (!isNaN(new_val)){
new_val = new_val.round(2/*default*/);
}
}
// 정수 변환이 불가능한 경우는 0으로 처리
if(isNaN(new_val) == true) {
new_val = 0;
}
if (new_val != pure_val){
alert("입력한 금액을 변경합니다.\n\n"+pure_val+" => "+new_val);
}
jQuery(this).val( new_val );
}
})
},
// for scroll
scrollInit : false,
scrollList : [],
scrollSleep : 50,
scrollDelay : 50,
scrollNow : 0,
scrollTimer : null,
scrollPos : {},
initScroll : function(obj) {
var D = Durian.initCommon;
if (!D.scrollList.has(obj)) {
D.scrollList.push(obj);
obj.gap = parseInt(jQuery(obj).css('top'), 10) || 0;
}
if (!D.scrollInit) {
jQuery(window).scroll(D.onScroll);
}
},
onScroll : function(evt) {
var D = Durian.initCommon;
D.scrollNow = 0;
if (D.scrollTimer) {
clearTimeout(D.scrollTimer);
}
D.scrollTop = jQuery(window).scrollTop();
D.scrollTimer = setTimeout(D.scrollPlay, D.scrollSleep);
},
scrollPlay : function() {
var D = Durian.initCommon;
D.scrollNow++;
var flag = false;
for (var i=0; i 1) {
obj.style.top = (top + parseInt(gap/2, 10)) + 'px';
flag = true;
} else {
obj.style.top = (top + gap) + 'px';
}
}
if (flag) {
D.scrollTimer = setTimeout(D.scrollPlay, D.scrollDelay);
}
},
onPopViewBBS : function(evt) {
jQuery.eventStop(evt);
var obj = this;
var url = obj.href;
var match = url.match(/&bbs_code=([^&]+)/);
var bbs_code = (typeof match[1] != 'undefined') ? match[1] : 'bbs_dummy';
Durian.openWin(bbs_code, url, 700, 500, 'yes');
}
}
// for flash wizard
function flashInfo(id, w, h)
{
jQuery('#' + id + '[inited!="1"]').setSize(w, h).attr('inited', 1);
jQuery('#' + id + '_box').setSize(w, h);
if (jQuery.browser.msie) {
jQuery('#' + id).setSize(w, h);
} else {
jQuery('#' + id + '_embed').setSize(w, h);
}
}
// return checkbox_value to text
// id : table/form obj
// mode : true/false
// name : checkbox name
function getCheckAll(obj, mode, name) {
var obj = $id(obj);
var input = obj.getElementsByTagName('input');
var temp = new Array();
if (mode == true) {
if (name != '' && typeof name != 'undefined' ) {
for (i = 0; i < input.length; i++) {
if ((input[i].type == 'checkbox' && input[i].value != '') && (input[i].name == name && input[i].checked == true)) {
temp.push(input[i].value);
}
}
} else {
for (i = 0; i < input.length; i++) {
if ((input[i].type == 'checkbox' && input[i].value != '') && input[i].checked == true) {
temp.push(input[i].value);
}
}
}
} else {
if (name != '' && typeof name != 'undefined' ) {
for (i = 0; i < input.length; i++) {
if ((input[i].type == 'checkbox' && input[i].value != '') && input[i].name == name) {
temp.push(input[i].value);
}
}
} else {
for (i = 0; i < input.length; i++) {
if (input[i].type == 'checkbox' && input[i].value != '') {
temp.push(input[i].value);
}
}
}
}
return temp.join(',');
}
// 상품 바로구매 및 장바구니 담기
function popupGoodTmp(good_seq, type, multi_seq, cate_code) {
var param = '';
if (multi_seq != '') {
param = '&multi_seq=' + multi_seq;
} else {
param = '&good_seq=' + good_seq;
}
if ( cate_code!='' && cate_code!='undefined' && cate_code!=undefined ) {
param += '&cate_code='+cate_code;
}
Durian.openWin('popup_goods_tmp', '?act=shop.popup_goods_tmp&mode=' + type + param, 400, 600, 'yes');
}
// console.log지원하지 않는 브라우져용
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
console.log = function(msg) {
/* 지원하지 않음 alert(msg); */
};
}
//소수점 특정 자릿수 이하 버림
function toDecimal(x, digit) {
var value = x.toString();
if (value.indexOf('.') < 0) {
} else {
value = value.substr(0, value.indexOf('.') + (digit + 1));
}
return value;
}
//소수점 계산 hjpark - 2013-10-17
function decimalMath(x, y, op, digit)
{
if(!isNaN(x) || !isNaN(y))
{
var xValue, yValue, base, xResult, yResult, result;
if(digit > 0) {
xValue = x * 100;
yValue = y * 100;
base = Math.pow(10, digit);
xValue = Math.round(xValue * base) / base;
yValue = Math.round(yValue * base) / base;
}else{
xValue = x;
yValue = y;
}
xResult = Math.floor(xValue);
yResult = Math.floor(yValue);
switch(op) {
case 'plus' : result = xResult + yResult; break;
case 'minus' : result = xResult - yResult; break;
case 'multiply' : result = xResult * yResult; break;
case 'divide' : result = xResult / yResult; break;
default : result = xResult + yResult;
}
result = result / 100;
}else{
result = null;
}
return result;
}
// 쿠폰 다운로드
function goCouponDown(seq)
{
jQuery.ajax({
url : './',
type : 'POST',
dataType : 'JSON',
data : {
act : 'shop.coupon_down_ajax',
coupon_seq : seq,
dummy : Util.random(1, 10000)
},
success : goCouponDownCallback
});
}
function goCouponDownCallback(r)
{
if (typeof r != 'undefined') {
alert(r.msg);
document.location.reload();
}
}
// Mobile Share
function onMobileShareClick(evt) {
var obj = this;
//*
var id = obj.id;
var sns_share_uri = '', site_uri = '', param = '', good_seq = '{good_seq}';
if (good_seq) {
site_uri = '?act=shop.goods_view%26GS=' + good_seq;
}
switch (id) {
case 'sns_share_facebook':
sns_share_uri = 'www.facebook.com/sharer.php/';
param = 'u=' + "{=mall_getShopMainUrl()}" + site_uri + '&t=' + "{mobile_policy.mobilep_title}";
param = encodeURI(param);
window.open('http://' + sns_share_uri + '?' + param, 'sns_pop', 'menubar=no');
break;
case 'sns_share_twitter':
sns_share_uri = 'twitter.com/';
param = 'status=' + "{=mall_getShopMainUrl()}" + site_uri + " {mobile_policy.mobilep_title}";
param = encodeURI(param);
window.open('http://' + sns_share_uri + '?' + param, 'sns_pop', 'menubar=no');
break;
case 'sns_share_kakaostory':
var sns_url = obj.getAttribute('sns_url');
var sns_img = obj.getAttribute('sns_img');
var sns_appid = obj.getAttribute('sns_appid');
var sns_appname = obj.getAttribute('sns_appname');
var sns_title = obj.getAttribute('sns_title');
var sns_msg = obj.getAttribute('sns_msg');
executeKakaoStoryLink(sns_url, sns_img, sns_appid, sns_appname, sns_title, sns_msg)
break;
}
}
function executeKakaoStoryLink(sns_url, sns_img, sns_appid, sns_appname, sns_title, sns_msg)
{
kakao.link("story").send({
post : sns_url,
appid : sns_appid,
appver : "1.0",
appname : sns_appname,
urlinfo : JSON.stringify({title:sns_title, desc:sns_msg, imageurl:[sns_img], type:"article"})
});
}
jQuery(document).ready(Durian.initCommon.init);