Make Magnific Popup compatible with Turbolinks

Turbolinks is a JavaScript library that comes with Ruby on Rails 4. 

https://github.com/rails/turbolinks
>Turbolinks makes following links in your web application faster. Instead of letting the browser recompile the >JavaScript and CSS between each page change, it keeps the current page instance alive and replaces only the >body and the title in the head. Think CGI vs persistent process.

My problem is that Magnific Popup doesn't work with Turbolinks, which means that it is also incompatible with Ruby on Rails 4. 

On a Turbolinks-enabled web page, you can get a popup with Magnific Popup once by clinking on a link, but from the second try onward clicking the same link won't bring up any popups. Just nothing happens. 

It seems that caching $(document).body causes the problem mentioned above. Magnific Popup is unaware of Turbolinks style page transitions and keeps old contents of the document.body element.

My workaround is shown in the commit I have sent. Probably, you will be able to come up with a better solution. My point is that I want to get Magnific Pop working properly with Turbolinks on Ruby on Rails.

Thank you very much in advance.