var win = $(window), nav_on = null; $(function () { // 导航栏控制 (function () { var nav = $('#nav'), shop = $('#shop'), // search_box = shop.find('#searchbox'), // search_btn = shop.find('.btn-search')[0], lis = nav.children(), lis_1 = lis.filter(':not(.more)'), lis_2 = lis.filter('.more'), links = lis.children(), links_1 = lis_1.children(), links_2 = lis_2.children(), subnav = $('#subnav'), subitem = $('#subnav').find('.item'), prev_item = $(), spans = links.children(), offs = spans.filter('.off'), ons = spans.filter('.on'), sbs = spans.filter('.slideblock'), hei = links.eq(0).height(), len = lis.length, // 记录当前 link_page = null, link_curr = null, timeout = -1; // 初始化当前链接 href = location.href.replace(/[_\d]{1,2}\./, '.'); // 静态页面用 // href = location.href, // 程序用 for (var i = 0; i < len; i++) { link_page = links.eq(i); if (href.indexof(link_page.attr('href').replace(/(?:_\d)?\..*/, '')) > 0) { // 静态页面用 // if (href.indexof(link_page.attr('href').replace(/(?:_\d)?\..*/, '')) > 0) { // 程序用 control(nav_on = link_curr = link_page = link_page[0], false); delete i; break; } } links_2.each(function (idx) { if (this === nav_on) return; this.setattribute('idx', idx); }); if (i === len) { if (href.indexof('/user') >= 0) { control(nav_on = link_curr = link_page = links.eq(5)[0], false); } else { control(nav_on = link_curr = link_page = links.eq(0)[0], false); } } win.on('load', function () { // 鼠标指向, 链接高亮 links_1.hover(function () { control(this, false) }, none); links_2.hover(function () { control(this, true) }, none); // 鼠标离开导航栏, 恢复当前页面高亮 nav.hover(none, function () { timeout = settimeout(function () { control(link_page, true); }, 10); }); subnav.hover(function () { cleartimeout(timeout); }, function () { control(link_page, true); }); }); function control(elem, flag, idx) { link_curr.classname = ""; elem.classname = "on"; link_curr = elem; prev_item.removeclass('on'); if (flag) { idx = parseint(elem.getattribute('idx')); prev_item = subitem.eq(idx).addclass('on'); // search_box.hide(); // search_btn.classname = "btn-search"; } } function none() { } // 2015.06.09 修改搜索, 添加语言 var subitem_search = subitem.filter('.search'), subitem_langs = subitem.filter('.langs'); shop.find('.btn-search').hover(function(){ prev_item.removeclass('on'); prev_item = subitem_search.addclass('on'); }, none); shop.find('.btn-lang').hover(function() { prev_item.removeclass('on'); prev_item = subitem_langs.addclass('on'); }, none); shop.hover(none, function() { timeout = settimeout(function() { prev_item.removeclass('on'); }, 300); }); }()); // 搜索按钮 (function () { var sup = $('#header'), btn = sup.find('.btn-search'), box = sup.find('#searchbox'), timeout = -1, delay = 1000; btn.hover(open, autofade); box.on('focus', function () { cleartimeout(timeout); }).on('blur', function () { autofade(); }); function open() { cleartimeout(timeout); btn.addclass('on'); box.stop(false, true).fadein(300); } function close() { btn.removeclass('on'); box.stop(false, true).fadeout(300); } function autofade() { timeout = settimeout(function () { close(); }, delay); } }()); // placeholder 处理 (function () { // 情况1,如果浏览器支持 placeholder,则优先使用默认。 var input = document.createelement("input"); input.type = "text"; if ("placeholder" in input) return; // 情况2,如果没有任何标签使用 placeholder,则不做任何处理。 var inputs = $("*[placeholder]"), val = ""; if (!inputs.length) return; // 情况3,对于不支持 placeholder 属性的元素进行预加载和事件挂载。 inputs .each(function () { input = $(this); input.val(input.attr("placeholder")); }) .on("focus", focus) .on("blur", blur) .on("change", change); // 处理函数 function focus() { input = $(this); val = input.val(); if (val && (val!==input.attr('placeholder'))) return; else input.val(""); } function blur() { // input.val(input.attr("placeholder")); val = input.val(); if (val && (val!==input.attr('placeholder'))) { return; } else { input.val(input.attr("placeholder")); } } function change() { if (input.val()) { input.off("focus").off("blur"); } else { input.on("focus", focus).on("blur", blur); } } })(); // 调整高度 (function() { var copyright = $('#copyright'), hei = $('html').height()-$('body').height(); if (hei<=0) return; copyright.find('.g-wrap div').height(37+hei); }()); });