2012-10-28 13 views
0

我try'd來縮小這個小插件with this minifier,但它出來是錯誤的。 (* a.b和c是undefined等*)如何使用JS-minifier

有沒有人看到有什麼問題,或者是否有一些在線工具也檢查它是否有效?

感謝,理查德

編輯 * 插件是沒有錯誤,現在 *

(function($) { 

$.fn.bar = function(options) { 
    var opts = $.extend({}, $.fn.bar.defaults, options); 
    return this.each(function() { 
     $this = $(this); 
     var o = $.meta ? $.extend({}, opts, $this.data()) : opts; 

     $this.click(function(e){ 
      if(!$('.jbar').length){ 
       var _remove_cross = ""; 
       timeout = setTimeout(function(){$.fn.bar.removebar();},o.time); 
       var _message_span = $(document.createElement('span')).addClass('jbar-content').html(o.message); 
       _message_span.css({"color" : o.color}); 
       var _wrap_bar; 
       _wrap_bar = (o.position == 'bottom') ? 
       $(document.createElement('div')).addClass('jbar jbar-bottom'): 
       $(document.createElement('div')).addClass('jbar jbar-top') ; 

       _wrap_bar.css({"background-color" : o.background_color}); 
       if(o.removebutton){ 
        _remove_cross = $(document.createElement('a')).addClass('jbar-cross'); 
        _remove_cross.click(function(e){$.fn.bar.removebar();}); 
       } 
       else{    
        _wrap_bar.css({"cursor" : "pointer"}); 
        _wrap_bar.click(function(e){$.fn.bar.removebar();}); 
       } 
       _wrap_bar.append(_message_span).append(_remove_cross).hide().insertBefore($('.content')).fadeIn('fast'); 
      }else{ 
       $('.jbar').find('.jbar-content').html(o.message); 
      } 
     }); 

     if(o.auto)$this.trigger('click'); 

    }); 
}; 
var timeout; 
$.fn.bar.removebar = function(txt) { 
    if($('.jbar').length){ 
     clearTimeout(timeout); 
     $('.jbar').fadeOut('fast',function(){ 
      $(this).remove(); 
     }); 
    } 
}; 
$.fn.bar.defaults = { 
    background_color : '#FFFFFF', 
    color    : '#191919', 
    position   : 'top', 
    removebutton  : false, 
    time    : 8000, 
    auto:true 
}; 
})(jQuery); 
+1

我不知道壓縮機,但你可以嘗試[較爲流行的一個(http://stackoverflow.com/questions/702907/what-are-some-good-css-and-js-極小換生產代碼)。 –

+0

感謝,我想這一個還不錯,從谷歌得到它,我會檢查出來 – Richard

+1

這不是微小的事..你的代碼是越野車.. http://jsbin.com/ipemud/1/edit – lrsjng

回答

1

你可以使用的UglifyJS在線版,或使用源GitHub所以你可以用它來你自己。

精縮版,

(function(e){e.fn.bar=function(n){var r=e.extend({},e.fn.bar.defaults,n);return this.each(function(){$this=e(this);var n=e.meta?e.extend({},r,$this.data()):r;$this.click(function(r){if(!e(".jbar").length){var i="";t=setTimeout(function(){e.fn.bar.removebar()},n.time);var s=e(document.createElement("span")).addClass("jbar-content").html(n.message);s.css({color:n.color});var u;u=n.position=="bottom"?e(document.createElement("div")).addClass("jbar jbar-bottom"):e(document.createElement("div")).addClass("jbar jbar-top"),u.css({"background-color":n.background_color}),n.removebutton?(i=e(document.createElement("a")).addClass("jbar-cross"),i.click(function(t){e.fn.bar.removebar()})):(u.css({cursor:"pointer"}),u.click(function(t){e.fn.bar.removebar()})),u.append(s).append(i).hide().insertBefore(e(".content")).fadeIn("fast")}else e(".jbar").find(".jbar-content").html(n.message)}),n.auto&&$this.trigger("click")})};var t;e.fn.bar.removebar=function(n){e(".jbar").length&&(clearTimeout(t),e(".jbar").fadeOut("fast",function(){e(this).remove()}))},e.fn.bar.defaults={background_color:"#FFFFFF",color:"#191919",position:"top",removebutton:!1,time:8e3,auto:!0}})(jQuery) 
+0

謝謝,uglify工作,除了最後缺少分號 – Richard

0

下一次給www.blimptontech.com一個鏡頭畫面的JS運行如下的需求。令人敬畏的工具,使用UglifyJS。甚至可以將文件合併成一個文件,同時在過程中對文件進行縮小。