marionettejs/backbone.marionette — pull request #1980 by trezy (2014-10-08 17:44:21+00:00)
Title: Add support for the replaceElement option on Region

**NOTE:** *I'll try to write the specs this evening and push them up. I just wanted to get the code in front of you guys for further discussion.*

I'll reiterate my approach from the issue comments:

1. Instead of changing the value of the `region.el`, I'm simply replacing the element in the DOM with [`region.replaceEl()`](#diff-b8da5292cb07ec757ac64e78ff5af5c1R143) and [`region.restoreEl()`](#diff-b8da5292cb07ec757ac64e78ff5af5c1R151). `region.el` stays in tact.
1. [On `region.show( view, { replaceElement: true })` I am setting `region.replaced`](#diff-b8da5292cb07ec757ac64e78ff5af5c1R147). This allows all future executions on region to determine if they need to address `region.el` or `view.el`.
1. [On `region.empty()` I am checking the value of `region.replaced`](#diff-b8da5292cb07ec757ac64e78ff5af5c1R184). If it's true, I'll replace the `view.el` with `region.el` before destroying the view. This way any future executions on `region.el` will refer to the correct node.

## TO DO

* I'm still not sure about handling this when a view is destroyed from outside of the region. It may just magically work if I'm super lucky. I'll test it later and hopefully come up with solution if necessary after I write the primary specs.
* `replaceEl()` and `restoreEl()` can probably be abstracted just a little more but I don't know that it's really necessary.
* A global configuration option to make this a default behavior would be nice. Again, I'm not sure that it's necessary. Even if it is it's probably worthy of a separate issue.

This needs WAY more testing. I only beat on it with `region.show()`, `region.empty()`, and `region.reset()`.