timcharper / calendar_date_select

A previously popular but no longer maintained JavaScript DatePicker for RubyOnRails (and others)
http://code.google.com/p/calendardateselect/
Other
409 stars 179 forks source link

Compressing with Asset Packager (using Google's Closure Compiler) does not work #19

Open jensb opened 13 years ago

jensb commented 13 years ago

We are using Asset Packager to compress our CSS and Javascript files. This is a great plus since it allows us to transmit only one compressed CSS and JS file, instead of (altogether) 27 files with each request.

However, when I include CDS's .js files in asset_packager's _config/assetpackages.yml, I get the following error upon clicking on a calendar icon:

"'that' is not a function", in initCalendarDiv

It seems that something that asset_packager does, breaks CDS's javascript. What could that be?

jensb commented 13 years ago

PS. Using Rails 3.0.4 (and the Rails 3 fork of CDS).

triemstr commented 13 years ago

I also had this problem last year and gave up on closure compiler. A better javascript coder than I may be able to figure it out. I would first try to upgrade to the most recent closure compiler to see if it is still a problem. Then if you have a chance, see if you can re-arrange this code in the main calendar_date_select.js file (I suspect it is a problem with the eval line):

https://github.com/timcharper/calendar_date_select/blob/master/public/javascripts/calendar_date_select/calendar_date_select.js

Look around line 145 inside initCalendarDiv:

var that = this;
    // create the divs
    $w("top header body buttons footer bottom").each(function(name) {
      eval("var " + name + "_div = that." + name + "_div = that.calendar_div.build('div', { className: 'cds_"+name+"' }, { clear: 'left'} ); ");
    });

Instead of solving this, I just moved to yui from closure. The uglifier gem may also work. I've never tried it but I think it comes with Rails 3.1 so it would be worth trying. I use the jammit gem and yui 0.9.1 to do mine. Yui has newer versions that you should try but I have other unrelated problems with them.