define ['jquery'], ($) ->
  $(document).ready ->
    if ENV.badge_counts
      for type, unread of ENV.badge_counts
        if unread > 0
          type = "grades" if type is "submissions"
          $badge = $("<b/>").text(unread).addClass("nav-badge")
          $("#section-tabs .#{type}").append($badge)

if ENV.badge_counts
  require.ensure [], () ->
    $ = require('jquery')
    $ ->
      for type, unread of ENV.badge_counts
        if unread > 0
          type = "grades" if type is "submissions"
          $badge = $("<b/>").text(unread).addClass("nav-badge")
          $("#section-tabs .#{type}").append($badge)
  , 'badgeCountsAsyncChunk'

Load badge counts async and only if needed
Load badge counts async and only if needed

closes:  CNVS-36300

test plan:
this chunk of js shouldn't be included in the common bundle and should
only be loaded if ENV.badge_counts is true and as a seperate chunk



Change-Id: Ia83418cb7604c50ad91c2bf54a4fac79ca381b5a
Reviewed-on: https://gerrit.instructure.com/108447
Tested-by: Jenkins
Reviewed-by: Clay Diffrient <9dff2e5c98626d20d2848250c411e8009465bb87@instructure.com>
Product-Review: Ryan Shaw <ea3cd978650417470535f3a4725b6b5042a6ab59@instructure.com>
QA-Review: Ryan Shaw <ea3cd978650417470535f3a4725b6b5042a6ab59@instructure.com>
