Reputation: 58405
I'm using rails, uglifier and have just started using coffeescript. My coffee script for handling ajax completion is:
handleAjaxComplete = (xhr, response, status) ->
myFeatherBox.close() if myFeatherBox?
if $(xhr.target).hasClass "crud_create"
#creation button hit
myFeatherBox = $.featherlight response.responseText, afterOpen: ->
$('form#frm_create').validate()
$('#frm_create input[type!=hidden]').first().focus()
return
else #etc.
This becomes the following javascript:
handleAjaxComplete = function(xhr, response, status) {
var new_aka_song_id;
if (myFeatherBox != null) {
myFeatherBox.close();
}
if ($(xhr.target).hasClass("crud_create")) {
myFeatherBox = $.featherlight(response.responseText, {
afterOpen: function() {
$('form#frm_create').validate();
$('#frm_create input[type!=hidden]').first().focus();
}
});
} else //etc.
But then when I open the hosted page (it's on heroku), myFeatherBox.close()
didn't seem to be running. I checked the uglified code and it seems to have become:
a=function(t,s) {
var o;
if(null!=h&&h.close(),$(t.target).hasClass("crud_create"))
h=$.featherlight(s.responseText,{
afterOpen:function(){
$("form#frm_create").validate(),
$("#frm_create input[type!=hidden]").first().focus()
}
});
else //etc.
(I've added some whitespace where I don't think it will matter to make it a little more readable).
My concern is with the condition on the third line of the uglified code. Am I correct that this is breaking what I'm trying to do? If so, how do I fix my coffee script so that the uglifier plays nice?
Upvotes: 1
Views: 325
Reputation: 382160
a, b
in this context, is an expression whose value is the value of b
(see the comma operator).
That's why the uglified test
if(null!=h&&h.close(),$(t.target).hasClass("crud_create"))
is the same as
null!=h && h.close();
if ($(t.target).hasClass("crud_create"))
which is equivalent, due to the short-circuit behavior of &&
, to
if (null!=h) h.close();
if ($(t.target).hasClass("crud_create"))
So there doesn't seem to be any problem in this uglyfication.
Upvotes: 2