Allow more flexible configuration for formatblock options
|Reported by:||ejucovy||Owned by:||gogo|
On my site we added a formatblock option "Pullquote." This wraps the selection in a <div class="pullquote">, and we have CSS that floats it to the right.
We had to modify XinhaCore.js internals to support this option to formatblock, for the following reasons:
- Since we're applying HTML that isn't just a tag name, we can't use a simple string to represent it in the formatblock config. Instead we had to provide a callback function to do the modification.
- Since other formatblock styles like heading, subheading, etc can be applied to elements within a pullquote, we had to use custom logic for detecting whether the current context is within a pullquote or not.
- We also had to use custom logic to deal with users selecting the "normal" option when the current context is within a pullquote, since that should remove the pullquote.
The attached patch is what we came up with. Currently the formatblock config's values are strings (HTML tag names) always. With the patch they can instead be objects with three items:
- tag: string, HTML tag name to be applied
- detect: callback function(xinha, el), with boolean return value, called to determine if the current cursor context is within this formatblock option
- invoke: callback function(xinha), which is executed (instead of execCommand) when the formatblock option is selected
I don't love this patch .. it seems poorly encapsulated, and I don't like putting so much code in the config.js -- I'd rather register it in a plugin somehow. But I'm not sure how to take a better approach.
The attached patch also contains the snippet from our xinhaconfig.js, to demonstrate the use.
Change History (9)
Changed 4 years ago by guest
Changed 4 years ago by ejucovy
comment:2 Changed 4 years ago by ejucovy
- Cc ejucovy@… removed
- Milestone set to 0.97
- Reporter changed from guest to ejucovy