$(document).ready(function() {
   $('table').each(function() {
      // Not apply to nested tables
      if ($(this).parents('table').length
         || $(this).closest('.table-container').length) {
         return;
      }

      $(this).wrap('<div class="table-container is-init is-finish"><div class="table-content"></div></div>');
   });

   $('.table-content').on('scroll', checkScroll);
   $('.table-content').each(checkScroll);

   function checkScroll() {
      var $thisTC = $(this);
      var isInit = $thisTC.scrollLeft() == 0;
      var curScroll = $thisTC[0].scrollWidth - $thisTC[0].clientWidth;
      var isFinish = curScroll == 0 ||
      curScroll > 0 && $thisTC.scrollLeft() == curScroll;

      $thisTC
         .parent()
            .toggleClass('is-init', isInit)
            .toggleClass('is-finish', isFinish);
   }
});
