$(function () {
// tabletのviewport変更処理
var getDevice = (function () {
var ua = navigator.userAgent;
if (ua.indexOf('iPhone') > 0 || ua.indexOf('iPod') > 0 || ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) {
return 'sp';
} else if (ua.indexOf('iPad') > 0 || ua.indexOf('Android') > 0) {
//return 'tab';
return 'other';
} else {
return 'other';
}
})();
if (getDevice != "tab") {
$("body").addClass("hover_on");
} else {
$("meta[name='viewport']").attr({ "content": "width=1100px" });
}
// SPメニューの開閉
// class_1
if ($(".st-notification_inner").length) {
$(".g_nav .inner ul.class_1").css({ "height": $(window).height() - 85 - $(".st-notification_inner p").height() }); // header + gnavitop + info height
} else {
$(".g_nav .inner ul.class_1").css({ "height": $(window).height() - 85 }); // header + gnavitop
}
$(".g_nav a.js_class_0_btn").on("click", function () {
if ($(this).parent().hasClass("class_1_open")) {
//$("body").removeClass("g_nav_open");
$(this).parent().removeClass("class_1_open");
$(this).next(".class_1").stop().slideUp(300);
} else {
//$("body").addClass("g_nav_open");
$(this).parent().addClass("class_1_open");
$(this).next(".class_1").stop().slideDown(300);
}
});
// class_2
$(".g_nav a.js_class_1_btn").on("click", function () {
if ($(this).parent().hasClass("class_2_open")) {
$(this).parent().removeClass("class_2_open");
$(this).next(".class_2").stop().slideUp(300);
} else {
$(this).parent().addClass("class_2_open");
$(this).next(".class_2").stop().slideDown(300);
}
});
// サイトマップの開閉
$(".bsitemap_parent_ttl a").on("click", function () {
if ($(window).width() < 1052) {
if ($(this).parent().next(".bsitemap_child").length > 0) {
if ($(this).parents(".bsitemap_parent").hasClass("is_open")) {
$(this).parents(".bsitemap_parent").removeClass("is_open");
$(this).parent().next(".bsitemap_child").stop().slideUp(300);
} else {
$(this).parents(".bsitemap_parent").addClass("is_open");
$(this).parent().next(".bsitemap_child").stop().slideDown(300);
}
return false;
}
}
});
// フローティングバナー
$(window).on("load scroll resize", function () {
//if ($(".wrap .float_area").is(':hidden')) { return; }
floating_bnr();
});
function floating_bnr() {
var top_offset = $(".wrap").offset().top;
var c_height = $(".wrap").innerHeight();
var floating_height = $(".wrap .float_area").innerHeight();
var floating_margin_top = parseInt($(".wrap .float_area").css("margin-top"));
// for Biz Page
var left_nav_h = $(".biz_wrap .left_nav_info").height();
if ($(".wrap .float_area").is(":hidden")) {
$(".wrap").css({
"min-height": 0
});
} else {
$(".wrap").css({
"min-height": floating_height
});
}
if ($(window).height() <= floating_height) {
$(".wrap .float_area").css({
"position": "absolute",
top: 0,
left: 0
});
} else {
// スクロール量がそれ以下の時
if ($(window).scrollTop() - top_offset <= 0) {
$(".wrap .float_area").css({
"position": "absolute",
top: 0,
left: 0
});
// スクロール量がそれ以下の時
} else if ($(window).scrollTop() >= top_offset + c_height - floating_height - floating_margin_top) {
$(".wrap .float_area").css({
"position": "absolute",
top: c_height - floating_height - floating_margin_top,
left: 0
});
} else {
$(".wrap .float_area").css({
"position": "fixed",
top: 0
});
$(".wrap .float_area").css({
left: -$(window).scrollLeft()
});
// for Biz Page
//$(".biz_wrap .list_filter").css({
// 'height': $(window).height() - left_nav_h - 55,
// 'overflow-y': 'auto'
//})
}
}
}
// General tabs
$(".tab_wrap .tab_list > li").on("click", function () {
if ($(this).hasClass("current")) {
return;
} else {
// タブ内表示コンテンツの初期化
$("[data-printer_type], [data-process_type]").hide();
$("[data-printer_btn], [data-process_btn]").removeClass("active");
$("[data-printer_type=-1]").show();
$(".map_list > li").hide();
$(".map_list > li.no_result").show();
var num = $(".tab_list > li").index(this);
// $(".tab_list > li").removeClass("current");
// $(".tab_list > li").eq(num).addClass("current");
$(this).closest(".tab_wrap").find(".tab_list >li").removeClass("current");
$(this).closest(".tab_wrap").find(".tab_list >li").eq(num).addClass("current");
$(this).closest(".tab_wrap").find(".tab_content >.tab_panel").removeClass("current");
$(this).closest(".tab_wrap").find(".tab_content >.tab_panel").eq(num).addClass("current");
$('.list_tab_status .item_inner .item.has_i').removeClass('active');
$('.list_tab_status .item_inner .item.not_i').removeClass('active');
}
});
// Modal js
var settings = {
//Model Popup
objModalPopupBtn: ".s_modalButton",
objModalCloseBtn: ".overlay, .btn_basic_gray",
objModalDataAttr: "data-popup"
}
$(settings.objModalPopupBtn).bind("click", function () {
if ($(this).attr(settings.objModalDataAttr)) {
var strDataPopupName = $(this).attr(settings.objModalDataAttr);
$('body').addClass("has_modal");
//Fade In Modal Pop Up
$(".overlay, #" + strDataPopupName).fadeIn(170);
}
});
$('.s_modal').click(function () {
$(".s_modal").fadeOut(90);
$('body').removeClass("has_modal");
});
$('.modal_dialog').click(function (e) {
e.stopPropagation();
});
//On clicking the modal background
$(settings.objModalCloseBtn).bind("click", function () {
$('body').removeClass("has_modal");
$(".s_modal").fadeOut(90);
});
// Click active button
$('.sc_tab .name_check').on('click', function () {
$(this).parent('.item.has_i[data-radio]').toggleClass('active');
})
$('.sc_tab .item.not_i').on('click', function () {
$(this).toggleClass('active');
})
//checkedだったら最初からチェックする
$('.list_tab_status .checkbox_label input[type=checkbox]').each(function () {
if ($(this).prop('checked') == true) {
$(this).parents('.checkbox_wrap').addClass('is_checked');
}
});
//クリックした要素にクラス割り当てる
$('.list_tab_status .checkbox_label input[type=checkbox]').click(function () {
if ($(this).parents('.checkbox_wrap').hasClass('is_checked')) {
$(this).parents('.checkbox_wrap').removeClass('is_checked').find('input').removeProp('checked');
$(this).parents('.item.has_i').removeClass('active');
} else {
$(this).parents('.checkbox_wrap').addClass('is_checked').find('input').prop('checked', true);
$(this).parents('.item.has_i').addClass('active');
}
});
// Accordion
var $element_tog = $('.title_st'),
$element_isTog = $('.collapse_body');
$element_tog.click(function (e) {
var $this = $(this);
$this.toggleClass('active')
$("div[id=" + $this.attr("data-id") + "]").toggleClass("open");
});
// redirect link sp
// change bg sp
var viewport = $(window).width();
if (viewport < 768) {
$('.btnimg_list .btnimg_listitem.style_01').on("click", function () {
var link = $(this).children('a').attr('href');
window.location.href = link;
})
$('.change_bg_sp').each(function () {
var data = $(this).attr('data-imgmb');
// alert(data);
$(this).attr('style', 'background-image:url("' + data + '")');
})
}
// set equal height for sc_block_item style_07
list_style_07();
$(window).on("load resize", function () { list_style_07(); });
function list_style_07() {
if ($('.list_style_07 ').length) {
$('.list_style_07').each(function () {
var $cmbodyTop = $(this).find('.sc_block_item.style_07 .block_info'),
cmheightArray = new Array(),
cmmaxHeight = 0;
$($cmbodyTop).css('min-height', 0);
for (var i = $cmbodyTop.length - 1; i >= 0; i--) {
cmheightArray.push($cmbodyTop[i].clientHeight);
}
cmmaxHeight = cmheightArray.reduce(function (a, b) {
return Math.max(a, b);
});
for (var i = $cmbodyTop.length - 1; i >= 0; i--) {
$($cmbodyTop[i]).css('min-height', cmmaxHeight);
}
});
}
}
// 印刷ボタン
var img_src = '/-/media/cojp/product/biz-navi/img/download';
var print_btn = '';
print_btn += '
';
$("body").append(print_btn);
set_print_btn_v();
$(window).on("load scroll", function () { set_print_btn_v(); });
function set_print_btn_v() {
var correction_height = $("header").innerHeight() + $(".g_nav").innerHeight();
var correction_top = $(window).scrollTop();
if ($(window).scrollTop() >= correction_height) {
var correction_top = correction_height;
}
$(".print_btn_wrap").css({ "margin-top": -(correction_top) });
}
});
// ビジネスNAVI内 グローバルメニュー
$(function () {
var $menu = $("#megamenu");
$menu.menuAim({
activate: activateSubmenu,
deactivate: deactivateSubmenu
});
function activateSubmenu(row) {
var $row = $(row),
submenuId = $row.data("submenuId"),
$submenu = $("#" + submenuId),
height = $menu.outerHeight(),
width = $menu.outerWidth();
// Show the submenu
$submenu.css({
display: "block",
top: -1,
left: width - 3, // main should overlay submenu
height: height - 4 // padding for main dropdown's arrow
});
$row.find("a").addClass("maintainHover");
}
function deactivateSubmenu(row) {
var $row = $(row),
submenuId = $row.data("submenuId"),
$submenu = $("#" + submenuId);
// Hide the submenu and remove the row's highlighted look
$submenu.css("display", "none");
$row.find("a").removeClass("maintainHover");
}
// ボックス内をクリックした際ボックスを非表示にしない
$('#g_subnav').on('click',function(event){
event.stopPropagation();
});
//メガメニュー
var $kids = $('#g_subnav').children();
//$('html').click(function() {
$(document).on('click','html', function(event) {
if (!$.contains($($kids)[0], event.target)){
// $(".popover").css("display", "none");
$("a.maintainHover").removeClass("maintainHover");
$('#nav-sub').slideUp();
$('.dropdown-toggle').removeClass('active');
}
});
$(".dropdown-toggle").click(function(){
var menu = $('#nav-sub');
$('.dropdown-toggle').addClass('active');//ボタンのオンオフのマーク付与
if (menu.is(':hidden')){
menu.slideUp();
menu.slideDown();
}else{
$('.dropdown-toggle').removeClass('active');
menu.slideUp();
}
});
});
(function($) {
$.fn.menuAim = function(opts) {
// Initialize menu-aim for all elements in jQuery collection
this.each(function() {
init.call(this, opts);
});
return this;
};
function init(opts) {
var $menu = $(this),
activeRow = null,
mouseLocs = [],
lastDelayLoc = null,
timeoutId = null,
options = $.extend({
rowSelector: "> li",
submenuSelector: "*",
submenuDirection: "right",
tolerance: 75, // bigger = more forgivey when entering submenu
enter: $.noop,
exit: $.noop,
activate: $.noop,
deactivate: $.noop,
exitMenu: $.noop
}, opts);
var MOUSE_LOCS_TRACKED = 3, // number of past mouse locations to track
DELAY = 300; // ms delay when user appears to be entering submenu
/**
* Keep track of the last few locations of the mouse.
*/
var mousemoveDocument = function(e) {
mouseLocs.push({x: e.pageX, y: e.pageY});
if (mouseLocs.length > MOUSE_LOCS_TRACKED) {
mouseLocs.shift();
}
};
/**
* Cancel possible row activations when leaving the menu entirely
*/
var mouseleaveMenu = function() {
if (timeoutId) {
clearTimeout(timeoutId);
}
// If exitMenu is supplied and returns true, deactivate the
// currently active row on menu exit.
if (options.exitMenu(this)) {
if (activeRow) {
options.deactivate(activeRow);
}
activeRow = null;
}
};
/**
* Trigger a possible row activation whenever entering a new row.
*/
var mouseenterRow = function() {
if (timeoutId) {
// Cancel any previous activation delays
clearTimeout(timeoutId);
}
options.enter(this);
possiblyActivate(this);
},
mouseleaveRow = function() {
options.exit(this);
};
/*
* Immediately activate a row if the user clicks on it.
*/
var clickRow = function() {
activate(this);
};
/**
* Activate a menu row.
*/
var activate = function(row) {
if (row == activeRow) {
return;
}
if (activeRow) {
options.deactivate(activeRow);
}
options.activate(row);
activeRow = row;
};
/**
* Possibly activate a menu row. If mouse movement indicates that we
* shouldn't activate yet because user may be trying to enter
* a submenu's content, then delay and check again later.
*/
var possiblyActivate = function(row) {
var delay = activationDelay();
if (delay) {
timeoutId = setTimeout(function() {
possiblyActivate(row);
}, delay);
} else {
activate(row);
}
};
/**
* Return the amount of time that should be used as a delay before the
* currently hovered row is activated.
*
* Returns 0 if the activation should happen immediately. Otherwise,
* returns the number of milliseconds that should be delayed before
* checking again to see if the row should be activated.
*/
var activationDelay = function() {
if (!activeRow || !$(activeRow).is(options.submenuSelector)) {
// If there is no other submenu row already active, then
// go ahead and activate immediately.
return 0;
}
var offset = $menu.offset(),
upperLeft = {
x: offset.left,
y: offset.top - options.tolerance
},
upperRight = {
x: offset.left + $menu.outerWidth(),
y: upperLeft.y
},
lowerLeft = {
x: offset.left,
y: offset.top + $menu.outerHeight() + options.tolerance
},
lowerRight = {
x: offset.left + $menu.outerWidth(),
y: lowerLeft.y
},
loc = mouseLocs[mouseLocs.length - 1],
prevLoc = mouseLocs[0];
if (!loc) {
return 0;
}
if (!prevLoc) {
prevLoc = loc;
}
if (prevLoc.x < offset.left || prevLoc.x > lowerRight.x ||
prevLoc.y < offset.top || prevLoc.y > lowerRight.y) {
// If the previous mouse location was outside of the entire
// menu's bounds, immediately activate.
return 0;
}
if (lastDelayLoc &&
loc.x == lastDelayLoc.x && loc.y == lastDelayLoc.y) {
// If the mouse hasn't moved since the last time we checked
// for activation status, immediately activate.
return 0;
}
// Detect if the user is moving towards the currently activated
// submenu.
//
// If the mouse is heading relatively clearly towards
// the submenu's content, we should wait and give the user more
// time before activating a new row. If the mouse is heading
// elsewhere, we can immediately activate a new row.
//
// We detect this by calculating the slope formed between the
// current mouse location and the upper/lower right points of
// the menu. We do the same for the previous mouse location.
// If the current mouse location's slopes are
// increasing/decreasing appropriately compared to the
// previous's, we know the user is moving toward the submenu.
//
// Note that since the y-axis increases as the cursor moves
// down the screen, we are looking for the slope between the
// cursor and the upper right corner to decrease over time, not
// increase (somewhat counterintuitively).
function slope(a, b) {
return (b.y - a.y) / (b.x - a.x);
};
var decreasingCorner = upperRight,
increasingCorner = lowerRight;
// Our expectations for decreasing or increasing slope values
// depends on which direction the submenu opens relative to the
// main menu. By default, if the menu opens on the right, we
// expect the slope between the cursor and the upper right
// corner to decrease over time, as explained above. If the
// submenu opens in a different direction, we change our slope
// expectations.
if (options.submenuDirection == "left") {
decreasingCorner = lowerLeft;
increasingCorner = upperLeft;
} else if (options.submenuDirection == "below") {
decreasingCorner = lowerRight;
increasingCorner = lowerLeft;
} else if (options.submenuDirection == "above") {
decreasingCorner = upperLeft;
increasingCorner = upperRight;
}
var decreasingSlope = slope(loc, decreasingCorner),
increasingSlope = slope(loc, increasingCorner),
prevDecreasingSlope = slope(prevLoc, decreasingCorner),
prevIncreasingSlope = slope(prevLoc, increasingCorner);
if (decreasingSlope < prevDecreasingSlope &&
increasingSlope > prevIncreasingSlope) {
// Mouse is moving from previous location towards the
// currently activated submenu. Delay before activating a
// new menu row, because user may be moving into submenu.
lastDelayLoc = loc;
return DELAY;
}
lastDelayLoc = null;
return 0;
};
/**
* Hook up initial menu events
*/
$menu
.mouseleave(mouseleaveMenu)
.find(options.rowSelector)
.mouseenter(mouseenterRow)
.mouseleave(mouseleaveRow)
.click(clickRow);
$(document).mousemove(mousemoveDocument);
};
})(jQuery);