Attached is a quick patch to update this to D7. There are only two changes in the JS:

The rest is indenting as a result of the "attach" change. Please note that I didn't touch the example module. If the formatting of this patch works OK, I can add that in too. Thanks!

CommentFileSizeAuthor
onbeforeunload_d7upgrade_v01.patch2.54 KBseanbfuller

Comments

seanbfuller’s picture

Status: Active » Needs review

Sorry, forgot to mark as needs review.

seanbfuller’s picture

I did some more digging into this to resolve some issues regarding the overlay in D7 (see #950736: DirtyForm Port to D7). I couldn't find a consistent way to catch any kind of onunload event for the overlay's iframe. I was able to get close by trying to bind the hashchange.drupal-overlay event, but there was no elegant way to stop overlay from processing the page change. I played around with adding a check in Drupal.overlay.redirect to see if Drupal.onBeforeUnload exists and then adding some sort of call confirm call, but that is obviously a hack to core and also probably not the best way to go about it.

Unless someone with a better understanding of the overlay module has a better idea, it seems that a patch to overlay allowing other modules to register a check that stops overlay from changing the page would be needed.

While looking into this, I also found #655388: Many ways to lose data on form input in the overlay, which mentions dirtyforms and different options for dealing with things this module might be used for.

As it stands, this patch and dirtyforms seems to be working for D7... unless you have the overlay enabled. Not sure of the best next step.

geek-merlin’s picture

Title: D7 version » D7 version of onbeforeunload
Status: Needs review » Reviewed & tested by the community
jimmyko’s picture

Issue summary: View changes

I am looking for this too... This module won't be continued?

jacob.embree’s picture

I created a fork here to contain the changes here and whatever other changes I find necessary.