Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple WMD editors (SO forked version) on one page?

Tags:

javascript

wmd

To be clear, I'm referring to the usage of stackoverflow's forked WMD, not the original version from attacklab.

I'd like to use the forked version, however it seems that the div id's which are used by the script to identify the page elements to WMDify are hardcoded in wmd.js:66:

// A collection of the important regions on the page.
// Cached so we don't have to keep traversing the DOM.
wmd.PanelCollection = function(){
    this.buttonBar = doc.getElementById("wmd-button-bar");
    this.preview = doc.getElementById("wmd-preview");
    this.output = doc.getElementById("wmd-output");
    this.input = doc.getElementById("wmd-input");
};

If I just wanted to use different region names I'd be fine on my own—but I want to use a variable number of WMD editors on a single page. I'd need a way to tell each instance of WMD about the page regions it should affect, but I don't see any 'hooks' for that.

The not-seeing is likely a product of my almost complete lack of js knowledge. The Right Thing To Do™ is to just learn javascript properly, but I'm in the middle of a project with a deadline. I'd really like to use this version of WMD but I need some clues on how to go about modifying the WMD script, or perhaps simply an example of how to call it in such a fashion that I can speficy which div id's to use.

Clues appreciated!

like image 841
Idan Gazit Avatar asked Mar 22 '09 12:03

Idan Gazit


Video Answer


2 Answers

I had similar problems so I re-factored WMD to be able to do just that. my version of wmd

Recently, I rechecked this. The version in Google code supports multiple versions on a page.
google code fork and is the latest out there.

like image 76
Itay Moav -Malimovka Avatar answered Sep 19 '22 10:09

Itay Moav -Malimovka


On a "project with a deadline" it is allowed to hack around some constraints. In this case I would just make multiple copies of the WMD editor script (or generate it on the server side) and replace the IDs by your needed identifiers. That way you can immediately deploy multiple WMDs on a single page.

You just have to be really clear about one thing: You are accruing technical debt ("the eventual consequences of slapdash software architecture and hasty software development") on your project there. You will have to revisit this to pay back this debt or you will drown in interest payments when doing maintenance.

like image 37
David Schmitt Avatar answered Sep 19 '22 10:09

David Schmitt