// GENERAL SCRIPT
// LAST UPDATE: 07-11-2014
jQuery(document).ready(function ($) {
//COPYRIGHT YEAR
var d = new Date();
var x = $("#footeryear");
var y = d.getFullYear();
x.html(y);
/* 00000000000////////////////////////////////////////////// */
$(".main_menu li").hover(function () {
$(".testingalert").html();
});
/* ---------------------------------------------------------------------- */
/* MAIN MENU
/* ---------------------------------------------------------------------- */
/* SUB MENU ////////////////// */
$(".main_menu_sub").prepend('
');
/* FOR NO-TOUCH DEVICES */
if ($("html").hasClass("no-touch")) {
$(".main_menu_sub").parent("li").hover(function () {
var mmsub_width = $(this).find(".main_menu_sub").width();
var mmitem_width = $(this).width();
var mmsub_newP = (mmitem_width - mmsub_width) / 2;
$(".main_menu_sub").css("margin-left", mmsub_newP);
$(this).find(".main_menu_sub").slideToggle("fast");
}, function () {
$(".main_menu_sub").hide();
});
}
/* FOR TOUCH DEVICES */
else {
$(".main_menu_sub").parent("li").click(function () {
var mmsub_width = $(this).find(".main_menu_sub").width();
var mmitem_width = $(this).width();
var mmsub_newP = (mmitem_width - mmsub_width) / 2;
$(".main_menu_sub").css("margin-left", mmsub_newP);
$(this).find(".main_menu_sub").toggleClass("active").slideToggle("fast");
});
}
/* MOB MAIN MENU ////////////////// */
$("#nav_main_menu").append('
');
$("#mob_menu").click(function () {
$("#nav_main_menu").hide();
var mob_menu_close = $("#mob_menu").hasClass("close");
if(mob_menu_close){
$("#mob_menu").removeClass("close");
$(".screen .inner").addClass("out");
setTimeout(function () {
$(".screenW").removeClass("active")
}, 400);
setTimeout(function () {
$(".screen,.screenW").remove()
}, 1e3);
}else{
$(".screen .main_menu a").click(function (e) {
e.stopPropagation();
});
$(this).addClass("close");
$("body").append('');
if ($(window).height() < 440) {
$(".screen").css({
position: "absolute"
});
$("html, body").animate({
scrollTop: "0"
}, 100)
}
setTimeout(function () {
$(".screen .inner").addClass("active");
$(".screenW").addClass("active")
}, 100);
//$("#header ul.main_menu").first().clone().appendTo(".screen .inner");
$(".screen .inner").append("");
$(".screen .inner .main_menu:first-child").append("");
$("#header ul.main_menu").children("li").each(function (index1, element1) {
var _li_a_href = $(element1).find("a:first").attr("href");
var _li_a_text = $(element1).find("a:first").text();
var _li_a_id = $(element1).find("a:first").attr("id");
$(".screen .inner .main_menu").append('' + _li_a_text + '');
if ($(element1).find(".main_menu_sub").length > 0) {
// console.log(index1);
$(".screen .inner .main_menu li:eq("+index1+")").addClass("mob_menu_level_2_ul").append(" [+] ");
//level 2
$(element1).find(".main_menu_sub").children("li").each(function (index2, element2) {
var _li_a_href = $(element2).find("a:first").attr("href");
//console.log(_li_a_href);
var _li_a_text = $(element2).find("a:first").text();
var _li_a_id = $(element2).find("a:first").attr("id");
var _parent_li_a_id = $(element1).find("a:first").attr("id");
$(".screen .inner .main_menu").append('');
if ($(element2).find(".third_menu_container").length > 0) {
//level 3
$(".screen .inner .main_menu li:eq("+(index1+index2+1)+")").addClass("mob_menu_level_3_ul").append(" [+] ");
$(element2).find(".third_menu_container li").each(function (index3, element3) {
var _li_a_href = $(element3).find("a:first").attr("href");
//console.log(_li_a_href);
var _li_a_text = $(element3).find("a:first").text();
var _li_a_id = $(element3).find("a:first").attr("id");
var _parent_li_a_id = $(element2).find("a:first").attr("id");
$(".screen .inner .main_menu ").append('');
});
}
});
}
});
return false;
}
});
$(document).on("click", "#close_mobile_menu", function () {
$("#mob_menu").removeClass("close");
$(".screen .inner").addClass("out");
setTimeout(function () {
$(".screenW").removeClass("active")
}, 400);
setTimeout(function () {
$(".screen,.screenW").remove()
}, 1e3);
$("#nav_main_menu").show();
});
$(document).on("click", ".screen .inner .main_menu .mob_menu_level_2_ul span", function () {
// console.log("mob_menu_level_2");
var cate_id = $(this).parent("li").attr("id");
if($(this).closest("ul").find(".parent_"+cate_id).is(":visible")){
$(this).closest("ul").find(".parent_"+cate_id).attr("style", "display: none !important");
//level 3
if($(this).closest("ul").find(".parent_"+cate_id).hasClass("mob_menu_level_3_ul")){
//hide level 3
console.log(cate_id);
var level_3 = $(this).closest("ul").find(".parent_"+cate_id+".mob_menu_level_3_ul").attr("id");
console.log(level_3);
$(this).closest("ul").find(".parent_"+level_3).attr("style", "display: none !important");
}
}else{
$(this).closest("ul").find(".parent_"+cate_id).attr("style", "display: block !important");
}
});
$(document).on("click", ".screen .inner .main_menu .mob_menu_level_3_ul span", function () {
//console.log("mob_menu_level_3");
var cate_id = $(this).parent("li").attr("id");
if($(this).closest("ul").find(".parent_"+cate_id).is(":visible")){
$(this).closest("ul").find(".parent_"+cate_id).attr("style", "display: none !important");
}else{
$(this).closest("ul").find(".parent_"+cate_id).attr("style", "display: block !important");
}
});
/* ---------------------------------------------------------------------- */
/* TOP BAR DROPDOWN
/* ---------------------------------------------------------------------- */
$(".log_dropdown").before('');
/* login/out dropdown */
$(".log_toggle").click(function () {
$(this).find(".log_dropdown").slideToggle();
$(this).find(".log_ass_hlep").slideToggle();
/*$(".log_dropdown").slideToggle();
$(".log_ass_hlep").slideToggle();*/
$(".login_container").click(function (e) {
e.stopPropagation();
});
return false;
});
/* language dropdown */
$(".change_language").click(function () {
$(this).parent().find(".lang_dropdown").slideToggle();
return false;
});
function hideAll() {
$('.language_toggle .lang_dropdown').hide();
$('.log_toggle .log_dropdown').hide();
$('.log_toggle .log_ass_hlep').hide();
}
$(document).click(hideAll);
/* ---------------------------------------------------------------------- */
/* HOME SUB CAROUSEL BANNERS
/* ---------------------------------------------------------------------- */
$(".new_pdt_list .item").prepend('
');
/* ---------------------------------------------------------------------- */
/* PRODUCT GRID WALL OPTIONS
/* ---------------------------------------------------------------------- */
/* dropdown */
$(".option.sort").click(function () {
$(this).find(".option_list").slideToggle();
return false
});
/* product image hover effect (change image) */
$(".grid_item_box").each(function () {
var toggleImg = $(this).find(".grid_item_img a").attr("data-img");
var originalImg = $(this).find(".grid_item_img img").attr("src");
$(this).hover(function () {
$(this).find(".grid_item_img img").attr({src: toggleImg});
}, function () {
$(this).find(".grid_item_img img").attr({src: originalImg});
});
});
/* MOB Catgories functions */
//$('.left_nav_block .left_nav_header').append('CATEGORIES
');
$('.left_nav_block .left_nav_header').click(function () {
$(this).parent('.left_nav_block').toggleClass('on');
});
/* product label =================== */
/*en*/
$("html:lang(en) .grid_item_box.flag.new").append('
');
$("html:lang(en) .grid_item_box.flag.hot").append('
');
$("html:lang(en) .grid_item_box.flag.sale").append('
');
/*tc*/
$("html:lang(tc) .grid_item_box.flag.new").append('
');
$("html:lang(tc) .grid_item_box.flag.hot").append('
');
$("html:lang(tc) .grid_item_box.flag.sale").append('
');
/*sc*/
$("html:lang(sc) .grid_item_box.flag.new").append('
');
$("html:lang(sc) .grid_item_box.flag.hot").append('
');
$("html:lang(sc) .grid_item_box.flag.sale").append('
');
/* ---------------------------------------------------------------------- */
/* PRODUCT DETAILS
/* ---------------------------------------------------------------------- */
/* Product Large Image replace */
$(".pdt_img_list .item").click(function () {
var largeSrc = $(this).find("img").attr("data-large-image");
$(".pdt_img_list .item").removeClass("active");
$(this).addClass("active");
$(".display_img img").attr({src: largeSrc});
});
$(".pdt_img_list .item").click(function () {
var largeSrc = $(this).find("div").attr("data-large-image");
$(".pdt_img_list .item").removeClass("active");
$(this).addClass("active");
$(".display_img div").css("background-image", "url('" + largeSrc + "')");
});
/* Product Inof Tabs */
$(".box_tab ul li").click(function () {
$(".box_tab ul li").removeClass("active");
$(this).addClass("active");
var activeBox = $(this).attr("tab-id");
/* for Product details */
$(".info_box li").removeClass("active");
/* for member notivications */
$(".general_table").removeClass("active");
$(activeBox).addClass("active");
return false
});
/* Product description show more */
$(".pdt_desc").after('CLOSE
');
$(".pdt_desc").find(".desc_content").clone().prependTo(".pdt_desc_show");
$(".pdt_desc .more").on("click", function () {
$(".pdt_desc_show").fadeIn();
$(this).hide();
$(".pdt_desc_show .close").click(function () {
$(".pdt_desc_show").fadeOut();
$(".pdt_desc .more").show();
});
});
/* Product options dropdwon */
/* $(".pdt_size .option_box").click(function () {
$(this).next(".option_list").slideToggle();
$(this).toggleClass("active");
return false
});*/
$(document).on("click", ".pdt_size .option_box", function () {
$(this).next(".option_list").slideToggle();
$(this).toggleClass("active");
return false
});
/* Product other promotion dropdown*/
$(".promotion_box .more").click(function () {
$(this).parent(".promotion_box").toggleClass("current");
return false
});
/* Product Share to friends popup */
$(".frd_share_box").prependTo(".frd_share");
$(".pdt_social_block .frd_share").click(function () {
$(".frd_share_box").toggle();
$(".frd_share_row").click(function (e) {
e.stopPropagation();
});
});
/*
$(".frd_share_box .option_box .fa").click(function () {
$(this).toggleClass("current");
$(this).parents().find(".frd_search").slideToggle();
return false
});*/
/* ---------------------------------------------------------------------- */
/* GENERAL FORM
/* ---------------------------------------------------------------------- */
$(".general_form .selector").click(function () {
$(this).find("ul").slideToggle();
$(this).toggleClass("active");
return false
});
$(".general_form .selector ul li").click(function () {
var newTxt = $(this).text();
$(this).parent('ul').find('li').removeClass('selected');
$(this).addClass('selected');
$(this).parents('.selector').find('.display_value').html(newTxt);
});
/* ---------------------------------------------------------------------- */
/* checkbox
/* (some problems here, i will corrected it later, might u will change them)
/* ---------------------------------------------------------------------- */
$(".general_table .icn_checkbox").on("click", function () {
$(".general_box .icn_checkbox").removeClass("selected");
$(this).toggleClass("selected");
//foreach checkbox
var remove_array = new Array();
$(".icn_checkbox").each(function () {
if (this.className == "icn_checkbox selected" && this.id != "") {
//console.log($(this));
remove_array.push(this.id);
}
});
if (remove_array.length > 0) {
$(".remove_btn").removeClass("hide");
} else {
$(".remove_btn").addClass("hide");
}
});
$(".general_box .icn_checkbox").on("click", function () {
$(this).toggleClass("selected");
if ($(".general_box i").hasClass("selected")) {
$(".general_table .icn_checkbox").addClass("selected");
} else {
$(".general_table .icn_checkbox").removeClass("selected");
}
//foreach checkbox
var remove_array = new Array();
$(".icn_checkbox").each(function () {
if (this.className == "icn_checkbox selected" && this.id != "") {
//console.log($(this));
remove_array.push(this.id);
}
});
if (remove_array.length > 0) {
$(".remove_btn").removeClass("hide");
} else {
$(".remove_btn").addClass("hide");
}
});
/* ---------------------------------------------------------------------- */
/* cart summary - discount list (modified by kelvin)
/* ---------------------------------------------------------------------- */
$(".discount_opt_list .dis_selector .selected_product_name").click(function () {
$(".dis_selector ul").slideUp();
if ($(this).closest('.dis_selector').find("ul").css('display') == 'none') {
$(this).closest('.dis_selector').find("ul").slideDown();
} else {
$(this).closest('.dis_selector').find("ul").slideUp();
}
$(this).closest('.dis_selector').toggleClass("active");
return false
});
$(".discount_opt_list .dis_selector li").click(function () {
var newTxt = $(this).text();
$(this).parent('ul').find('li').removeClass('selected');
$(this).addClass('selected');
// $(this).parents('.selector').find('.display_value').html(newTxt);
$(this).closest('.dis_selector').find('.selected_product_name').text(newTxt);
$(this).parent('ul').slideUp();
});
/* ---------------------------------------------------------------------- */
/* Special gift
/* ---------------------------------------------------------------------- */
$(".sp_item_box .selector").click(function () {
$(this).find("ul").slideToggle();
$(this).toggleClass("active");
return false
});
$(".sp_item_box .selector ul li").click(function () {
var newTxt = $(this).text();
$(this).parent('ul').find('li').removeClass('selected');
$(this).addClass('selected');
$(this).parents('.selector').find('.display_value').html(newTxt);
});
/* ---------------------------------------------------------------------- */
/* Back to Top
/* ---------------------------------------------------------------------- */
$("body").append('
');
(function () {
oldiOS = false,
oldAndroid = false;
// Detect if older iOS device, which doesn't support fixed position
if (/(iPhone|iPod|iPad)\sOS\s[0-4][_\d]+/i.test(navigator.userAgent))
oldiOS = true;
// Detect if older Android device, which doesn't support fixed position
if (/Android\s+([0-2][\.\d]+)/i.test(navigator.userAgent))
oldAndroid = true;
$('#back-to-top').click(function (e) {
$('html, body').animate({scrollTop: 0}, 500);
e.preventDefault();
});
$(window).scroll(function () {
var position = $(window).scrollTop();
if (oldiOS || oldAndroid) {
$(settings.button).css({
'position': 'absolute',
'top': position + $(window).height()
});
}
if (position > 200)
$('#back-to-top').fadeIn(400);
else
$('#back-to-top').fadeOut(400);
});
})();
/* end UItoTop (Back to Top) */
/* marquee responsive */
function marquee_responsive(init) {
var top_bar_right_width = $("#top_bar .tier0").width();
var top_bar_width = $("#top_bar .container").width();
/* console.log(top_bar_right_width);
console.log(top_bar_width);*/
/*if ($(".tier0 li").hasClass("afterlogin")) {
if(parseInt(top_bar_right_width) < 440){
top_bar_right_width = 455;
}
} else {
console.log(top_bar_right_width);
console.log(top_bar_width);
if(parseInt(top_bar_right_width) < 365){
top_bar_right_width = 365;
}
}*/
var top_bar_left_width = parseInt(top_bar_width) - top_bar_right_width - 20;
$("#top_bar .marquee_list").css("width", top_bar_left_width + "px");
$("#top_bar .pointer").css("width", top_bar_left_width + "px");
$("#top_bar .pointer div:first-child").css("padding", "0px " + top_bar_left_width + "px");
}
$(window).resize(function () {
marquee_responsive();
});
marquee_responsive();
});