rstacruz / nprogress

For slim progress bars like on YouTube, Medium, etc
http://ricostacruz.com/nprogress
MIT License
25.99k stars 1.81k forks source link

It don't stop in iframes #174

Open alphamarket opened 7 years ago

alphamarket commented 7 years ago

I have a parent window which uses the NProgress and it works great but:

  1. When I call an iframe which has the NProgress too, at ajax:start it starts spinning but at ajax:stop it doesn't stop! I can confirm that the ajax:stop fires in an iframe.
  2. Also, I have tried to remove the spinner manually in the iframe but it restarts itself again after a second or so, and also I can confirm that there is no new ajax call initiated in that period.

WHY is this & HOW can I fix this?

alphamarket commented 7 years ago

I am no master JScriptor and just looking into the codings and googled some stuff and it seems that nprogress.js#L11 the NProgess is setting to the window not document; I have no clue (nor google I guess :D) that how can I assign the document as root in the code, so I have come up with a workaround, just assign the window.NProgess to document.NProgress and then create a ajax:start and ajax:stop to start/stop the document.NProgress and you are good to go with iframes.

jQuery(function() {
  document.NProgress = window.NProgress; 
  $(document)
    .ajaxStart(function(){ document.NProgress.start(); })
    .ajaxStop(function(){ document.NProgress.done(); });
});
// do stuff with `document.NProgress` in iframe

I would have create a nprogress-ajax-iframe module for this repo and create a pull request, but since this project is so inactive(i.e having 28 pending pull requests at the moment I am writing this :-1: ) I don't think it's worthy of my time, and just writting this stuffs for the sake of future wonders ;)