Skip to content

Commit

Permalink
doc: coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
MOxFIVE committed Jun 17, 2016
1 parent b2c30f3 commit d4d04a9
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 85 deletions.
157 changes: 75 additions & 82 deletions source/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ require([], function (){
require([yiliaConfig.rootUrl + 'js/mobile.js'], function(mobile){
mobile.init();
isMobileInit = true;
});
})
}
var isPCInit = false;
var loadPC = function(){
require([yiliaConfig.rootUrl + 'js/pc.js'], function(pc){
pc.init();
isPCInit = true;
});
})
}

var browser={
versions:function(){
var browser = {
versions: function() {
var u = window.navigator.userAgent;
return {
trident: u.indexOf('Trident') > -1, //IE内核
Expand All @@ -34,22 +34,22 @@ require([], function (){
}()
}

$(window).bind("resize", function(){
if(isMobileInit && isPCInit){
$(window).bind("resize", function() {
if (isMobileInit && isPCInit) {
$(window).unbind("resize");
return;
}
var w = $(window).width();
if(w >= 700){
if (w >= 700) {
loadPC();
}else{
} else {
loadMobile();
}
});

if(browser.versions.mobile === true || $(window).width() < 800){
if(!!browser.versions.mobile || $(window).width() < 800){
loadMobile();
}else{
} else {
loadPC();
}

Expand All @@ -58,12 +58,12 @@ require([], function (){
for(var i = 0; i < tags.length; i++){
var num = Math.floor(Math.random()*7);
tags.eq(i).addClass("color" + num);
};
}
$(".article-category a:nth-child(-n+2)").attr("class", "color0");
}

//是否使用fancybox
if(yiliaConfig.fancybox === true){
// fancyBox
if(!!yiliaConfig.fancybox){
require([yiliaConfig.fancybox_js], function(pc){
var isFancy = $(".isFancy");
if(isFancy.length != 0){
Expand All @@ -80,97 +80,89 @@ require([], function (){
}
$(".article-inner .fancy-ctn").fancybox();
}
});

})
}
//是否开启动画
if(yiliaConfig.animate === true){

if(yiliaConfig.isHome === true) {
// 滚动条监听使用scrollreveal.js
// https://github.com/jlmakes/scrollreveal.js
require([yiliaConfig.scrollreveal], function (ScrollReveal) {
// 更多animation:
// http://daneden.github.io/animate.css/
var animationNames = [
"pulse", "fadeIn","fadeInRight", "flipInX", "lightSpeedIn","rotateInUpLeft", "slideInUp","zoomIn",
],
len = animationNames.length,
randomAnimationName = animationNames[Math.ceil(Math.random() * len) - 1];

// ie9 不支持css3 keyframe动画, safari不支持requestAnimationFrame, 不使用随机动画,切回原来的动画
if (!window.requestAnimationFrame) {
$('.body-wrap > article').css({opacity: 1});

if (navigator.userAgent.match(/Safari/i)) {
function showArticle(){
$(".article").each(function(){
if( $(this).offset().top <= $(window).scrollTop()+$(window).height() && !($(this).hasClass('show')) ) {
$(this).removeClass("hidden").addClass("show");
$(this).addClass("is-hiddened");
}else{
if(!$(this).hasClass("is-hiddened")){
$(this).addClass("hidden");
}
}
});
}
$(window).on('scroll', function(){
showArticle();
});
showArticle();
}
return;
}
var animateScope = ".body-wrap > article";
var $firstArticle = $(".body-wrap > article:first-child");
if ($firstArticle.height() > $(window).height()) {
var animateScope = ".body-wrap > article:not(:first-child)";
$firstArticle.css({opacity: 1});
}
// document.body有些浏览器不支持监听scroll,所以使用默认的document.documentElement
ScrollReveal({
duration: 0,
afterReveal: function (domEl) {
// safari不支持requestAnimationFrame不支持document.documentElement的onscroll所以这里不会执行
// 初始状态设为opacity: 0, 动画效果更平滑一些(由于脚本加载是异步,页面元素渲染后在执行动画,感觉像是延时)
$(domEl).addClass('animated ' + randomAnimationName).css({opacity: 1});
}
}).reveal(animateScope);

});
} else {
$('.body-wrap > article').css({opacity: 1});
}
// Animate on Homepage
if(!!yiliaConfig.animate) {
if(!!yiliaConfig.isHome) {
require([yiliaConfig.scrollreveal], function (ScrollReveal) {
var animationNames = [
"pulse", "fadeIn","fadeInRight", "flipInX", "lightSpeedIn","rotateInUpLeft", "slideInUp","zoomIn",
],
len = animationNames.length,
randomAnimationName = animationNames[Math.ceil(Math.random() * len) - 1];

// Fallback (CSS3 keyframe, requestAnimationFrame)
if (!window.requestAnimationFrame) {
$('.body-wrap > article').css({opacity: 1});
if (navigator.userAgent.match(/Safari/i)) {
function showArticle(){
$(".article").each(function(){
if( $(this).offset().top <= $(window).scrollTop()+$(window).height() && !($(this).hasClass('show')) ) {
$(this).removeClass("hidden").addClass("show");
$(this).addClass("is-hiddened");
} else {
if(!$(this).hasClass("is-hiddened")) {
$(this).addClass("hidden");
}
}
})
}
$(window).on('scroll', function(){
showArticle();
});
showArticle();
}
return;
}

var animateScope = ".body-wrap > article";
var $firstArticle = $(".body-wrap > article:first-child");
if ($firstArticle.height() > $(window).height()) {
var animateScope = ".body-wrap > article:not(:first-child)";
$firstArticle.css({opacity: 1});
}
ScrollReveal({
duration: 0,
afterReveal: function (domEl) {
$(domEl).addClass('animated ' + randomAnimationName).css({opacity: 1})
}
}).reveal(animateScope);
})
} else {
$('.body-wrap > article').css({opacity: 1});
}
}

// TOC
if (yiliaConfig.toc) {
require(['toc'], function(){ })
}

//是否新窗口打开链接
if(yiliaConfig.open_in_new == true){
// Open in New Tab
if(!!yiliaConfig.open_in_new){
$(".article a[href]").attr("target", "_blank")
}
$(".archive-article-title, .github-widget a").attr("target", "_blank");

//随机颜色

// Random Color 边栏顶部随机颜色
var colorList = ["#6da336", "#ff945c", "#66CC66", "#99CC99", "#CC6666", "#76becc", "#c99979", "#918597", "#4d4d4d"];
var id = Math.ceil(Math.random()*(colorList.length-1));
//PC
// PC
$("#container .left-col .overlay").css({"background-color": colorList[id],"opacity": .3});
//移动端
// Mobile
$("#container #mobile-nav .overlay").css({"background-color": colorList[id],"opacity": .7});

// Table
$("table").wrap("<div class='table-area'></div>");

// Hide Comment Button
$(document).ready(function() {
if ($("#comments").length < 1) {
$("#scroll > a:nth-child(2)").hide();
};
}
})

// Hide Labels
Expand All @@ -179,8 +171,8 @@ require([], function (){
$("#footer").after("<button class='hide-labels'>TAGS</button>");
$(".hide-labels").click(function() {
$(".article-info").toggle(200);
});
});
})
})
}

// Task lists in markdown
Expand Down Expand Up @@ -215,4 +207,5 @@ require([], function (){
}
}
})
});

})
3 changes: 0 additions & 3 deletions source/js/pc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ define([], function(){
'-ms-transform: translate(-' + idx * 100 + '%, 0);',
'transform: translate(-' + idx * 100 + '%, 0);'
];
//$wrap.css({
// "transform": "translate(-"+idx*100+"%, 0 )"
//});
$wrap[0].style.cssText = transform.join('');
$(".icon-wrap").addClass("hide");
$(".icon-wrap").eq(idx).removeClass("hide");
Expand Down

0 comments on commit d4d04a9

Please sign in to comment.