actmd / abraham

Trackable application tours for Rails with i18n support
MIT License
124 stars 45 forks source link

Remove jQuery dependency #39

Closed marwann closed 3 years ago

marwann commented 3 years ago

Hello,

As I understand you only need jQuery for the following lines: https://github.com/actmd/abraham/blob/160ec8e10b2be56e81b367d6d6ed2046e0c0c68b/app/assets/javascripts/abraham/index.js#L5

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

Cheers

scarroll32 commented 3 years ago

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 %>'
      })
    });
jabbett commented 3 years ago

BTW, this cheat sheet is proving helpful: https://tobiasahlin.com/blog/move-from-jquery-to-vanilla-javascript/

jabbett commented 3 years ago

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.)

jabbett commented 3 years ago

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