//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require_tree .

document.addEventListener("turbolinks:load", function() {
  $('button.archive_selected').click(function () { archive(); });
  $('input.archive').change(function() {
    marked = $(".table-notifications input:checked");
    if ( marked.length > 0 ) {
      $('button.archive_selected').show();
    } else {
      $('button.archive_selected').hide();
    }
  });
  $('.unarchive').click(function() {
    loadTurbolinksArchiveURL(this, 'unarchive')
  });
  $('.toggle-star').click(function() {
    $(this).toggleClass("star-active star-inactive")
    $.get('/notifications/'+$(this).data('id')+'/star')
  });
  $('.sync .octicon').on('click', function() {
    $(this).toggleClass('spinning')
  });
  recoverPreviousCursorPosition()
});

document.addEventListener("turbolinks:before-cache", function() {
  $('td.current').removeClass("current");
});

// Add shortcut events only once
$(document).ready(enableKeyboardShortcuts);

$(document).on('click', '[data-toggle="offcanvas"]', function () {
  $('.row-offcanvas').toggleClass('active')
});

if(!('ontouchstart' in window))
{
  $(function () {
    $('[data-toggle="tooltip"]').tooltip()
  })
}

function enableKeyboardShortcuts() {
  window.row_index = 1
  window.current_id = undefined

  $(document).keydown(function(e) {
    var shortcutFunction = shortcuts[e.which]
    if (shortcutFunction) { shortcutFunction(e) }
  });
}

var shortcuts = {
  74:  cursorDown,      // j
  75:  cursorUp,        // k
  83:  toggleStar,      // s
  88:  markCurrent,     // x
  89:  archive,         // y
  13:  openCurrentLink, // Enter
  79:  openCurrentLink, // o
  191: openModal,       // ?
  190: sync,            // .
  82:  sync             // r
}

function cursorDown() {
  moveCursor('up')
}

function cursorUp() {
  moveCursor('down')
}

function markCurrent() {
  checkbox = $('td.current').parent().find("input[type=checkbox]")
  checkbox.prop('checked', function (i, value) {
    return !value;
  });
  checkbox.change();
}

function archive() {
  if ( $(".table-notifications tr").length == 0 ) return;
  marked = $(".table-notifications input:checked");
  if ( marked.length > 0 ) {
    ids = marked.map(function() { return this.value; }).get();
  } else {
    ids = [ $('td.current input.archive').val() ];
  }
  $.post( "/notifications/archive_selected", { 'id[]': ids } ).done(function () {
    // calculating new position of the cursor
    current = $('td.current').parent();
    while ( $.inArray(current.find('input').val(), ids) > -1 && current.next().length > 0) {
      current = current.next();
    }
    window.current_id = current.find('input').val();
    if ( $.inArray(window.current_id, ids ) > -1 ) {
      window.current_id = $(".table-notifications input:not(:checked)").last().val();
    } 
    Turbolinks.visit("/"+location.search);
  });
}

function toggleStar() {
  clickCurrentRow('.toggle-star')
}

function openModal() {
  $("#help-box").modal();
}

function openCurrentLink(e) {
  e.preventDefault(e);
  $('td.current').parent().find('.link')[0].click();
}

function sync() {
  $("a.sync").click();
}

function clickCurrentRow(cssClass) {
  $('td.current').parent().find(cssClass).click();
}

function moveCursor(upOrDown) {
  var current = $('td.current');
  var parent = $(current).parent()
  var target = upOrDown === 'up' ? parent.next() : parent.prev()
  if(target.length > 0) {
    $(current).removeClass("current");
    $(target).find('td').first().addClass("current");
    row_index += upOrDown === 'up' ? 1 : -1;
  }
}

function recoverPreviousCursorPosition() {
  if ( current_id == undefined ) {
    row_index = Math.min(row_index, $(".table-notifications tr").length);
    row_index = Math.max(row_index, 1);
  } else {
    row_index = $("input[value=" + current_id + "]").parents('tr').index() + 1;
    current_id = undefined;
  }
  $(".table-notifications tbody tr:nth-child(" + row_index + ")").first().find("td").first().addClass("current");
}

function loadTurbolinksArchiveURL(link, route) {
  Turbolinks.visit('/notifications/'+$(link).val()+'/'+route+location.search)
}

@@ -2874,10 +2874,9 @@
    %7D
- 
 %0A
+
     
@@ -2949,31 +2949,45 @@
 r() %7B%0A  
-clickCurrentRow
+$('td.current').parent().find
 ('.toggl
@@ -2994,16 +2994,25 @@
 e-star')
+.click();
 %0A%7D%0A%0Afunc
@@ -3182,24 +3182,24 @@
 on sync() %7B%0A
+
   $(%22a.sync%22
@@ -3216,99 +3216,8 @@
 %0A%7D%0A%0A
-function clickCurrentRow(cssClass) %7B%0A  $('td.current').parent().find(cssClass).click();%0A%7D%0A%0A
 func

Remove needless extra method in application.js