ant-design/static/script.js

148 lines
4.4 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-08-19 11:26:30 +08:00
// 移动 API 文档到演示下方
$('.markdown #api').nextAll().andSelf().appendTo('.api-container');
$.easing['jswing'] = $.easing['swing'];
$.extend($.easing,{
easeInCirc: function (x, t, b, c, d) {
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
},
easeOutCirc: function (x, t, b, c, d) {
return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
},
easeInOutCirc: function (x, t, b, c, d) {
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
}
});
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.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
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) {
2015-06-10 11:51:51 +08:00
var parent = $(this).parent(),
2015-08-19 11:26:30 +08:00
list=parent.find("ul");
2015-06-02 20:23:18 +08:00
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
}
2015-06-10 11:51:51 +08:00
list.animate({marginTop:-list.height()},400,"easeInOutCirc",function (){
2015-08-19 11:26:30 +08:00
list.css({"display":"none"})
2015-06-10 11:51:51 +08:00
})
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
}
2015-08-19 11:26:30 +08:00
list.css({"display":"block","margin-top":-list.height()});
list.animate({marginTop:0},400,"easeInOutCirc")
2015-06-02 20:23:18 +08:00
}
2015-06-10 11:51:51 +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
});