ant-design/site/static/script.js

146 lines
4.1 KiB
JavaScript
Raw Normal View History

2015-09-11 14:57:32 +08:00
InstantClickChangeFns.push(function() {
2015-12-13 20:08:58 +08:00
// fix hash id link
if (window.location.href.indexOf('#') > 0) {
setTimeout(function() {
window.location.href = window.location.href;
}, 0);
}
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');
2015-08-26 22:16:20 +08:00
$('.nav-phone-icon').click(function() {
$(this).prev().toggle();
});
2015-08-19 11:26:30 +08:00
$.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() {
2015-12-19 14:00:40 +08:00
this.navBox = $(".nav");
this.navBar = this.navBox.find(".bar");
this.navList = this.navBox.find("ul li");
this.navNum = $(".current").index();
this.navBarAnim();
this.highlightCurrentNav();
$(window).bind("resize", this.highlightCurrentNav);
this.navBar.show();
2015-05-27 11:35:01 +08:00
},
2015-12-19 14:00:40 +08:00
highlightCurrentNav: function(target) {
target = target || this.navList.eq(this.navNum);
2015-12-25 17:19:24 +08:00
this.navBar && this.navBar.css({
2015-12-19 14:00:40 +08:00
left: target.position().left,
width: target.outerWidth()
});
2015-05-27 11:35:01 +08:00
},
2015-06-02 20:23:18 +08:00
navBarAnim: function() {
2015-12-19 14:00:40 +08:00
var self = this, delay;
2015-06-02 20:23:18 +08:00
self.navList.bind("mouseenter", function(e) {
2015-05-27 11:35:01 +08:00
clearTimeout(delay);
2015-12-19 14:00:40 +08:00
self.highlightCurrentNav($(e.currentTarget));
2015-05-27 11:35:01 +08:00
});
2015-06-02 20:23:18 +08:00
self.navList.bind("mouseleave", function(e) {
delay = setTimeout(function() {
2015-12-19 14:00:40 +08:00
self.highlightCurrentNav();
2015-05-27 11:35:01 +08:00
}, 500);
});
}
};
navFunc.init();
2015-06-02 20:23:18 +08:00
var listFunc = {
num: 0,
init: function() {
2015-12-19 14:00:40 +08:00
this.listBox = $(".aside-container>ul");
if (!this.listBox.length) {
2015-06-02 20:36:53 +08:00
return;
2015-06-02 20:23:18 +08:00
}
2015-12-19 14:00:40 +08:00
this.getUrlNum();
this.addTitleEvent();
2015-06-02 20:23:18 +08:00
},
getUrlNum: function() {
var self = this,
url = location.href,
str = "";
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-02 20:36:53 +08:00
});
2015-06-02 20:23:18 +08:00
}
};
listFunc.init();
2015-05-08 14:57:59 +08:00
});