/* NHN (developers@xpressengine.com) */
jQuery(function($){
// iSO mobile device toolbar remove
window.scrollTo(0,0);
// Skip to content
$('.x .skipNav>a').click(function(){
$($(this).attr('href')).attr('tabindex','0').css('outline','0').focus();
});
// TARGET toggle
$(document.body).on('click', '.x [data-toggle]', function(){
var $this = $(this);
var $target = $($this.attr('data-toggle'));
var focusable = 'a,input,button,textarea,select';
$target.toggle();
if($target.is(':visible') && !$target.find(focusable).length){
$target.attr('tabindex','0').not(':disabled').focus();
} else if($target.is(':visible') && $target.find(focusable).length) {
$target.find(focusable).not(':disabled').eq(0).focus();
} else {
$this.focus();
}
return false;
});
// TARGET show
$(document.body).on('click', '.x [data-show]', function(){
$($(this).attr('data-show')).show().attr('tabindex','0').focus();
return false;
});
// TARGET hide
$(document.body).on('click', '.x [data-hide]', function(){
var $this = $(this);
$($this.attr('data-hide')).hide();
$this.focus();
return false;
});
// Tab Navigation
$.fn.xeTabbable = function(){
$(this).each(function(){
var $this = $(this);
$this.find('>.x_nav-tabs>li>a').each(function(index){
$(this).attr('data-index', index+1);
});
$this.find('>.x_tab-content>.x_tab-pane').each(function(index){
$(this).attr('data-index', index+1);
});
});
$('.x .x_tab-content>.x_tab-pane:not(".x_active")').hide();
}
$('.x .x_tabbable').xeTabbable();
$(document.body).on('click', '.x .x_nav-tabs>li>a[href*="#"]', function(){
var $this = $(this);
$this.parent('li').addClass('x_active').siblings().removeClass('x_active');
$this.closest('.x_nav-tabs').next('.x_tab-content').find('>.x_tab-pane').eq($this.attr('data-index')-1).addClass('x_active').show().siblings().removeClass('x_active').hide();
return false;
});
// GNB
var $xBody = $('.x>.body');
var $xContent = $xBody.children('#content.content');
var $xGnb = $xBody.find('>.gnb');
var $xGnb_li = $xGnb.find('>ul>li');
// Add icon
$xGnb_li.find('a').prepend('');
// Active Submenu Copy
$xGnb_li.find('>ul>li.active_').clone().addClass('active').prependTo('#gnbNav');
// GNB Hover toggle
function reflow(){ // Browser bug fix & resize height
$xContent.width('99.99%');
setTimeout(function(){
$xContent.removeAttr('style');
if($xGnb.height() > $xContent.height()){
$xContent.height($xGnb.height());
}
}, 100);
}
// GNB Click toggle
$xGnb_li.find('ul').prev('a')
.bind('click focus', function(){
var $this = $(this);
$this.parent('li').addClass('open').siblings('li').removeClass('open');
$xBody.removeClass('wide');
reflow();
return false;
});
// GNB Mobile Toggle
$xGnb.find('>a[href="#gnbNav"]').click(function(){
$(this).parent('.gnb').toggleClass('open');
$xBody.toggleClass('wide');
reflow();
return false;
});
// GNB Close
$xGnb
.prepend('')
.append('');
$xGnb.find('>.close').focus(function(){
$xBody.addClass('wide');
reflow();
});
// Check All
$('.x th>input[type="checkbox"]')
.change(function() {
var $this = $(this), name = $this.data('name');
$this.closest('table')
.find('input:checkbox')
.filter(function(){
var $this = $(this);
return !$this.prop('disabled') && (($this.attr('name') == name) || ($this.data('name') == name));
})
.prop('checked', $this.prop('checked'))
.end()
.end()
.trigger('update.checkbox', [name, this.checked]);
});
// Pagination
$(document.body).on('click', '.x .x_pagination .x_disabled, .x .x_pagination .x_active', function(){
return false;
});
// Section Toggle
var $section_heading = $('.x .section').find('>h1:first');
$section_heading.append('');
$section_heading.find('>.snToggle').click(function(){
var $this = $(this);
var $section = $this.closest('.section');
if(!$section.hasClass('collapse')){
$section.addClass('collapse').children('h1:first').siblings().hide();
$this.removeClass('x_icon-chevron-up').addClass('x_icon-chevron-down');
} else {
$section.removeClass('collapse').children('h1:first').siblings().show();
$this.removeClass('x_icon-chevron-down').addClass('x_icon-chevron-up');
}
reflow();
});
// Alert Closer
var $xAlert = $('.x .x_alert');
$xAlert.prepend('');
$xAlert.children('.x_close').click(function(){
$(this).parent('.x_alert').hide();
});
// Desabled Buttons
$('.x .x_btn').click(function(){
if($(this).hasClass('x_disabled')){
return false;
}
});
// Vertical Divider
$('.x i').each(function(){
var $this = $(this);
if($this.text() == '|'){
$this.addClass('vr').filter(':first-child, :last-child').remove();
}
});
// label[for] + input[id]/textarea[id]/select[id] creator
$('label:not([for])').each(function(index){
index = index + 1;
var $this = $(this);
var input = 'input, textarea, select';
var check = ':radio, :checkbox';
var id = '[id]';
var value = 'i' + index;
if($this.next(input).filter(id).not(check).length){
// next input, textarea, select id true
$this.attr('for', $this.next().attr('id'));
} else if ($this.next(input).not(id).not(check).length) {
// next input, textarea, select id false
$this.attr('for', value).next().attr('id', value);
} else if ($this.prev(check).filter(id).length) {
// prev :radio :checkbox id true
$this.attr('for', $this.prev().attr('id'));
} else if ($this.prev(check).not(id).length) {
// prev :radio :checkbox id false
$this.attr('for', value).prev().attr('id', value);
} else if ($this.children(input).filter(id).length) {
// children id true
$this.attr('for', $this.children(input).filter(id).eq(0).attr('id'));
} else if ($this.children(input).not(id).length) {
// children id false
$this.attr('for', value).children(input).not(id).eq(0).attr('id', value);
}
});
// :radio, :checkbox checked class
$(':radio, :checkbox').change(function(){
var $this = $(this);
if($this.is(':checked')){
$this.parent('label').addClass('checked');
}
$(':radio, :checkbox').not(':checked').parent('label').removeClass('checked');
}).change();
// File input .overlap style
$('input[type="file"].overlap').each(function(){
var $this = $(this);
$this.wrap('').before('