mduvall/grande.js — pull request #5 by earlcochran (2013-09-01 16:37:35+00:00)
Title: Change the way that heading are applied to elements so that they no longer destroy the parent element by replacing the original tag.

Before if someone attempted to add h1 or h2 a `

` or `
` element, it would wrap the parent element in the selected heading tag. This works fine, until the user attempts to remove the heading, upon which the wrapped element would be replaced with a `

` tag, and the `

` tag was left in place.

**To replicate the bug**:
* Select a `

` or `
` element.
* Click on h1 to add h1 to the selected element.
* Attempt to remove h1 from the selected element.

I've fixed it by adding a `toggleFormatHeading(tag)` function. This function attempts to match the chosen heading `tag` in the selected elements class names. It removes it if it is found, and adds it if it isn't.

I've also added the proper functionality to `reloadMenuState()` to properly check for class names so that the right menu action can be highlighted.