From 963d609e62d24193364e813c3b58ec10418a876d Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 25 Jul 2012 16:30:35 +0800 Subject: [PATCH] min js --- helper/compressor/grunt.js | 63 ++++++++------------------------------ neoease/js/neoease.min.js | 21 ++++++++++++- 2 files changed, 32 insertions(+), 52 deletions(-) diff --git a/helper/compressor/grunt.js b/helper/compressor/grunt.js index 1bf335c..b000f8c 100644 --- a/helper/compressor/grunt.js +++ b/helper/compressor/grunt.js @@ -1,24 +1,17 @@ -/*var jsp = require("uglify-js").parser; -var pro = require("uglify-js").uglify; - - - - - - -var orig_code = "... JS code here"; -var ast = jsp.parse(orig_code); // parse code and get the initial AST -ast = pro.ast_mangle(ast); // get a new AST with mangled names -ast = pro.ast_squeeze(ast); // get an AST with compression optimizations -var final_code = pro.gen_code(ast); // compressed code here - -// js compress -var jsPaths = ["../neoease/js/neoease.js"]*/ - -// css compress var fs = require("fs"), exec = require("child_process").exec; +// js compress +var jsPaths = ["neoease"]; +for (var i = 0; i < jsPaths.length; i++) { + var content = ""; + exec("uglifyjs ../../" + jsPaths[i] + "/js/" + jsPaths[i] + ".js > ../../" + jsPaths[i] + "/js/" + jsPaths[i] + ".min.js", function (error, stdout, stderr) { + if (error !== null) { + console.log(error); + } + }); +} +// css compress var skinsCsses = ["andrea", "classic", "community", "favourite", "i-nove", "neoease", "owmx-3.0", "tree-house"]; for (var i = 0; i < skinsCsses.length; i++) { @@ -28,36 +21,4 @@ for (var i = 0; i < skinsCsses.length; i++) { console.log(error); } }); -} - - - - -/* -var fs = require("fs"); -var less = require('C:\\Users\\Vanessa\\AppData\\Roaming\\npm\\node_modules\\less'); -var parser = new(less.Parser)(); - -fs.readFile('../../andrea/css/andrea.css', 'UTF-8', function (err, data) { - if (err) throw err; - - new(less.Parser)({ - paths: ["../../andrea/css"], - filename: "andrea.css" - }).parse(data, function (e, root) { - var result = root.toCSS({ compress: true }); - console.log(result); - }); - -}); - - - -/*var cssPaths = ["../andrea/css/andrea.css", "../classic/css/classic.css", - "../community/css/community.css", "../favourite/css/favourite.css", - "../i-nove/css/i-nove.css", "../neoease/css/neoease.css", - "../owmx-3.0/css/owmx-3.0.css", "../terr-house/css/tree-house.css"]; - -for (var i = 0; i < cssPaths.lengtg; i++) { - -}*/ \ No newline at end of file +} \ No newline at end of file diff --git a/neoease/js/neoease.min.js b/neoease/js/neoease.min.js index 6dd1d89..7ade48d 100644 --- a/neoease/js/neoease.min.js +++ b/neoease/js/neoease.min.js @@ -1 +1,20 @@ -var goTop=function(acceleration){acceleration=acceleration||0.1;var y=$(window).scrollTop();var speed=1+acceleration;window.scrollTo(0,Math.floor(y/speed));if(y>0){var invokeFunction="goTop("+acceleration+")";window.setTimeout(invokeFunction,16)}};var collapseArchive=function(it,year){var tag=true;if(it.className==="collapse-ico"){it.className="expand-ico";tag=false}else{it.className="collapse-ico"}$("#archiveSide li").each(function(){var $this=$(this);if($this.data("year")===year){if(tag){$(this).show()}else{$(this).hide()}}})};var getArticle=function(it,id){var $abstract=$("#abstract"+id),$content=$("#content"+id);if($content.html()===""){$.ajax({url:"/get-article-content?id="+id,type:"GET",dataType:"html",beforeSend:function(){$abstract.css("background","url(/skins/neoease/images/ajax-loader.gif) no-repeat scroll center center transparent")},success:function(result,textStatus){it.className="collapse-ico";$content.html(result);$abstract.hide().css("background","none");$content.fadeIn("slow")}})}else{if(it.className==="expand-ico"){$abstract.hide();$content.fadeIn();it.className="collapse-ico"}else{$content.hide();$abstract.fadeIn();it.className="expand-ico"}}return false};var goTranslate=function(){window.open("http://translate.google.com/translate?sl=auto&tl=auto&u="+location.href)};(function(){$(window).scroll(function(){var y=$(window).scrollTop();if(y>182){var bodyH=$(window).height();var top=y+bodyH-21;if($("body").height()-58<=y+bodyH){top=$(".footer").offset().top-21}$("#goTop").fadeIn("slow").css("top",top)}else{$("#goTop").hide()}});var currentYear=(new Date()).getFullYear(),year=currentYear;$("#archiveSide li").each(function(i){var $this=$(this);if($this.data("year")!==currentYear){$(this).hide()}if(year!==$this.data("year")){year=$this.data("year");$this.before("
  • "+year+" \u5e74
  • ")}});$(".recent-comments .expand-ico").click(function(){if(this.className==="expand-ico"){$(this).parent().next().css({"height":"auto","white-space":"normal"});this.className="collapse-ico"}else{$(this).parent().next().animate({"height":"18px"},function(){$(this).css("white-space","nowrap")});this.className="expand-ico"}});$(".nav ul a").each(function(){var $this=$(this);if($this.attr("href")===location.pathname){$this.parent().addClass("current")}else if(/\/[0-9]+$/.test(location.pathname)){$(".nav ul li")[0].className="current"}});Util.init();Util.replaceSideEm($(".recent-comments-content"));Util.buildTags("tagsSide");$(".recent-comments .recent-comments-main").each(function(){if($(this).find(".recent-comments-content>a").height()<30){$(this).find(".expand-ico").remove()}else{$(this).find(".expand-ico").parent().next().css({"white-space":"nowrap"})}})})(); \ No newline at end of file +/* + * Copyright (c) 2009, 2010, 2011, 2012, B3log Team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *//** + * @fileoverview neoease js. + * + * @author Liyuan Li + * @version 1.0.0.7, May 11, 2012 + */var goTop=function(e){e=e||.1;var t=$(window).scrollTop(),n=1+e;window.scrollTo(0,Math.floor(t/n));if(t>0){var r="goTop("+e+")";window.setTimeout(r,16)}},collapseArchive=function(e,t){var n=!0;e.className==="collapse-ico"?(e.className="expand-ico",n=!1):e.className="collapse-ico",$("#archiveSide li").each(function(){var e=$(this);e.data("year")===t&&(n?$(this).show():$(this).hide())})},getArticle=function(e,t){var n=$("#abstract"+t),r=$("#content"+t);return r.html()===""?$.ajax({url:"/get-article-content?id="+t,type:"GET",dataType:"html",beforeSend:function(){n.css("background","url(/skins/neoease/images/ajax-loader.gif) no-repeat scroll center center transparent")},success:function(t,i){e.className="collapse-ico",r.html(t),n.hide().css("background","none"),r.fadeIn("slow")}}):e.className==="expand-ico"?(n.hide(),r.fadeIn(),e.className="collapse-ico"):(r.hide(),n.fadeIn(),e.className="expand-ico"),!1},goTranslate=function(){window.open("http://translate.google.com/translate?sl=auto&tl=auto&u="+location.href)};(function(){$(window).scroll(function(){var e=$(window).scrollTop();if(e>182){var t=$(window).height(),n=e+t-21;$("body").height()-58<=e+t&&(n=$(".footer").offset().top-21),$("#goTop").fadeIn("slow").css("top",n)}else $("#goTop").hide()});var e=(new Date).getFullYear(),t=e;$("#archiveSide li").each(function(n){var r=$(this);r.data("year")!==e&&$(this).hide(),t!==r.data("year")&&(t=r.data("year"),r.before("
  • "+t+" 年
  • "))}),$(".recent-comments .expand-ico").click(function(){this.className==="expand-ico"?($(this).parent().next().css({height:"auto","white-space":"normal"}),this.className="collapse-ico"):($(this).parent().next().animate({height:"18px"},function(){$(this).css("white-space","nowrap")}),this.className="expand-ico")}),$(".nav ul a").each(function(){var e=$(this);e.attr("href")===location.pathname?e.parent().addClass("current"):/\/[0-9]+$/.test(location.pathname)&&($(".nav ul li")[0].className="current")}),Util.init(),Util.replaceSideEm($(".recent-comments-content")),Util.buildTags("tagsSide"),$(".recent-comments .recent-comments-main").each(function(){$(this).find(".recent-comments-content>a").height()<30?$(this).find(".expand-ico").remove():$(this).find(".expand-ico").parent().next().css({"white-space":"nowrap"})})})(); \ No newline at end of file