ant-design/static/script.js

145 lines
4.2 KiB
JavaScript
Raw Normal View History

2015-05-08 14:57:59 +08:00
$(function() {
2015-05-16 16:20:49 +08:00
$('.component-demos .icon-all').on('click', function() {
2015-06-03 17:23:05 +08:00
if ($(this).hasClass('expand')) {
$(this).removeClass('expand');
$('.code-box .highlight').animate({
height: 'hide',
opacity: 0
}, 150);
} else {
$(this).addClass('expand');
$('.code-box .highlight').animate({
height: 'show',
opacity: 1
}, 150);
}
2015-05-18 17:33:42 +08:00
});
$('.code-box').each(function(i, item) {
item = $(item);
item.find('.highlight').appendTo(item);
});
$('.code-boxes').on('click', '.collapse', function() {
2015-06-04 10:57:06 +08:00
var highlightBox = $(this).parent().parent().find('.highlight');
2015-06-08 22:42:36 +08:00
var codeVisible = highlightBox.is(':visible');
2015-06-04 10:57:06 +08:00
highlightBox.animate({
2015-06-08 22:42:36 +08:00
height: codeVisible ? 'hide' : 'show',
opacity: codeVisible ? 0 : 1
2015-06-03 17:23:05 +08:00
}, 150);
2015-06-08 22:42:36 +08:00
if (codeVisible) {
$(this).parent().parent().removeClass('expand');
} else {
$(this).parent().parent().addClass('expand');
}
2015-06-02 20:49:40 +08:00
});
2015-05-27 10:35:37 +08:00
2015-06-02 20:23:18 +08:00
var navFunc = {
2015-05-27 11:35:01 +08:00
navStrArr: [],
2015-06-02 20:23:18 +08:00
init: function() {
var self = this;
2015-05-27 11:35:01 +08:00
self.navBox = $(".nav");
self.navBar = self.navBox.find(".bar");
self.navList = self.navBox.find("ul li");
2015-06-02 20:23:18 +08:00
self.navNum = $(".current").index();
2015-05-27 11:35:01 +08:00
self.search($(".search"));
self.navBarAnim();
self.navResize(null);
$(window).bind("resize", self.navResize);
2015-06-08 12:59:22 +08:00
self.navBar.show();
2015-05-27 11:35:01 +08:00
},
2015-06-02 20:23:18 +08:00
navResize: function(e) {
2015-05-27 11:35:01 +08:00
var self = navFunc;
self.navBar.css("left", self.navList.width() * self.navNum);
self.navList.eq(self.navNum).find("a").addClass("hover");
},
2015-06-02 20:23:18 +08:00
search: function(c) {
2015-05-27 11:35:01 +08:00
var self = this;
self.searchBox = c;
self.searchInput = self.searchBox.find("input[type='text']");
self.searchBtn = self.searchBox.find("button");
2015-06-02 20:23:18 +08:00
self.searchInput.focus(function(e) {
2015-05-27 11:35:01 +08:00
$(this).addClass("focus");
self.searchBtn.css("left", self.searchBox.width() + 13);
});
2015-06-02 20:23:18 +08:00
self.searchInput.blur(function(e) {
2015-05-27 11:35:01 +08:00
if (!self.searchInput.val()) {
self.searchBtn.attr("style", "");
$(this).removeClass("focus");
2015-05-27 10:35:37 +08:00
}
2015-05-27 11:35:01 +08:00
});
2015-06-02 20:23:18 +08:00
self.searchBtn.click(function(e) {
2015-05-27 11:35:01 +08:00
self.searchBox.find("form").submit();
});
},
2015-06-02 20:23:18 +08:00
navBarAnim: function() {
var self = this,
delay;
2015-05-27 11:35:01 +08:00
function startBarAnim(num) {
self.navBar.css("left", self.navList.width() * num);
self.navList.eq(num).find("a").addClass("hover");
}
2015-06-02 20:23:18 +08:00
self.navList.bind("mouseenter", function(e) {
2015-05-27 11:35:01 +08:00
clearTimeout(delay);
var m = e.currentTarget;
self.navList.find("a").removeClass("hover");
self.navBar.addClass("barAnim").css("left", $(m).width() * $(m).index());
});
2015-06-02 20:23:18 +08:00
self.navList.bind("mouseleave", function(e) {
delay = setTimeout(function() {
2015-05-27 11:35:01 +08:00
startBarAnim(self.navNum);
}, 500);
});
}
};
navFunc.init();
2015-06-02 20:23:18 +08:00
var listFunc = {
num: 0,
init: function() {
var self = this;
self.listBox = $(".aside-container>ul");
if (!self.listBox.length) {
2015-06-02 20:36:53 +08:00
return;
2015-06-02 20:23:18 +08:00
}
self.getUrlNum();
self.listBox.children().eq(self.num).attr("open", true).find("ul").css("display", "block");
//添加标题事件;
2015-06-02 20:36:53 +08:00
self.addTitleEvent();
2015-06-02 20:23:18 +08:00
},
getUrlNum: function() {
var self = this,
url = location.href,
str = "";
//console.log(self.listBox.find("a"))
for (var i = 0; i < self.listBox.find("a").length; i++) {
var m = self.listBox.find("a").eq(i);
if (m.attr("href") == "./" || url.indexOf(m.attr("href")) >= 0) {
self.num = m.parent().parent().parent().index();
2015-05-27 18:28:38 +08:00
}
2015-06-02 20:23:18 +08:00
}
},
addTitleEvent: function() {
var self = this;
var title = self.listBox.find("h4");
title.bind("click", function(e) {
var parent = $(this).parent();
if (parent.attr("open")) {
parent.removeAttr("open");
if (parent.index() == self.num) {
2015-06-02 20:36:53 +08:00
$(this).addClass("current");
2015-06-02 20:23:18 +08:00
}
} else {
parent.attr("open", true);
if (parent.index() == self.num) {
2015-06-02 20:36:53 +08:00
$(this).removeClass("current");
2015-06-02 20:23:18 +08:00
}
}
parent.find("ul").slideToggle(300);
2015-06-02 20:36:53 +08:00
});
2015-06-02 20:23:18 +08:00
}
};
listFunc.init();
2015-05-08 14:57:59 +08:00
});