I have this function in CoffeeScript
render: ->
_.each @$elements, ($el) =>
if $el[0].id is 'tabs-div'
emptySlate = "<div class='js-empty-slate' style='padding:40px;'><h3>no data available</h3><div>"
@setEmptyPlacholde($el, emptySlate)
return
@setEmptyPlacholde($el)
setEmptyPlacholde: ($el, emptySlate)->
emptySlateHTML = emptySlate or "<h3 class='js-empty-slate'>no data available</h3>"
if $el.hasClass('mobile-os-con') or
$el.hasClass('time-of-visit-con') or
$el.hasClass('gender-visit-con') or
$el.hasClass('time-redemption-sales-con') or
$el.hasClass('gender-redemption-con')
$el.children().hide()
else
$el.empty()
$el.append emptySlateHTML
$elements is a jQuery variable which uses array like this:
$elements: [
$("#tabs-div")
$("#visits-male")
$("#visits-female")
$("#days-of-visits")
$(".time-of-visit-con")
]
When I used RequireJS optimizer r.js
which uses Uglify
the generated minified code .. looks like this:
render:function(){var e=this;return _.each(this.$elements,function(t){var n;if(t[0].id==="tabs-div"){n="<div class='js-empty-slate' style='padding:40px;'><h3>no data available</h3><div>",e.setEmptyPlacholde(t,n);return}return e.setEmptyPlacholde(t)})}
In the previous minified code, the $el
became t
.. So this refused to execute the $el
as jQuery element in the production.
This is the problem but I don't know why this occurs. Can anyone explain why this happens for me, thanks.
Update: The minified code was not the problem but the script executed before the nodes in the array load properly ,however I am invoking the function after document be ready which means the DOM must be fully loaded.
Hint: I am putting the script tag in the ,and this works properly when the code is not minified.