actmd/abraham

Remove jQuery dependency

marwann opened this issue · 4 comments

Hello,

As I understand you only need jQuery for the following lines:

$(document).on('turbolinks:before-cache', function() {

Wouldn't it be more judicious to remove the dependency altogether and rewrite that part in vanilla JS?

Cheers

There is also this ajax call, but it could be replaced with Rails.ajax

https://github.com/actmd/abraham/blob/master/app/views/application/_abraham.html.erb#L6

tour.on("complete", function() {
    // ajax
    return $.ajax({
      url: "/abraham_histories/",
      type: "POST",
      dataType: "json",
      contentType: "application/json",
      data: JSON.stringify({
        authenticity_token: '<%= form_authenticity_token %>',
        controller_name: '<%= controller_name %>',
        action_name: '<%= action_name %>',
        tour_name: '<%= tour_name %>'
      })
    });

FYI — this change will eliminate any (theoretical) support for Internet Explorer, as it relies on the javascript fetch method for AJAX calls. (Please note that Rails.ajax is only available if you're using rails-ujs and that also seems like an overkill requirement to add to this gem.)

I imagine anyone who needs to support IE and wants to use Abraham could include a fetch polyfill... https://github.com/github/fetch